From 8ad9524c6f63f0b6e61f79596ecd88512053516e Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:06:13 +0800 Subject: [PATCH 01/31] rename PingbackEntity to MentionEntity --- .../Configurations/PingbackConfiguration.cs | 4 ++-- .../Configurations/PingbackConfiguration.cs | 4 ++-- .../Configurations/PingbackConfiguration.cs | 4 ++-- src/Moonglade.Data/BlogDbContext.cs | 2 +- .../Entities/{PingbackEntity.cs => MentionEntity.cs} | 2 +- src/Moonglade.Data/Specifications/PingbackReadOnlySpec.cs | 2 +- src/Moonglade.Data/Specifications/PingbackSpec.cs | 2 +- src/Moonglade.Pingback/ClearPingbackCommand.cs | 2 +- src/Moonglade.Pingback/DeletePingbackCommand.cs | 2 +- src/Moonglade.Pingback/GetPingbacksQuery.cs | 8 ++++---- src/Moonglade.Pingback/ReceivePingCommand.cs | 8 ++++---- src/Moonglade.Web/Controllers/PingbackController.cs | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) rename src/Moonglade.Data/Entities/{PingbackEntity.cs => MentionEntity.cs} (93%) diff --git a/src/Moonglade.Data.MySql/Configurations/PingbackConfiguration.cs b/src/Moonglade.Data.MySql/Configurations/PingbackConfiguration.cs index 6b988f6da..4a7d0e9d9 100644 --- a/src/Moonglade.Data.MySql/Configurations/PingbackConfiguration.cs +++ b/src/Moonglade.Data.MySql/Configurations/PingbackConfiguration.cs @@ -5,9 +5,9 @@ namespace Moonglade.Data.MySql.Configurations; -internal class PingbackConfiguration : IEntityTypeConfiguration +internal class PingbackConfiguration : IEntityTypeConfiguration { - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { builder.Property(e => e.Id).ValueGeneratedNever(); builder.Property(e => e.PingTimeUtc).HasColumnType("datetime"); diff --git a/src/Moonglade.Data.PostgreSql/Configurations/PingbackConfiguration.cs b/src/Moonglade.Data.PostgreSql/Configurations/PingbackConfiguration.cs index 18ff9a596..fb3f1f7fe 100644 --- a/src/Moonglade.Data.PostgreSql/Configurations/PingbackConfiguration.cs +++ b/src/Moonglade.Data.PostgreSql/Configurations/PingbackConfiguration.cs @@ -5,9 +5,9 @@ namespace Moonglade.Data.PostgreSql.Configurations; -internal class PingbackConfiguration : IEntityTypeConfiguration +internal class PingbackConfiguration : IEntityTypeConfiguration { - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { builder.Property(e => e.Id).ValueGeneratedNever(); builder.Property(e => e.PingTimeUtc).HasColumnType("timestamp"); diff --git a/src/Moonglade.Data.SqlServer/Configurations/PingbackConfiguration.cs b/src/Moonglade.Data.SqlServer/Configurations/PingbackConfiguration.cs index 088eb665c..32f439617 100644 --- a/src/Moonglade.Data.SqlServer/Configurations/PingbackConfiguration.cs +++ b/src/Moonglade.Data.SqlServer/Configurations/PingbackConfiguration.cs @@ -5,9 +5,9 @@ namespace Moonglade.Data.SqlServer.Configurations; -internal class PingbackConfiguration : IEntityTypeConfiguration +internal class PingbackConfiguration : IEntityTypeConfiguration { - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { builder.Property(e => e.Id).ValueGeneratedNever(); builder.Property(e => e.PingTimeUtc).HasColumnType("datetime"); diff --git a/src/Moonglade.Data/BlogDbContext.cs b/src/Moonglade.Data/BlogDbContext.cs index 28a6bbac7..b50a825da 100644 --- a/src/Moonglade.Data/BlogDbContext.cs +++ b/src/Moonglade.Data/BlogDbContext.cs @@ -23,7 +23,7 @@ public BlogDbContext(DbContextOptions options) public virtual DbSet FriendLink { get; set; } public virtual DbSet CustomPage { get; set; } public virtual DbSet LoginHistory { get; set; } - public virtual DbSet Pingback { get; set; } + public virtual DbSet Pingback { get; set; } public virtual DbSet BlogTheme { get; set; } public virtual DbSet StyleSheet { get; set; } public virtual DbSet BlogAsset { get; set; } diff --git a/src/Moonglade.Data/Entities/PingbackEntity.cs b/src/Moonglade.Data/Entities/MentionEntity.cs similarity index 93% rename from src/Moonglade.Data/Entities/PingbackEntity.cs rename to src/Moonglade.Data/Entities/MentionEntity.cs index 283513826..6d6c7dd12 100644 --- a/src/Moonglade.Data/Entities/PingbackEntity.cs +++ b/src/Moonglade.Data/Entities/MentionEntity.cs @@ -1,6 +1,6 @@ namespace Moonglade.Data.Entities; -public class PingbackEntity +public class MentionEntity { public Guid Id { get; set; } public string Domain { get; set; } diff --git a/src/Moonglade.Data/Specifications/PingbackReadOnlySpec.cs b/src/Moonglade.Data/Specifications/PingbackReadOnlySpec.cs index 5bb80f712..36e67e8d3 100644 --- a/src/Moonglade.Data/Specifications/PingbackReadOnlySpec.cs +++ b/src/Moonglade.Data/Specifications/PingbackReadOnlySpec.cs @@ -2,7 +2,7 @@ namespace Moonglade.Data.Specifications; -public sealed class PingbackReadOnlySpec : Specification +public sealed class PingbackReadOnlySpec : Specification { public PingbackReadOnlySpec() { diff --git a/src/Moonglade.Data/Specifications/PingbackSpec.cs b/src/Moonglade.Data/Specifications/PingbackSpec.cs index 42d2a6e49..856cac249 100644 --- a/src/Moonglade.Data/Specifications/PingbackSpec.cs +++ b/src/Moonglade.Data/Specifications/PingbackSpec.cs @@ -2,7 +2,7 @@ namespace Moonglade.Data.Specifications; -public sealed class PingbackSpec : Specification +public sealed class PingbackSpec : Specification { public PingbackSpec(Guid postId, string sourceUrl, string sourceIp) { diff --git a/src/Moonglade.Pingback/ClearPingbackCommand.cs b/src/Moonglade.Pingback/ClearPingbackCommand.cs index 564ce684f..ab941091e 100644 --- a/src/Moonglade.Pingback/ClearPingbackCommand.cs +++ b/src/Moonglade.Pingback/ClearPingbackCommand.cs @@ -6,7 +6,7 @@ namespace Moonglade.Pingback; public record ClearPingbackCommand : IRequest; -public class ClearPingbackCommandHandler(MoongladeRepository repo) : IRequestHandler +public class ClearPingbackCommandHandler(MoongladeRepository repo) : IRequestHandler { public Task Handle(ClearPingbackCommand request, CancellationToken ct) => repo.Clear(ct); } \ No newline at end of file diff --git a/src/Moonglade.Pingback/DeletePingbackCommand.cs b/src/Moonglade.Pingback/DeletePingbackCommand.cs index 4e6289907..ea4422192 100644 --- a/src/Moonglade.Pingback/DeletePingbackCommand.cs +++ b/src/Moonglade.Pingback/DeletePingbackCommand.cs @@ -6,7 +6,7 @@ namespace Moonglade.Pingback; public record DeletePingbackCommand(Guid Id) : IRequest; -public class DeletePingbackCommandHandler(MoongladeRepository repo) : IRequestHandler +public class DeletePingbackCommandHandler(MoongladeRepository repo) : IRequestHandler { public async Task Handle(DeletePingbackCommand request, CancellationToken ct) { diff --git a/src/Moonglade.Pingback/GetPingbacksQuery.cs b/src/Moonglade.Pingback/GetPingbacksQuery.cs index 368e3dd0c..4e29442c3 100644 --- a/src/Moonglade.Pingback/GetPingbacksQuery.cs +++ b/src/Moonglade.Pingback/GetPingbacksQuery.cs @@ -5,11 +5,11 @@ namespace Moonglade.Pingback; -public record GetPingbacksQuery : IRequest>; +public record GetPingbacksQuery : IRequest>; -public class GetPingbacksQueryHandler(MoongladeRepository repo) : - IRequestHandler> +public class GetPingbacksQueryHandler(MoongladeRepository repo) : + IRequestHandler> { - public Task> Handle(GetPingbacksQuery request, CancellationToken ct) => + public Task> Handle(GetPingbacksQuery request, CancellationToken ct) => repo.ListAsync(new PingbackReadOnlySpec(), ct); } \ No newline at end of file diff --git a/src/Moonglade.Pingback/ReceivePingCommand.cs b/src/Moonglade.Pingback/ReceivePingCommand.cs index b6f83571a..aef80471f 100644 --- a/src/Moonglade.Pingback/ReceivePingCommand.cs +++ b/src/Moonglade.Pingback/ReceivePingCommand.cs @@ -8,20 +8,20 @@ namespace Moonglade.Pingback; -public class ReceivePingCommand(string requestBody, string ip, Action action) +public class ReceivePingCommand(string requestBody, string ip, Action action) : IRequest { public string RequestBody { get; set; } = requestBody; public string IP { get; set; } = ip; - public Action Action { get; set; } = action; + public Action Action { get; set; } = action; } public class ReceivePingCommandHandler( ILogger logger, IPingSourceInspector pingSourceInspector, - MoongladeRepository pingbackRepo, + MoongladeRepository pingbackRepo, MoongladeRepository postRepo) : IRequestHandler { private string _sourceUrl; @@ -72,7 +72,7 @@ public async Task Handle(ReceivePingCommand request, Cancellat logger.LogInformation("Adding received pingback..."); var uri = new Uri(_sourceUrl); - var obj = new PingbackEntity + var obj = new MentionEntity { Id = Guid.NewGuid(), PingTimeUtc = DateTime.UtcNow, diff --git a/src/Moonglade.Web/Controllers/PingbackController.cs b/src/Moonglade.Web/Controllers/PingbackController.cs index e4636d046..bbbd15dfa 100644 --- a/src/Moonglade.Web/Controllers/PingbackController.cs +++ b/src/Moonglade.Web/Controllers/PingbackController.cs @@ -28,7 +28,7 @@ public async Task Process() return new PingbackResult(response); } - private async void SendPingbackEmailAction(PingbackEntity history) + private async void SendPingbackEmailAction(MentionEntity history) { try { From 35287b75f7039e28d0dc6f82e8a67cd0e2a46850 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:08:52 +0800 Subject: [PATCH 02/31] empty Moonglade.Webmention lib --- src/Moonglade.Pingback/Moonglade.Pingback.csproj | 4 ---- .../Moonglade.Webmention.csproj | 16 ++++++++++++++++ src/Moonglade.sln | 9 ++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/Moonglade.Webmention/Moonglade.Webmention.csproj diff --git a/src/Moonglade.Pingback/Moonglade.Pingback.csproj b/src/Moonglade.Pingback/Moonglade.Pingback.csproj index 0dd3204cf..d2c573dbe 100644 --- a/src/Moonglade.Pingback/Moonglade.Pingback.csproj +++ b/src/Moonglade.Pingback/Moonglade.Pingback.csproj @@ -2,10 +2,6 @@ Library net8.0 - Moonglade.Pingback - Moonglade.Pingback - false - false enable .NET implementation for Pingback http://www.hixie.ch/specs/pingback/pingback diff --git a/src/Moonglade.Webmention/Moonglade.Webmention.csproj b/src/Moonglade.Webmention/Moonglade.Webmention.csproj new file mode 100644 index 000000000..bf6909838 --- /dev/null +++ b/src/Moonglade.Webmention/Moonglade.Webmention.csproj @@ -0,0 +1,16 @@ + + + net8.0 + enable + + + + + + + + + + + + diff --git a/src/Moonglade.sln b/src/Moonglade.sln index 0f84cee8d..dc0b99055 100644 --- a/src/Moonglade.sln +++ b/src/Moonglade.sln @@ -56,6 +56,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moonglade.Data.MySql", "Moo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moonglade.Data.PostgreSql", "Moonglade.Data.PostgreSql\Moonglade.Data.PostgreSql.csproj", "{5750F136-DD4B-42F8-BA64-2371C2527505}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moonglade.Webmention", "Moonglade.Webmention\Moonglade.Webmention.csproj", "{D901FAD3-FB6C-4C24-8B43-52DFA68CA369}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -126,6 +128,10 @@ Global {5750F136-DD4B-42F8-BA64-2371C2527505}.Debug|Any CPU.Build.0 = Debug|Any CPU {5750F136-DD4B-42F8-BA64-2371C2527505}.Release|Any CPU.ActiveCfg = Release|Any CPU {5750F136-DD4B-42F8-BA64-2371C2527505}.Release|Any CPU.Build.0 = Release|Any CPU + {D901FAD3-FB6C-4C24-8B43-52DFA68CA369}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D901FAD3-FB6C-4C24-8B43-52DFA68CA369}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D901FAD3-FB6C-4C24-8B43-52DFA68CA369}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D901FAD3-FB6C-4C24-8B43-52DFA68CA369}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -148,9 +154,10 @@ Global {1ED1FD2A-703E-471D-AEDA-9885748194FF} = {41072B8B-1052-4CC6-930F-83A5F8EA7482} {0267C513-2DB9-4697-A6FA-39BB83E1CA9B} = {41072B8B-1052-4CC6-930F-83A5F8EA7482} {5750F136-DD4B-42F8-BA64-2371C2527505} = {41072B8B-1052-4CC6-930F-83A5F8EA7482} + {D901FAD3-FB6C-4C24-8B43-52DFA68CA369} = {97439361-03B4-46C9-BC06-49F76BA57879} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {EBD14882-9899-4C4B-B9BC-22C0B93BD559} RESX_CultureCountyOverrides = zh=zh-Hant + SolutionGuid = {EBD14882-9899-4C4B-B9BC-22C0B93BD559} EndGlobalSection EndGlobal From d5e4e2db191b9a050e878000097bcb9ab0de3cb4 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:15:52 +0800 Subject: [PATCH 03/31] rename Pingback table to Mention --- src/Moonglade.Data/BlogDbContext.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Moonglade.Data/BlogDbContext.cs b/src/Moonglade.Data/BlogDbContext.cs index b50a825da..1067293b3 100644 --- a/src/Moonglade.Data/BlogDbContext.cs +++ b/src/Moonglade.Data/BlogDbContext.cs @@ -23,7 +23,7 @@ public BlogDbContext(DbContextOptions options) public virtual DbSet FriendLink { get; set; } public virtual DbSet CustomPage { get; set; } public virtual DbSet LoginHistory { get; set; } - public virtual DbSet Pingback { get; set; } + public virtual DbSet Mention { get; set; } public virtual DbSet BlogTheme { get; set; } public virtual DbSet StyleSheet { get; set; } public virtual DbSet BlogAsset { get; set; } @@ -62,7 +62,7 @@ public static async Task ClearAllData(this BlogDbContext context) context.Tag.RemoveRange(); context.Comment.RemoveRange(); context.FriendLink.RemoveRange(); - context.Pingback.RemoveRange(); + context.Mention.RemoveRange(); context.Post.RemoveRange(); context.BlogConfiguration.RemoveRange(); context.BlogAsset.RemoveRange(); From 62f5382f3aae99010bf39442f0480a290b4180bd Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:22:18 +0800 Subject: [PATCH 04/31] Update mssql-migration.sql --- Deployment/mssql-migration.sql | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/Deployment/mssql-migration.sql b/Deployment/mssql-migration.sql index 1aa9aec1d..db05e8dc0 100644 --- a/Deployment/mssql-migration.sql +++ b/Deployment/mssql-migration.sql @@ -1,33 +1,7 @@ --- v14.3.x - v14.4.0 -CREATE TABLE [dbo].[LoginHistory]( - [Id] [int] IDENTITY(1,1) NOT NULL, - [LoginTimeUtc] [datetime] NOT NULL, - [LoginIp] [nvarchar](64) NULL, - [LoginUserAgent] [nvarchar](128) NULL, - [DeviceFingerprint] [nvarchar](128) NULL, - CONSTRAINT [PK_LoginHistory] PRIMARY KEY CLUSTERED -( - [Id] ASC -)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] -) ON [PRIMARY] -GO +-- v14.4.1 - v14.5.x -DROP TABLE [LocalAccount] +EXEC sp_rename 'Pingback', 'Mention' GO -EXEC sys.sp_rename - @objname = N'Category.RouteName', - @newname = 'Slug', - @objtype = 'COLUMN' +ALTER TABLE Mention ADD Worker NVARCHAR(16) GO - -IF EXISTS ( - SELECT 1 - FROM sys.columns c - JOIN sys.objects o ON c.object_id = o.object_id - WHERE o.name = 'Post' AND c.name = 'InlineCss' -) -BEGIN - ALTER TABLE Post DROP COLUMN InlineCss; -END; -GO \ No newline at end of file From 965505f7b08e2c4dc9f25904e6e9e3fd629f9b32 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:22:31 +0800 Subject: [PATCH 05/31] update MentionEntity --- .../Configurations/MentionConfiguration.cs | 15 ++++++++++++++ .../Configurations/PingbackConfiguration.cs | 20 ------------------- .../MySqlBlogDbContext.cs | 2 +- ...nfiguration.cs => MentionConfiguration.cs} | 7 +------ .../PostgreSqlBlogDbContext.cs | 2 +- ...nfiguration.cs => MentionConfiguration.cs} | 7 +------ .../SqlServerBlogDbContext.cs | 2 +- src/Moonglade.Data/Entities/MentionEntity.cs | 18 ++++++++++++++++- src/Moonglade.Pingback/ReceivePingCommand.cs | 3 ++- src/Moonglade.sln | 1 + 10 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 src/Moonglade.Data.MySql/Configurations/MentionConfiguration.cs delete mode 100644 src/Moonglade.Data.MySql/Configurations/PingbackConfiguration.cs rename src/Moonglade.Data.PostgreSql/Configurations/{PingbackConfiguration.cs => MentionConfiguration.cs} (50%) rename src/Moonglade.Data.SqlServer/Configurations/{PingbackConfiguration.cs => MentionConfiguration.cs} (50%) diff --git a/src/Moonglade.Data.MySql/Configurations/MentionConfiguration.cs b/src/Moonglade.Data.MySql/Configurations/MentionConfiguration.cs new file mode 100644 index 000000000..9c8d05852 --- /dev/null +++ b/src/Moonglade.Data.MySql/Configurations/MentionConfiguration.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Moonglade.Data.Entities; + +namespace Moonglade.Data.MySql.Configurations; + + +internal class MentionConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.Property(e => e.Id).ValueGeneratedNever(); + builder.Property(e => e.PingTimeUtc).HasColumnType("datetime"); + } +} \ No newline at end of file diff --git a/src/Moonglade.Data.MySql/Configurations/PingbackConfiguration.cs b/src/Moonglade.Data.MySql/Configurations/PingbackConfiguration.cs deleted file mode 100644 index 4a7d0e9d9..000000000 --- a/src/Moonglade.Data.MySql/Configurations/PingbackConfiguration.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Moonglade.Data.Entities; - -namespace Moonglade.Data.MySql.Configurations; - - -internal class PingbackConfiguration : IEntityTypeConfiguration -{ - public void Configure(EntityTypeBuilder builder) - { - builder.Property(e => e.Id).ValueGeneratedNever(); - builder.Property(e => e.PingTimeUtc).HasColumnType("datetime"); - builder.Property(e => e.TargetPostTitle).HasMaxLength(128); - builder.Property(e => e.SourceIp).HasMaxLength(64); - builder.Property(e => e.SourceTitle).HasMaxLength(256); - builder.Property(e => e.SourceUrl).HasMaxLength(256); - builder.Property(e => e.Domain).HasMaxLength(256); - } -} \ No newline at end of file diff --git a/src/Moonglade.Data.MySql/MySqlBlogDbContext.cs b/src/Moonglade.Data.MySql/MySqlBlogDbContext.cs index ee6c135f3..7dd1921d8 100644 --- a/src/Moonglade.Data.MySql/MySqlBlogDbContext.cs +++ b/src/Moonglade.Data.MySql/MySqlBlogDbContext.cs @@ -21,7 +21,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.ApplyConfiguration(new CommentReplyConfiguration()); modelBuilder.ApplyConfiguration(new PostConfiguration()); modelBuilder.ApplyConfiguration(new PostCategoryConfiguration()); - modelBuilder.ApplyConfiguration(new PingbackConfiguration()); + modelBuilder.ApplyConfiguration(new MentionConfiguration()); modelBuilder.ApplyConfiguration(new BlogThemeConfiguration()); modelBuilder.ApplyConfiguration(new BlogAssetConfiguration()); modelBuilder.ApplyConfiguration(new StyleSheetConfiguration()); diff --git a/src/Moonglade.Data.PostgreSql/Configurations/PingbackConfiguration.cs b/src/Moonglade.Data.PostgreSql/Configurations/MentionConfiguration.cs similarity index 50% rename from src/Moonglade.Data.PostgreSql/Configurations/PingbackConfiguration.cs rename to src/Moonglade.Data.PostgreSql/Configurations/MentionConfiguration.cs index fb3f1f7fe..85daeffa8 100644 --- a/src/Moonglade.Data.PostgreSql/Configurations/PingbackConfiguration.cs +++ b/src/Moonglade.Data.PostgreSql/Configurations/MentionConfiguration.cs @@ -5,16 +5,11 @@ namespace Moonglade.Data.PostgreSql.Configurations; -internal class PingbackConfiguration : IEntityTypeConfiguration +internal class MentionConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.Property(e => e.Id).ValueGeneratedNever(); builder.Property(e => e.PingTimeUtc).HasColumnType("timestamp"); - builder.Property(e => e.TargetPostTitle).HasMaxLength(128); - builder.Property(e => e.SourceIp).HasMaxLength(64); - builder.Property(e => e.SourceTitle).HasMaxLength(256); - builder.Property(e => e.SourceUrl).HasMaxLength(256); - builder.Property(e => e.Domain).HasMaxLength(256); } } \ No newline at end of file diff --git a/src/Moonglade.Data.PostgreSql/PostgreSqlBlogDbContext.cs b/src/Moonglade.Data.PostgreSql/PostgreSqlBlogDbContext.cs index 44815882f..7d57e5f30 100644 --- a/src/Moonglade.Data.PostgreSql/PostgreSqlBlogDbContext.cs +++ b/src/Moonglade.Data.PostgreSql/PostgreSqlBlogDbContext.cs @@ -20,7 +20,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.ApplyConfiguration(new PostConfiguration()); modelBuilder.ApplyConfiguration(new PostCategoryConfiguration()); modelBuilder.ApplyConfiguration(new LoginHistoryConfiguration()); - modelBuilder.ApplyConfiguration(new PingbackConfiguration()); + modelBuilder.ApplyConfiguration(new MentionConfiguration()); modelBuilder.ApplyConfiguration(new BlogThemeConfiguration()); modelBuilder.ApplyConfiguration(new BlogAssetConfiguration()); modelBuilder.ApplyConfiguration(new StyleSheetConfiguration()); diff --git a/src/Moonglade.Data.SqlServer/Configurations/PingbackConfiguration.cs b/src/Moonglade.Data.SqlServer/Configurations/MentionConfiguration.cs similarity index 50% rename from src/Moonglade.Data.SqlServer/Configurations/PingbackConfiguration.cs rename to src/Moonglade.Data.SqlServer/Configurations/MentionConfiguration.cs index 32f439617..5673df2aa 100644 --- a/src/Moonglade.Data.SqlServer/Configurations/PingbackConfiguration.cs +++ b/src/Moonglade.Data.SqlServer/Configurations/MentionConfiguration.cs @@ -5,16 +5,11 @@ namespace Moonglade.Data.SqlServer.Configurations; -internal class PingbackConfiguration : IEntityTypeConfiguration +internal class MentionConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.Property(e => e.Id).ValueGeneratedNever(); builder.Property(e => e.PingTimeUtc).HasColumnType("datetime"); - builder.Property(e => e.TargetPostTitle).HasMaxLength(128); - builder.Property(e => e.SourceIp).HasMaxLength(64); - builder.Property(e => e.SourceTitle).HasMaxLength(256); - builder.Property(e => e.SourceUrl).HasMaxLength(256); - builder.Property(e => e.Domain).HasMaxLength(256); } } \ No newline at end of file diff --git a/src/Moonglade.Data.SqlServer/SqlServerBlogDbContext.cs b/src/Moonglade.Data.SqlServer/SqlServerBlogDbContext.cs index 6c39cead6..41de9b4d3 100644 --- a/src/Moonglade.Data.SqlServer/SqlServerBlogDbContext.cs +++ b/src/Moonglade.Data.SqlServer/SqlServerBlogDbContext.cs @@ -22,7 +22,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.ApplyConfiguration(new PostConfiguration()); modelBuilder.ApplyConfiguration(new PostCategoryConfiguration()); modelBuilder.ApplyConfiguration(new LoginHistoryConfiguration()); - modelBuilder.ApplyConfiguration(new PingbackConfiguration()); + modelBuilder.ApplyConfiguration(new MentionConfiguration()); modelBuilder.ApplyConfiguration(new BlogThemeConfiguration()); modelBuilder.ApplyConfiguration(new BlogAssetConfiguration()); modelBuilder.ApplyConfiguration(new StyleSheetConfiguration()); diff --git a/src/Moonglade.Data/Entities/MentionEntity.cs b/src/Moonglade.Data/Entities/MentionEntity.cs index 6d6c7dd12..c08129819 100644 --- a/src/Moonglade.Data/Entities/MentionEntity.cs +++ b/src/Moonglade.Data/Entities/MentionEntity.cs @@ -1,13 +1,29 @@ -namespace Moonglade.Data.Entities; +using System.ComponentModel.DataAnnotations; + +namespace Moonglade.Data.Entities; public class MentionEntity { public Guid Id { get; set; } + + [MaxLength(256)] public string Domain { get; set; } + + [MaxLength(256)] public string SourceUrl { get; set; } + + [MaxLength(256)] public string SourceTitle { get; set; } + + [MaxLength(64)] public string SourceIp { get; set; } + public Guid TargetPostId { get; set; } public DateTime PingTimeUtc { get; set; } + + [MaxLength(100)] public string TargetPostTitle { get; set; } + + [MaxLength(16)] + public string Worker { get; set; } } \ No newline at end of file diff --git a/src/Moonglade.Pingback/ReceivePingCommand.cs b/src/Moonglade.Pingback/ReceivePingCommand.cs index aef80471f..fed6a2b6d 100644 --- a/src/Moonglade.Pingback/ReceivePingCommand.cs +++ b/src/Moonglade.Pingback/ReceivePingCommand.cs @@ -81,7 +81,8 @@ public async Task Handle(ReceivePingCommand request, Cancellat SourceTitle = pingRequest.Title, TargetPostId = id, TargetPostTitle = title, - SourceIp = request.IP + SourceIp = request.IP, + Worker = "Pingback" }; await pingbackRepo.AddAsync(obj, ct); diff --git a/src/Moonglade.sln b/src/Moonglade.sln index dc0b99055..0be364d99 100644 --- a/src/Moonglade.sln +++ b/src/Moonglade.sln @@ -34,6 +34,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Deployment", "Deployment", "{F2B7F09C-55B8-4A24-9CCB-9883C0B72DF1}" ProjectSection(SolutionItems) = preProject ..\Deployment\AzureQuickDeploy.ps1 = ..\Deployment\AzureQuickDeploy.ps1 + ..\Deployment\mssql-migration.sql = ..\Deployment\mssql-migration.sql EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{F9400B71-ADCD-4FBE-A88F-F85873FDC60B}" From b3dcc96911c6a9bce06693e3b109de1933621386 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:23:44 +0800 Subject: [PATCH 06/31] Update mssql-migration.sql --- Deployment/mssql-migration.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Deployment/mssql-migration.sql b/Deployment/mssql-migration.sql index db05e8dc0..2f00e2792 100644 --- a/Deployment/mssql-migration.sql +++ b/Deployment/mssql-migration.sql @@ -5,3 +5,6 @@ GO ALTER TABLE Mention ADD Worker NVARCHAR(16) GO + +UPDATE Mention SET Worker = N'Pingback' +GO From 6002f62e69258474ef2e01400a58819444e7ed1e Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:27:52 +0800 Subject: [PATCH 07/31] Create WebmentionController.cs --- src/Moonglade.Web/WebmentionController.cs | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/Moonglade.Web/WebmentionController.cs diff --git a/src/Moonglade.Web/WebmentionController.cs b/src/Moonglade.Web/WebmentionController.cs new file mode 100644 index 000000000..55616a807 --- /dev/null +++ b/src/Moonglade.Web/WebmentionController.cs @@ -0,0 +1,26 @@ +using System.ComponentModel.DataAnnotations; + +namespace Moonglade.Web; + +[ApiController] +[Route("[controller]")] +public class WebmentionController( + ILogger logger, + IBlogConfig blogConfig, + IMediator mediator) : ControllerBase +{ + [HttpPost] + public async Task ReceiveWebmention( + [FromForm][Required] string source, + [FromForm][Required] string target) + { + // Verify that the source URL links to the target URL + // TODO + + // Process the Webmention + // TODO + + // For demonstration purposes, we'll just return a success message. + return Ok("Webmention received and verified."); + } +} \ No newline at end of file From f494b7b6b8eaaf3c3bd1007c586bcb8702546e35 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:29:24 +0800 Subject: [PATCH 08/31] EnableWebmention settings --- src/Moonglade.Configuration/AdvancedSettings.cs | 3 +++ src/Moonglade.Web/Pages/Settings/Advanced.cshtml | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Moonglade.Configuration/AdvancedSettings.cs b/src/Moonglade.Configuration/AdvancedSettings.cs index 6338b24d2..824d97ff1 100644 --- a/src/Moonglade.Configuration/AdvancedSettings.cs +++ b/src/Moonglade.Configuration/AdvancedSettings.cs @@ -18,6 +18,9 @@ public class AdvancedSettings : IBlogSettings [Display(Name = "Enable Pingback")] public bool EnablePingback { get; set; } = true; + [Display(Name = "Enable Webmention")] + public bool EnableWebmention { get; set; } = true; + [Display(Name = "Enable OpenSearch")] public bool EnableOpenSearch { get; set; } = true; diff --git a/src/Moonglade.Web/Pages/Settings/Advanced.cshtml b/src/Moonglade.Web/Pages/Settings/Advanced.cshtml index e9bbee8e1..79daf5602 100644 --- a/src/Moonglade.Web/Pages/Settings/Advanced.cshtml +++ b/src/Moonglade.Web/Pages/Settings/Advanced.cshtml @@ -96,6 +96,21 @@

@SharedLocalizer["Advanced Settings"]

+ +
+
+ +
+
+ +
+
+
+ + +
+
+
From 9b0e97f5951c4ef498bcfe82fae968721f7f82fe Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:30:24 +0800 Subject: [PATCH 09/31] use EnableWebmention --- src/Moonglade.Web/{ => Controllers}/WebmentionController.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename src/Moonglade.Web/{ => Controllers}/WebmentionController.cs (85%) diff --git a/src/Moonglade.Web/WebmentionController.cs b/src/Moonglade.Web/Controllers/WebmentionController.cs similarity index 85% rename from src/Moonglade.Web/WebmentionController.cs rename to src/Moonglade.Web/Controllers/WebmentionController.cs index 55616a807..10b7e5b72 100644 --- a/src/Moonglade.Web/WebmentionController.cs +++ b/src/Moonglade.Web/Controllers/WebmentionController.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace Moonglade.Web; +namespace Moonglade.Web.Controllers; [ApiController] [Route("[controller]")] @@ -14,6 +14,8 @@ public async Task ReceiveWebmention( [FromForm][Required] string source, [FromForm][Required] string target) { + if (!blogConfig.AdvancedSettings.EnableWebmention) return Forbid(); + // Verify that the source URL links to the target URL // TODO From c7ccfdea1da6a9a4c6500ea978742c89cc2e483d Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:32:40 +0800 Subject: [PATCH 10/31] update admin menu --- .../Pages/Admin/{Pingback.cshtml => Mention.cshtml} | 4 ++-- src/Moonglade.Web/Pages/Shared/_AsideAdmin.cshtml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/Moonglade.Web/Pages/Admin/{Pingback.cshtml => Mention.cshtml} (98%) diff --git a/src/Moonglade.Web/Pages/Admin/Pingback.cshtml b/src/Moonglade.Web/Pages/Admin/Mention.cshtml similarity index 98% rename from src/Moonglade.Web/Pages/Admin/Pingback.cshtml rename to src/Moonglade.Web/Pages/Admin/Mention.cshtml index aac30dbe5..137d9f412 100644 --- a/src/Moonglade.Web/Pages/Admin/Pingback.cshtml +++ b/src/Moonglade.Web/Pages/Admin/Mention.cshtml @@ -1,8 +1,8 @@ -@page "/admin/pingback" +@page "/admin/mention" @using Moonglade.Pingback @inject IMediator Mediator @{ - ViewBag.Title = "Pingback"; + ViewBag.Title = "Mentions"; var pingbackRecords = await Mediator.Send(new GetPingbacksQuery()); } diff --git a/src/Moonglade.Web/Pages/Shared/_AsideAdmin.cshtml b/src/Moonglade.Web/Pages/Shared/_AsideAdmin.cshtml index 7fce334c5..b94a53844 100644 --- a/src/Moonglade.Web/Pages/Shared/_AsideAdmin.cshtml +++ b/src/Moonglade.Web/Pages/Shared/_AsideAdmin.cshtml @@ -43,10 +43,10 @@ @SharedLocalizer["Friend links"] - - - @SharedLocalizer["Pingbacks"] + + + @SharedLocalizer["Mentions"]
From 7da7780fb666e37a6ed7d7e5d12f141d2a6341e8 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:33:33 +0800 Subject: [PATCH 11/31] rename to GetMentionsQuery --- src/Moonglade.Pingback/GetMentionsQuery.cs | 15 +++++++++++++++ src/Moonglade.Pingback/GetPingbacksQuery.cs | 15 --------------- src/Moonglade.Web/Pages/Admin/Mention.cshtml | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 src/Moonglade.Pingback/GetMentionsQuery.cs delete mode 100644 src/Moonglade.Pingback/GetPingbacksQuery.cs diff --git a/src/Moonglade.Pingback/GetMentionsQuery.cs b/src/Moonglade.Pingback/GetMentionsQuery.cs new file mode 100644 index 000000000..f0d40c7f6 --- /dev/null +++ b/src/Moonglade.Pingback/GetMentionsQuery.cs @@ -0,0 +1,15 @@ +using MediatR; +using Moonglade.Data; +using Moonglade.Data.Entities; +using Moonglade.Data.Specifications; + +namespace Moonglade.Pingback; + +public record GetMentionsQuery : IRequest>; + +public class GetMentionsQueryHandler(MoongladeRepository repo) : + IRequestHandler> +{ + public Task> Handle(GetMentionsQuery request, CancellationToken ct) => + repo.ListAsync(new PingbackReadOnlySpec(), ct); +} \ No newline at end of file diff --git a/src/Moonglade.Pingback/GetPingbacksQuery.cs b/src/Moonglade.Pingback/GetPingbacksQuery.cs deleted file mode 100644 index 4e29442c3..000000000 --- a/src/Moonglade.Pingback/GetPingbacksQuery.cs +++ /dev/null @@ -1,15 +0,0 @@ -using MediatR; -using Moonglade.Data; -using Moonglade.Data.Entities; -using Moonglade.Data.Specifications; - -namespace Moonglade.Pingback; - -public record GetPingbacksQuery : IRequest>; - -public class GetPingbacksQueryHandler(MoongladeRepository repo) : - IRequestHandler> -{ - public Task> Handle(GetPingbacksQuery request, CancellationToken ct) => - repo.ListAsync(new PingbackReadOnlySpec(), ct); -} \ No newline at end of file diff --git a/src/Moonglade.Web/Pages/Admin/Mention.cshtml b/src/Moonglade.Web/Pages/Admin/Mention.cshtml index 137d9f412..e346dc6b5 100644 --- a/src/Moonglade.Web/Pages/Admin/Mention.cshtml +++ b/src/Moonglade.Web/Pages/Admin/Mention.cshtml @@ -3,7 +3,7 @@ @inject IMediator Mediator @{ ViewBag.Title = "Mentions"; - var pingbackRecords = await Mediator.Send(new GetPingbacksQuery()); + var pingbackRecords = await Mediator.Send(new GetMentionsQuery()); } @Html.AntiForgeryToken() From 987b9304b46b081902a1a91ccbe303c6f3cd3c11 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:33:53 +0800 Subject: [PATCH 12/31] MentionReadOnlySpec --- .../{PingbackReadOnlySpec.cs => MentionReadOnlySpec.cs} | 4 ++-- src/Moonglade.Pingback/GetMentionsQuery.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/Moonglade.Data/Specifications/{PingbackReadOnlySpec.cs => MentionReadOnlySpec.cs} (53%) diff --git a/src/Moonglade.Data/Specifications/PingbackReadOnlySpec.cs b/src/Moonglade.Data/Specifications/MentionReadOnlySpec.cs similarity index 53% rename from src/Moonglade.Data/Specifications/PingbackReadOnlySpec.cs rename to src/Moonglade.Data/Specifications/MentionReadOnlySpec.cs index 36e67e8d3..b13b0aeba 100644 --- a/src/Moonglade.Data/Specifications/PingbackReadOnlySpec.cs +++ b/src/Moonglade.Data/Specifications/MentionReadOnlySpec.cs @@ -2,9 +2,9 @@ namespace Moonglade.Data.Specifications; -public sealed class PingbackReadOnlySpec : Specification +public sealed class MentionReadOnlySpec : Specification { - public PingbackReadOnlySpec() + public MentionReadOnlySpec() { Query.AsNoTracking(); } diff --git a/src/Moonglade.Pingback/GetMentionsQuery.cs b/src/Moonglade.Pingback/GetMentionsQuery.cs index f0d40c7f6..83a7ebf79 100644 --- a/src/Moonglade.Pingback/GetMentionsQuery.cs +++ b/src/Moonglade.Pingback/GetMentionsQuery.cs @@ -11,5 +11,5 @@ public class GetMentionsQueryHandler(MoongladeRepository repo) : IRequestHandler> { public Task> Handle(GetMentionsQuery request, CancellationToken ct) => - repo.ListAsync(new PingbackReadOnlySpec(), ct); + repo.ListAsync(new MentionReadOnlySpec(), ct); } \ No newline at end of file From 8433865f75b3171c4b785d1778be57c88ed45176 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Mon, 27 May 2024 16:34:30 +0800 Subject: [PATCH 13/31] mentions-container --- src/Moonglade.Web/Pages/Admin/Mention.cshtml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Moonglade.Web/Pages/Admin/Mention.cshtml b/src/Moonglade.Web/Pages/Admin/Mention.cshtml index e346dc6b5..70428a93f 100644 --- a/src/Moonglade.Web/Pages/Admin/Mention.cshtml +++ b/src/Moonglade.Web/Pages/Admin/Mention.cshtml @@ -10,7 +10,7 @@ @section head {