From db78b13bd5020ef3fab29d1ece4d99fab1456a4d Mon Sep 17 00:00:00 2001 From: Lachlan Young Date: Thu, 3 Dec 2026 14:14:57 +1000 Subject: [PATCH 1/6] feat: push notifications when syncing stops --- CLAUDE.md | 3 +- Directory.Build.props | 6 +- .../ControllerAuthorizationTests.cs | 1 + LetterboxdSync.Tests/DashboardMarkupTests.cs | 68 ++ LetterboxdSync.Tests/NotificationLogTests.cs | 168 ++++ .../NotificationMessagesTests.cs | 126 +++ .../NotificationSenderTests.cs | 271 +++++++ LetterboxdSync.Tests/NotificationTestRig.cs | 85 ++ .../NotificationTriggerTests.cs | 726 ++++++++++++++++++ LetterboxdSync.Tests/PlaybackHandlerTests.cs | 14 + LetterboxdSync.Tests/WriteOnlySecretsTests.cs | 234 ++++++ LetterboxdSync/Api/AccountUpdateRequest.cs | 6 + LetterboxdSync/Api/LetterboxdController.cs | 24 + LetterboxdSync/AuthBreaker.cs | 50 +- .../Configuration/PluginConfiguration.cs | 37 + LetterboxdSync/Configuration/SecretMerge.cs | 18 +- LetterboxdSync/LetterboxdSync.csproj | 4 +- LetterboxdSync/LetterboxdSyncRunner.cs | 9 + LetterboxdSync/Notifications/GiveUpNotice.cs | 64 ++ .../Notifications/NotificationLog.cs | 176 +++++ .../Notifications/NotificationMessages.cs | 86 +++ .../Notifications/NotificationSender.cs | 172 +++++ LetterboxdSync/Notifications/Notifications.cs | 106 +++ LetterboxdSync/PlaybackHandler.cs | 8 +- LetterboxdSync/Plugin.cs | 10 + .../Serializd/SerializdServiceFactory.cs | 22 +- LetterboxdSync/ServiceRegistrator.cs | 2 + LetterboxdSync/SyncHistory.cs | 9 + LetterboxdSync/Web/configPage.html | 61 ++ README.md | 28 +- SECURITY.md | 3 +- .../.openspec.yaml | 2 + .../add-sync-failure-notifications/design.md | 153 ++++ .../proposal.md | 49 ++ .../specs/sync-failure-notifications/spec.md | 189 +++++ .../add-sync-failure-notifications/tasks.md | 54 ++ site/src/data/release-notes.ts | 15 + 37 files changed, 3020 insertions(+), 39 deletions(-) create mode 100644 LetterboxdSync.Tests/NotificationLogTests.cs create mode 100644 LetterboxdSync.Tests/NotificationMessagesTests.cs create mode 100644 LetterboxdSync.Tests/NotificationSenderTests.cs create mode 100644 LetterboxdSync.Tests/NotificationTestRig.cs create mode 100644 LetterboxdSync.Tests/NotificationTriggerTests.cs create mode 100644 LetterboxdSync/Notifications/GiveUpNotice.cs create mode 100644 LetterboxdSync/Notifications/NotificationLog.cs create mode 100644 LetterboxdSync/Notifications/NotificationMessages.cs create mode 100644 LetterboxdSync/Notifications/NotificationSender.cs create mode 100644 LetterboxdSync/Notifications/Notifications.cs create mode 100644 openspec/changes/add-sync-failure-notifications/.openspec.yaml create mode 100644 openspec/changes/add-sync-failure-notifications/design.md create mode 100644 openspec/changes/add-sync-failure-notifications/proposal.md create mode 100644 openspec/changes/add-sync-failure-notifications/specs/sync-failure-notifications/spec.md create mode 100644 openspec/changes/add-sync-failure-notifications/tasks.md diff --git a/CLAUDE.md b/CLAUDE.md index 02b322f0..a4581f12 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -78,7 +78,8 @@ Treat the key as public. It ships in every `Jellyscribe.dll` and a decompiler sh - `Api/LetterboxdController.cs` exposes the REST endpoints the dashboards call; `Api/SidebarController.cs` serves the static web assets (`sidebar.js`, `jellyscribe.js`, `jellyscribe.css`), the only anonymous routes. `LetterboxdController` also serves the read-only `ItemRating` endpoint the review modal uses to pre-fill its stars from the caller's stored Jellyfin rating. - `POST Review` with text (not a rewatch, no date given, TMDb id known) holds `FilmSyncLock` for that user, account and film, then looks up the latest `Success`/`Rewatch` history row for that user, account and film. When one exists, `ILetterboxdService.AddReviewToDiaryEntryAsync` puts the review on Letterboxd's entry for that viewing date (API path: `GET /log-entries?member=&film=`, every page and read a second time after 3s when nothing is on that date because diary reads lag writes, then `PATCH /log-entry/{id}` with only `review` and `rating`; an entry that already has a review is never overwritten and the request is refused). The website session keeps the interface default, `Unsupported`, so it and a missing entry fall back to a new entry dated on the row's viewing date, never today, and the per-account reply carries a `note` saying so. Any other review is a new entry sent with an explicit date (today is the server's day, `Helpers.ToLocalViewingDate`). The review's history row records the real TMDb id, account and viewing date, so the diary sync's duplicate checks see it. - `Api/LoginCheckLimiter.cs` rate-limits both Verify (login check) endpoints in memory: 5 failed checks per Jellyfin user, 20 checks of any outcome per user, and 20 failed checks server-wide, per service per 10 minutes, answering 429. `ControllerAuthorizationTests` pins which actions are anonymous and which are admin-only, so a new action has to be added there on purpose. -- Stored secrets (Letterboxd and Serializd passwords, raw cookies, the Seerr API key) are write-only: the plaintext properties are `[JsonIgnore]`, responses carry only `Has*`/`has*` flags, and `Configuration/SecretMerge.cs` turns every save back into the intended change (blank keeps, typed replaces, `ClearRawCookies`/`ClearJellyseerrApiKey` drop, and the write-only `Original*` fields carry secrets across a rename or an admin's owner change). `Plugin.UpdateConfiguration` applies it to Jellyfin's own plugin-config POST. Both Verify endpoints use the stored password when the field is blank, and `TestJellyseerr` sends the stored key only to the stored URL. +- Stored secrets (Letterboxd and Serializd passwords, raw cookies, the Seerr API key, the notification access token) are write-only: the plaintext properties are `[JsonIgnore]`, responses carry only `Has*`/`has*` flags, and `Configuration/SecretMerge.cs` turns every save back into the intended change (blank keeps, typed replaces, `ClearRawCookies`/`ClearJellyseerrApiKey`/`ClearNotificationToken` drop, the notification token is also dropped when its address changes with no token typed, and the write-only `Original*` fields carry secrets across a rename or an admin's owner change). `Plugin.UpdateConfiguration` applies it to Jellyfin's own plugin-config POST. Both Verify endpoints use the stored password when the field is blank, and `TestJellyseerr` sends the stored key only to the stored URL. +- Failure notifications (`Notifications/`): optional ntfy push notifications to the admin's `NotificationUrl`, off until one is saved. `NotificationSender` (a hosted singleton) does one POST with a 10 s limit, follows no redirects, logs the server's host only (the topic name is a secret on a public server) and never throws; static code reaches it through `Notifications.Notify`, a no-op until the sender starts. Each condition is raised at one choke point, so no sync entry point knows about it: a paused Letterboxd login inside `AuthBreaker.NotifyOpenedAsync` (once per pause), a Serializd login refused with 401 or 403 inside `SerializdServiceFactory.CreateAuthenticatedAsync` (once per account per 24 h through `NotificationLog`, lifted when a different password is saved but never below once an hour; Verify does not use the factory), and films just given up on through `GiveUpNotice.AfterRun`, called after the film loop in `LetterboxdSyncRunner` (after `SyncHistory.MarkOutage`, and before a cancellation is rethrown) and after a failed film in `PlaybackHandler`. `NotificationMessages` builds the text: header values are fixed ASCII, and no message carries a secret, a Serializd email or a service's error text. `Plugin.UpdateConfiguration` stores no address that is not `http`/`https`. The admin-only `POST Notifications/Test` sends the stored token only to the stored address and describes a failure in fixed words. - `Api/LibrariesController.cs` lists the film, TV, and mixed libraries the caller can access, for the per-account "Excluded libraries" checklist on both settings pages (Jellyfin's own `/Library/VirtualFolders` is admin-only). - `Web/*.html`, `Web/*.js` and `Web/*.css` are embedded resources (see `LetterboxdSync.csproj`). `configPage.html` and `userPage.html` are the plugin's config pages; what they share (most of the code, every common style, and the bundled WS Sans/WS Mono fonts) lives in `jellyscribe.js` and `jellyscribe.css`, which `SidebarController` serves anonymously as static files. Each page loads them with `?v=`, reuses a loaded copy only under that version, and starts with the factory `jellyscribe.js` registered under it, so after an upgrade a page never runs against an older shared script left in the tab. The build stamps the version into both pages and `jellyscribe.js` (the `StampWebAssetVersion` target replaces `@@JELLYSCRIBE_VERSION@@`; a Debug build stamps `-dev`), and the server caches the files for good only under this build's version. A fix to shared behaviour goes in `jellyscribe.js` once; page-specific code (how each page talks to the server, its own sections) stays in the page. Both dashboards scope every CSS rule to their root (never `html`/`body`), pick their light or dark palette from the background Jellyfin's theme paints (`applyTheme`; the OS setting only outside Jellyfin), and use native `` modals opened with `showModal()`. `DashboardMarkupTests` pins their contrast (4.5:1 in both palettes), scoping, phone layout and keyboard markup. - Telemetry and log bundles (`Telemetry/TelemetryService.cs`, the `Telemetry/*` actions in `LetterboxdController`): the admin page previews the exact ping (`Telemetry/Preview`) and log bundle (`Telemetry/PreviewLogs`, built by the same method as the send) before anything leaves the server, and `Telemetry/RegenerateId` replaces the instance id. Never log a Serializd email: name the account with `LogRedaction.AccountTag`. The shared log reader masks emails with `LogRedaction.RedactEmails` (encoded forms too) and cuts review-reply bodies older releases logged, so the Logs tab, the preview and the upload match. Error counts in the payload stay exact integers (the ingest Worker drops non-numbers); the docs say so. diff --git a/Directory.Build.props b/Directory.Build.props index d315a3f9..c66d9e4d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 2.15.2.0 - 2.15.2.0 - 2.15.2.0 + 2.16.0.0 + 2.16.0.0 + 2.16.0.0 diff --git a/LetterboxdSync.Tests/ControllerAuthorizationTests.cs b/LetterboxdSync.Tests/ControllerAuthorizationTests.cs index 50d4bbb0..31f13dc5 100644 --- a/LetterboxdSync.Tests/ControllerAuthorizationTests.cs +++ b/LetterboxdSync.Tests/ControllerAuthorizationTests.cs @@ -38,6 +38,7 @@ public class ControllerAuthorizationTests "LetterboxdController.RegenerateTelemetryId", "LetterboxdController.SendLogs", "LetterboxdController.TestJellyseerr", + "LetterboxdController.TestNotification", }; private sealed record ActionInfo(string Name, bool Anonymous, bool Authorized, bool AdminOnly, bool Routed); diff --git a/LetterboxdSync.Tests/DashboardMarkupTests.cs b/LetterboxdSync.Tests/DashboardMarkupTests.cs index 35540ab6..e2e71f8c 100644 --- a/LetterboxdSync.Tests/DashboardMarkupTests.cs +++ b/LetterboxdSync.Tests/DashboardMarkupTests.cs @@ -296,6 +296,74 @@ public void AdminPage_OffersThePromisedTelemetryAndLogBundlePreviews() Assert.DoesNotContain("exact numbers", page, StringComparison.Ordinal); } + [Fact] + public void AdminPage_NotificationsPanel_IsLabelledScopedAndShowsServerTextAsText() + { + var page = Read("configPage.html"); + var start = page.IndexOf("

Notifications

", StringComparison.Ordinal); + Assert.True(start >= 0, "no Notifications panel"); + var panel = page.Substring(start, page.IndexOf("

Anonymous telemetry

", start, StringComparison.Ordinal) - start); + + // It sits on the Integrations tab, after Seerr, and is saved by that tab's one Save button. + Assert.True(page.IndexOf("

Seerr

", StringComparison.Ordinal) < start); + Assert.True(page.IndexOf("", StringComparison.Ordinal) < start); + Assert.DoesNotContain("primary", panel, StringComparison.Ordinal); + + // Every field has a label, in the order a keyboard reaches them: address, token, remove, test. + Assert.Contains("