From 1091caf79d652e51191adbae91d9251a77eb467c Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Sat, 4 Jan 2025 10:35:39 -0600 Subject: [PATCH] Finished the overhaul to the License info screen. --- API.Tests/API.Tests.csproj | 6 +++--- API/API.csproj | 6 +++--- API/Services/Plus/LicenseService.cs | 2 +- API/Services/TaskScheduler.cs | 4 +++- API/Services/Tasks/VersionUpdaterService.cs | 15 +++++++-------- UI/Web/src/app/_models/kavitaplus/license-info.ts | 2 +- .../src/app/admin/license/license.component.html | 8 ++++---- 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/API.Tests/API.Tests.csproj b/API.Tests/API.Tests.csproj index 4198cf1a70..2550cbc906 100644 --- a/API.Tests/API.Tests.csproj +++ b/API.Tests/API.Tests.csproj @@ -9,14 +9,14 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/API/API.csproj b/API/API.csproj index f3f0f653ea..44f362bc3d 100644 --- a/API/API.csproj +++ b/API/API.csproj @@ -71,7 +71,7 @@ - + @@ -104,10 +104,10 @@ - + - + diff --git a/API/Services/Plus/LicenseService.cs b/API/Services/Plus/LicenseService.cs index 1c162c53cb..e31f047b7c 100644 --- a/API/Services/Plus/LicenseService.cs +++ b/API/Services/Plus/LicenseService.cs @@ -266,7 +266,7 @@ public async Task ResetLicense(string license, string email) .WithKavitaPlusHeaders(encryptedLicense.Value) .GetJsonAsync(); - // This indicates a mismatch on installid or no active subscription + // This indicates a mismatch on installId or no active subscription if (response == null) return null; // Ensure that current version is within the 3 version limit. Don't count Nightly releases or Hotfixes diff --git a/API/Services/TaskScheduler.cs b/API/Services/TaskScheduler.cs index 2dbd4ed34a..8cfabb1ca1 100644 --- a/API/Services/TaskScheduler.cs +++ b/API/Services/TaskScheduler.cs @@ -204,7 +204,9 @@ public async Task ScheduleKavitaPlusTasks() RecurringJob.AddOrUpdate(CheckScrobblingTokensId, () => _scrobblingService.CheckExternalAccessTokens(), Cron.Daily, RecurringJobOptions); BackgroundJob.Enqueue(() => _scrobblingService.CheckExternalAccessTokens()); // We also kick off an immediate check on startup - RecurringJob.AddOrUpdate(LicenseCheckId, () => _licenseService.HasActiveLicense(true), + + // Get the License Info (and cache it) on first load. This will internally cache the Github releases for the Version Service + RecurringJob.AddOrUpdate(LicenseCheckId, () => _licenseService.GetLicenseInfo(true), LicenseService.Cron, RecurringJobOptions); // KavitaPlus Scrobbling (every 4 hours) diff --git a/API/Services/Tasks/VersionUpdaterService.cs b/API/Services/Tasks/VersionUpdaterService.cs index 349fc67318..fd4d5b4bc7 100644 --- a/API/Services/Tasks/VersionUpdaterService.cs +++ b/API/Services/Tasks/VersionUpdaterService.cs @@ -339,16 +339,15 @@ public async Task> GetAllReleases(int count = 0) return updateDtos; } - private async Task?> TryGetCachedReleases() + private static async Task?> TryGetCachedReleases() { - if (File.Exists(_cacheFilePath)) + if (!File.Exists(_cacheFilePath)) return null; + + var fileInfo = new FileInfo(_cacheFilePath); + if (DateTime.UtcNow - fileInfo.LastWriteTimeUtc <= CacheDuration) { - var fileInfo = new FileInfo(_cacheFilePath); - if (DateTime.UtcNow - fileInfo.LastWriteTimeUtc <= CacheDuration) - { - var cachedData = await File.ReadAllTextAsync(_cacheFilePath); - return System.Text.Json.JsonSerializer.Deserialize>(cachedData); - } + var cachedData = await File.ReadAllTextAsync(_cacheFilePath); + return System.Text.Json.JsonSerializer.Deserialize>(cachedData); } return null; diff --git a/UI/Web/src/app/_models/kavitaplus/license-info.ts b/UI/Web/src/app/_models/kavitaplus/license-info.ts index 139a6ae3fd..4a724b3ff5 100644 --- a/UI/Web/src/app/_models/kavitaplus/license-info.ts +++ b/UI/Web/src/app/_models/kavitaplus/license-info.ts @@ -2,7 +2,7 @@ export interface LicenseInfo { expirationDate: string; isActive: boolean; isCancelled: boolean; - isVersionValid: boolean; + isValidVersion: boolean; registeredEmail: string; totalMonthsSubbed: number; hasLicense: boolean; diff --git a/UI/Web/src/app/admin/license/license.component.html b/UI/Web/src/app/admin/license/license.component.html index ba8622d31d..9cfb5a27a9 100644 --- a/UI/Web/src/app/admin/license/license.component.html +++ b/UI/Web/src/app/admin/license/license.component.html @@ -10,7 +10,7 @@
- +