Koreader progress sync interface (#3025)
Co-authored-by: Joe Milazzo <josephmajora@gmail.com>
This commit is contained in:
parent
1a88dd4fc0
commit
180b49b8ea
45 changed files with 5848 additions and 8312 deletions
|
@ -26,5 +26,10 @@
|
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="Data\AesopsFables.epub">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
BIN
API.Benchmark/Data/AesopsFables.epub
Normal file
BIN
API.Benchmark/Data/AesopsFables.epub
Normal file
Binary file not shown.
44
API.Benchmark/KoreaderHashBenchmark.cs
Normal file
44
API.Benchmark/KoreaderHashBenchmark.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using API.Helpers.Builders;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Order;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using API.Entities.Enums;
|
||||
|
||||
namespace API.Benchmark
|
||||
{
|
||||
[StopOnFirstError]
|
||||
[MemoryDiagnoser]
|
||||
[RankColumn]
|
||||
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
|
||||
[SimpleJob(launchCount: 1, warmupCount: 5, invocationCount: 20)]
|
||||
public class KoreaderHashBenchmark
|
||||
{
|
||||
private const string sourceEpub = "./Data/AesopsFables.epub";
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void TestBuildManga_baseline()
|
||||
{
|
||||
var file = new MangaFileBuilder(sourceEpub, MangaFormat.Epub)
|
||||
.Build();
|
||||
if (file == null)
|
||||
{
|
||||
throw new Exception("Failed to build manga file");
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void TestBuildManga_withHash()
|
||||
{
|
||||
var file = new MangaFileBuilder(sourceEpub, MangaFormat.Epub)
|
||||
.WithHash()
|
||||
.Build();
|
||||
if (file == null)
|
||||
{
|
||||
throw new Exception("Failed to build manga file");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,12 +6,12 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="21.0.29" />
|
||||
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="21.0.29" />
|
||||
<PackageReference Include="xunit" Version="2.9.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
@ -35,4 +35,10 @@
|
|||
<None Remove="Extensions\Test Data\modified on run.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Data\AesopsFables.epub">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
BIN
API.Tests/Data/AesopsFables.epub
Normal file
BIN
API.Tests/Data/AesopsFables.epub
Normal file
Binary file not shown.
60
API.Tests/Helpers/KoreaderHelperTests.cs
Normal file
60
API.Tests/Helpers/KoreaderHelperTests.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using API.DTOs.Koreader;
|
||||
using API.DTOs.Progress;
|
||||
using API.Helpers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Xunit;
|
||||
|
||||
namespace API.Tests.Helpers;
|
||||
|
||||
|
||||
public class KoreaderHelperTests
|
||||
{
|
||||
|
||||
[Theory]
|
||||
[InlineData("/body/DocFragment[11]/body/div/a", 10, null)]
|
||||
[InlineData("/body/DocFragment[1]/body/div/p[40]", 0, 40)]
|
||||
[InlineData("/body/DocFragment[8]/body/div/p[28]/text().264", 7, 28)]
|
||||
public void GetEpubPositionDto(string koreaderPosition, int page, int? pNumber)
|
||||
{
|
||||
var expected = EmptyProgressDto();
|
||||
expected.BookScrollId = pNumber.HasValue ? $"//html[1]/BODY/APP-ROOT[1]/DIV[1]/DIV[1]/DIV[1]/APP-BOOK-READER[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/P[{pNumber}]" : null;
|
||||
expected.PageNum = page;
|
||||
var actual = EmptyProgressDto();
|
||||
|
||||
KoreaderHelper.UpdateProgressDto(koreaderPosition, actual);
|
||||
Assert.Equal(expected.BookScrollId, actual.BookScrollId);
|
||||
Assert.Equal(expected.PageNum, actual.PageNum);
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData("//html[1]/BODY/APP-ROOT[1]/DIV[1]/DIV[1]/DIV[1]/APP-BOOK-READER[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/P[20]", 5, "/body/DocFragment[6]/body/div/p[20]")]
|
||||
[InlineData(null, 10, "/body/DocFragment[11]/body/div/a")]
|
||||
public void GetKoreaderPosition(string scrollId, int page, string koreaderPosition)
|
||||
{
|
||||
var given = EmptyProgressDto();
|
||||
given.BookScrollId = scrollId;
|
||||
given.PageNum = page;
|
||||
|
||||
Assert.Equal(koreaderPosition, KoreaderHelper.GetKoreaderPosition(given));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("./Data/AesopsFables.epub", "8795ACA4BF264B57C1EEDF06A0CEE688")]
|
||||
public void GetKoreaderHash(string filePath, string hash)
|
||||
{
|
||||
Assert.Equal(KoreaderHelper.HashContents(filePath), hash);
|
||||
}
|
||||
|
||||
private ProgressDto EmptyProgressDto()
|
||||
{
|
||||
return new ProgressDto
|
||||
{
|
||||
ChapterId = 0,
|
||||
PageNum = 0,
|
||||
VolumeId = 0,
|
||||
SeriesId = 0,
|
||||
LibraryId = 0
|
||||
};
|
||||
}
|
||||
}
|
|
@ -12,11 +12,13 @@
|
|||
<LangVersion>latestmajor</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- <Target Name="PostBuild" AfterTargets="Build" Condition=" '$(Configuration)' == 'Debug' ">-->
|
||||
<!-- <Delete Files="../openapi.json" />-->
|
||||
<!-- <Exec Command="swagger tofile --output ../openapi.json bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).dll v1" />-->
|
||||
<!-- </Target>-->
|
||||
<Target Name="PostBuild" AfterTargets="Build" Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<Delete Files="../openapi.json" />
|
||||
<Exec Command="swagger tofile --output ../openapi.json bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).dll v1" />
|
||||
</Target>
|
||||
|
||||
=======
|
||||
>>>>>>> fc7f84f2bffadf9a0127d35fa01166c847b20dc0
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<ApplicationIcon>../favicon.ico</ApplicationIcon>
|
||||
|
@ -55,41 +57,41 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CsvHelper" Version="33.0.1" />
|
||||
<PackageReference Include="MailKit" Version="4.7.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
|
||||
<PackageReference Include="MailKit" Version="4.8.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||
<PackageReference Include="Docnet.Core" Version="2.6.0" />
|
||||
<PackageReference Include="EasyCaching.InMemory" Version="1.9.2" />
|
||||
<PackageReference Include="ExCSS" Version="4.2.5" />
|
||||
<PackageReference Include="ExCSS" Version="4.3.0" />
|
||||
<PackageReference Include="Flurl" Version="3.0.7" />
|
||||
<PackageReference Include="Flurl.Http" Version="3.2.4" />
|
||||
<PackageReference Include="Hangfire" Version="1.8.14" />
|
||||
<PackageReference Include="Hangfire" Version="1.8.15" />
|
||||
<PackageReference Include="Hangfire.InMemory" Version="1.0.0" />
|
||||
<PackageReference Include="Hangfire.MaximumConcurrentExecutions" Version="1.1.0" />
|
||||
<PackageReference Include="Hangfire.Storage.SQLite" Version="0.4.2" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.66" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.69" />
|
||||
<PackageReference Include="MarkdownDeep.NET.Core" Version="1.5.0.4" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.14" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.15" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
|
||||
<PackageReference Include="MimeTypeMapOfficial" Version="1.0.17" />
|
||||
<PackageReference Include="Nager.ArticleNumber" Version="1.0.7" />
|
||||
<PackageReference Include="NetVips" Version="2.4.1" />
|
||||
<PackageReference Include="NetVips" Version="2.4.2" />
|
||||
<PackageReference Include="NetVips.Native" Version="8.15.3" />
|
||||
<PackageReference Include="NReco.Logging.File" Version="1.2.1" />
|
||||
<PackageReference Include="Serilog" Version="4.0.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.AspNetCore.SignalR" Version="0.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
|
@ -100,11 +102,11 @@
|
|||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
|
||||
<PackageReference Include="System.IO.Abstractions" Version="21.0.29" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.8" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
<PackageReference Include="VersOne.Epub" Version="3.3.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
99
API/Controllers/KoreaderController.cs
Normal file
99
API/Controllers/KoreaderController.cs
Normal file
|
@ -0,0 +1,99 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using API.Data;
|
||||
using API.Data.Repositories;
|
||||
using API.DTOs.Koreader;
|
||||
using API.Entities;
|
||||
using API.Services;
|
||||
using Kavita.Common;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static System.Net.WebRequestMethods;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// The endpoint to interface with Koreader's Progress Sync plugin.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Koreader uses a different form of athentication. It stores the user name
|
||||
/// and password in headers.
|
||||
/// </remarks>
|
||||
/// <see cref="https://github.com/koreader/koreader/blob/master/plugins/kosync.koplugin/KOSyncClient.lua"/>
|
||||
[AllowAnonymous]
|
||||
public class KoreaderController : BaseApiController
|
||||
{
|
||||
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IKoreaderService _koreaderService;
|
||||
private readonly ILogger<KoreaderController> _logger;
|
||||
|
||||
public KoreaderController(IUnitOfWork unitOfWork, ILocalizationService localizationService,
|
||||
IKoreaderService koreaderService, ILogger<KoreaderController> logger)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_localizationService = localizationService;
|
||||
_koreaderService = koreaderService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// We won't allow users to be created from Koreader. Rather, they
|
||||
// must already have an account.
|
||||
/*
|
||||
[HttpPost("/users/create")]
|
||||
public IActionResult CreateUser(CreateUserRequest request)
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
[HttpGet("{apiKey}/users/auth")]
|
||||
public async Task<IActionResult> Authenticate(string apiKey)
|
||||
{
|
||||
var userId = await GetUserId(apiKey);
|
||||
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);
|
||||
|
||||
return Ok(new { username = user.UserName });
|
||||
}
|
||||
|
||||
|
||||
[HttpPut("{apiKey}/syncs/progress")]
|
||||
public async Task<IActionResult> UpdateProgress(string apiKey, KoreaderBookDto request)
|
||||
{
|
||||
_logger.LogDebug("Koreader sync progress: {Progress}", request.Progress);
|
||||
var userId = await GetUserId(apiKey);
|
||||
await _koreaderService.SaveProgress(request, userId);
|
||||
|
||||
return Ok(new { document = request.Document, timestamp = DateTime.UtcNow });
|
||||
}
|
||||
|
||||
[HttpGet("{apiKey}/syncs/progress/{ebookHash}")]
|
||||
public async Task<IActionResult> GetProgress(string apiKey, string ebookHash)
|
||||
{
|
||||
var userId = await GetUserId(apiKey);
|
||||
var response = await _koreaderService.GetProgress(ebookHash, userId);
|
||||
_logger.LogDebug("Koreader response progress: {Progress}", response.Progress);
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user from the API key
|
||||
/// </summary>
|
||||
/// <returns>The user's Id</returns>
|
||||
private async Task<int> GetUserId(string apiKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new KavitaException(await _localizationService.Get("en", "user-doesnt-exist"));
|
||||
}
|
||||
}
|
||||
}
|
33
API/DTOs/Koreader/KoreaderBookDto.cs
Normal file
33
API/DTOs/Koreader/KoreaderBookDto.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using API.DTOs.Progress;
|
||||
|
||||
namespace API.DTOs.Koreader;
|
||||
|
||||
/// <summary>
|
||||
/// This is the interface for receiving and sending updates to Koreader. The only fields
|
||||
/// that are actually used are the Document and Progress fields.
|
||||
/// </summary>
|
||||
public class KoreaderBookDto
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the Koreader hash of the book. It is used to identify the book.
|
||||
/// </summary>
|
||||
public string Document { get; set; }
|
||||
/// <summary>
|
||||
/// A randomly generated id from the koreader device. Only used to maintain the Koreader interface.
|
||||
/// </summary>
|
||||
public string Device_id { get; set; }
|
||||
/// <summary>
|
||||
/// The Koreader device name. Only used to maintain the Koreader interface.
|
||||
/// </summary>
|
||||
public string Device { get; set; }
|
||||
/// <summary>
|
||||
/// Percent progress of the book. Only used to maintain the Koreader interface.
|
||||
/// </summary>
|
||||
public float Percentage { get; set; }
|
||||
/// <summary>
|
||||
/// An XPath string read by Koreader to determine the location within the epub.
|
||||
/// Essentially, it is Koreader's equivalent to ProgressDto.BookScrollId.
|
||||
/// </summary>
|
||||
/// <seealso cref="ProgressDto.BookScrollId"/>
|
||||
public string Progress { get; set; }
|
||||
}
|
3148
API/Data/Migrations/20240914041512_KoreaderHash.Designer.cs
generated
Normal file
3148
API/Data/Migrations/20240914041512_KoreaderHash.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
28
API/Data/Migrations/20240914041512_KoreaderHash.cs
Normal file
28
API/Data/Migrations/20240914041512_KoreaderHash.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class KoreaderHash : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "KoreaderHash",
|
||||
table: "MangaFile",
|
||||
type: "TEXT",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "KoreaderHash",
|
||||
table: "MangaFile");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1174,6 +1174,9 @@ namespace API.Data.Migrations
|
|||
b.Property<int>("Format")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("KoreaderHash")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastFileAnalysis")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
|
@ -10,6 +11,7 @@ public interface IMangaFileRepository
|
|||
{
|
||||
void Update(MangaFile file);
|
||||
Task<IList<MangaFile>> GetAllWithMissingExtension();
|
||||
Task<MangaFile> GetByKoreaderHash(string hash);
|
||||
}
|
||||
|
||||
public class MangaFileRepository : IMangaFileRepository
|
||||
|
@ -32,4 +34,10 @@ public class MangaFileRepository : IMangaFileRepository
|
|||
.Where(f => string.IsNullOrEmpty(f.Extension))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public Task<MangaFile> GetByKoreaderHash(string hash)
|
||||
{
|
||||
return _context.MangaFile
|
||||
.FirstOrDefaultAsync(f => f.KoreaderHash == hash.ToUpper());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using API.Entities.Enums;
|
||||
|
@ -21,6 +21,11 @@ public class MangaFile : IEntityDate
|
|||
/// </summary>
|
||||
public required string FilePath { get; set; }
|
||||
/// <summary>
|
||||
/// A hash of the document using Koreader's unique hashing algorithm
|
||||
/// <remark> KoreaderHash is only available for epub types </remark>
|
||||
/// </summary>
|
||||
public string? KoreaderHash { get; set; }
|
||||
/// <summary>
|
||||
/// Number of pages for the given file
|
||||
/// </summary>
|
||||
public int Pages { get; set; }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.IO.Abstractions;
|
||||
using System.IO.Abstractions;
|
||||
using API.Constants;
|
||||
using API.Data;
|
||||
using API.Helpers;
|
||||
|
@ -54,6 +54,7 @@ public static class ApplicationServiceExtensions
|
|||
services.AddScoped<IMediaConversionService, MediaConversionService>();
|
||||
services.AddScoped<IRecommendationService, RecommendationService>();
|
||||
services.AddScoped<IStreamService, StreamService>();
|
||||
services.AddScoped<IKoreaderService, KoreaderService>();
|
||||
|
||||
services.AddScoped<IScannerService, ScannerService>();
|
||||
services.AddScoped<IProcessSeries, ProcessSeries>();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
|
@ -20,7 +20,7 @@ public class MangaFileBuilder : IEntityBuilder<MangaFile>
|
|||
Pages = pages,
|
||||
LastModified = File.GetLastWriteTime(filePath),
|
||||
LastModifiedUtc = File.GetLastWriteTimeUtc(filePath),
|
||||
FileName = Parser.RemoveExtensionIfSupported(filePath)
|
||||
FileName = Parser.RemoveExtensionIfSupported(filePath),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -60,4 +60,14 @@ public class MangaFileBuilder : IEntityBuilder<MangaFile>
|
|||
_mangaFile.Id = Math.Max(id, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MangaFileBuilder WithHash()
|
||||
{
|
||||
if (_mangaFile.Format == MangaFormat.Epub)
|
||||
{
|
||||
_mangaFile.KoreaderHash = KoreaderHelper.HashContents(_mangaFile.FilePath);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
107
API/Helpers/KoreaderHelper.cs
Normal file
107
API/Helpers/KoreaderHelper.cs
Normal file
|
@ -0,0 +1,107 @@
|
|||
using API.DTOs.Koreader;
|
||||
using API.DTOs.Progress;
|
||||
using API.Services;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace API.Helpers;
|
||||
|
||||
public static class KoreaderHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Hashes the document according to a custom Koreader hashing algorithm.
|
||||
/// Look at the util.partialMD5 method in the attached link.
|
||||
/// </summary>
|
||||
/// <remarks>The hashing algorithm is relatively quick as it only hashes ~10,000 bytes for the biggest of files.</remarks>
|
||||
/// <see href="https://github.com/koreader/koreader/blob/master/frontend/util.lua#L1040"/>
|
||||
/// <param name="filePath">The path to the file to hash</param>
|
||||
public static string HashContents(string filePath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var file = File.OpenRead(filePath);
|
||||
|
||||
var step = 1024;
|
||||
var size = 1024;
|
||||
MD5 md5 = MD5.Create();
|
||||
byte[] buffer = new byte[size];
|
||||
|
||||
for (var i = -1; i < 10; i++)
|
||||
{
|
||||
file.Position = step << 2 * i;
|
||||
var bytesRead = file.Read(buffer, 0, size);
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
md5.TransformBlock(buffer, 0, bytesRead, buffer, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
file.Close();
|
||||
md5.TransformFinalBlock(new byte[0], 0, 0);
|
||||
|
||||
return BitConverter.ToString(md5.Hash).Replace("-", string.Empty).ToUpper();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Koreader can identitfy documents based on contents or title.
|
||||
/// For now we only support by contents.
|
||||
/// </summary>
|
||||
public static string HashTitle(string filePath)
|
||||
{
|
||||
var fileName = Path.GetFileName(filePath);
|
||||
var fileNameBytes = Encoding.ASCII.GetBytes(fileName);
|
||||
var bytes = MD5.HashData(fileNameBytes);
|
||||
|
||||
return BitConverter.ToString(bytes).Replace("-", string.Empty);
|
||||
}
|
||||
|
||||
public static void UpdateProgressDto(string koreaderPosition, ProgressDto progress)
|
||||
{
|
||||
var path = koreaderPosition.Split('/');
|
||||
if (path.Length < 6)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var docNumber = path[2].Replace("DocFragment[", string.Empty).Replace("]", string.Empty);
|
||||
progress.PageNum = Int32.Parse(docNumber) - 1;
|
||||
var lastTag = path[5].ToUpper();
|
||||
if (lastTag == "A")
|
||||
{
|
||||
progress.BookScrollId = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The format that Kavita accpets as a progress string. It tells Kavita where Koreader last left off.
|
||||
progress.BookScrollId = $"//html[1]/BODY/APP-ROOT[1]/DIV[1]/DIV[1]/DIV[1]/APP-BOOK-READER[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/{lastTag}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static string GetKoreaderPosition(ProgressDto progressDto)
|
||||
{
|
||||
string lastTag;
|
||||
var koreaderPageNumber = progressDto.PageNum + 1;
|
||||
if (string.IsNullOrEmpty(progressDto.BookScrollId))
|
||||
{
|
||||
lastTag = "a";
|
||||
}
|
||||
else
|
||||
{
|
||||
lastTag = progressDto.BookScrollId.Split('/').Last().ToLower();
|
||||
}
|
||||
// The format that Koreader accepts as a progress string. It tells Koreader where Kavita last left off.
|
||||
return $"/body/DocFragment[{koreaderPageNumber}]/body/div/{lastTag}";
|
||||
}
|
||||
}
|
60
API/Services/KoreaderService.cs
Normal file
60
API/Services/KoreaderService.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using System.Threading.Tasks;
|
||||
using API.Data;
|
||||
using API.DTOs.Koreader;
|
||||
using API.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace API.Services;
|
||||
|
||||
#nullable enable
|
||||
|
||||
public interface IKoreaderService
|
||||
{
|
||||
Task SaveProgress(KoreaderBookDto koreaderBookDto, int userId);
|
||||
Task<KoreaderBookDto> GetProgress(string bookHash, int userId);
|
||||
}
|
||||
|
||||
public class KoreaderService : IKoreaderService
|
||||
{
|
||||
private IReaderService _readerService;
|
||||
private IUnitOfWork _unitOfWork;
|
||||
private ILogger<KoreaderService> _logger;
|
||||
|
||||
public KoreaderService(IReaderService readerService, IUnitOfWork unitOfWork,
|
||||
ILogger<KoreaderService> logger)
|
||||
{
|
||||
_readerService = readerService;
|
||||
_unitOfWork = unitOfWork;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task SaveProgress(KoreaderBookDto koreaderBookDto, int userId)
|
||||
{
|
||||
var file = await _unitOfWork.MangaFileRepository.GetByKoreaderHash(koreaderBookDto.Document);
|
||||
var userProgressDto = await _unitOfWork.AppUserProgressRepository.GetUserProgressDtoAsync(file.ChapterId, userId);
|
||||
|
||||
_logger.LogInformation("Saving Koreader progress to Kavita: {KoreaderProgress}", koreaderBookDto.Progress);
|
||||
KoreaderHelper.UpdateProgressDto(koreaderBookDto.Progress, userProgressDto);
|
||||
await _readerService.SaveReadingProgress(userProgressDto, userId);
|
||||
|
||||
await _unitOfWork.CommitAsync();
|
||||
}
|
||||
|
||||
public async Task<KoreaderBookDto> GetProgress(string bookHash, int userId)
|
||||
{
|
||||
var file = await _unitOfWork.MangaFileRepository.GetByKoreaderHash(bookHash);
|
||||
var progressDto = await _unitOfWork.AppUserProgressRepository.GetUserProgressDtoAsync(file.ChapterId, userId);
|
||||
_logger.LogInformation("Transmitting Kavita progress to Koreader: {KoreaderProgress}", progressDto.BookScrollId);
|
||||
var koreaderProgress = KoreaderHelper.GetKoreaderPosition(progressDto);
|
||||
var settingsDto = await _unitOfWork.SettingsRepository.GetSettingsDtoAsync();
|
||||
|
||||
return new KoreaderBookDto
|
||||
{
|
||||
Document = bookHash,
|
||||
Device_id = settingsDto.InstallId,
|
||||
Device = "Kavita",
|
||||
Progress = koreaderProgress,
|
||||
Percentage = progressDto.PageNum / (float) file.Pages
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
@ -816,6 +816,7 @@ public class ProcessSeries : IProcessSeries
|
|||
var file = new MangaFileBuilder(info.FullFilePath, info.Format, _readingItemService.GetNumberOfPages(info.FullFilePath, info.Format))
|
||||
.WithExtension(fileInfo.Extension)
|
||||
.WithBytes(fileInfo.Length)
|
||||
.WithHash()
|
||||
.Build();
|
||||
chapter.Files.Add(file);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Company>kavitareader.com</Company>
|
||||
<Product>Kavita</Product>
|
||||
<AssemblyVersion>0.8.3.17</AssemblyVersion>
|
||||
<AssemblyVersion>0.8.3.18</AssemblyVersion>
|
||||
<NeutralLanguage>en</NeutralLanguage>
|
||||
<TieredPGO>true</TieredPGO>
|
||||
</PropertyGroup>
|
||||
|
@ -13,11 +13,11 @@
|
|||
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
|
||||
<PackageReference Include="Flurl.Http" Version="3.2.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
|
||||
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.32.0.97167">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit.assert" Version="2.9.1" />
|
||||
<PackageReference Include="xunit.assert" Version="2.9.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -24,13 +24,14 @@
|
|||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:application",
|
||||
"builder": "@angular/build:application",
|
||||
"options": {
|
||||
"outputPath": "dist",
|
||||
"index": "src/index.html",
|
||||
"browser": "src/main.ts",
|
||||
"polyfills": [
|
||||
"zone.js"
|
||||
"@angular/localize/init",
|
||||
"zone.js"
|
||||
],
|
||||
"inlineStyleLanguage": "scss",
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
|
@ -87,7 +88,7 @@
|
|||
"defaultConfiguration": ""
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"builder": "@angular/build:dev-server",
|
||||
"options": {
|
||||
"sslKey": "./ssl/server.key",
|
||||
"sslCert": "./ssl/server.crt",
|
||||
|
@ -101,7 +102,7 @@
|
|||
}
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||
"builder": "@angular/build:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "kavita-webui:build"
|
||||
}
|
||||
|
|
10310
UI/Web/package-lock.json
generated
10310
UI/Web/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -16,70 +16,69 @@
|
|||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^17.3.4",
|
||||
"@angular/cdk": "^17.3.4",
|
||||
"@angular/common": "^17.3.4",
|
||||
"@angular/compiler": "^17.3.4",
|
||||
"@angular/core": "^17.3.4",
|
||||
"@angular/forms": "^17.3.4",
|
||||
"@angular/localize": "^17.3.4",
|
||||
"@angular/platform-browser": "^17.3.4",
|
||||
"@angular/platform-browser-dynamic": "^17.3.4",
|
||||
"@angular/router": "^17.3.4",
|
||||
"@fortawesome/fontawesome-free": "^6.5.2",
|
||||
"@angular-slider/ngx-slider": "^18.0.0",
|
||||
"@angular/animations": "^18.2.9",
|
||||
"@angular/cdk": "^18.2.10",
|
||||
"@angular/common": "^18.2.9",
|
||||
"@angular/compiler": "^18.2.9",
|
||||
"@angular/core": "^18.2.9",
|
||||
"@angular/forms": "^18.2.9",
|
||||
"@angular/localize": "^18.2.9",
|
||||
"@angular/platform-browser": "^18.2.9",
|
||||
"@angular/platform-browser-dynamic": "^18.2.9",
|
||||
"@angular/router": "^18.2.9",
|
||||
"@fortawesome/fontawesome-free": "^6.6.0",
|
||||
"@iharbeck/ngx-virtual-scroller": "^17.0.2",
|
||||
"@iplab/ngx-file-upload": "^17.1.0",
|
||||
"@jsverse/transloco": "^7.4.3",
|
||||
"@iplab/ngx-file-upload": "^18.0.0",
|
||||
"@jsverse/transloco": "^7.5.0",
|
||||
"@jsverse/transloco-locale": "^7.0.1",
|
||||
"@jsverse/transloco-persist-lang": "^7.0.1",
|
||||
"@jsverse/transloco-persist-lang": "^7.0.2",
|
||||
"@jsverse/transloco-persist-translations": "^7.0.1",
|
||||
"@jsverse/transloco-preload-langs": "^7.0.1",
|
||||
"@microsoft/signalr": "^7.0.14",
|
||||
"@ng-bootstrap/ng-bootstrap": "^16.0.0",
|
||||
"@microsoft/signalr": "^8.0.7",
|
||||
"@ng-bootstrap/ng-bootstrap": "^17.0.1",
|
||||
"@popperjs/core": "^2.11.7",
|
||||
"@swimlane/ngx-charts": "^20.5.0",
|
||||
"@tweenjs/tween.js": "^23.1.1",
|
||||
"@tweenjs/tween.js": "^23.1.3",
|
||||
"bootstrap": "^5.3.2",
|
||||
"charts.css": "^1.1.0",
|
||||
"file-saver": "^2.0.5",
|
||||
"luxon": "^3.4.4",
|
||||
"luxon": "^3.5.0",
|
||||
"ng-circle-progress": "^1.7.1",
|
||||
"ng-lazyload-image": "^9.1.3",
|
||||
"ng-select2-component": "^14.0.1",
|
||||
"ngx-color-picker": "^16.0.0",
|
||||
"ngx-extended-pdf-viewer": "^18.1.9",
|
||||
"ngx-color-picker": "^17.0.0",
|
||||
"ngx-extended-pdf-viewer": "^21.4.6",
|
||||
"ngx-file-drop": "^16.0.0",
|
||||
"ngx-slider-v2": "^17.0.0",
|
||||
"ngx-stars": "^1.6.5",
|
||||
"ngx-toaster": "^1.0.1",
|
||||
"ngx-toastr": "^18.0.0",
|
||||
"ngx-toastr": "^19.0.0",
|
||||
"nosleep.js": "^0.12.0",
|
||||
"rxjs": "^7.8.0",
|
||||
"screenfull": "^6.0.2",
|
||||
"swiper": "^8.4.6",
|
||||
"tslib": "^2.6.2",
|
||||
"zone.js": "^0.14.3"
|
||||
"tslib": "^2.8.0",
|
||||
"zone.js": "^0.14.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "^17.3.4",
|
||||
"@angular-eslint/builder": "^17.3.0",
|
||||
"@angular-eslint/eslint-plugin": "^17.3.0",
|
||||
"@angular-eslint/eslint-plugin-template": "^17.3.0",
|
||||
"@angular-eslint/schematics": "^17.3.0",
|
||||
"@angular-eslint/template-parser": "^17.3.0",
|
||||
"@angular/cli": "^17.3.4",
|
||||
"@angular/compiler-cli": "^17.3.4",
|
||||
"@angular-eslint/builder": "^18.4.0",
|
||||
"@angular-eslint/eslint-plugin": "^18.4.0",
|
||||
"@angular-eslint/eslint-plugin-template": "^18.4.0",
|
||||
"@angular-eslint/schematics": "^18.4.0",
|
||||
"@angular-eslint/template-parser": "^18.4.0",
|
||||
"@angular/build": "^18.2.10",
|
||||
"@angular/cli": "^18.2.10",
|
||||
"@angular/compiler-cli": "^18.2.9",
|
||||
"@types/d3": "^7.4.3",
|
||||
"@types/file-saver": "^2.0.7",
|
||||
"@types/luxon": "^3.4.0",
|
||||
"@types/node": "^20.10.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
||||
"@typescript-eslint/parser": "^7.2.0",
|
||||
"@types/node": "^22.8.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
||||
"@typescript-eslint/parser": "^8.11.0",
|
||||
"eslint": "^8.57.0",
|
||||
"jsonminify": "^0.4.2",
|
||||
"karma-coverage": "~2.2.0",
|
||||
"ts-node": "~10.9.1",
|
||||
"typescript": "^5.2.2",
|
||||
"typescript": "^5.5.4",
|
||||
"webpack-bundle-analyzer": "^4.10.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
} from '@angular/common/http';
|
||||
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { Router } from '@angular/router';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
} from '@angular/common/http';
|
||||
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
|
||||
import {Observable, switchMap} from 'rxjs';
|
||||
import { AccountService } from '../_services/account.service';
|
||||
import { take } from 'rxjs/operators';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {environment} from "../../environments/environment";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import {Chapter} from "../_models/chapter";
|
||||
import {TextResonse} from "../_types/text-response";
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {HttpClient} from '@angular/common/http';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {environment} from 'src/environments/environment';
|
||||
import {UserCollection} from '../_models/collection-tag';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {TextResonse} from "../_types/text-response";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import {environment} from "../../environments/environment";
|
||||
import {DashboardStream} from "../_models/dashboard/dashboard-stream";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {environment} from "../../environments/environment";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import {ExternalSource} from "../_models/sidenav/external-source";
|
||||
import {TextResonse} from "../_types/text-response";
|
||||
import {map} from "rxjs/operators";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {SeriesFilterV2} from "../_models/metadata/v2/series-filter-v2";
|
||||
import {environment} from "../../environments/environment";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import {JumpKey} from "../_models/jumpbar/jump-key";
|
||||
import {SmartFilter} from "../_models/metadata/v2/smart-filter";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {environment} from "../../environments/environment";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import {Language} from "../_models/metadata/language";
|
||||
|
||||
@Injectable({
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {HttpClient} from '@angular/common/http';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {tap} from 'rxjs/operators';
|
||||
import {of} from 'rxjs';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {DOCUMENT} from '@angular/common';
|
||||
import {DestroyRef, inject, Inject, Injectable, Renderer2, RendererFactory2, RendererStyleFlags2} from '@angular/core';
|
||||
import {distinctUntilChanged, filter, ReplaySubject, take} from 'rxjs';
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import {environment} from "../../environments/environment";
|
||||
import {SideNavStream} from "../_models/sidenav/sidenav-stream";
|
||||
import {TextResonse} from "../_types/text-response";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {HttpClient, HttpParams} from "@angular/common/http";
|
||||
import { HttpClient, HttpParams } from "@angular/common/http";
|
||||
import {environment} from "../../environments/environment";
|
||||
import {Person, PersonRole} from "../_models/metadata/person";
|
||||
import {SeriesFilterV2} from "../_models/metadata/v2/series-filter-v2";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import {Injectable} from '@angular/core';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {DOCUMENT} from '@angular/common';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {
|
||||
DestroyRef,
|
||||
inject,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {environment} from "../../environments/environment";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import {Volume} from "../_models/volume";
|
||||
import {TextResonse} from "../_types/text-response";
|
||||
|
||||
|
|
|
@ -121,18 +121,18 @@ export class AppComponent implements OnInit {
|
|||
this.libraryService.getLibraryNames().pipe(take(1), shareReplay({refCount: true, bufferSize: 1})).subscribe();
|
||||
|
||||
// Get the server version, compare vs localStorage, and if different bust locale cache
|
||||
const versionKey = 'kavita--version';
|
||||
this.serverService.getVersion(user.apiKey).subscribe(version => {
|
||||
const cachedVersion = localStorage.getItem('kavita--version');
|
||||
const cachedVersion = localStorage.getItem(versionKey);
|
||||
console.log('Kavita version: ', version, ' Running version: ', cachedVersion);
|
||||
|
||||
if (cachedVersion == null || cachedVersion != version) {
|
||||
// Bust locale cache
|
||||
localStorage.removeItem('@transloco/translations/timestamp');
|
||||
localStorage.removeItem('@transloco/translations');
|
||||
(this.translocoService as any).cache.delete(localStorage.getItem('kavita-locale') || 'en');
|
||||
(this.translocoService as any).cache.clear();
|
||||
localStorage.setItem('kavita--version', version);
|
||||
this.bustLocaleCache();
|
||||
localStorage.setItem(versionKey, version);
|
||||
location.reload();
|
||||
}
|
||||
localStorage.setItem('kavita--version', version);
|
||||
localStorage.setItem(versionKey, version);
|
||||
});
|
||||
|
||||
// Every hour, have the UI check for an update. People seriously stay out of date
|
||||
|
@ -153,4 +153,12 @@ export class AppComponent implements OnInit {
|
|||
)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
private bustLocaleCache() {
|
||||
localStorage.removeItem('@transloco/translations/timestamp');
|
||||
localStorage.removeItem('@transloco/translations');
|
||||
localStorage.removeItem('translocoLang');
|
||||
(this.translocoService as any).cache.delete(localStorage.getItem('kavita-locale') || 'en');
|
||||
(this.translocoService as any).cache.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import {
|
|||
take,
|
||||
tap
|
||||
} from 'rxjs';
|
||||
import {ChangeContext, LabelType, NgxSliderModule, Options} from 'ngx-slider-v2';
|
||||
import {ChangeContext, LabelType, NgxSliderModule, Options} from '@angular-slider/ngx-slider';
|
||||
import {animate, state, style, transition, trigger} from '@angular/animations';
|
||||
import {FormBuilder, FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
|
||||
import {NgbModal, NgbProgressbar} from '@ng-bootstrap/ng-bootstrap';
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
height="100vh"
|
||||
[(page)]="currentPage"
|
||||
[textLayer]="true"
|
||||
[useBrowserLocale]="true"
|
||||
[showHandToolButton]="true"
|
||||
[showOpenFileButton]="false"
|
||||
[showPrintButton]="false"
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
import {
|
||||
HttpEvent,
|
||||
HttpEventType,
|
||||
HttpHeaders,
|
||||
HttpProgressEvent,
|
||||
HttpResponse
|
||||
} from "@angular/common/http";
|
||||
import { HttpEvent, HttpEventType, HttpHeaders, HttpProgressEvent, HttpResponse } from "@angular/common/http";
|
||||
import { Observable } from "rxjs";
|
||||
import { scan } from "rxjs/operators";
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import {FilterStatement} from "../../_models/metadata/v2/filter-statement";
|
|||
import {FilterCombination} from "../../_models/metadata/v2/filter-combination";
|
||||
import {FilterField} from "../../_models/metadata/v2/filter-field";
|
||||
import {FilterComparison} from "../../_models/metadata/v2/filter-comparison";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import {TextResonse} from "../../_types/text-response";
|
||||
import {environment} from "../../../environments/environment";
|
||||
import {map, tap} from "rxjs/operators";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {Injectable} from "@angular/core";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import {Translation, TranslocoLoader} from "@jsverse/transloco";
|
||||
import cacheBusting from 'i18n-cache-busting.json'; // allowSyntheticDefaultImports must be true
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import { AppRoutingModule } from './app/app-routing.module';
|
|||
import { Title, BrowserModule, bootstrapApplication } from '@angular/platform-browser';
|
||||
import { JwtInterceptor } from './app/_interceptors/jwt.interceptor';
|
||||
import { ErrorInterceptor } from './app/_interceptors/error.interceptor';
|
||||
import {HTTP_INTERCEPTORS, withInterceptorsFromDi, provideHttpClient} from '@angular/common/http';
|
||||
import { HTTP_INTERCEPTORS, withInterceptorsFromDi, provideHttpClient } from '@angular/common/http';
|
||||
import {
|
||||
provideTransloco, TranslocoConfig,
|
||||
TranslocoService
|
||||
|
|
|
@ -6,20 +6,19 @@
|
|||
"outDir": "./dist/out-tsc",
|
||||
"removeComments": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"esModuleInterop": true,
|
||||
"strict": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"declaration": false,
|
||||
"downlevelIteration": true,
|
||||
"experimentalDecorators": true,
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"useDefineForClassFields": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"lib": [
|
||||
"ES2022",
|
||||
"dom"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue