mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-05 06:35:30 -04:00
* Added parser case for "The Duke of Death and His Black Maid - Ch. 177 - The Ball (3).cbz" * Removed a file that is created and modified every test run. * Fixed a bad parser case for "Batman Beyond 02 (of 6) (1999)" which was consuming too many characters * Removed a lot of "Volume" parsing for Comics that don't make sense. This is prep work for the upcoming Comic Rework release. * Reworked a lot of parsing cases for comics based on naming conventions observed from releases found online. * Added a way for external scripts to use a user api key to authenticate * Fixed an issue if the manga only had one page, the bottom menu would be missing page and chapter controls. * Fixed a bug where on small phones, nav bar could overflow due to scroll to top * Tweaked a lot of regex for manga parsing to handle some cases where poorly named files, like "Vol. 03 Ch. 21" would end up parsing as Series "Vol. 03". * Even more handling of parser cases. Manga parser should be as it was but more robust to handle bad naming. * Fixed: Don't force metadata refresh on Scan Series, only on refresh metadata * Implemented the ability to automatically refresh after a series scan based on when server finishes. Remove a duplicate API call from series detail. * Removed another API call for series metadata that isn't needed. * Refactored Message creation to a factory, hardcoded strings are centralized, and RefreshSeriesMetadata sends an event and is refactored to be async. * Fixed a bug when really poorly named files are within a folder that contains the series name, fallback couldn't occur due to it being taken as root folder. Now we detect said condition and will go one level higher, resulting in potentially more I/O, but the series will not be deleted. * Added the Read in Incognito context item for Chapter cards * Skip an additional check for series summary for series that aren't EPUB or Archive formats. * Fixed an issue where cover image generation could occur due to a bad check on LastWriteTime on the underlying file. * Added some extra comic parser tests * Added a ScanLibrary event (not hooked up in UI) * Performance improvement on metadata service. Now when we scan for cover image changes, we emit when a change occurs and only then do we update parent entities (array copy). * Removed an hr from series detail and ensure we update the cover image for series when scan series finishes. * Updated the infinite scroller to use a Flags pattern for the debug mode. Updated a few logical conditions for mobile. * Removed the concurrency check on row progress as if too many calls hit the DB, it will throw, but it doesn't matter. Fixed a bad logic code which could cause scrolling after hitting the bottom of the chapter. * Ensure prefetching uses totalPages + 1 since we pass in totalPages as - 1 from manga reader * Fixed issue where last page of webtoon wouldn't be prefetched due to a < instead of <= on prefetching code * Implemented ability to send images from archives to the UI without incurring any extra memory pressure. * Dropdown menus now have a darker background * Webtoon reader now works on mobile. * Fixed how keyboard presses for up/down/left/right work with MANGA_UD reading mode. See issue #579 * Fixed cont reader for webtoons on mobile * Fixed a small issue where top spacer would too quickly switch to prev chapter * Updated user preferences to use same slider style. Removed some css that is not used. * Added comic parser case for "Saga 001 (2012) (Digital) (Empire-Zone)" * Added accessibility toggle to reading list order and aligned sliders to all use the same style. * Removed a todo for checking on new image serving code. It works great. * Fixed a missing await * Auth guard will now check if an existing toast is present giving same message before poping the toast. * Fixed alignment on phones for reading lists * Moved sorters so they aren't resused between multiple threads. Slightly higher memory footprint. * Fixed a broken unit test * Code smells * More unit test fixing
168 lines
6.0 KiB
C#
168 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using API.DTOs.Update;
|
|
using API.Interfaces.Services;
|
|
using API.SignalR;
|
|
using API.SignalR.Presence;
|
|
using Flurl.Http;
|
|
using Flurl.Http.Configuration;
|
|
using Kavita.Common.EnvironmentInfo;
|
|
using MarkdownDeep;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API.Services.Tasks
|
|
{
|
|
internal class GithubReleaseMetadata
|
|
{
|
|
/// <summary>
|
|
/// Name of the Tag
|
|
/// <example>v0.4.3</example>
|
|
/// </summary>
|
|
// ReSharper disable once InconsistentNaming
|
|
public string Tag_Name { get; init; }
|
|
/// <summary>
|
|
/// Name of the Release
|
|
/// </summary>
|
|
public string Name { get; init; }
|
|
/// <summary>
|
|
/// Body of the Release
|
|
/// </summary>
|
|
public string Body { get; init; }
|
|
/// <summary>
|
|
/// Url of the release on Github
|
|
/// </summary>
|
|
// ReSharper disable once InconsistentNaming
|
|
public string Html_Url { get; init; }
|
|
}
|
|
|
|
public class UntrustedCertClientFactory : DefaultHttpClientFactory
|
|
{
|
|
public override HttpMessageHandler CreateMessageHandler() {
|
|
return new HttpClientHandler {
|
|
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
|
|
};
|
|
}
|
|
}
|
|
|
|
public class VersionUpdaterService : IVersionUpdaterService
|
|
{
|
|
private readonly ILogger<VersionUpdaterService> _logger;
|
|
private readonly IHubContext<MessageHub> _messageHub;
|
|
private readonly IPresenceTracker _tracker;
|
|
private readonly Markdown _markdown = new MarkdownDeep.Markdown();
|
|
#pragma warning disable S1075
|
|
private static readonly string GithubLatestReleasesUrl = "https://api.github.com/repos/Kareadita/Kavita/releases/latest";
|
|
private static readonly string GithubAllReleasesUrl = "https://api.github.com/repos/Kareadita/Kavita/releases";
|
|
#pragma warning restore S1075
|
|
|
|
public VersionUpdaterService(ILogger<VersionUpdaterService> logger, IHubContext<MessageHub> messageHub, IPresenceTracker tracker)
|
|
{
|
|
_logger = logger;
|
|
_messageHub = messageHub;
|
|
_tracker = tracker;
|
|
|
|
FlurlHttp.ConfigureClient(GithubLatestReleasesUrl, cli =>
|
|
cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());
|
|
FlurlHttp.ConfigureClient(GithubAllReleasesUrl, cli =>
|
|
cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetches the latest release from Github
|
|
/// </summary>
|
|
public async Task<UpdateNotificationDto> CheckForUpdate()
|
|
{
|
|
var update = await GetGithubRelease();
|
|
return CreateDto(update);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<UpdateNotificationDto>> GetAllReleases()
|
|
{
|
|
var updates = await GetGithubReleases();
|
|
return updates.Select(CreateDto);
|
|
}
|
|
|
|
private UpdateNotificationDto CreateDto(GithubReleaseMetadata update)
|
|
{
|
|
if (update == null || string.IsNullOrEmpty(update.Tag_Name)) return null;
|
|
var updateVersion = new Version(update.Tag_Name.Replace("v", string.Empty));
|
|
var currentVersion = BuildInfo.Version.ToString();
|
|
|
|
if (updateVersion.Revision == -1)
|
|
{
|
|
currentVersion = currentVersion.Substring(0, currentVersion.LastIndexOf(".", StringComparison.Ordinal));
|
|
}
|
|
|
|
return new UpdateNotificationDto()
|
|
{
|
|
CurrentVersion = currentVersion,
|
|
UpdateVersion = updateVersion.ToString(),
|
|
UpdateBody = _markdown.Transform(update.Body.Trim()),
|
|
UpdateTitle = update.Name,
|
|
UpdateUrl = update.Html_Url,
|
|
IsDocker = new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker
|
|
};
|
|
}
|
|
|
|
public async Task PushUpdate(UpdateNotificationDto update)
|
|
{
|
|
if (update == null) return;
|
|
|
|
var admins = await _tracker.GetOnlineAdmins();
|
|
var updateVersion = new Version(update.CurrentVersion);
|
|
|
|
if (BuildInfo.Version < updateVersion)
|
|
{
|
|
_logger.LogInformation("Server is out of date. Current: {CurrentVersion}. Available: {AvailableUpdate}", BuildInfo.Version, updateVersion);
|
|
await SendEvent(update, admins);
|
|
}
|
|
else if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == Environments.Development)
|
|
{
|
|
_logger.LogInformation("Server is up to date. Current: {CurrentVersion}", BuildInfo.Version);
|
|
await SendEvent(update, admins);
|
|
}
|
|
}
|
|
|
|
private async Task SendEvent(UpdateNotificationDto update, IReadOnlyList<string> admins)
|
|
{
|
|
var connections = new List<string>();
|
|
foreach (var admin in admins)
|
|
{
|
|
connections.AddRange(await _tracker.GetConnectionsForUser(admin));
|
|
}
|
|
|
|
await _messageHub.Clients.Users(admins).SendAsync(SignalREvents.UpdateVersion, MessageFactory.UpdateVersionEvent(update));
|
|
}
|
|
|
|
|
|
private static async Task<GithubReleaseMetadata> GetGithubRelease()
|
|
{
|
|
var update = await GithubLatestReleasesUrl
|
|
.WithHeader("Accept", "application/json")
|
|
.WithHeader("User-Agent", "Kavita")
|
|
.GetJsonAsync<GithubReleaseMetadata>();
|
|
|
|
return update;
|
|
}
|
|
|
|
private static async Task<IEnumerable<GithubReleaseMetadata>> GetGithubReleases()
|
|
{
|
|
var update = await GithubAllReleasesUrl
|
|
.WithHeader("Accept", "application/json")
|
|
.WithHeader("User-Agent", "Kavita")
|
|
.GetJsonAsync<IEnumerable<GithubReleaseMetadata>>();
|
|
|
|
return update;
|
|
}
|
|
}
|
|
}
|