♻️ Move the web reader from Sphere to Insight (w.i.p)
This commit is contained in:
41
DysonNetwork.Shared/Models/Embed/EmbeddableBase.cs
Normal file
41
DysonNetwork.Shared/Models/Embed/EmbeddableBase.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Text.Json;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
|
||||
namespace DysonNetwork.Shared.Models.Embed;
|
||||
|
||||
/// <summary>
|
||||
/// The embeddable can be used in the post or messages' meta's embeds fields
|
||||
/// To render a richer type of content.
|
||||
///
|
||||
/// A simple example of using link preview embed:
|
||||
/// <code>
|
||||
/// {
|
||||
/// // ... post content
|
||||
/// "meta": {
|
||||
/// "embeds": [
|
||||
/// {
|
||||
/// "type": "link",
|
||||
/// "title: "...",
|
||||
/// /// ...
|
||||
/// }
|
||||
/// ]
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </summary>
|
||||
public abstract class EmbeddableBase
|
||||
{
|
||||
public abstract string Type { get; }
|
||||
|
||||
public static Dictionary<string, object> ToDictionary(dynamic input)
|
||||
{
|
||||
var jsonRaw = JsonSerializer.Serialize(
|
||||
input,
|
||||
GrpcTypeHelper.SerializerOptionsWithoutIgnore
|
||||
);
|
||||
return JsonSerializer.Deserialize<Dictionary<string, object>>(
|
||||
jsonRaw,
|
||||
GrpcTypeHelper.SerializerOptionsWithoutIgnore
|
||||
);
|
||||
}
|
||||
}
|
||||
55
DysonNetwork.Shared/Models/Embed/LinkEmbed.cs
Normal file
55
DysonNetwork.Shared/Models/Embed/LinkEmbed.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace DysonNetwork.Shared.Models.Embed;
|
||||
|
||||
/// <summary>
|
||||
/// The link embed is a part of the embeddable implementations
|
||||
/// It can be used in the post or messages' meta's embeds fields
|
||||
/// </summary>
|
||||
public class LinkEmbed : EmbeddableBase
|
||||
{
|
||||
public override string Type => "link";
|
||||
|
||||
/// <summary>
|
||||
/// The original URL that was processed
|
||||
/// </summary>
|
||||
public required string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Title of the linked content (from OpenGraph og:title, meta title, or page title)
|
||||
/// </summary>
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Description of the linked content (from OpenGraph og:description or meta description)
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// URL to the thumbnail image (from OpenGraph og:image or other meta tags)
|
||||
/// </summary>
|
||||
public string? ImageUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The favicon URL of the site
|
||||
/// </summary>
|
||||
public string? FaviconUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The site name (from OpenGraph og:site_name)
|
||||
/// </summary>
|
||||
public string? SiteName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Type of the content (from OpenGraph og:type)
|
||||
/// </summary>
|
||||
public string? ContentType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Author of the content if available
|
||||
/// </summary>
|
||||
public string? Author { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Published date of the content if available
|
||||
/// </summary>
|
||||
public DateTime? PublishedDate { get; set; }
|
||||
}
|
||||
61
DysonNetwork.Shared/Models/WebArticle.cs
Normal file
61
DysonNetwork.Shared/Models/WebArticle.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
using DysonNetwork.Shared.Models.Embed;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Shared.Models;
|
||||
|
||||
public class SnWebArticle : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
[MaxLength(4096)] public string Title { get; set; } = null!;
|
||||
[MaxLength(8192)] public string Url { get; set; } = null!;
|
||||
[MaxLength(4096)] public string? Author { get; set; }
|
||||
|
||||
[Column(TypeName = "jsonb")] public Dictionary<string, object>? Meta { get; set; }
|
||||
[Column(TypeName = "jsonb")] public LinkEmbed? Preview { get; set; }
|
||||
|
||||
// ReSharper disable once EntityFramework.ModelValidation.UnlimitedStringLength
|
||||
public string? Content { get; set; }
|
||||
|
||||
public DateTime? PublishedAt { get; set; }
|
||||
|
||||
public Guid FeedId { get; set; }
|
||||
public SnWebFeed Feed { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class WebFeedConfig
|
||||
{
|
||||
public bool ScrapPage { get; set; }
|
||||
}
|
||||
|
||||
public class SnWebFeed : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
[MaxLength(8192)] public string Url { get; set; } = null!;
|
||||
[MaxLength(4096)] public string Title { get; set; } = null!;
|
||||
[MaxLength(8192)] public string? Description { get; set; }
|
||||
|
||||
public Instant? VerifiedAt { get; set; }
|
||||
[JsonIgnore] [MaxLength(8192)] public string? VerificationKey { get; set; }
|
||||
|
||||
[Column(TypeName = "jsonb")] public LinkEmbed? Preview { get; set; }
|
||||
[Column(TypeName = "jsonb")] public WebFeedConfig Config { get; set; } = new();
|
||||
|
||||
public Guid PublisherId { get; set; }
|
||||
public SnPublisher Publisher { get; set; } = null!;
|
||||
|
||||
[JsonIgnore] public List<SnWebArticle> Articles { get; set; } = new();
|
||||
}
|
||||
|
||||
public class SnWebFeedSubscription : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
public Guid FeedId { get; set; }
|
||||
public SnWebFeed Feed { get; set; } = null!;
|
||||
public Guid AccountId { get; set; }
|
||||
[NotMapped] public SnAccount Account { get; set; } = null!;
|
||||
}
|
||||
Reference in New Issue
Block a user