From c3cd7b5a16cb8d6f902d77a1539c2e0c97dbdf14 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Thu, 31 Jul 2025 12:57:47 -0500 Subject: [PATCH 1/6] Added ChangeLog Added change log to track updates to the database, for easier pinging from Syncer client. --- FreeTubeSync/EndPoints/PingEndpoint.cs | 29 ++++++++++++++++++++++++ FreeTubeSync/Model/Database/ChangeLog.cs | 9 ++++++++ 2 files changed, 38 insertions(+) create mode 100644 FreeTubeSync/EndPoints/PingEndpoint.cs create mode 100644 FreeTubeSync/Model/Database/ChangeLog.cs diff --git a/FreeTubeSync/EndPoints/PingEndpoint.cs b/FreeTubeSync/EndPoints/PingEndpoint.cs new file mode 100644 index 0000000..bda93ec --- /dev/null +++ b/FreeTubeSync/EndPoints/PingEndpoint.cs @@ -0,0 +1,29 @@ +using FreeTubeSync.Database; +using FreeTubeSync.Model.Database; + +namespace FreeTubeSync.EndPoints; + +public static class PingEndpoint +{ + public static void MapPingEndpoints(this WebApplication app) + { + var group = app.MapGroup("ping"); + group.MapGet("/", async (CancellationToken token) => + { + await Task.Delay(10); + var dict = new { AppVersion = "0.1.3" }; + return Results.Ok(dict); + }); + + group.MapGet("/lastUpdated", async (DataContext dbContext, CancellationToken token) => + { + var log = await dbContext.GetLatestChangeAsync(token); + + if (log == null) + return Results.NotFound(); + + var dict = new { LastUpdated = log.ChangeTime }; + return Results.Ok(dict); + }); + } +} \ No newline at end of file diff --git a/FreeTubeSync/Model/Database/ChangeLog.cs b/FreeTubeSync/Model/Database/ChangeLog.cs new file mode 100644 index 0000000..8d6a7f5 --- /dev/null +++ b/FreeTubeSync/Model/Database/ChangeLog.cs @@ -0,0 +1,9 @@ +namespace FreeTubeSync.Model.Database; + +public class ChangeLog +{ + public int Id { get; set; } + public string TableName { get; set; } = string.Empty; + public string ChangeType { get; set; } = string.Empty; + public DateTime ChangeTime { get; set; } = DateTime.MinValue; +} \ No newline at end of file From e2d0c327eb8911aac9cec61d92c6875b31821e8a Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Thu, 31 Jul 2025 12:59:39 -0500 Subject: [PATCH 2/6] Updated ProfileEndpoint Added an UpdateAsync() call for each subscription, to ensure that subscriptions actually get updated in the database. --- FreeTubeSync/EndPoints/ProfileEndpoint.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FreeTubeSync/EndPoints/ProfileEndpoint.cs b/FreeTubeSync/EndPoints/ProfileEndpoint.cs index 7382889..a8ac2df 100644 --- a/FreeTubeSync/EndPoints/ProfileEndpoint.cs +++ b/FreeTubeSync/EndPoints/ProfileEndpoint.cs @@ -51,7 +51,10 @@ public static class ProfileEndpoint if (f == null) notFound.Add(subscription); else + { subscription.MapFrom(f); + await subRepo.UpdateAsync(subscription, ct, false); + } } var newSubs = (from subscription in profileJson.subscriptions let f = res.subscriptions.FirstOrDefault(s => s.id == subscription.id) where f == null select subscription).ToList(); @@ -72,7 +75,7 @@ public static class ProfileEndpoint { res.subscriptions.Remove(nfSub); } - + await repository.UpdateAsync(res, ct); } From 72dca6c1fef179d5f4e086e7bdadf5b1285e1b09 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Thu, 31 Jul 2025 13:00:32 -0500 Subject: [PATCH 3/6] Updated DataContext Added DbSet for ChangeLog table. --- FreeTubeSync/Database/DataContext.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/FreeTubeSync/Database/DataContext.cs b/FreeTubeSync/Database/DataContext.cs index a4d16de..33be524 100644 --- a/FreeTubeSync/Database/DataContext.cs +++ b/FreeTubeSync/Database/DataContext.cs @@ -26,4 +26,5 @@ public class DataContext : DbContext public DbSet Settings { get; set; } public DbSet Subscriptions { get; set; } public DbSet