Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
C# annotationscbzcomicinfocomicscomics-readercross-platformcsharpepubepub-readerfreelinuxmangamedia-servermetadataopdsopds-feedpdfself-hostedubooquitywindows
v0.5.0 Release (#960)
Joseph Milazzo41096d6dc5a8
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.mdindex 1fe2d72e8..bfd2bab0a 100644--- a/.github/ISSUE_TEMPLATE/bug_report.md+++ b/.github/ISSUE_TEMPLATE/bug_report.md@@ -9,7 +9,7 @@ assignees: ''**If this is a feature request, request [here](https://feats.kavitareader.com/) instead. Feature requests will be deleted from Github.**-+Please put as much information as possible to help me understand your issue. OS, browser, version are very important!**Describe the bug**A clear and concise description of what the bug is.diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.ymlindex 48a93318a..6673f3f00 100644--- a/.github/workflows/sonar-scan.yml+++ b/.github/workflows/sonar-scan.yml@@ -20,7 +20,8 @@ jobs:- name: Setup .NET Coreuses: actions/setup-dotnet@v1with:- dotnet-version: 5.0.100+ include-prerelease: True+ dotnet-version: '6.0'- name: Install dependenciesrun: dotnet restore@@ -35,67 +36,68 @@ jobs:name: csprojpath: Kavita.Common/Kavita.Common.csproj- test:- name: Install Sonar & Test- needs: build- runs-on: windows-latest- steps:- - name: Checkout Repo- uses: actions/checkout@v2- with:- fetch-depth: 0-- - name: Setup .NET Core- uses: actions/setup-dotnet@v1- with:- dotnet-version: 5.0.100-- - name: Install dependencies- run: dotnet restore-- - name: Set up JDK 11- uses: actions/setup-java@v1- with:- java-version: 1.11-- - name: Cache SonarCloud packages- uses: actions/cache@v1- with:- path: ~\sonar\cache- key: ${{ runner.os }}-sonar- restore-keys: ${{ runner.os }}-sonar-- - name: Cache SonarCloud scanner- id: cache-sonar-scanner- uses: actions/cache@v1- with:- path: .\.sonar\scanner- key: ${{ runner.os }}-sonar-scanner- restore-keys: ${{ runner.os }}-sonar-scanner-- - name: Install SonarCloud scanner- if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'- shell: powershell- run: |- New-Item -Path .\.sonar\scanner -ItemType Directory- dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner-- - name: Sonar Scan- env:- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any- SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}- shell: powershell- run: |- .\.sonar\scanner\dotnet-sonarscanner begin /k:"Kareadita_Kavita" /o:"kareadita" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"- dotnet build --configuration Release- .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"-- - name: Test- run: dotnet test --no-restore --verbosity normal+# test:+# name: Install Sonar & Test+# needs: build+# runs-on: windows-latest+# steps:+# - name: Checkout Repo+# uses: actions/checkout@v2+# with:+# fetch-depth: 0+#+# - name: Setup .NET Core+# uses: actions/setup-dotnet@v1+# with:+# include-prerelease: True+# dotnet-version: '6.0'+#+# - name: Install dependencies+# run: dotnet restore+#+# - name: Set up JDK 11+# uses: actions/setup-java@v1+# with:+# java-version: 1.11+#+# - name: Cache SonarCloud packages+# uses: actions/cache@v1+# with:+# path: ~\sonar\cache+# key: ${{ runner.os }}-sonar+# restore-keys: ${{ runner.os }}-sonar+#+# - name: Cache SonarCloud scanner+# id: cache-sonar-scanner+# uses: actions/cache@v1+# with:+# path: .\.sonar\scanner+# key: ${{ runner.os }}-sonar-scanner+# restore-keys: ${{ runner.os }}-sonar-scanner+#+# - name: Install SonarCloud scanner+# if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'+# shell: powershell+# run: |+# New-Item -Path .\.sonar\scanner -ItemType Directory+# dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner+#+# - name: Sonar Scan+# env:+# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any+# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}+# shell: powershell+# run: |+# .\.sonar\scanner\dotnet-sonarscanner begin /k:"Kareadita_Kavita" /o:"kareadita" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"+# dotnet build --configuration Release+# .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"+#+# - name: Test+# run: dotnet test --no-restore --verbosity normalversion:name: Bump version on Develop push- needs: [ build, test ]+ needs: [ build ]runs-on: ubuntu-latestif: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }}steps:@@ -106,7 +108,8 @@ jobs:- name: Setup .NET Coreuses: actions/setup-dotnet@v1with:- dotnet-version: 5.0.100+ include-prerelease: True+ dotnet-version: '6.0'- name: Install dependenciesrun: dotnet restore@@ -122,7 +125,7 @@ jobs:develop:name: Build Nightly Docker if Develop push- needs: [ build, test, version ]+ needs: [ build, version ]runs-on: ubuntu-latestif: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }}steps:@@ -186,7 +189,8 @@ jobs:- name: Compile dotnet appuses: actions/setup-dotnet@v1with:- dotnet-version: '5.0.x'+ include-prerelease: True+ dotnet-version: '6.0'- run: ./monorepo-build.sh- name: Login to Docker Hub@@ -225,7 +229,7 @@ jobs:stable:name: Build Stable Docker if Main push- needs: [ build, test ]+ needs: [ build ]runs-on: ubuntu-latestif: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}steps:@@ -299,7 +303,8 @@ jobs:- name: Compile dotnet appuses: actions/setup-dotnet@v1with:- dotnet-version: '5.0.x'+ include-prerelease: True+ dotnet-version: '6.0'- run: ./monorepo-build.sh- name: Login to Docker Hubdiff --git a/.gitignore b/.gitignoreindex bc28fac8f..1ee566816 100644--- a/.gitignore+++ b/.gitignore@@ -508,6 +508,7 @@ UI/Web/dist//API/config/cache//API/config/temp//API/config/stats/+/API/config/bookmarks//API/config/kavita.db/API/config/kavita.db-shm/API/config/kavita.db-wal@@ -517,5 +518,8 @@ API/config/covers/API/config/*.dbAPI/config/stats/*API/config/stats/app_stats.json-+API/config/pre-metadata/+API/config/post-metadata/+API.Tests/TestResults/UI/Web/.vscode/settings.json+/API.Tests/Services/Test Data/ArchiveService/CoverImages/output/*diff --git a/API.Benchmark/API.Benchmark.csproj b/API.Benchmark/API.Benchmark.csprojindex d63d24ddc..cbf7d76f9 100644--- a/API.Benchmark/API.Benchmark.csproj+++ b/API.Benchmark/API.Benchmark.csproj@@ -1,7 +1,7 @@<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup>- <TargetFramework>net5.0</TargetFramework>+ <TargetFramework>net6.0</TargetFramework><OutputType>Exe</OutputType></PropertyGroup>diff --git a/API.Benchmark/ParseScannedFilesBenchmarks.cs b/API.Benchmark/ParseScannedFilesBenchmarks.csindex 8681c1261..a180d566f 100644--- a/API.Benchmark/ParseScannedFilesBenchmarks.cs+++ b/API.Benchmark/ParseScannedFilesBenchmarks.cs@@ -1,6 +1,6 @@using System.IO;+using System.IO.Abstractions;using API.Entities.Enums;-using API.Interfaces.Services;using API.Parser;using API.Services;using API.Services.Tasks.Scanner;@@ -20,11 +20,15 @@ namespace API.Benchmarkprivate readonly ParseScannedFiles _parseScannedFiles;private readonly ILogger<ParseScannedFiles> _logger = Substitute.For<ILogger<ParseScannedFiles>>();private readonly ILogger<BookService> _bookLogger = Substitute.For<ILogger<BookService>>();+ private readonly IArchiveService _archiveService = Substitute.For<ArchiveService>();public ParseScannedFilesBenchmarks(){- IBookService bookService = new BookService(_bookLogger);- _parseScannedFiles = new ParseScannedFiles(bookService, _logger);+ var directoryService = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), new FileSystem());+ _parseScannedFiles = new ParseScannedFiles(+ Substitute.For<ILogger>(),+ directoryService,+ new ReadingItemService(_archiveService, new BookService(_bookLogger, directoryService, new ImageService(Substitute.For<ILogger<ImageService>>(), directoryService)), Substitute.For<ImageService>(), directoryService));}// [Benchmark]diff --git a/API.Benchmark/TestBenchmark.cs b/API.Benchmark/TestBenchmark.csindex a2aabdd8a..618a8b93c 100644--- a/API.Benchmark/TestBenchmark.cs+++ b/API.Benchmark/TestBenchmark.cs@@ -3,6 +3,7 @@ using System.Collections.Generic;using System.Linq;using API.Comparators;using API.DTOs;+using API.Extensions;using BenchmarkDotNet.Attributes;using BenchmarkDotNet.Order;@@ -16,9 +17,6 @@ namespace API.Benchmark[RankColumn]public class TestBenchmark{- private readonly NaturalSortComparer _naturalSortComparer = new ();--private static IEnumerable<VolumeDto> GenerateVolumes(int max){var random = new Random();@@ -50,11 +48,11 @@ namespace API.Benchmarkreturn list;}- private void SortSpecialChapters(IEnumerable<VolumeDto> volumes)+ private static void SortSpecialChapters(IEnumerable<VolumeDto> volumes){foreach (var v in volumes.Where(vDto => vDto.Number == 0)){- v.Chapters = v.Chapters.OrderBy(x => x.Range, _naturalSortComparer).ToList();+ v.Chapters = v.Chapters.OrderByNatural(x => x.Range).ToList();}}diff --git a/API.Tests/API.Tests.csproj b/API.Tests/API.Tests.csprojindex 59ecff406..4f268a38a 100644--- a/API.Tests/API.Tests.csproj+++ b/API.Tests/API.Tests.csproj@@ -1,15 +1,16 @@<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup>- <TargetFramework>net5.0</TargetFramework>+ <TargetFramework>net6.0</TargetFramework><IsPackable>false</IsPackable></PropertyGroup><ItemGroup>- <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.10" />- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />+ <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.1" />+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /><PackageReference Include="NSubstitute" Version="4.2.2" />+ <PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="16.1.2" /><PackageReference Include="xunit" Version="2.4.1" /><PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>diff --git a/API.Tests/Comparers/ChapterSortComparerZeroFirstTests.cs b/API.Tests/Comparers/ChapterSortComparerZeroFirstTests.csnew file mode 100644index 000000000..72d6908c6--- /dev/null+++ b/API.Tests/Comparers/ChapterSortComparerZeroFirstTests.cs@@ -0,0 +1,17 @@+using System.Linq;+using API.Comparators;+using Xunit;++namespace API.Tests.Comparers;++public class ChapterSortComparerZeroFirstTests+{+ [Theory]+ [InlineData(new[] {1, 2, 0}, new[] {0, 1, 2,})]+ [InlineData(new[] {3, 1, 2}, new[] {1, 2, 3})]+ [InlineData(new[] {1, 0, 0}, new[] {0, 0, 1})]+ public void ChapterSortComparerZeroFirstTest(int[] input, int[] expected)+ {+ Assert.Equal(expected, input.OrderBy(f => f, new ChapterSortComparerZeroFirst()).ToArray());+ }+}diff --git a/API.Tests/Comparers/NumericComparerTests.cs b/API.Tests/Comparers/NumericComparerTests.csnew file mode 100644index 000000000..9a66e7666--- /dev/null+++ b/API.Tests/Comparers/NumericComparerTests.cs@@ -0,0 +1,26 @@+using System;+using API.Comparators;+using Xunit;++namespace API.Tests.Comparers;++public class NumericComparerTests+{+ [Theory]+ [InlineData(+ new[] {"x1.jpg", "x10.jpg", "x3.jpg", "x4.jpg", "x11.jpg"},+ new[] {"x1.jpg", "x3.jpg", "x4.jpg", "x10.jpg", "x11.jpg"}+ )]+ public void NumericComparerTest(string[] input, string[] expected)+ {+ var nc = new NumericComparer();+ Array.Sort(input, nc);++ var i = 0;+ foreach (var s in input)+ {+ Assert.Equal(s, expected[i]);+ i++;+ }+ }+}diff --git a/API.Tests/Comparers/StringLogicalComparerTest.cs b/API.Tests/Comparers/StringLogicalComparerTest.csindex ae93b3b46..3d13e43ac 100644--- a/API.Tests/Comparers/StringLogicalComparerTest.cs+++ b/API.Tests/Comparers/StringLogicalComparerTest.cs@@ -8,13 +8,20 @@ namespace API.Tests.Comparers{[Theory][InlineData(- new[] {"x1.jpg", "x10.jpg", "x3.jpg", "x4.jpg", "x11.jpg"},- new[] {"x1.jpg", "x3.jpg", "x4.jpg", "x10.jpg", "x11.jpg"}+ new[] {"x1.jpg", "x10.jpg", "x3.jpg", "x4.jpg", "x11.jpg"},+ new[] {"x1.jpg", "x3.jpg", "x4.jpg", "x10.jpg", "x11.jpg"})]- public void TestLogicalComparer(string[] input, string[] expected)+ [InlineData(+ new[] {"a.jpg", "aaa.jpg", "1.jpg", },+ new[] {"1.jpg", "a.jpg", "aaa.jpg"}+ )]+ [InlineData(+ new[] {"a.jpg", "aaa.jpg", "1.jpg", "!cover.png"},+ new[] {"!cover.png", "1.jpg", "a.jpg", "aaa.jpg"}+ )]+ public void StringComparer(string[] input, string[] expected){- NumericComparer nc = new NumericComparer();- Array.Sort(input, nc);+ Array.Sort(input, StringLogicalComparer.Compare);var i = 0;foreach (var s in input)@@ -24,4 +31,4 @@ namespace API.Tests.Comparers}}}-}\ No newline at end of file+}diff --git a/API.Tests/Converters/CronConverterTests.cs b/API.Tests/Converters/CronConverterTests.csindex 34efbd59e..813d82426 100644--- a/API.Tests/Converters/CronConverterTests.cs+++ b/API.Tests/Converters/CronConverterTests.cs@@ -9,9 +9,11 @@ namespace API.Tests.Converters[InlineData("daily", "0 0 * * *")][InlineData("disabled", "0 0 31 2 *")][InlineData("weekly", "0 0 * * 1")]+ [InlineData("", "0 0 31 2 *")]+ [InlineData("sdfgdf", "")]public void ConvertTest(string input, string expected){Assert.Equal(expected, CronConverter.ConvertToCronNotation(input));}}-}\ No newline at end of file+}diff --git a/API.Tests/Entities/ComicInfoTests.cs b/API.Tests/Entities/ComicInfoTests.csnew file mode 100644index 000000000..7b7106eb9--- /dev/null+++ b/API.Tests/Entities/ComicInfoTests.cs@@ -0,0 +1,38 @@+using API.Data.Metadata;+using API.Entities.Enums;+using Xunit;++namespace API.Tests.Entities;++public class ComicInfoTests+{+ #region ConvertAgeRatingToEnum++ [Theory]+ [InlineData("G", AgeRating.G)]+ [InlineData("Everyone", AgeRating.Everyone)]+ [InlineData("Teen", AgeRating.Teen)]+ [InlineData("Adults Only 18+", AgeRating.AdultsOnly)]+ [InlineData("Early Childhood", AgeRating.EarlyChildhood)]+ [InlineData("Everyone 10+", AgeRating.Everyone10Plus)]+ [InlineData("M", AgeRating.Mature)]+ [InlineData("MA 15+", AgeRating.Mature15Plus)]+ [InlineData("Mature 17+", AgeRating.Mature17Plus)]+ [InlineData("Rating Pending", AgeRating.RatingPending)]+ [InlineData("X18+", AgeRating.X18Plus)]+ [InlineData("Kids to Adults", AgeRating.KidsToAdults)]+ [InlineData("NotValid", AgeRating.Unknown)]+ [InlineData("PG", AgeRating.PG)]+ [InlineData("R18+", AgeRating.R18Plus)]+ public void ConvertAgeRatingToEnum_ShouldConvertCorrectly(string input, AgeRating expected)+ {+ Assert.Equal(expected, ComicInfo.ConvertAgeRatingToEnum(input));+ }++ [Fact]+ public void ConvertAgeRatingToEnum_ShouldCompareCaseInsensitive()+ {+ Assert.Equal(AgeRating.RatingPending, ComicInfo.ConvertAgeRatingToEnum("rating pending"));+ }+ #endregion+}diff --git a/API.Tests/Extensions/ChapterListExtensionsTests.cs b/API.Tests/Extensions/ChapterListExtensionsTests.csindex 2251c660b..845b1387b 100644--- a/API.Tests/Extensions/ChapterListExtensionsTests.cs+++ b/API.Tests/Extensions/ChapterListExtensionsTests.cs@@ -1,4 +1,5 @@using System.Collections.Generic;+using System.Linq;using API.Entities;using API.Entities.Enums;using API.Extensions;@@ -9,7 +10,7 @@ namespace API.Tests.Extensions{public class ChapterListExtensionsTests{- private Chapter CreateChapter(string range, string number, MangaFile file, bool isSpecial)+ private static Chapter CreateChapter(string range, string number, MangaFile file, bool isSpecial){return new Chapter(){@@ -20,7 +21,7 @@ namespace API.Tests.Extensions};}- private MangaFile CreateFile(string file, MangaFormat format)+ private static MangaFile CreateFile(string file, MangaFormat format){return new MangaFile(){@@ -28,7 +29,7 @@ namespace API.Tests.ExtensionsFormat = format};}-+[Fact]public void GetAnyChapterByRange_Test_ShouldBeNull(){@@ -51,11 +52,11 @@ namespace API.Tests.Extensions};var actualChapter = chapterList.GetChapterByRange(info);-+Assert.NotEqual(chapterList[0], actualChapter);-+}-+[Fact]public void GetAnyChapterByRange_Test_ShouldBeNotNull(){@@ -78,9 +79,39 @@ namespace API.Tests.Extensions};var actualChapter = chapterList.GetChapterByRange(info);-+Assert.Equal(chapterList[0], actualChapter);-}++ #region GetFirstChapterWithFiles++ [Fact]+ public void GetFirstChapterWithFiles_ShouldReturnAllChapters()+ {+ var chapterList = new List<Chapter>()+ {+ CreateChapter("darker than black", "0", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), true),+ CreateChapter("darker than black", "1", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), false),+ };++ Assert.Equal(chapterList.First(), chapterList.GetFirstChapterWithFiles());+ }++ [Fact]+ public void GetFirstChapterWithFiles_ShouldReturnSecondChapter()+ {+ var chapterList = new List<Chapter>()+ {+ CreateChapter("darker than black", "0", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), true),+ CreateChapter("darker than black", "1", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), false),+ };++ chapterList.First().Files = new List<MangaFile>();++ Assert.Equal(chapterList.Last(), chapterList.GetFirstChapterWithFiles());+ }+++ #endregion}-}\ No newline at end of file+}diff --git a/API.Tests/Comparers/NaturalSortComparerTest.cs b/API.Tests/Extensions/EnumerableExtensionsTests.cssimilarity index 64%rename from API.Tests/Comparers/NaturalSortComparerTest.csrename to API.Tests/Extensions/EnumerableExtensionsTests.csindex b624caac8..0f04ac9d7 100644--- a/API.Tests/Comparers/NaturalSortComparerTest.cs+++ b/API.Tests/Extensions/EnumerableExtensionsTests.cs@@ -1,15 +1,12 @@-using System;-using System.Linq;-using API.Comparators;+using System.Linq;+using API.Extensions;using Xunit;-namespace API.Tests.Comparers-{- public class NaturalSortComparerTest- {- private readonly NaturalSortComparer _nc = new NaturalSortComparer();+namespace API.Tests.Extensions;- [Theory]+public class EnumerableExtensionsTests+{+ [Theory][InlineData(new[] {"x1.jpg", "x10.jpg", "x3.jpg", "x4.jpg", "x11.jpg"},new[] {"x1.jpg", "x3.jpg", "x4.jpg", "x10.jpg", "x11.jpg"}@@ -46,19 +43,43 @@ namespace API.Tests.Comparersnew[] {"Solo Leveling - c000 (v01) - p000 [Cover] [dig] [Yen Press] [LuCaZ].jpg", "Solo Leveling - c000 (v01) - p001 [dig] [Yen Press] [LuCaZ].jpg", "Solo Leveling - c000 (v01) - p002 [dig] [Yen Press] [LuCaZ].jpg", "Solo Leveling - c000 (v01) - p003 [dig] [Yen Press] [LuCaZ].jpg"},new[] {"Solo Leveling - c000 (v01) - p000 [Cover] [dig] [Yen Press] [LuCaZ].jpg", "Solo Leveling - c000 (v01) - p001 [dig] [Yen Press] [LuCaZ].jpg", "Solo Leveling - c000 (v01) - p002 [dig] [Yen Press] [LuCaZ].jpg", "Solo Leveling - c000 (v01) - p003 [dig] [Yen Press] [LuCaZ].jpg"})]- public void TestNaturalSortComparer(string[] input, string[] expected)+ [InlineData(+ new[] {"Marvel2In1-7", "Marvel2In1-7-01", "Marvel2In1-7-02"},+ new[] {"Marvel2In1-7", "Marvel2In1-7-01", "Marvel2In1-7-02"}+ )]+ [InlineData(+ new[] {"001", "002", "!001"},+ new[] {"!001", "001", "002"}+ )]+ [InlineData(+ new[] {"001.jpg", "002.jpg", "!001.jpg"},+ new[] {"!001.jpg", "001.jpg", "002.jpg"}+ )]+ [InlineData(+ new[] {"001", "002", "!002"},+ new[] {"!002", "001", "002"}+ )]+ [InlineData(+ new[] {"001", ""},+ new[] {"", "001"}+ )]+ [InlineData(+ new[] {"Honzuki no Gekokujou_ Part 2/_Ch.019/002.jpg", "Honzuki no Gekokujou_ Part 2/_Ch.019/001.jpg", "Honzuki no Gekokujou_ Part 2/_Ch.020/001.jpg"},+ new[] {"Honzuki no Gekokujou_ Part 2/_Ch.019/001.jpg", "Honzuki no Gekokujou_ Part 2/_Ch.019/002.jpg", "Honzuki no Gekokujou_ Part 2/_Ch.020/001.jpg"}+ )]+ [InlineData(+ new[] {@"F:\/Anime_Series_Pelis/MANGA/Mangahere (EN)\Kirara Fantasia\_Ch.001\001.jpg", @"F:\/Anime_Series_Pelis/MANGA/Mangahere (EN)\Kirara Fantasia\_Ch.001\002.jpg"},+ new[] {@"F:\/Anime_Series_Pelis/MANGA/Mangahere (EN)\Kirara Fantasia\_Ch.001\001.jpg", @"F:\/Anime_Series_Pelis/MANGA/Mangahere (EN)\Kirara Fantasia\_Ch.001\002.jpg"}+ )]+ [InlineData(+ new[] {"01/001.jpg", "001.jpg"},+ new[] {"001.jpg", "01/001.jpg"}+ )]+ public void TestNaturalSort(string[] input, string[] expected){- Array.Sort(input, _nc);-- var i = 0;- foreach (var s in input)- {- Assert.Equal(s, expected[i]);- i++;- }+ Assert.Equal(expected, input.OrderByNatural(x => x).ToArray());}-[Theory][InlineData(new[] {"x1.jpg", "x10.jpg", "x3.jpg", "x4.jpg", "x11.jpg"},@@ -84,6 +105,10 @@ namespace API.Tests.Comparersnew[] {"001.jpg", "10.jpg",},new[] {"001.jpg", "10.jpg",})]+ [InlineData(+ new[] {"001", "002", "!001"},+ new[] {"!001", "001", "002"}+ )][InlineData(new[] {"10/001.jpg", "10.jpg",},new[] {"10.jpg", "10/001.jpg",}@@ -92,9 +117,13 @@ namespace API.Tests.Comparersnew[] {"Batman - Black white vol 1 #04.cbr", "Batman - Black white vol 1 #03.cbr", "Batman - Black white vol 1 #01.cbr", "Batman - Black white vol 1 #02.cbr"},new[] {"Batman - Black white vol 1 #01.cbr", "Batman - Black white vol 1 #02.cbr", "Batman - Black white vol 1 #03.cbr", "Batman - Black white vol 1 #04.cbr"})]- public void TestNaturalSortComparerLinq(string[] input, string[] expected)+ [InlineData(+ new[] {"Honzuki no Gekokujou_ Part 2/_Ch.019/002.jpg", "Honzuki no Gekokujou_ Part 2/_Ch.019/001.jpg"},+ new[] {"Honzuki no Gekokujou_ Part 2/_Ch.019/001.jpg", "Honzuki no Gekokujou_ Part 2/_Ch.019/002.jpg"}+ )]+ public void TestNaturalSortLinq(string[] input, string[] expected){- var output = input.OrderBy(c => c, _nc);+ var output = input.OrderByNatural(x => x);var i = 0;foreach (var s in output)@@ -103,5 +132,4 @@ namespace API.Tests.Comparersi++;}}- }}diff --git a/API.Tests/Extensions/FilterDtoExtensionsTests.cs b/API.Tests/Extensions/FilterDtoExtensionsTests.csnew file mode 100644index 000000000..c9985f509--- /dev/null+++ b/API.Tests/Extensions/FilterDtoExtensionsTests.cs@@ -0,0 +1,48 @@+using System;+using System.Collections.Generic;+using API.DTOs.Filtering;+using API.Entities.Enums;+using API.Extensions;+using Xunit;++namespace API.Tests.Extensions;++public class FilterDtoExtensionsTests+{+ [Fact]+ public void GetSqlFilter_ShouldReturnAllFormats()+ {+ var filter = new FilterDto()+ {+ Formats = null+ };++ Assert.Equal(Enum.GetValues<MangaFormat>(), filter.GetSqlFilter());+ }++ [Fact]+ public void GetSqlFilter_ShouldReturnAllFormats2()+ {+ var filter = new FilterDto()+ {+ Formats = new List<MangaFormat>()+ };++ Assert.Equal(Enum.GetValues<MangaFormat>(), filter.GetSqlFilter());+ }++ [Fact]+ public void GetSqlFilter_ShouldReturnJust2()+ {+ var formats = new List<MangaFormat>()+ {+ MangaFormat.Archive, MangaFormat.Epub+ };+ var filter = new FilterDto()+ {+ Formats = formats+ };++ Assert.Equal(formats, filter.GetSqlFilter());+ }+}diff --git a/API.Tests/Extensions/ParserInfoListExtensionsTests.cs b/API.Tests/Extensions/ParserInfoListExtensionsTests.csindex f6119cc69..e7c8e9994 100644--- a/API.Tests/Extensions/ParserInfoListExtensionsTests.cs+++ b/API.Tests/Extensions/ParserInfoListExtensionsTests.cs@@ -1,15 +1,27 @@using System.Collections.Generic;+using System.IO.Abstractions.TestingHelpers;using System.Linq;using API.Entities.Enums;using API.Extensions;using API.Parser;+using API.Services;using API.Tests.Helpers;+using Microsoft.Extensions.Logging;+using NSubstitute;using Xunit;namespace API.Tests.Extensions{public class ParserInfoListExtensions{+ private readonly DefaultParser _defaultParser;+ public ParserInfoListExtensions()+ {+ _defaultParser =+ new DefaultParser(new DirectoryService(Substitute.For<ILogger<DirectoryService>>(),+ new MockFileSystem()));+ }+[Theory][InlineData(new[] {"1", "1", "3-5", "5", "8", "0", "0"}, new[] {"1", "3-5", "5", "8", "0"})]public void DistinctVolumesTest(string[] volumeNumbers, string[] expectedNumbers)@@ -17,7 +29,7 @@ namespace API.Tests.Extensionsvar infos = volumeNumbers.Select(n => new ParserInfo() {Volumes = n}).ToList();Assert.Equal(expectedNumbers, infos.DistinctVolumes());}-+[Theory][InlineData(new[] {@"Cynthia The Mission - c000-006 (v06) [Desudesu&Brolen].zip"}, new[] {@"E:\Manga\Cynthia the Mission\Cynthia The Mission - c000-006 (v06) [Desudesu&Brolen].zip"}, true)][InlineData(new[] {@"Cynthia The Mission - c000-006 (v06-07) [Desudesu&Brolen].zip"}, new[] {@"E:\Manga\Cynthia the Mission\Cynthia The Mission - c000-006 (v06) [Desudesu&Brolen].zip"}, true)]@@ -27,7 +39,7 @@ namespace API.Tests.Extensionsvar infos = new List<ParserInfo>();foreach (var filename in inputInfos){- infos.Add(API.Parser.Parser.Parse(+ infos.Add(_defaultParser.Parse(filename,string.Empty));}@@ -38,4 +50,4 @@ namespace API.Tests.ExtensionsAssert.Equal(expectedHasInfo, infos.HasInfo(chapter));}}-}\ No newline at end of file+}diff --git a/API.Tests/Extensions/PathExtensionsTests.cs b/API.Tests/Extensions/PathExtensionsTests.csnew file mode 100644index 000000000..bdc752a92--- /dev/null+++ b/API.Tests/Extensions/PathExtensionsTests.cs@@ -0,0 +1,20 @@+using System.IO;+using Xunit;+using API.Extensions;++namespace API.Tests.Extensions;++public class PathExtensionsTests+{+ #region GetFullPathWithoutExtension++ [Theory]+ [InlineData("joe.png", "joe")]+ [InlineData("c:/directory/joe.png", "c:/directory/joe")]+ public void GetFullPathWithoutExtension_Test(string input, string expected)+ {+ Assert.Equal(Path.GetFullPath(expected), input.GetFullPathWithoutExtension());+ }++ #endregion+}diff --git a/API.Tests/Extensions/SeriesExtensionsTests.cs b/API.Tests/Extensions/SeriesExtensionsTests.csindex 35054770b..fc5b5b8ca 100644--- a/API.Tests/Extensions/SeriesExtensionsTests.cs+++ b/API.Tests/Extensions/SeriesExtensionsTests.cs@@ -1,6 +1,11 @@-using API.Entities;+using System.Linq;+using API.Entities;+using API.Entities.Enums;+using API.Entities.Metadata;using API.Extensions;using API.Parser;+using API.Services.Tasks.Scanner;+using API.Tests.Helpers;using Xunit;namespace API.Tests.Extensions@@ -31,6 +36,38 @@ namespace API.Tests.ExtensionsAssert.Equal(expected, series.NameInList(list));}+ [Theory]+ [InlineData(new [] {"Darker than Black", "Darker Than Black", "Darker than Black"}, new [] {"Darker than Black"}, MangaFormat.Archive, true)]+ [InlineData(new [] {"Darker than Black", "Darker Than Black", "Darker than Black"}, new [] {"Darker_than_Black"}, MangaFormat.Archive, true)]+ [InlineData(new [] {"Darker than Black", "Darker Than Black", "Darker than Black"}, new [] {"Darker then Black!"}, MangaFormat.Archive, false)]+ [InlineData(new [] {"Salem's Lot", "Salem's Lot", "Salem's Lot"}, new [] {"Salem's Lot"}, MangaFormat.Archive, true)]+ [InlineData(new [] {"Salem's Lot", "Salem's Lot", "Salem's Lot"}, new [] {"salems lot"}, MangaFormat.Archive, true)]+ [InlineData(new [] {"Salem's Lot", "Salem's Lot", "Salem's Lot"}, new [] {"salem's lot"}, MangaFormat.Archive, true)]+ // Different normalizations pass as we check normalization against an on-the-fly calculation so we don't delete series just because we change how normalization works+ [InlineData(new [] {"Salem's Lot", "Salem's Lot", "Salem's Lot", "salems lot"}, new [] {"salem's lot"}, MangaFormat.Archive, true)]+ [InlineData(new [] {"Rent-a-Girlfriend", "Rent-a-Girlfriend", "Kanojo, Okarishimasu", "rentagirlfriend"}, new [] {"Kanojo, Okarishimasu"}, MangaFormat.Archive, true)]+ public void NameInListParserInfoTest(string[] seriesInput, string[] list, MangaFormat format, bool expected)+ {+ var series = new Series()+ {+ Name = seriesInput[0],+ LocalizedName = seriesInput[1],+ OriginalName = seriesInput[2],+ NormalizedName = seriesInput.Length == 4 ? seriesInput[3] : API.Parser.Parser.Normalize(seriesInput[0]),+ Metadata = new SeriesMetadata(),+ };++ var parserInfos = list.Select(s => new ParsedSeries()+ {+ Name = s,+ NormalizedName = API.Parser.Parser.Normalize(s),+ }).ToList();++ // This doesn't do any checks against format+ Assert.Equal(expected, series.NameInList(parserInfos));+ }++[Theory][InlineData(new [] {"Darker than Black", "Darker Than Black", "Darker than Black"}, "Darker than Black", true)][InlineData(new [] {"Rent-a-Girlfriend", "Rent-a-Girlfriend", "Kanojo, Okarishimasu", "rentagirlfriend"}, "Kanojo, Okarishimasu", true)]diff --git a/API.Tests/Extensions/VolumeListExtensionsTests.cs b/API.Tests/Extensions/VolumeListExtensionsTests.csnew file mode 100644index 000000000..48d39aa24--- /dev/null+++ b/API.Tests/Extensions/VolumeListExtensionsTests.cs@@ -0,0 +1,177 @@+using System.Collections.Generic;+using API.Entities;+using API.Entities.Enums;+using API.Extensions;+using API.Tests.Helpers;+using Xunit;++namespace API.Tests.Extensions;++public class VolumeListExtensionsTests+{+ #region FirstWithChapters++ [Fact]+ public void FirstWithChapters_ReturnsVolumeWithChapters()+ {+ var volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("0", new List<Chapter>()),+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false),+ EntityFactory.CreateChapter("2", false),+ }),+ };++ Assert.Equal(volumes[1].Number, volumes.FirstWithChapters(false).Number);+ Assert.Equal(volumes[1].Number, volumes.FirstWithChapters(true).Number);+ }++ [Fact]+ public void FirstWithChapters_Book()+ {+ var volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("3", false),+ EntityFactory.CreateChapter("4", false),+ }),+ EntityFactory.CreateVolume("0", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false),+ EntityFactory.CreateChapter("0", true),+ }),+ };++ Assert.Equal(volumes[0].Number, volumes.FirstWithChapters(true).Number);+ }++ [Fact]+ public void FirstWithChapters_NonBook()+ {+ var volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("3", false),+ EntityFactory.CreateChapter("4", false),+ }),+ EntityFactory.CreateVolume("0", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false),+ EntityFactory.CreateChapter("0", true),+ }),+ };++ Assert.Equal(volumes[0].Number, volumes.FirstWithChapters(false).Number);+ }++ #endregion++ #region GetCoverImage++ [Fact]+ public void GetCoverImage_ArchiveFormat()+ {+ var volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("3", false),+ EntityFactory.CreateChapter("4", false),+ }),+ EntityFactory.CreateVolume("0", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false),+ EntityFactory.CreateChapter("0", true),+ }),+ };++ Assert.Equal(volumes[0].Number, volumes.GetCoverImage(MangaFormat.Archive).Number);+ }++ [Fact]+ public void GetCoverImage_EpubFormat()+ {+ var volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("3", false),+ EntityFactory.CreateChapter("4", false),+ }),+ EntityFactory.CreateVolume("0", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false),+ EntityFactory.CreateChapter("0", true),+ }),+ };++ Assert.Equal(volumes[1].Name, volumes.GetCoverImage(MangaFormat.Epub).Name);+ }++ [Fact]+ public void GetCoverImage_PdfFormat()+ {+ var volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("3", false),+ EntityFactory.CreateChapter("4", false),+ }),+ EntityFactory.CreateVolume("0", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false),+ EntityFactory.CreateChapter("0", true),+ }),+ };++ Assert.Equal(volumes[1].Name, volumes.GetCoverImage(MangaFormat.Pdf).Name);+ }++ [Fact]+ public void GetCoverImage_ImageFormat()+ {+ var volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("3", false),+ EntityFactory.CreateChapter("4", false),+ }),+ EntityFactory.CreateVolume("0", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false),+ EntityFactory.CreateChapter("0", true),+ }),+ };++ Assert.Equal(volumes[0].Name, volumes.GetCoverImage(MangaFormat.Image).Name);+ }++ [Fact]+ public void GetCoverImage_ImageFormat_NoSpecials()+ {+ var volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("2", new List<Chapter>()+ {+ EntityFactory.CreateChapter("3", false),+ EntityFactory.CreateChapter("4", false),+ }),+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false),+ EntityFactory.CreateChapter("0", true),+ }),+ };++ Assert.Equal(volumes[1].Name, volumes.GetCoverImage(MangaFormat.Image).Name);+ }+++ #endregion+}diff --git a/API.Tests/Helpers/CacheHelperTests.cs b/API.Tests/Helpers/CacheHelperTests.csnew file mode 100644index 000000000..9d1024ff0--- /dev/null+++ b/API.Tests/Helpers/CacheHelperTests.cs@@ -0,0 +1,293 @@+using System;+using System.Collections.Generic;+using System.IO;+using System.IO.Abstractions.TestingHelpers;+using API.Entities;+using API.Helpers;+using API.Services;+using Microsoft.Extensions.Logging;+using NSubstitute;+using Xunit;++namespace API.Tests.Helpers;++public class CacheHelperTests+{+ private const string TestCoverImageDirectory = @"c:\";+ private const string TestCoverImageFile = "thumbnail.jpg";+ private readonly string _testCoverPath = Path.Join(TestCoverImageDirectory, TestCoverImageFile);+ private const string TestCoverArchive = @"file in folder.zip";+ private readonly ICacheHelper _cacheHelper;++ public CacheHelperTests()+ {+ var file = new MockFileData("")+ {+ LastWriteTime = DateTimeOffset.Now.Subtract(TimeSpan.FromMinutes(1))+ };+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>+ {+ { Path.Join(TestCoverImageDirectory, TestCoverArchive), file },+ { Path.Join(TestCoverImageDirectory, TestCoverImageFile), file }+ });++ var fileService = new FileService(fileSystem);+ _cacheHelper = new CacheHelper(fileService);+ }++ [Theory]+ [InlineData("", false)]+ [InlineData("C:/", false)]+ [InlineData(null, false)]+ public void CoverImageExists_DoesFileExist(string coverImage, bool exists)+ {+ Assert.Equal(exists, _cacheHelper.CoverImageExists(coverImage));+ }++ [Fact]+ public void CoverImageExists_FileExists()+ {+ Assert.True(_cacheHelper.CoverImageExists(TestCoverArchive));+ }++ [Fact]+ public void ShouldUpdateCoverImage_OnFirstRun()+ {+ var file = new MangaFile()+ {+ FilePath = TestCoverArchive,+ LastModified = DateTime.Now+ };+ Assert.True(_cacheHelper.ShouldUpdateCoverImage(null, file, DateTime.Now.Subtract(TimeSpan.FromMinutes(1)),+ false, false));+ }++ [Fact]+ public void ShouldUpdateCoverImage_ShouldNotUpdateOnSecondRunWithCoverImageSetNotLocked()+ {+ // Represents first run+ var file = new MangaFile()+ {+ FilePath = TestCoverArchive,+ LastModified = DateTime.Now+ };+ Assert.False(_cacheHelper.ShouldUpdateCoverImage(_testCoverPath, file, DateTime.Now.Subtract(TimeSpan.FromMinutes(1)),+ false, false));+ }++ [Fact]+ public void ShouldUpdateCoverImage_ShouldNotUpdateOnSecondRunWithCoverImageSetNotLocked_2()+ {+ // Represents first run+ var file = new MangaFile()+ {+ FilePath = TestCoverArchive,+ LastModified = DateTime.Now+ };+ Assert.False(_cacheHelper.ShouldUpdateCoverImage(_testCoverPath, file, DateTime.Now,+ false, false));+ }++ [Fact]+ public void ShouldUpdateCoverImage_ShouldNotUpdateOnSecondRunWithCoverImageSetLocked()+ {+ // Represents first run+ var file = new MangaFile()+ {+ FilePath = TestCoverArchive,+ LastModified = DateTime.Now+ };+ Assert.False(_cacheHelper.ShouldUpdateCoverImage(_testCoverPath, file, DateTime.Now.Subtract(TimeSpan.FromMinutes(1)),+ false, true));+ }++ [Fact]+ public void ShouldUpdateCoverImage_ShouldNotUpdateOnSecondRunWithCoverImageSetLocked_Modified()+ {+ // Represents first run+ var file = new MangaFile()+ {+ FilePath = TestCoverArchive,+ LastModified = DateTime.Now+ };+ Assert.False(_cacheHelper.ShouldUpdateCoverImage(_testCoverPath, file, DateTime.Now.Subtract(TimeSpan.FromMinutes(1)),+ false, true));+ }++ [Fact]+ public void ShouldUpdateCoverImage_CoverImageSetAndReplaced_Modified()+ {+ var filesystemFile = new MockFileData("")+ {+ LastWriteTime = DateTimeOffset.Now+ };+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>+ {+ { Path.Join(TestCoverImageDirectory, TestCoverArchive), filesystemFile },+ { Path.Join(TestCoverImageDirectory, TestCoverImageFile), filesystemFile }+ });++ var fileService = new FileService(fileSystem);+ var cacheHelper = new CacheHelper(fileService);++ var created = DateTime.Now.Subtract(TimeSpan.FromHours(1));+ var file = new MangaFile()+ {+ FilePath = TestCoverArchive,+ LastModified = DateTime.Now.Subtract(TimeSpan.FromMinutes(1))+ };+ Assert.True(cacheHelper.ShouldUpdateCoverImage(_testCoverPath, file, created,+ false, false));+ }++ [Fact]+ public void HasFileNotChangedSinceCreationOrLastScan_NotChangedSinceCreated()+ {+ var filesystemFile = new MockFileData("")+ {+ LastWriteTime = DateTimeOffset.Now+ };+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>+ {+ { Path.Join(TestCoverImageDirectory, TestCoverArchive), filesystemFile },+ { Path.Join(TestCoverImageDirectory, TestCoverImageFile), filesystemFile }+ });++ var fileService = new FileService(fileSystem);+ var cacheHelper = new CacheHelper(fileService);++ var chapter = new Chapter()+ {+ Created = filesystemFile.LastWriteTime.DateTime,+ LastModified = filesystemFile.LastWriteTime.DateTime+ };++ var file = new MangaFile()+ {+ FilePath = TestCoverArchive,+ LastModified = filesystemFile.LastWriteTime.DateTime+ };+ Assert.True(cacheHelper.HasFileNotChangedSinceCreationOrLastScan(chapter, false, file));+ }++ [Fact]+ public void HasFileNotChangedSinceCreationOrLastScan_NotChangedSinceLastModified()+ {+ var filesystemFile = new MockFileData("")+ {+ LastWriteTime = DateTimeOffset.Now+ };+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>+ {+ { Path.Join(TestCoverImageDirectory, TestCoverArchive), filesystemFile },+ { Path.Join(TestCoverImageDirectory, TestCoverImageFile), filesystemFile }+ });++ var fileService = new FileService(fileSystem);+ var cacheHelper = new CacheHelper(fileService);++ var chapter = new Chapter()+ {+ Created = filesystemFile.LastWriteTime.DateTime,+ LastModified = filesystemFile.LastWriteTime.DateTime+ };++ var file = new MangaFile()+ {+ FilePath = TestCoverArchive,+ LastModified = filesystemFile.LastWriteTime.DateTime+ };+ Assert.True(cacheHelper.HasFileNotChangedSinceCreationOrLastScan(chapter, false, file));+ }++ [Fact]+ public void HasFileNotChangedSinceCreationOrLastScan_NotChangedSinceLastModified_ForceUpdate()+ {+ var filesystemFile = new MockFileData("")+ {+ LastWriteTime = DateTimeOffset.Now+ };+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>+ {+ { Path.Join(TestCoverImageDirectory, TestCoverArchive), filesystemFile },+ { Path.Join(TestCoverImageDirectory, TestCoverImageFile), filesystemFile }+ });++ var fileService = new FileService(fileSystem);+ var cacheHelper = new CacheHelper(fileService);++ var chapter = new Chapter()+ {+ Created = filesystemFile.LastWriteTime.DateTime,+ LastModified = filesystemFile.LastWriteTime.DateTime+ };++ var file = new MangaFile()+ {+ FilePath = TestCoverArchive,+ LastModified = filesystemFile.LastWriteTime.DateTime+ };+ Assert.False(cacheHelper.HasFileNotChangedSinceCreationOrLastScan(chapter, true, file));+ }++ [Fact]+ public void HasFileNotChangedSinceCreationOrLastScan_ModifiedSinceLastScan()+ {+ var filesystemFile = new MockFileData("")+ {+ LastWriteTime = DateTimeOffset.Now+ };+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>+ {+ { Path.Join(TestCoverImageDirectory, TestCoverArchive), filesystemFile },+ { Path.Join(TestCoverImageDirectory, TestCoverImageFile), filesystemFile }+ });++ var fileService = new FileService(fileSystem);+ var cacheHelper = new CacheHelper(fileService);++ var chapter = new Chapter()+ {+ Created = filesystemFile.LastWriteTime.DateTime.Subtract(TimeSpan.FromMinutes(10)),+ LastModified = filesystemFile.LastWriteTime.DateTime.Subtract(TimeSpan.FromMinutes(10))+ };++ var file = new MangaFile()+ {+ FilePath = Path.Join(TestCoverImageDirectory, TestCoverArchive),+ LastModified = filesystemFile.LastWriteTime.DateTime+ };+ Assert.False(cacheHelper.HasFileNotChangedSinceCreationOrLastScan(chapter, false, file));+ }++ [Fact]+ public void HasFileNotChangedSinceCreationOrLastScan_ModifiedSinceLastScan_ButLastModifiedSame()+ {+ var filesystemFile = new MockFileData("")+ {+ LastWriteTime = DateTimeOffset.Now+ };+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>+ {+ { Path.Join(TestCoverImageDirectory, TestCoverArchive), filesystemFile },+ { Path.Join(TestCoverImageDirectory, TestCoverImageFile), filesystemFile }+ });++ var fileService = new FileService(fileSystem);+ var cacheHelper = new CacheHelper(fileService);++ var chapter = new Chapter()+ {+ Created = filesystemFile.LastWriteTime.DateTime.Subtract(TimeSpan.FromMinutes(10)),+ LastModified = filesystemFile.LastWriteTime.DateTime+ };++ var file = new MangaFile()+ {+ FilePath = Path.Join(TestCoverImageDirectory, TestCoverArchive),+ LastModified = filesystemFile.LastWriteTime.DateTime+ };+ Assert.False(cacheHelper.HasFileNotChangedSinceCreationOrLastScan(chapter, false, file));+ }++}diff --git a/API.Tests/Helpers/EntityFactory.cs b/API.Tests/Helpers/EntityFactory.csindex 456cd1b52..7b55df108 100644--- a/API.Tests/Helpers/EntityFactory.cs+++ b/API.Tests/Helpers/EntityFactory.cs@@ -1,6 +1,8 @@-using System.Collections.Generic;+using System;+using System.Collections.Generic;using API.Entities;using API.Entities.Enums;+using API.Entities.Metadata;namespace API.Tests.Helpers{@@ -27,6 +29,7 @@ namespace API.Tests.Helpersreturn new Volume(){Name = volumeNumber,+ Number = int.Parse(volumeNumber),Pages = 0,Chapters = chapters ?? new List<Chapter>()};@@ -75,4 +78,4 @@ namespace API.Tests.Helpers};}}-}\ No newline at end of file+}diff --git a/API.Tests/Helpers/GenreHelperTests.cs b/API.Tests/Helpers/GenreHelperTests.csnew file mode 100644index 000000000..0d0aebe0c--- /dev/null+++ b/API.Tests/Helpers/GenreHelperTests.cs@@ -0,0 +1,110 @@+using System.Collections.Generic;+using API.Data;+using API.Entities;+using API.Helpers;+using Xunit;++namespace API.Tests.Helpers;++public class GenreHelperTests+{+ [Fact]+ public void UpdateGenre_ShouldAddNewGenre()+ {+ var allGenres = new List<Genre>+ {+ DbFactory.Genre("Action", false),+ DbFactory.Genre("action", false),+ DbFactory.Genre("Sci-fi", false),+ };+ var genreAdded = new List<Genre>();++ GenreHelper.UpdateGenre(allGenres, new[] {"Action", "Adventure"}, false, genre =>+ {+ genreAdded.Add(genre);+ });++ Assert.Equal(2, genreAdded.Count);+ Assert.Equal(4, allGenres.Count);+ }++ [Fact]+ public void UpdateGenre_ShouldNotAddDuplicateGenre()+ {+ var allGenres = new List<Genre>+ {+ DbFactory.Genre("Action", false),+ DbFactory.Genre("action", false),+ DbFactory.Genre("Sci-fi", false),++ };+ var genreAdded = new List<Genre>();++ GenreHelper.UpdateGenre(allGenres, new[] {"Action", "Scifi"}, false, genre =>+ {+ genreAdded.Add(genre);+ });++ Assert.Equal(3, allGenres.Count);+ }++ [Fact]+ public void AddGenre_ShouldAddOnlyNonExistingGenre()+ {+ var existingGenres = new List<Genre>+ {+ DbFactory.Genre("Action", false),+ DbFactory.Genre("action", false),+ DbFactory.Genre("Sci-fi", false),+ };+++ GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("Action", false));+ Assert.Equal(3, existingGenres.Count);++ GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("action", false));+ Assert.Equal(3, existingGenres.Count);++ GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("Shonen", false));+ Assert.Equal(4, existingGenres.Count);+ }++ [Fact]+ public void AddGenre_ShouldNotAddSameNameAndExternal()+ {+ var existingGenres = new List<Genre>+ {+ DbFactory.Genre("Action", false),+ DbFactory.Genre("action", false),+ DbFactory.Genre("Sci-fi", false),+ };+++ GenreHelper.AddGenreIfNotExists(existingGenres, DbFactory.Genre("Action", true));+ Assert.Equal(3, existingGenres.Count);+ }++ [Fact]+ public void KeepOnlySamePeopleBetweenLists()+ {+ var existingGenres = new List<Genre>+ {+ DbFactory.Genre("Action", false),+ DbFactory.Genre("Sci-fi", false),+ };++ var peopleFromChapters = new List<Genre>+ {+ DbFactory.Genre("Action", false),+ };++ var genreRemoved = new List<Genre>();+ GenreHelper.KeepOnlySameGenreBetweenLists(existingGenres,+ peopleFromChapters, genre =>+ {+ genreRemoved.Add(genre);+ });++ Assert.Equal(1, genreRemoved.Count);+ }+}diff --git a/API.Tests/Helpers/ParserInfoFactory.cs b/API.Tests/Helpers/ParserInfoFactory.csindex 7dcf564e1..2dc2f2869 100644--- a/API.Tests/Helpers/ParserInfoFactory.cs+++ b/API.Tests/Helpers/ParserInfoFactory.cs@@ -1,6 +1,10 @@-using System.IO;+using System.Collections.Concurrent;+using System.Collections.Generic;+using System.IO;+using System.Linq;using API.Entities.Enums;using API.Parser;+using API.Services.Tasks.Scanner;namespace API.Tests.Helpers{@@ -21,5 +25,49 @@ namespace API.Tests.HelpersVolumes = volumes};}++ public static void AddToParsedInfo(IDictionary<ParsedSeries, List<ParserInfo>> collectedSeries, ParserInfo info)+ {+ var existingKey = collectedSeries.Keys.FirstOrDefault(ps =>+ ps.Format == info.Format && ps.NormalizedName == API.Parser.Parser.Normalize(info.Series));+ existingKey ??= new ParsedSeries()+ {+ Format = info.Format,+ Name = info.Series,+ NormalizedName = API.Parser.Parser.Normalize(info.Series)+ };+ if (collectedSeries.GetType() == typeof(ConcurrentDictionary<,>))+ {+ ((ConcurrentDictionary<ParsedSeries, List<ParserInfo>>) collectedSeries).AddOrUpdate(existingKey, new List<ParserInfo>() {info}, (_, oldValue) =>+ {+ oldValue ??= new List<ParserInfo>();+ if (!oldValue.Contains(info))+ {+ oldValue.Add(info);+ }++ return oldValue;+ });+ }+ else+ {+ if (!collectedSeries.ContainsKey(existingKey))+ {+ collectedSeries.Add(existingKey, new List<ParserInfo>() {info});+ }+ else+ {+ var list = collectedSeries[existingKey];+ if (!list.Contains(info))+ {+ list.Add(info);+ }++ collectedSeries[existingKey] = list;+ }++ }++ }}-}\ No newline at end of file+}diff --git a/API.Tests/Helpers/ParserInfoHelperTests.cs b/API.Tests/Helpers/ParserInfoHelperTests.csnew file mode 100644index 000000000..d3b58d96b--- /dev/null+++ b/API.Tests/Helpers/ParserInfoHelperTests.cs@@ -0,0 +1,75 @@+using System.Collections.Generic;+using API.Entities;+using API.Entities.Enums;+using API.Entities.Metadata;+using API.Helpers;+using API.Parser;+using API.Services.Tasks.Scanner;+using Xunit;++namespace API.Tests.Helpers;++public class ParserInfoHelperTests+{+ #region SeriesHasMatchingParserInfoFormat++ [Fact]+ public void SeriesHasMatchingParserInfoFormat_ShouldBeFalse()+ {+ var infos = new Dictionary<ParsedSeries, List<ParserInfo>>();++ ParserInfoFactory.AddToParsedInfo(infos, new ParserInfo() {Series = "Darker than Black", Volumes = "1", Format = MangaFormat.Archive});+ //AddToParsedInfo(infos, new ParserInfo() {Series = "Darker than Black", Volumes = "1", Format = MangaFormat.Epub});++ var series = new Series()+ {+ Name = "Darker Than Black",+ LocalizedName = "Darker Than Black",+ OriginalName = "Darker Than Black",+ Volumes = new List<Volume>()+ {+ new Volume()+ {+ Number = 1,+ Name = "1"+ }+ },+ NormalizedName = API.Parser.Parser.Normalize("Darker Than Black"),+ Metadata = new SeriesMetadata(),+ Format = MangaFormat.Epub+ };++ Assert.False(ParserInfoHelpers.SeriesHasMatchingParserInfoFormat(series, infos));+ }++ [Fact]+ public void SeriesHasMatchingParserInfoFormat_ShouldBeTrue()+ {+ var infos = new Dictionary<ParsedSeries, List<ParserInfo>>();++ ParserInfoFactory.AddToParsedInfo(infos, new ParserInfo() {Series = "Darker than Black", Volumes = "1", Format = MangaFormat.Archive});+ ParserInfoFactory.AddToParsedInfo(infos, new ParserInfo() {Series = "Darker than Black", Volumes = "1", Format = MangaFormat.Epub});++ var series = new Series()+ {+ Name = "Darker Than Black",+ LocalizedName = "Darker Than Black",+ OriginalName = "Darker Than Black",+ Volumes = new List<Volume>()+ {+ new Volume()+ {+ Number = 1,+ Name = "1"+ }+ },+ NormalizedName = API.Parser.Parser.Normalize("Darker Than Black"),+ Metadata = new SeriesMetadata(),+ Format = MangaFormat.Epub+ };++ Assert.True(ParserInfoHelpers.SeriesHasMatchingParserInfoFormat(series, infos));+ }++ #endregion+}diff --git a/API.Tests/Helpers/PersonHelperTests.cs b/API.Tests/Helpers/PersonHelperTests.csnew file mode 100644index 000000000..f5b5551ae--- /dev/null+++ b/API.Tests/Helpers/PersonHelperTests.cs@@ -0,0 +1,140 @@+using System.Collections.Generic;+using API.Data;+using API.Entities;+using API.Entities.Enums;+using API.Helpers;+using Xunit;++namespace API.Tests.Helpers;++public class PersonHelperTests+{+ [Fact]+ public void UpdatePeople_ShouldAddNewPeople()+ {+ var allPeople = new List<Person>+ {+ DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),+ DbFactory.Person("Joe Shmo", PersonRole.Writer)+ };+ var peopleAdded = new List<Person>();++ PersonHelper.UpdatePeople(allPeople, new[] {"Joseph Shmo", "Sally Ann"}, PersonRole.Writer, person =>+ {+ peopleAdded.Add(person);+ });++ Assert.Equal(2, peopleAdded.Count);+ Assert.Equal(4, allPeople.Count);+ }++ [Fact]+ public void UpdatePeople_ShouldNotAddDuplicatePeople()+ {+ var allPeople = new List<Person>+ {+ DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),+ DbFactory.Person("Joe Shmo", PersonRole.Writer),+ DbFactory.Person("Sally Ann", PersonRole.CoverArtist),++ };+ var peopleAdded = new List<Person>();++ PersonHelper.UpdatePeople(allPeople, new[] {"Joe Shmo", "Sally Ann"}, PersonRole.CoverArtist, person =>+ {+ peopleAdded.Add(person);+ });++ Assert.Equal(3, allPeople.Count);+ }++ [Fact]+ public void RemovePeople_ShouldRemovePeopleOfSameRole()+ {+ var existingPeople = new List<Person>+ {+ DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),+ DbFactory.Person("Joe Shmo", PersonRole.Writer)+ };+ var peopleRemoved = new List<Person>();+ PersonHelper.RemovePeople(existingPeople, new[] {"Joe Shmo", "Sally Ann"}, PersonRole.Writer, person =>+ {+ peopleRemoved.Add(person);+ });++ Assert.NotEqual(existingPeople, peopleRemoved);+ Assert.Equal(1, peopleRemoved.Count);+ }++ [Fact]+ public void RemovePeople_ShouldRemovePeopleFromBothRoles()+ {+ var existingPeople = new List<Person>+ {+ DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),+ DbFactory.Person("Joe Shmo", PersonRole.Writer)+ };+ var peopleRemoved = new List<Person>();+ PersonHelper.RemovePeople(existingPeople, new[] {"Joe Shmo", "Sally Ann"}, PersonRole.Writer, person =>+ {+ peopleRemoved.Add(person);+ });++ Assert.NotEqual(existingPeople, peopleRemoved);+ Assert.Equal(1, peopleRemoved.Count);++ PersonHelper.RemovePeople(existingPeople, new[] {"Joe Shmo"}, PersonRole.CoverArtist, person =>+ {+ peopleRemoved.Add(person);+ });++ Assert.Equal(0, existingPeople.Count);+ Assert.Equal(2, peopleRemoved.Count);+ }++ [Fact]+ public void KeepOnlySamePeopleBetweenLists()+ {+ var existingPeople = new List<Person>+ {+ DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),+ DbFactory.Person("Joe Shmo", PersonRole.Writer),+ DbFactory.Person("Sally", PersonRole.Writer),+ };++ var peopleFromChapters = new List<Person>+ {+ DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),+ };++ var peopleRemoved = new List<Person>();+ PersonHelper.KeepOnlySamePeopleBetweenLists(existingPeople,+ peopleFromChapters, person =>+ {+ peopleRemoved.Add(person);+ });++ Assert.Equal(2, peopleRemoved.Count);+ }++ [Fact]+ public void AddPeople_ShouldAddOnlyNonExistingPeople()+ {+ var existingPeople = new List<Person>+ {+ DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),+ DbFactory.Person("Joe Shmo", PersonRole.Writer),+ DbFactory.Person("Sally", PersonRole.Writer),+ };+++ PersonHelper.AddPersonIfNotExists(existingPeople, DbFactory.Person("Joe Shmo", PersonRole.CoverArtist));+ Assert.Equal(3, existingPeople.Count);++ PersonHelper.AddPersonIfNotExists(existingPeople, DbFactory.Person("Joe Shmo", PersonRole.Writer));+ Assert.Equal(3, existingPeople.Count);++ PersonHelper.AddPersonIfNotExists(existingPeople, DbFactory.Person("Joe Shmo Two", PersonRole.CoverArtist));+ Assert.Equal(4, existingPeople.Count);+ }+}diff --git a/API.Tests/Helpers/SeriesHelperTests.cs b/API.Tests/Helpers/SeriesHelperTests.csnew file mode 100644index 000000000..8acd4bb85--- /dev/null+++ b/API.Tests/Helpers/SeriesHelperTests.cs@@ -0,0 +1,160 @@+using System.Collections.Generic;+using System.Linq;+using API.Data;+using API.Entities;+using API.Entities.Enums;+using API.Helpers;+using API.Services.Tasks.Scanner;+using Xunit;++namespace API.Tests.Helpers;++public class SeriesHelperTests+{+ #region FindSeries+ [Fact]+ public void FindSeries_ShouldFind_SameFormat()+ {+ var series = DbFactory.Series("Darker than Black");+ series.OriginalName = "Something Random";+ series.Format = MangaFormat.Archive;+ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Archive,+ Name = "Darker than Black",+ NormalizedName = API.Parser.Parser.Normalize("Darker than Black")+ }));++ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Archive,+ Name = "Darker than Black".ToLower(),+ NormalizedName = API.Parser.Parser.Normalize("Darker than Black")+ }));++ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Archive,+ Name = "Darker than Black".ToUpper(),+ NormalizedName = API.Parser.Parser.Normalize("Darker than Black")+ }));+ }++ [Fact]+ public void FindSeries_ShouldNotFind_WrongFormat()+ {+ var series = DbFactory.Series("Darker than Black");+ series.OriginalName = "Something Random";+ series.Format = MangaFormat.Archive;+ Assert.False(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "Darker than Black",+ NormalizedName = API.Parser.Parser.Normalize("Darker than Black")+ }));++ Assert.False(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "Darker than Black".ToLower(),+ NormalizedName = API.Parser.Parser.Normalize("Darker than Black")+ }));++ Assert.False(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "Darker than Black".ToUpper(),+ NormalizedName = API.Parser.Parser.Normalize("Darker than Black")+ }));+ }++ [Fact]+ public void FindSeries_ShouldFind_UsingOriginalName()+ {+ var series = DbFactory.Series("Darker than Black");+ series.OriginalName = "Something Random";+ series.Format = MangaFormat.Image;+ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "Something Random",+ NormalizedName = API.Parser.Parser.Normalize("Something Random")+ }));++ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "Something Random".ToLower(),+ NormalizedName = API.Parser.Parser.Normalize("Something Random")+ }));++ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "Something Random".ToUpper(),+ NormalizedName = API.Parser.Parser.Normalize("Something Random")+ }));++ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "SomethingRandom".ToUpper(),+ NormalizedName = API.Parser.Parser.Normalize("SomethingRandom")+ }));+ }++ [Fact]+ public void FindSeries_ShouldFind_UsingLocalizedName()+ {+ var series = DbFactory.Series("Darker than Black");+ series.LocalizedName = "Something Random";+ series.Format = MangaFormat.Image;+ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "Something Random",+ NormalizedName = API.Parser.Parser.Normalize("Something Random")+ }));++ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "Something Random".ToLower(),+ NormalizedName = API.Parser.Parser.Normalize("Something Random")+ }));++ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "Something Random".ToUpper(),+ NormalizedName = API.Parser.Parser.Normalize("Something Random")+ }));++ Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries()+ {+ Format = MangaFormat.Image,+ Name = "SomethingRandom".ToUpper(),+ NormalizedName = API.Parser.Parser.Normalize("SomethingRandom")+ }));+ }+ #endregion++ [Fact]+ public void RemoveMissingSeries_Should_RemoveSeries()+ {+ var existingSeries = new List<Series>()+ {+ EntityFactory.CreateSeries("Darker than Black Vol 1"),+ EntityFactory.CreateSeries("Darker than Black"),+ EntityFactory.CreateSeries("Beastars"),+ };+ var missingSeries = new List<Series>()+ {+ EntityFactory.CreateSeries("Darker than Black Vol 1"),+ };+ existingSeries = SeriesHelper.RemoveMissingSeries(existingSeries, missingSeries, out var removeCount).ToList();++ Assert.DoesNotContain(missingSeries[0].Name, existingSeries.Select(s => s.Name));+ Assert.Equal(missingSeries.Count, removeCount);+ }+}diff --git a/API.Tests/Helpers/TagHelperTests.cs b/API.Tests/Helpers/TagHelperTests.csnew file mode 100644index 000000000..5370d9971--- /dev/null+++ b/API.Tests/Helpers/TagHelperTests.cs@@ -0,0 +1,119 @@+using System.Collections.Generic;+using API.Data;+using API.Entities;+using API.Helpers;+using Xunit;++namespace API.Tests.Helpers;++public class TagHelperTests+{+ [Fact]+ public void UpdateTag_ShouldAddNewTag()+ {+ var allTags = new List<Tag>+ {+ DbFactory.Tag("Action", false),+ DbFactory.Tag("action", false),+ DbFactory.Tag("Sci-fi", false),+ };+ var tagAdded = new List<Tag>();++ TagHelper.UpdateTag(allTags, new[] {"Action", "Adventure"}, false, (tag, added) =>+ {+ if (added)+ {+ tagAdded.Add(tag);+ }++ });++ Assert.Equal(1, tagAdded.Count);+ Assert.Equal(4, allTags.Count);+ }++ [Fact]+ public void UpdateTag_ShouldNotAddDuplicateTag()+ {+ var allTags = new List<Tag>+ {+ DbFactory.Tag("Action", false),+ DbFactory.Tag("action", false),+ DbFactory.Tag("Sci-fi", false),++ };+ var tagAdded = new List<Tag>();++ TagHelper.UpdateTag(allTags, new[] {"Action", "Scifi"}, false, (tag, added) =>+ {+ if (added)+ {+ tagAdded.Add(tag);+ }+ TagHelper.AddTagIfNotExists(allTags, tag);+ });++ Assert.Equal(3, allTags.Count);+ Assert.Empty(tagAdded);+ }++ [Fact]+ public void AddTag_ShouldAddOnlyNonExistingTag()+ {+ var existingTags = new List<Tag>+ {+ DbFactory.Tag("Action", false),+ DbFactory.Tag("action", false),+ DbFactory.Tag("Sci-fi", false),+ };+++ TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Action", false));+ Assert.Equal(3, existingTags.Count);++ TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("action", false));+ Assert.Equal(3, existingTags.Count);++ TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Shonen", false));+ Assert.Equal(4, existingTags.Count);+ }++ [Fact]+ public void AddTag_ShouldNotAddSameNameAndExternal()+ {+ var existingTags = new List<Tag>+ {+ DbFactory.Tag("Action", false),+ DbFactory.Tag("action", false),+ DbFactory.Tag("Sci-fi", false),+ };+++ TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Action", true));+ Assert.Equal(3, existingTags.Count);+ }++ [Fact]+ public void KeepOnlySamePeopleBetweenLists()+ {+ var existingTags = new List<Tag>+ {+ DbFactory.Tag("Action", false),+ DbFactory.Tag("Sci-fi", false),+ };++ var peopleFromChapters = new List<Tag>+ {+ DbFactory.Tag("Action", false),+ };++ var tagRemoved = new List<Tag>();+ TagHelper.KeepOnlySameTagBetweenLists(existingTags,+ peopleFromChapters, tag =>+ {+ tagRemoved.Add(tag);+ });++ Assert.Equal(1, tagRemoved.Count);+ }+}diff --git a/API.Tests/Parser/ComicParserTests.cs b/API.Tests/Parser/ComicParserTests.csindex 043c0e027..fe0cd0961 100644--- a/API.Tests/Parser/ComicParserTests.cs+++ b/API.Tests/Parser/ComicParserTests.cs@@ -1,7 +1,10 @@-using System;using System.Collections.Generic;+using System.IO.Abstractions.TestingHelpers;using API.Entities.Enums;using API.Parser;+using API.Services;+using Microsoft.Extensions.Logging;+using NSubstitute;using Xunit;using Xunit.Abstractions;@@ -10,10 +13,14 @@ namespace API.Tests.Parserpublic class ComicParserTests{private readonly ITestOutputHelper _testOutputHelper;+ private readonly DefaultParser _defaultParser;public ComicParserTests(ITestOutputHelper testOutputHelper){_testOutputHelper = testOutputHelper;+ _defaultParser =+ new DefaultParser(new DirectoryService(Substitute.For<ILogger<DirectoryService>>(),+ new MockFileSystem()));}[Theory]@@ -61,8 +68,17 @@ namespace API.Tests.Parser[InlineData("Demon 012 (Sep 1973) c2c", "Demon")][InlineData("Dragon Age - Until We Sleep 01 (of 03)", "Dragon Age - Until We Sleep")][InlineData("Green Lantern v2 017 - The Spy-Eye that doomed Green Lantern v2", "Green Lantern")]- [InlineData("Green Lantern - Circle of Fire Special - Adam Strange (2000)", "Green Lantern - Circle of Fire - Adam Strange")]- [InlineData("Identity Crisis Extra - Rags Morales Sketches (2005)", "Identity Crisis - Rags Morales Sketches")]+ [InlineData("Green Lantern - Circle of Fire Special - Adam Strange (2000)", "Green Lantern - Circle of Fire - Adam Strange")]+ [InlineData("Identity Crisis Extra - Rags Morales Sketches (2005)", "Identity Crisis - Rags Morales Sketches")]+ [InlineData("Daredevil - t6 - 10 - (2019)", "Daredevil")]+ [InlineData("Batgirl T2000 #57", "Batgirl")]+ [InlineData("Teen Titans t1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus)", "Teen Titans")]+ [InlineData("Conquistador_-Tome_2", "Conquistador")]+ [InlineData("Max_l_explorateur-_Tome_0", "Max l explorateur")]+ [InlineData("Chevaliers d'Héliopolis T3 - Rubedo, l'oeuvre au rouge (Jodorowsky & Jérémy)", "Chevaliers d'Héliopolis")]+ [InlineData("Bd Fr-Aldebaran-Antares-t6", "Aldebaran-Antares")]+ [InlineData("Tintin - T22 Vol 714 pour Sydney", "Tintin")]+ [InlineData("Fables 2010 Vol. 1 Legends in Exile", "Fables 2010")]public void ParseComicSeriesTest(string filename, string expected){Assert.Equal(expected, API.Parser.Parser.ParseComicSeries(filename));@@ -101,6 +117,15 @@ namespace API.Tests.Parser[InlineData("Cyberpunk 2077 - Trauma Team 04.cbz", "0")][InlineData("2000 AD 0366 [1984-04-28] (flopbie)", "0")][InlineData("Daredevil - v6 - 10 - (2019)", "6")]+ // Tome Tests+ [InlineData("Daredevil - t6 - 10 - (2019)", "6")]+ [InlineData("Batgirl T2000 #57", "2000")]+ [InlineData("Teen Titans t1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus)", "1")]+ [InlineData("Conquistador_Tome_2", "2")]+ [InlineData("Max_l_explorateur-_Tome_0", "0")]+ [InlineData("Chevaliers d'Héliopolis T3 - Rubedo, l'oeuvre au rouge (Jodorowsky & Jérémy)", "3")]+ [InlineData("Adventure Time (2012)/Adventure Time #1 (2012)", "0")]+ [InlineData("Adventure Time TPB (2012)/Adventure Time v01 (2012).cbz", "1")]public void ParseComicVolumeTest(string filename, string expected){Assert.Equal(expected, API.Parser.Parser.ParseComicVolume(filename));@@ -144,6 +169,8 @@ namespace API.Tests.Parser[InlineData("2000 AD 0366 [1984-04-28] (flopbie)", "366")][InlineData("Daredevil - v6 - 10 - (2019)", "10")][InlineData("Batman Beyond 2016 - Chapter 001.cbz", "1")]+ [InlineData("Adventure Time (2012)/Adventure Time #1 (2012)", "1")]+ [InlineData("Adventure Time TPB (2012)/Adventure Time v01 (2012).cbz", "0")]public void ParseComicChapterTest(string filename, string expected){Assert.Equal(expected, API.Parser.Parser.ParseComicChapter(filename));@@ -155,76 +182,13 @@ namespace API.Tests.Parser[InlineData("Zombie Tramp vs. Vampblade TPB (2016) (Digital) (TheArchivist-Empire)", true)][InlineData("Baldwin the Brave & Other Tales Special SP1.cbr", true)][InlineData("Mouse Guard Specials - Spring 1153 - Fraggle Rock FCBD 2010", true)]+ [InlineData("Boule et Bill - THS -Bill à disparu", true)]+ [InlineData("Asterix - HS - Les 12 travaux d'Astérix", true)]+ [InlineData("Sillage Hors Série - Le Collectionneur - Concordance-DKFR", true)]+ [InlineData("laughs", false)]public void ParseComicSpecialTest(string input, bool expected){Assert.Equal(expected, !string.IsNullOrEmpty(API.Parser.Parser.ParseComicSpecial(input)));}-- [Fact]- public void ParseInfoTest()- {- const string rootPath = @"E:/Comics/";- var expected = new Dictionary<string, ParserInfo>();- var filepath = @"E:/Comics/Teen Titans/Teen Titans v1 Annual 01 (1967) SP01.cbr";- expected.Add(filepath, new ParserInfo- {- Series = "Teen Titans", Volumes = "0",- Chapters = "0", Filename = "Teen Titans v1 Annual 01 (1967) SP01.cbr", Format = MangaFormat.Archive,- FullFilePath = filepath- });-- // Fallback test with bad naming- filepath = @"E:\Comics\Comics\Babe\Babe Vol.1 #1-4\Babe 01.cbr";- expected.Add(filepath, new ParserInfo- {- Series = "Babe", Volumes = "0", Edition = "",- Chapters = "1", Filename = "Babe 01.cbr", Format = MangaFormat.Archive,- FullFilePath = filepath, IsSpecial = false- });-- filepath = @"E:\Comics\Comics\Publisher\Batman the Detective (2021)\Batman the Detective - v6 - 11 - (2021).cbr";- expected.Add(filepath, new ParserInfo- {- Series = "Batman the Detective", Volumes = "6", Edition = "",- Chapters = "11", Filename = "Batman the Detective - v6 - 11 - (2021).cbr", Format = MangaFormat.Archive,- FullFilePath = filepath, IsSpecial = false- });-- filepath = @"E:\Comics\Comics\Batman - The Man Who Laughs #1 (2005)\Batman - The Man Who Laughs #1 (2005).cbr";- expected.Add(filepath, new ParserInfo- {- Series = "Batman - The Man Who Laughs", Volumes = "0", Edition = "",- Chapters = "1", Filename = "Batman - The Man Who Laughs #1 (2005).cbr", Format = MangaFormat.Archive,- FullFilePath = filepath, IsSpecial = false- });-- foreach (var file in expected.Keys)- {- var expectedInfo = expected[file];- var actual = API.Parser.Parser.Parse(file, rootPath, LibraryType.Comic);- if (expectedInfo == null)- {- Assert.Null(actual);- return;- }- Assert.NotNull(actual);- _testOutputHelper.WriteLine($"Validating {file}");- Assert.Equal(expectedInfo.Format, actual.Format);- _testOutputHelper.WriteLine("Format ✓");- Assert.Equal(expectedInfo.Series, actual.Series);- _testOutputHelper.WriteLine("Series ✓");- Assert.Equal(expectedInfo.Chapters, actual.Chapters);- _testOutputHelper.WriteLine("Chapters ✓");- Assert.Equal(expectedInfo.Volumes, actual.Volumes);- _testOutputHelper.WriteLine("Volumes ✓");- Assert.Equal(expectedInfo.Edition, actual.Edition);- _testOutputHelper.WriteLine("Edition ✓");- Assert.Equal(expectedInfo.Filename, actual.Filename);- _testOutputHelper.WriteLine("Filename ✓");- Assert.Equal(expectedInfo.FullFilePath, actual.FullFilePath);- _testOutputHelper.WriteLine("FullFilePath ✓");- }- }-}}diff --git a/API.Tests/Parser/DefaultParserTests.cs b/API.Tests/Parser/DefaultParserTests.csnew file mode 100644index 000000000..a9c593de9--- /dev/null+++ b/API.Tests/Parser/DefaultParserTests.cs@@ -0,0 +1,312 @@+using System.Collections.Generic;+using System.IO.Abstractions.TestingHelpers;+using API.Entities.Enums;+using API.Parser;+using API.Services;+using Microsoft.Extensions.Logging;+using NSubstitute;+using Xunit;+using Xunit.Abstractions;++namespace API.Tests.Parser;++public class DefaultParserTests+{+ private readonly ITestOutputHelper _testOutputHelper;+ private readonly DefaultParser _defaultParser;++ public DefaultParserTests(ITestOutputHelper testOutputHelper)+ {+ _testOutputHelper = testOutputHelper;+ var directoryService = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), new MockFileSystem());+ _defaultParser = new DefaultParser(directoryService);+ }+++ #region ParseFromFallbackFolders+ [Theory]+ [InlineData("C:/", "C:/Love Hina/Love Hina - Special.cbz", "Love Hina")]+ [InlineData("C:/", "C:/Love Hina/Specials/Ani-Hina Art Collection.cbz", "Love Hina")]+ [InlineData("C:/", "C:/Mujaki no Rakuen Something/Mujaki no Rakuen Vol12 ch76.cbz", "Mujaki no Rakuen")]+ [InlineData("C:/", "C:/Something Random/Mujaki no Rakuen SP01.cbz", "Something Random")]+ public void ParseFromFallbackFolders_FallbackShouldParseSeries(string rootDir, string inputPath, string expectedSeries)+ {+ var actual = _defaultParser.Parse(inputPath, rootDir);+ if (actual == null)+ {+ Assert.NotNull(actual);+ return;+ }++ Assert.Equal(expectedSeries, actual.Series);+ }++ [Theory]+ [InlineData("/manga/Btooom!/Vol.1/Chapter 1/1.cbz", "Btooom!~1~1")]+ [InlineData("/manga/Btooom!/Vol.1 Chapter 2/1.cbz", "Btooom!~1~2")]+ [InlineData("/manga/Monster #8/Ch. 001-016 [MangaPlus] [Digital] [amit34521]/Monster #8 Ch. 001 [MangaPlus] [Digital] [amit34521]/13.jpg", "Monster #8~0~1")]+ public void ParseFromFallbackFolders_ShouldParseSeriesVolumeAndChapter(string inputFile, string expectedParseInfo)+ {+ const string rootDirectory = "/manga/";+ var tokens = expectedParseInfo.Split("~");+ var actual = new ParserInfo {Chapters = "0", Volumes = "0"};+ _defaultParser.ParseFromFallbackFolders(inputFile, rootDirectory, LibraryType.Manga, ref actual);+ Assert.Equal(tokens[0], actual.Series);+ Assert.Equal(tokens[1], actual.Volumes);+ Assert.Equal(tokens[2], actual.Chapters);+ }++ #endregion+++ #region Parse++ [Fact]+ public void Parse_ParseInfo_Manga()+ {+ const string rootPath = @"E:/Manga/";+ var expected = new Dictionary<string, ParserInfo>();+ var filepath = @"E:/Manga/Mujaki no Rakuen/Mujaki no Rakuen Vol12 ch76.cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Mujaki no Rakuen", Volumes = "12",+ Chapters = "76", Filename = "Mujaki no Rakuen Vol12 ch76.cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ filepath = @"E:/Manga/Shimoneta to Iu Gainen ga Sonzai Shinai Taikutsu na Sekai Man-hen/Vol 1.cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Shimoneta to Iu Gainen ga Sonzai Shinai Taikutsu na Sekai Man-hen", Volumes = "1",+ Chapters = "0", Filename = "Vol 1.cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ filepath = @"E:\Manga\Beelzebub\Beelzebub_01_[Noodles].zip";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Beelzebub", Volumes = "0",+ Chapters = "1", Filename = "Beelzebub_01_[Noodles].zip", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ filepath = @"E:\Manga\Ichinensei ni Nacchattara\Ichinensei_ni_Nacchattara_v01_ch01_[Taruby]_v1.1.zip";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Ichinensei ni Nacchattara", Volumes = "1",+ Chapters = "1", Filename = "Ichinensei_ni_Nacchattara_v01_ch01_[Taruby]_v1.1.zip", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ filepath = @"E:\Manga\Tenjo Tenge (Color)\Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Tenjo Tenge", Volumes = "1", Edition = "Full Contact Edition",+ Chapters = "0", Filename = "Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ filepath = @"E:\Manga\Akame ga KILL! ZERO (2016-2019) (Digital) (LuCaZ)\Akame ga KILL! ZERO v01 (2016) (Digital) (LuCaZ).cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Akame ga KILL! ZERO", Volumes = "1", Edition = "",+ Chapters = "0", Filename = "Akame ga KILL! ZERO v01 (2016) (Digital) (LuCaZ).cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ filepath = @"E:\Manga\Dorohedoro\Dorohedoro v01 (2010) (Digital) (LostNerevarine-Empire).cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Dorohedoro", Volumes = "1", Edition = "",+ Chapters = "0", Filename = "Dorohedoro v01 (2010) (Digital) (LostNerevarine-Empire).cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ filepath = @"E:\Manga\APOSIMZ\APOSIMZ 040 (2020) (Digital) (danke-Empire).cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "APOSIMZ", Volumes = "0", Edition = "",+ Chapters = "40", Filename = "APOSIMZ 040 (2020) (Digital) (danke-Empire).cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ filepath = @"E:\Manga\Corpse Party Musume\Kedouin Makoto - Corpse Party Musume, Chapter 09.cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Kedouin Makoto - Corpse Party Musume", Volumes = "0", Edition = "",+ Chapters = "9", Filename = "Kedouin Makoto - Corpse Party Musume, Chapter 09.cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ filepath = @"E:\Manga\Goblin Slayer\Goblin Slayer - Brand New Day 006.5 (2019) (Digital) (danke-Empire).cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Goblin Slayer - Brand New Day", Volumes = "0", Edition = "",+ Chapters = "6.5", Filename = "Goblin Slayer - Brand New Day 006.5 (2019) (Digital) (danke-Empire).cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ filepath = @"E:\Manga\Summer Time Rendering\Specials\Record 014 (between chapter 083 and ch084) SP11.cbr";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Summer Time Rendering", Volumes = "0", Edition = "",+ Chapters = "0", Filename = "Record 014 (between chapter 083 and ch084) SP11.cbr", Format = MangaFormat.Archive,+ FullFilePath = filepath, IsSpecial = true+ });++ filepath = @"E:\Manga\Seraph of the End\Seraph of the End - Vampire Reign 093 (2020) (Digital) (LuCaZ).cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Seraph of the End - Vampire Reign", Volumes = "0", Edition = "",+ Chapters = "93", Filename = "Seraph of the End - Vampire Reign 093 (2020) (Digital) (LuCaZ).cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath, IsSpecial = false+ });++ filepath = @"E:\Manga\Kono Subarashii Sekai ni Bakuen wo!\Vol. 00 Ch. 000.cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Kono Subarashii Sekai ni Bakuen wo!", Volumes = "0", Edition = "",+ Chapters = "0", Filename = "Vol. 00 Ch. 000.cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath, IsSpecial = false+ });++ filepath = @"E:\Manga\Toukyou Akazukin\Vol. 01 Ch. 001.cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Toukyou Akazukin", Volumes = "1", Edition = "",+ Chapters = "1", Filename = "Vol. 01 Ch. 001.cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath, IsSpecial = false+ });++ filepath = @"E:\Manga\Harrison, Kim - The Good, The Bad, and the Undead - Hollows Vol 2.5.epub";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Harrison, Kim - The Good, The Bad, and the Undead - Hollows", Volumes = "2.5", Edition = "",+ Chapters = "0", Filename = "Harrison, Kim - The Good, The Bad, and the Undead - Hollows Vol 2.5.epub", Format = MangaFormat.Epub,+ FullFilePath = filepath, IsSpecial = false+ });++ // If an image is cover exclusively, ignore it+ filepath = @"E:\Manga\Seraph of the End\cover.png";+ expected.Add(filepath, null);++ filepath = @"E:\Manga\The Beginning After the End\Chapter 001.cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "The Beginning After the End", Volumes = "0", Edition = "",+ Chapters = "1", Filename = "Chapter 001.cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath, IsSpecial = false+ });++ filepath = @"E:\Manga\Monster #8\Ch. 001-016 [MangaPlus] [Digital] [amit34521]\Monster #8 Ch. 001 [MangaPlus] [Digital] [amit34521]\13.jpg";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Monster #8", Volumes = "0", Edition = "",+ Chapters = "1", Filename = "13.jpg", Format = MangaFormat.Archive,+ FullFilePath = filepath, IsSpecial = false+ });++ filepath = @"E:\Manga\Air Gear\Air Gear Omnibus v01 (2016) (Digital) (Shadowcat-Empire).cbz";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Air Gear", Volumes = "1", Edition = "Omnibus",+ Chapters = "0", Filename = "Air Gear Omnibus v01 (2016) (Digital) (Shadowcat-Empire).cbz", Format = MangaFormat.Archive,+ FullFilePath = filepath, IsSpecial = false+ });+++ foreach (var file in expected.Keys)+ {+ var expectedInfo = expected[file];+ var actual = _defaultParser.Parse(file, rootPath);+ if (expectedInfo == null)+ {+ Assert.Null(actual);+ return;+ }+ Assert.NotNull(actual);+ _testOutputHelper.WriteLine($"Validating {file}");+ Assert.Equal(expectedInfo.Format, actual.Format);+ _testOutputHelper.WriteLine("Format ✓");+ Assert.Equal(expectedInfo.Series, actual.Series);+ _testOutputHelper.WriteLine("Series ✓");+ Assert.Equal(expectedInfo.Chapters, actual.Chapters);+ _testOutputHelper.WriteLine("Chapters ✓");+ Assert.Equal(expectedInfo.Volumes, actual.Volumes);+ _testOutputHelper.WriteLine("Volumes ✓");+ Assert.Equal(expectedInfo.Edition, actual.Edition);+ _testOutputHelper.WriteLine("Edition ✓");+ Assert.Equal(expectedInfo.Filename, actual.Filename);+ _testOutputHelper.WriteLine("Filename ✓");+ Assert.Equal(expectedInfo.FullFilePath, actual.FullFilePath);+ _testOutputHelper.WriteLine("FullFilePath ✓");+ }+ }++ [Fact]+ public void Parse_ParseInfo_Comic()+ {+ const string rootPath = @"E:/Comics/";+ var expected = new Dictionary<string, ParserInfo>();+ var filepath = @"E:/Comics/Teen Titans/Teen Titans v1 Annual 01 (1967) SP01.cbr";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Teen Titans", Volumes = "0",+ Chapters = "0", Filename = "Teen Titans v1 Annual 01 (1967) SP01.cbr", Format = MangaFormat.Archive,+ FullFilePath = filepath+ });++ // Fallback test with bad naming+ filepath = @"E:\Comics\Comics\Babe\Babe Vol.1 #1-4\Babe 01.cbr";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Babe", Volumes = "0", Edition = "",+ Chapters = "1", Filename = "Babe 01.cbr", Format = MangaFormat.Archive,+ FullFilePath = filepath, IsSpecial = false+ });++ filepath = @"E:\Comics\Comics\Publisher\Batman the Detective (2021)\Batman the Detective - v6 - 11 - (2021).cbr";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Batman the Detective", Volumes = "6", Edition = "",+ Chapters = "11", Filename = "Batman the Detective - v6 - 11 - (2021).cbr", Format = MangaFormat.Archive,+ FullFilePath = filepath, IsSpecial = false+ });++ filepath = @"E:\Comics\Comics\Batman - The Man Who Laughs #1 (2005)\Batman - The Man Who Laughs #1 (2005).cbr";+ expected.Add(filepath, new ParserInfo+ {+ Series = "Batman - The Man Who Laughs", Volumes = "0", Edition = "",+ Chapters = "1", Filename = "Batman - The Man Who Laughs #1 (2005).cbr", Format = MangaFormat.Archive,+ FullFilePath = filepath, IsSpecial = false+ });++ foreach (var file in expected.Keys)+ {+ var expectedInfo = expected[file];+ var actual = _defaultParser.Parse(file, rootPath, LibraryType.Comic);+ if (expectedInfo == null)+ {+ Assert.Null(actual);+ return;+ }+ Assert.NotNull(actual);+ _testOutputHelper.WriteLine($"Validating {file}");+ Assert.Equal(expectedInfo.Format, actual.Format);+ _testOutputHelper.WriteLine("Format ✓");+ Assert.Equal(expectedInfo.Series, actual.Series);+ _testOutputHelper.WriteLine("Series ✓");+ Assert.Equal(expectedInfo.Chapters, actual.Chapters);+ _testOutputHelper.WriteLine("Chapters ✓");+ Assert.Equal(expectedInfo.Volumes, actual.Volumes);+ _testOutputHelper.WriteLine("Volumes ✓");+ Assert.Equal(expectedInfo.Edition, actual.Edition);+ _testOutputHelper.WriteLine("Edition ✓");+ Assert.Equal(expectedInfo.Filename, actual.Filename);+ _testOutputHelper.WriteLine("Filename ✓");+ Assert.Equal(expectedInfo.FullFilePath, actual.FullFilePath);+ _testOutputHelper.WriteLine("FullFilePath ✓");+ }+ }+ #endregion+}diff --git a/API.Tests/Parser/MangaParserTests.cs b/API.Tests/Parser/MangaParserTests.csindex 1576cbb07..fe4dd5e42 100644--- a/API.Tests/Parser/MangaParserTests.cs+++ b/API.Tests/Parser/MangaParserTests.cs@@ -167,6 +167,9 @@ namespace API.Tests.Parser[InlineData("Great_Teacher_Onizuka_v16[TheSpectrum]", "Great Teacher Onizuka")][InlineData("[Renzokusei]_Kimi_wa_Midara_na_Boku_no_Joou_Ch5_Final_Chapter", "Kimi wa Midara na Boku no Joou")][InlineData("Battle Royale, v01 (2000) [TokyoPop] [Manga-Sketchbook]", "Battle Royale")]+ [InlineData("Kaiju No. 8 036 (2021) (Digital)", "Kaiju No. 8")]+ [InlineData("Seraph of the End - Vampire Reign 093 (2020) (Digital) (LuCaZ).cbz", "Seraph of the End - Vampire Reign")]+ [InlineData("Love Hina - Volume 01 [Scans].pdf", "Love Hina")]public void ParseSeriesTest(string filename, string expected){Assert.Equal(expected, API.Parser.Parser.ParseSeries(filename));@@ -240,6 +243,8 @@ namespace API.Tests.Parser[InlineData("Deku_&_Bakugo_-_Rising_v1_c1.1.cbz", "1.1")][InlineData("Chapter 63 - The Promise Made for 520 Cenz.cbr", "63")][InlineData("Harrison, Kim - The Good, The Bad, and the Undead - Hollows Vol 2.5.epub", "0")]+ [InlineData("Kaiju No. 8 036 (2021) (Digital)", "36")]+ [InlineData("Samurai Jack Vol. 01 - The threads of Time", "0")]public void ParseChaptersTest(string filename, string expected){Assert.Equal(expected, API.Parser.Parser.ParseChapter(filename));@@ -255,6 +260,7 @@ namespace API.Tests.Parser[InlineData("Chobits Omnibus Edition v01 [Dark Horse]", "Omnibus Edition")][InlineData("[dmntsf.net] One Piece - Digital Colored Comics Vol. 20 Ch. 177 - 30 Million vs 81 Million.cbz", "")][InlineData("AKIRA - c003 (v01) [Full Color] [Darkhorse].cbz", "Full Color")]+ [InlineData("Love Hina Omnibus v05 (2015) (Digital-HD) (Asgard-Empire).cbz", "Omnibus")]public void ParseEditionTest(string input, string expected){Assert.Equal(expected, API.Parser.Parser.ParseEdition(input));@@ -272,6 +278,8 @@ namespace API.Tests.Parser[InlineData("Yuki Merry - 4-Komga Anthology", false)][InlineData("Beastars - SP01", false)][InlineData("Beastars SP01", false)]+ [InlineData("The League of Extraordinary Gentlemen", false)]+ [InlineData("The League of Extra-ordinary Gentlemen", false)]public void ParseMangaSpecialTest(string input, bool expected){Assert.Equal(expected, !string.IsNullOrEmpty(API.Parser.Parser.ParseMangaSpecial(input)));@@ -294,194 +302,6 @@ namespace API.Tests.Parser}- [Theory]- [InlineData("/manga/Btooom!/Vol.1/Chapter 1/1.cbz", "Btooom!~1~1")]- [InlineData("/manga/Btooom!/Vol.1 Chapter 2/1.cbz", "Btooom!~1~2")]- [InlineData("/manga/Monster #8/Ch. 001-016 [MangaPlus] [Digital] [amit34521]/Monster #8 Ch. 001 [MangaPlus] [Digital] [amit34521]/13.jpg", "Monster #8~0~1")]- public void ParseFromFallbackFoldersTest(string inputFile, string expectedParseInfo)- {- const string rootDirectory = "/manga/";- var tokens = expectedParseInfo.Split("~");- var actual = new ParserInfo {Chapters = "0", Volumes = "0"};- API.Parser.Parser.ParseFromFallbackFolders(inputFile, rootDirectory, LibraryType.Manga, ref actual);- Assert.Equal(tokens[0], actual.Series);- Assert.Equal(tokens[1], actual.Volumes);- Assert.Equal(tokens[2], actual.Chapters);-- }-- [Fact]- public void ParseInfoTest()- {- const string rootPath = @"E:/Manga/";- var expected = new Dictionary<string, ParserInfo>();- var filepath = @"E:/Manga/Mujaki no Rakuen/Mujaki no Rakuen Vol12 ch76.cbz";- expected.Add(filepath, new ParserInfo- {- Series = "Mujaki no Rakuen", Volumes = "12",- Chapters = "76", Filename = "Mujaki no Rakuen Vol12 ch76.cbz", Format = MangaFormat.Archive,- FullFilePath = filepath- });-- filepath = @"E:/Manga/Shimoneta to Iu Gainen ga Sonzai Shinai Taikutsu na Sekai Man-hen/Vol 1.cbz";- expected.Add(filepath, new ParserInfo- {- Series = "Shimoneta to Iu Gainen ga Sonzai Shinai Taikutsu na Sekai Man-hen", Volumes = "1",- Chapters = "0", Filename = "Vol 1.cbz", Format = MangaFormat.Archive,- FullFilePath = filepath- });-- filepath = @"E:\Manga\Beelzebub\Beelzebub_01_[Noodles].zip";- expected.Add(filepath, new ParserInfo- {- Series = "Beelzebub", Volumes = "0",- Chapters = "1", Filename = "Beelzebub_01_[Noodles].zip", Format = MangaFormat.Archive,- FullFilePath = filepath- });-- filepath = @"E:\Manga\Ichinensei ni Nacchattara\Ichinensei_ni_Nacchattara_v01_ch01_[Taruby]_v1.1.zip";- expected.Add(filepath, new ParserInfo- {- Series = "Ichinensei ni Nacchattara", Volumes = "1",- Chapters = "1", Filename = "Ichinensei_ni_Nacchattara_v01_ch01_[Taruby]_v1.1.zip", Format = MangaFormat.Archive,- FullFilePath = filepath- });-- filepath = @"E:\Manga\Tenjo Tenge (Color)\Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz";- expected.Add(filepath, new ParserInfo- {- Series = "Tenjo Tenge", Volumes = "1", Edition = "Full Contact Edition",- Chapters = "0", Filename = "Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz", Format = MangaFormat.Archive,- FullFilePath = filepath- });-- filepath = @"E:\Manga\Akame ga KILL! ZERO (2016-2019) (Digital) (LuCaZ)\Akame ga KILL! ZERO v01 (2016) (Digital) (LuCaZ).cbz";- expected.Add(filepath, new ParserInfo- {- Series = "Akame ga KILL! ZERO", Volumes = "1", Edition = "",- Chapters = "0", Filename = "Akame ga KILL! ZERO v01 (2016) (Digital) (LuCaZ).cbz", Format = MangaFormat.Archive,- FullFilePath = filepath- });-- filepath = @"E:\Manga\Dorohedoro\Dorohedoro v01 (2010) (Digital) (LostNerevarine-Empire).cbz";- expected.Add(filepath, new ParserInfo- {- Series = "Dorohedoro", Volumes = "1", Edition = "",- Chapters = "0", Filename = "Dorohedoro v01 (2010) (Digital) (LostNerevarine-Empire).cbz", Format = MangaFormat.Archive,- FullFilePath = filepath- });-- filepath = @"E:\Manga\APOSIMZ\APOSIMZ 040 (2020) (Digital) (danke-Empire).cbz";- expected.Add(filepath, new ParserInfo- {- Series = "APOSIMZ", Volumes = "0", Edition = "",- Chapters = "40", Filename = "APOSIMZ 040 (2020) (Digital) (danke-Empire).cbz", Format = MangaFormat.Archive,- FullFilePath = filepath- });- filepath = @"E:\Manga\Corpse Party Musume\Kedouin Makoto - Corpse Party Musume, Chapter 09.cbz";- expected.Add(filepath, new ParserInfo- {- Series = "Kedouin Makoto - Corpse Party Musume", Volumes = "0", Edition = "",- Chapters = "9", Filename = "Kedouin Makoto - Corpse Party Musume, Chapter 09.cbz", Format = MangaFormat.Archive,- FullFilePath = filepath- });-- filepath = @"E:\Manga\Goblin Slayer\Goblin Slayer - Brand New Day 006.5 (2019) (Digital) (danke-Empire).cbz";- expected.Add(filepath, new ParserInfo- {- Series = "Goblin Slayer - Brand New Day", Volumes = "0", Edition = "",- Chapters = "6.5", Filename = "Goblin Slayer - Brand New Day 006.5 (2019) (Digital) (danke-Empire).cbz", Format = MangaFormat.Archive,- FullFilePath = filepath- });-- filepath = @"E:\Manga\Summer Time Rendering\Specials\Record 014 (between chapter 083 and ch084) SP11.cbr";- expected.Add(filepath, new ParserInfo- {- Series = "Summer Time Rendering", Volumes = "0", Edition = "",- Chapters = "0", Filename = "Record 014 (between chapter 083 and ch084) SP11.cbr", Format = MangaFormat.Archive,- FullFilePath = filepath, IsSpecial = true- });-- filepath = @"E:\Manga\Seraph of the End\Seraph of the End - Vampire Reign 093 (2020) (Digital) (LuCaZ).cbz";- expected.Add(filepath, new ParserInfo- {- Series = "Seraph of the End - Vampire Reign", Volumes = "0", Edition = "",- Chapters = "93", Filename = "Seraph of the End - Vampire Reign 093 (2020) (Digital) (LuCaZ).cbz", Format = MangaFormat.Archive,- FullFilePath = filepath, IsSpecial = false- });-- filepath = @"E:\Manga\Kono Subarashii Sekai ni Bakuen wo!\Vol. 00 Ch. 000.cbz";- expected.Add(filepath, new ParserInfo- {- Series = "Kono Subarashii Sekai ni Bakuen wo!", Volumes = "0", Edition = "",- Chapters = "0", Filename = "Vol. 00 Ch. 000.cbz", Format = MangaFormat.Archive,- FullFilePath = filepath, IsSpecial = false- });-- filepath = @"E:\Manga\Toukyou Akazukin\Vol. 01 Ch. 001.cbz";- expected.Add(filepath, new ParserInfo- {- Series = "Toukyou Akazukin", Volumes = "1", Edition = "",- Chapters = "1", Filename = "Vol. 01 Ch. 001.cbz", Format = MangaFormat.Archive,- FullFilePath = filepath, IsSpecial = false- });-- filepath = @"E:\Manga\Harrison, Kim - The Good, The Bad, and the Undead - Hollows Vol 2.5.epub";- expected.Add(filepath, new ParserInfo- {- Series = "Harrison, Kim - The Good, The Bad, and the Undead - Hollows", Volumes = "2.5", Edition = "",- Chapters = "0", Filename = "Harrison, Kim - The Good, The Bad, and the Undead - Hollows Vol 2.5.epub", Format = MangaFormat.Epub,- FullFilePath = filepath, IsSpecial = false- });-- // If an image is cover exclusively, ignore it- filepath = @"E:\Manga\Seraph of the End\cover.png";- expected.Add(filepath, null);-- filepath = @"E:\Manga\The Beginning After the End\Chapter 001.cbz";- expected.Add(filepath, new ParserInfo- {- Series = "The Beginning After the End", Volumes = "0", Edition = "",- Chapters = "1", Filename = "Chapter 001.cbz", Format = MangaFormat.Archive,- FullFilePath = filepath, IsSpecial = false- });-- filepath = @"E:\Manga\Monster #8\Ch. 001-016 [MangaPlus] [Digital] [amit34521]\Monster #8 Ch. 001 [MangaPlus] [Digital] [amit34521]\13.jpg";- expected.Add(filepath, new ParserInfo- {- Series = "Monster #8", Volumes = "0", Edition = "",- Chapters = "1", Filename = "13.jpg", Format = MangaFormat.Archive,- FullFilePath = filepath, IsSpecial = false- });--- foreach (var file in expected.Keys)- {- var expectedInfo = expected[file];- var actual = API.Parser.Parser.Parse(file, rootPath);- if (expectedInfo == null)- {- Assert.Null(actual);- return;- }- Assert.NotNull(actual);- _testOutputHelper.WriteLine($"Validating {file}");- Assert.Equal(expectedInfo.Format, actual.Format);- _testOutputHelper.WriteLine("Format ✓");- Assert.Equal(expectedInfo.Series, actual.Series);- _testOutputHelper.WriteLine("Series ✓");- Assert.Equal(expectedInfo.Chapters, actual.Chapters);- _testOutputHelper.WriteLine("Chapters ✓");- Assert.Equal(expectedInfo.Volumes, actual.Volumes);- _testOutputHelper.WriteLine("Volumes ✓");- Assert.Equal(expectedInfo.Edition, actual.Edition);- _testOutputHelper.WriteLine("Edition ✓");- Assert.Equal(expectedInfo.Filename, actual.Filename);- _testOutputHelper.WriteLine("Filename ✓");- Assert.Equal(expectedInfo.FullFilePath, actual.FullFilePath);- _testOutputHelper.WriteLine("FullFilePath ✓");- }- }}}diff --git a/API.Tests/Parser/ParserInfoTests.cs b/API.Tests/Parser/ParserInfoTests.csindex 78b879de7..16906cf55 100644--- a/API.Tests/Parser/ParserInfoTests.cs+++ b/API.Tests/Parser/ParserInfoTests.cs@@ -20,7 +20,7 @@ namespace API.Tests.ParserTitle = "darker than black",Volumes = "0"};-+var p2 = new ParserInfo(){Chapters = "1",@@ -32,7 +32,7 @@ namespace API.Tests.ParserTitle = "Darker Than Black",Volumes = "0"};-+var expected = new ParserInfo(){Chapters = "1",@@ -45,11 +45,11 @@ namespace API.Tests.ParserVolumes = "0"};p1.Merge(p2);-+AssertSame(expected, p1);}-+[Fact]public void MergeFromTest2(){@@ -64,7 +64,7 @@ namespace API.Tests.ParserTitle = "darker than black",Volumes = "0"};-+var p2 = new ParserInfo(){Chapters = "0",@@ -76,7 +76,7 @@ namespace API.Tests.ParserTitle = "Darker Than Black",Volumes = "1"};-+var expected = new ParserInfo(){Chapters = "1",@@ -93,9 +93,9 @@ namespace API.Tests.ParserAssertSame(expected, p1);}-- private void AssertSame(ParserInfo expected, ParserInfo actual)++ private static void AssertSame(ParserInfo expected, ParserInfo actual){Assert.Equal(expected.Chapters, actual.Chapters);Assert.Equal(expected.Volumes, actual.Volumes);@@ -107,4 +107,4 @@ namespace API.Tests.ParserAssert.Equal(expected.FullFilePath, actual.FullFilePath);}}-}\ No newline at end of file+}diff --git a/API.Tests/Parser/ParserTest.cs b/API.Tests/Parser/ParserTest.csindex 8fdf0509d..5068b39b3 100644--- a/API.Tests/Parser/ParserTest.cs+++ b/API.Tests/Parser/ParserTest.cs@@ -1,3 +1,5 @@+using System.Linq;+using API.Entities.Enums;using Xunit;using static API.Parser.Parser;@@ -5,6 +7,14 @@ namespace API.Tests.Parser{public class ParserTests{+ [Theory]+ [InlineData("Joe Shmo, Green Blue", "Joe Shmo, Green Blue")]+ [InlineData("Shmo, Joe", "Shmo, Joe")]+ [InlineData(" Joe Shmo ", "Joe Shmo")]+ public void CleanAuthorTest(string input, string expected)+ {+ Assert.Equal(expected, CleanAuthor(input));+ }[Theory][InlineData("Beastars - SP01", true)]@@ -40,6 +50,8 @@ namespace API.Tests.Parser[InlineData("Hello_I_am_here ", false, "Hello I am here")][InlineData("[ReleaseGroup] The Title", false, "The Title")][InlineData("[ReleaseGroup]_The_Title", false, "The Title")]+ [InlineData("-The Title", false, "The Title")]+ [InlineData("- The Title", false, "The Title")][InlineData("[Suihei Kiki]_Kasumi_Otoko_no_Ko_[Taruby]_v1.1", false, "Kasumi Otoko no Ko v1.1")][InlineData("Batman - Detective Comics - Rebirth Deluxe Edition Book 04 (2019) (digital) (Son of Ultron-Empire)", true, "Batman - Detective Comics - Rebirth Deluxe Edition")]public void CleanTitleTest(string input, bool isComic, string expected)@@ -47,20 +59,28 @@ namespace API.Tests.ParserAssert.Equal(expected, CleanTitle(input, isComic));}+ [Theory]+ [InlineData("src: url(fonts/AvenirNext-UltraLight.ttf)", true)]+ [InlineData("src: url(ideal-sans-serif.woff)", true)]+ [InlineData("src: local(\"Helvetica Neue Bold\")", true)]+ [InlineData("src: url(\"/fonts/OpenSans-Regular-webfont.woff2\")", true)]+ [InlineData("src: local(\"/fonts/OpenSans-Regular-webfont.woff2\")", true)]+ [InlineData("src: url(data:application/x-font-woff", false)]+ public void FontCssRewriteMatches(string input, bool expectedMatch)+ {+ Assert.Equal(expectedMatch, FontSrcUrlRegex.Matches(input).Count > 0);+ }- // [Theory]- // //[InlineData("@font-face{font-family:\"PaytoneOne\";src:url(\"..\\/Fonts\\/PaytoneOne.ttf\")}", "@font-face{font-family:\"PaytoneOne\";src:url(\"PaytoneOne.ttf\")}")]- // [InlineData("@font-face{font-family:\"PaytoneOne\";src:url(\"..\\/Fonts\\/PaytoneOne.ttf\")}", "..\\/Fonts\\/PaytoneOne.ttf")]- // //[InlineData("@font-face{font-family:'PaytoneOne';src:url('..\\/Fonts\\/PaytoneOne.ttf')}", "@font-face{font-family:'PaytoneOne';src:url('PaytoneOne.ttf')}")]- // //[InlineData("@font-face{\r\nfont-family:'PaytoneOne';\r\nsrc:url('..\\/Fonts\\/PaytoneOne.ttf')\r\n}", "@font-face{font-family:'PaytoneOne';src:url('PaytoneOne.ttf')}")]- // public void ReplaceStyleUrlTest(string input, string expected)- // {- // var replacementStr = "PaytoneOne.ttf";- // // Use Match to validate since replace is weird- // //Assert.Equal(expected, FontSrcUrlRegex.Replace(input, "$1" + replacementStr + "$2" + "$3"));- // var match = FontSrcUrlRegex.Match(input);- // Assert.Equal(!string.IsNullOrEmpty(expected), FontSrcUrlRegex.Match(input).Success);- // }+ [Theory]+ [InlineData("src: url(fonts/AvenirNext-UltraLight.ttf)", new [] {"src: url(", "fonts/AvenirNext-UltraLight.ttf", ")"})]+ [InlineData("src: url(ideal-sans-serif.woff)", new [] {"src: url(", "ideal-sans-serif.woff", ")"})]+ [InlineData("src: local(\"Helvetica Neue Bold\")", new [] {"src: local(\"", "Helvetica Neue Bold", "\")"})]+ [InlineData("src: url(\"/fonts/OpenSans-Regular-webfont.woff2\")", new [] {"src: url(\"", "/fonts/OpenSans-Regular-webfont.woff2", "\")"})]+ [InlineData("src: local(\"/fonts/OpenSans-Regular-webfont.woff2\")", new [] {"src: local(\"", "/fonts/OpenSans-Regular-webfont.woff2", "\")"})]+ public void FontCssCorrectlySeparates(string input, string[] expected)+ {+ Assert.Equal(expected, FontSrcUrlRegex.Match(input).Groups.Values.Select(g => g.Value).Where((_, i) => i > 0).ToArray());+ }[Theory]@@ -132,28 +152,14 @@ namespace API.Tests.Parser[InlineData("test.jpeg", true)][InlineData("test.png", true)][InlineData(".test.jpg", false)]- [InlineData("!test.jpg", false)]+ [InlineData("!test.jpg", true)][InlineData("test.webp", true)]public void IsImageTest(string filename, bool expected){Assert.Equal(expected, IsImage(filename));}- [Theory]- [InlineData("C:/", "C:/Love Hina/Love Hina - Special.cbz", "Love Hina")]- [InlineData("C:/", "C:/Love Hina/Specials/Ani-Hina Art Collection.cbz", "Love Hina")]- [InlineData("C:/", "C:/Mujaki no Rakuen Something/Mujaki no Rakuen Vol12 ch76.cbz", "Mujaki no Rakuen")]- public void FallbackTest(string rootDir, string inputPath, string expectedSeries)- {- var actual = Parse(inputPath, rootDir);- if (actual == null)- {- Assert.NotNull(actual);- return;- }- Assert.Equal(expectedSeries, actual.Series);- }[Theory][InlineData("Love Hina - Special.jpg", false)]@@ -164,6 +170,8 @@ namespace API.Tests.Parser[InlineData("cover.jpg", true)][InlineData("cover.png", true)][InlineData("ch1/cover.png", true)]+ [InlineData("ch1/backcover.png", false)]+ [InlineData("backcover.png", false)]public void IsCoverImageTest(string inputPath, bool expected){Assert.Equal(expected, IsCoverImage(inputPath));@@ -174,9 +182,23 @@ namespace API.Tests.Parser[InlineData("TEST/Love Hina - Special.jpg", false)][InlineData("__macosx/Love Hina/", false)][InlineData("MACOSX/Love Hina/", false)]+ [InlineData("._Love Hina/Love Hina/", true)]+ [InlineData("@Recently-Snapshot/Love Hina/", true)]public void HasBlacklistedFolderInPathTest(string inputPath, bool expected){Assert.Equal(expected, HasBlacklistedFolderInPath(inputPath));}++ [Theory]+ [InlineData("/manga/1/1/1", "/manga/1/1/1")]+ [InlineData("/manga/1/1/1.jpg", "/manga/1/1/1.jpg")]+ [InlineData(@"/manga/1/1\1.jpg", @"/manga/1/1/1.jpg")]+ [InlineData("/manga/1/1//1", "/manga/1/1//1")]+ [InlineData("/manga/1\\1\\1", "/manga/1/1/1")]+ [InlineData("C:/manga/1\\1\\1.jpg", "C:/manga/1/1/1.jpg")]+ public void NormalizePathTest(string inputPath, string expected)+ {+ Assert.Equal(expected, NormalizePath(inputPath));+ }}}diff --git a/API.Tests/Services/ArchiveServiceTests.cs b/API.Tests/Services/ArchiveServiceTests.csindex 7bdc18f1d..526abde3e 100644--- a/API.Tests/Services/ArchiveServiceTests.cs+++ b/API.Tests/Services/ArchiveServiceTests.cs@@ -1,11 +1,14 @@using System.Diagnostics;using System.IO;+using System.IO.Abstractions;+using System.IO.Abstractions.TestingHelpers;using System.IO.Compression;+using System.Linq;using API.Archive;using API.Data.Metadata;-using API.Interfaces.Services;using API.Services;using Microsoft.Extensions.Logging;+using NetVips;using NSubstitute;using NSubstitute.Extensions;using Xunit;@@ -19,12 +22,12 @@ namespace API.Tests.Servicesprivate readonly ArchiveService _archiveService;private readonly ILogger<ArchiveService> _logger = Substitute.For<ILogger<ArchiveService>>();private readonly ILogger<DirectoryService> _directoryServiceLogger = Substitute.For<ILogger<DirectoryService>>();- private readonly IDirectoryService _directoryService = new DirectoryService(Substitute.For<ILogger<DirectoryService>>());+ private readonly IDirectoryService _directoryService = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), new FileSystem());public ArchiveServiceTests(ITestOutputHelper testOutputHelper){_testOutputHelper = testOutputHelper;- _archiveService = new ArchiveService(_logger, _directoryService);+ _archiveService = new ArchiveService(_logger, _directoryService, new ImageService(Substitute.For<ILogger<ImageService>>(), _directoryService));}[Theory]@@ -107,15 +110,15 @@ namespace API.Tests.Servicesvar testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives");var extractDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives/Extraction");- DirectoryService.ClearAndDeleteDirectory(extractDirectory);+ _directoryService.ClearAndDeleteDirectory(extractDirectory);- Stopwatch sw = Stopwatch.StartNew();+ var sw = Stopwatch.StartNew();_archiveService.ExtractArchive(Path.Join(testDirectory, archivePath), extractDirectory);var di1 = new DirectoryInfo(extractDirectory);- Assert.Equal(expectedFileCount, di1.Exists ? di1.GetFiles().Length : 0);+ Assert.Equal(expectedFileCount, di1.Exists ? _directoryService.GetFiles(extractDirectory, searchOption:SearchOption.AllDirectories).Count() : 0);_testOutputHelper.WriteLine($"Processed in {sw.ElapsedMilliseconds} ms");- DirectoryService.ClearAndDeleteDirectory(extractDirectory);+ _directoryService.ClearAndDeleteDirectory(extractDirectory);}@@ -128,7 +131,7 @@ namespace API.Tests.Services[InlineData(new [] {"Akame ga KILL! ZERO - c055 (v10) - p000 [Digital] [LuCaZ].jpg", "Akame ga KILL! ZERO - c055 (v10) - p000 [Digital] [LuCaZ].jpg", "Akame ga KILL! ZERO - c060 (v10) - p200 [Digital] [LuCaZ].jpg", "folder.jpg"}, "folder.jpg")]public void FindFolderEntry(string[] files, string expected){- var foundFile = _archiveService.FindFolderEntry(files);+ var foundFile = ArchiveService.FindFolderEntry(files);Assert.Equal(expected, string.IsNullOrEmpty(foundFile) ? "" : foundFile);}@@ -141,6 +144,7 @@ namespace API.Tests.Services[InlineData(new [] {"__MACOSX/cover.jpg", "vol1/page 01.jpg"}, "vol1/page 01.jpg")][InlineData(new [] {"Akame ga KILL! ZERO - c055 (v10) - p000 [Digital] [LuCaZ].jpg", "Akame ga KILL! ZERO - c055 (v10) - p000 [Digital] [LuCaZ].jpg", "Akame ga KILL! ZERO - c060 (v10) - p200 [Digital] [LuCaZ].jpg", "folder.jpg"}, "Akame ga KILL! ZERO - c055 (v10) - p000 [Digital] [LuCaZ].jpg")][InlineData(new [] {"001.jpg", "001 - chapter 1/001.jpg"}, "001.jpg")]+ [InlineData(new [] {"chapter 1/001.jpg", "chapter 2/002.jpg", "somefile.jpg"}, "somefile.jpg")]public void FindFirstEntry(string[] files, string expected){var foundFile = ArchiveService.FirstFileEntry(files, string.Empty);@@ -157,27 +161,29 @@ namespace API.Tests.Services[InlineData("macos_native.zip", "macos_native.jpg")][InlineData("v10 - duplicate covers.cbz", "v10 - duplicate covers.expected.jpg")][InlineData("sorting.zip", "sorting.expected.jpg")]+ [InlineData("test.zip", "test.expected.jpg")] // https://github.com/kleisauke/net-vips/issues/155public void GetCoverImage_Default_Test(string inputFile, string expectedOutputFile){- var archiveService = Substitute.For<ArchiveService>(_logger, new DirectoryService(_directoryServiceLogger));- var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/CoverImages");- var expectedBytes = File.ReadAllBytes(Path.Join(testDirectory, expectedOutputFile));+ var ds = Substitute.For<DirectoryService>(_directoryServiceLogger, new FileSystem());+ var imageService = new ImageService(Substitute.For<ILogger<ImageService>>(), ds);+ var archiveService = Substitute.For<ArchiveService>(_logger, ds, imageService);++ var testDirectory = Path.GetFullPath(Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/CoverImages"));+ var expectedBytes = Image.Thumbnail(Path.Join(testDirectory, expectedOutputFile), 320).WriteToBuffer(".png");+archiveService.Configure().CanOpen(Path.Join(testDirectory, inputFile)).Returns(ArchiveLibrary.Default);- var sw = Stopwatch.StartNew();var outputDir = Path.Join(testDirectory, "output");- DirectoryService.ClearAndDeleteDirectory(outputDir);- DirectoryService.ExistOrCreate(outputDir);-+ _directoryService.ClearDirectory(outputDir);+ _directoryService.ExistOrCreate(outputDir);var coverImagePath = archiveService.GetCoverImage(Path.Join(testDirectory, inputFile),- Path.GetFileNameWithoutExtension(inputFile) + "_output");- var actual = File.ReadAllBytes(coverImagePath);+ Path.GetFileNameWithoutExtension(inputFile) + "_output", outputDir);+ var actual = File.ReadAllBytes(Path.Join(outputDir, coverImagePath));Assert.Equal(expectedBytes, actual);- _testOutputHelper.WriteLine($"Processed in {sw.ElapsedMilliseconds} ms");- DirectoryService.ClearAndDeleteDirectory(outputDir);+ //_directoryService.ClearAndDeleteDirectory(outputDir);}@@ -191,35 +197,69 @@ namespace API.Tests.Services[InlineData("sorting.zip", "sorting.expected.jpg")]public void GetCoverImage_SharpCompress_Test(string inputFile, string expectedOutputFile){- var archiveService = Substitute.For<ArchiveService>(_logger, new DirectoryService(_directoryServiceLogger));+ var imageService = new ImageService(Substitute.For<ILogger<ImageService>>(), _directoryService);+ var archiveService = Substitute.For<ArchiveService>(_logger,+ new DirectoryService(_directoryServiceLogger, new FileSystem()), imageService);var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/CoverImages");var expectedBytes = File.ReadAllBytes(Path.Join(testDirectory, expectedOutputFile));+ var outputDir = Path.Join(testDirectory, "output");+ _directoryService.ClearDirectory(outputDir);+ _directoryService.ExistOrCreate(outputDir);+archiveService.Configure().CanOpen(Path.Join(testDirectory, inputFile)).Returns(ArchiveLibrary.SharpCompress);- Stopwatch sw = Stopwatch.StartNew();- Assert.Equal(expectedBytes, File.ReadAllBytes(archiveService.GetCoverImage(Path.Join(testDirectory, inputFile), Path.GetFileNameWithoutExtension(inputFile) + "_output")));- _testOutputHelper.WriteLine($"Processed in {sw.ElapsedMilliseconds} ms");+ var actualBytes = File.ReadAllBytes(archiveService.GetCoverImage(Path.Join(testDirectory, inputFile),+ Path.GetFileNameWithoutExtension(inputFile) + "_output", outputDir));+ Assert.Equal(expectedBytes, actualBytes);++ _directoryService.ClearAndDeleteDirectory(outputDir);}- // TODO: This is broken on GA due to DirectoryService.CoverImageDirectory- //[Theory]+ [Theory][InlineData("Archives/macos_native.zip")][InlineData("Formats/One File with DB_Supported.zip")]public void CanParseCoverImage(string inputFile){+ var imageService = Substitute.For<IImageService>();+ imageService.WriteCoverThumbnail(Arg.Any<Stream>(), Arg.Any<string>(), Arg.Any<string>()).Returns(x => "cover.jpg");+ var archiveService = new ArchiveService(_logger, _directoryService, imageService);var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/");- Assert.NotEmpty(File.ReadAllBytes(_archiveService.GetCoverImage(Path.Join(testDirectory, inputFile), Path.GetFileNameWithoutExtension(inputFile) + "_output")));+ var inputPath = Path.GetFullPath(Path.Join(testDirectory, inputFile));+ var outputPath = Path.Join(testDirectory, Path.GetFileNameWithoutExtension(inputFile) + "_output");+ new DirectoryInfo(outputPath).Create();+ var expectedImage = archiveService.GetCoverImage(inputPath, inputFile, outputPath);+ Assert.Equal("cover.jpg", expectedImage);+ new DirectoryInfo(outputPath).Delete();}- [Fact]- public void ShouldHaveComicInfo()- {- var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/ComicInfos");- var archive = Path.Join(testDirectory, "file in folder.zip");- var summaryInfo = "By all counts, Ryouta Sakamoto is a loser when he's not holed up in his room, bombing things into oblivion in his favorite online action RPG. But his very own uneventful life is blown to pieces when he's abducted and taken to an uninhabited island, where he soon learns the hard way that he's being pitted against others just like him in a explosives-riddled death match! How could this be happening? Who's putting them up to this? And why!? The name, not to mention the objective, of this very real survival game is eerily familiar to Ryouta, who has mastered its virtual counterpart-BTOOOM! Can Ryouta still come out on top when he's playing for his life!?";+ #region ShouldHaveComicInfo- Assert.Equal(summaryInfo, _archiveService.GetComicInfo(archive).Summary);- }+ [Fact]+ public void ShouldHaveComicInfo()+ {+ var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/ComicInfos");+ var archive = Path.Join(testDirectory, "ComicInfo.zip");+ const string summaryInfo = "By all counts, Ryouta Sakamoto is a loser when he's not holed up in his room, bombing things into oblivion in his favorite online action RPG. But his very own uneventful life is blown to pieces when he's abducted and taken to an uninhabited island, where he soon learns the hard way that he's being pitted against others just like him in a explosives-riddled death match! How could this be happening? Who's putting them up to this? And why!? The name, not to mention the objective, of this very real survival game is eerily familiar to Ryouta, who has mastered its virtual counterpart-BTOOOM! Can Ryouta still come out on top when he's playing for his life!?";++ var comicInfo = _archiveService.GetComicInfo(archive);+ Assert.NotNull(comicInfo);+ Assert.Equal(summaryInfo, comicInfo.Summary);+ }++ [Fact]+ public void ShouldHaveComicInfo_WithAuthors()+ {+ var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/ComicInfos");+ var archive = Path.Join(testDirectory, "ComicInfo_authors.zip");++ var comicInfo = _archiveService.GetComicInfo(archive);+ Assert.NotNull(comicInfo);+ Assert.Equal("Junya Inoue", comicInfo.Writer);+ }++ #endregion++ #region CanParseComicInfo[Fact]public void CanParseComicInfo()@@ -243,5 +283,38 @@ namespace API.Tests.ServicesAssert.NotStrictEqual(expected, actual);}++ #endregion++ #region FindCoverImageFilename++ [Theory]+ [InlineData(new string[] {}, "", null)]+ [InlineData(new [] {"001.jpg", "002.jpg"}, "Test.zip", "001.jpg")]+ [InlineData(new [] {"001.jpg", "!002.jpg"}, "Test.zip", "!002.jpg")]+ [InlineData(new [] {"001.jpg", "!001.jpg"}, "Test.zip", "!001.jpg")]+ [InlineData(new [] {"001.jpg", "cover.jpg"}, "Test.zip", "cover.jpg")]+ [InlineData(new [] {"001.jpg", "Chapter 20/cover.jpg", "Chapter 21/0001.jpg"}, "Test.zip", "Chapter 20/cover.jpg")]+ [InlineData(new [] {"._/001.jpg", "._/cover.jpg", "010.jpg"}, "Test.zip", "010.jpg")]+ [InlineData(new [] {"001.txt", "002.txt", "a.jpg"}, "Test.zip", "a.jpg")]+ public void FindCoverImageFilename(string[] filenames, string archiveName, string expected)+ {+ Assert.Equal(expected, _archiveService.FindCoverImageFilename(archiveName, filenames));+ }+++ #endregion++ #region CreateZipForDownload++ //[Fact]+ public void CreateZipForDownloadTest()+ {+ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ //_archiveService.CreateZipForDownload(new []{}, outputDirectory)+ }++ #endregion}}diff --git a/API.Tests/Services/BackupServiceTests.cs b/API.Tests/Services/BackupServiceTests.csnew file mode 100644index 000000000..1af01632c--- /dev/null+++ b/API.Tests/Services/BackupServiceTests.cs@@ -0,0 +1,143 @@+using System.Collections.Generic;+using System.Data.Common;+using System.IO.Abstractions.TestingHelpers;+using System.Linq;+using System.Threading.Tasks;+using API.Data;+using API.Entities;+using API.Entities.Enums;+using API.Extensions;+using API.Services;+using API.Services.Tasks;+using API.SignalR;+using AutoMapper;+using Microsoft.AspNetCore.SignalR;+using Microsoft.Data.Sqlite;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.Extensions.Configuration;+using Microsoft.Extensions.Logging;+using NSubstitute;+using Xunit;++namespace API.Tests.Services;++public class BackupServiceTests+{+ private readonly ILogger<BackupService> _logger = Substitute.For<ILogger<BackupService>>();+ private readonly IUnitOfWork _unitOfWork;+ private readonly IHubContext<MessageHub> _messageHub = Substitute.For<IHubContext<MessageHub>>();+ private readonly IConfiguration _config;++ private readonly DbConnection _connection;+ private readonly DataContext _context;++ private const string CacheDirectory = "C:/kavita/config/cache/";+ private const string CoverImageDirectory = "C:/kavita/config/covers/";+ private const string BackupDirectory = "C:/kavita/config/backups/";+ private const string LogDirectory = "C:/kavita/config/logs/";++ public BackupServiceTests()+ {+ var contextOptions = new DbContextOptionsBuilder()+ .UseSqlite(CreateInMemoryDatabase())+ .Options;+ _connection = RelationalOptionsExtension.Extract(contextOptions).Connection;++ _context = new DataContext(contextOptions);+ Task.Run(SeedDb).GetAwaiter().GetResult();++ _unitOfWork = new UnitOfWork(_context, Substitute.For<IMapper>(), null);+ _config = Substitute.For<IConfiguration>();++ }++ #region Setup++ private static DbConnection CreateInMemoryDatabase()+ {+ var connection = new SqliteConnection("Filename=:memory:");++ connection.Open();++ return connection;+ }++ public void Dispose() => _connection.Dispose();++ private async Task<bool> SeedDb()+ {+ await _context.Database.MigrateAsync();+ var filesystem = CreateFileSystem();++ await Seed.SeedSettings(_context, new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem));++ var setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.CacheDirectory).SingleAsync();+ setting.Value = CacheDirectory;++ setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.BackupDirectory).SingleAsync();+ setting.Value = BackupDirectory;++ _context.ServerSetting.Update(setting);++ _context.Library.Add(new Library()+ {+ Name = "Manga",+ Folders = new List<FolderPath>()+ {+ new FolderPath()+ {+ Path = "C:/data/"+ }+ }+ });+ return await _context.SaveChangesAsync() > 0;+ }++ private async Task ResetDB()+ {+ _context.Series.RemoveRange(_context.Series.ToList());++ await _context.SaveChangesAsync();+ }++ private static MockFileSystem CreateFileSystem()+ {+ var fileSystem = new MockFileSystem();+ fileSystem.Directory.SetCurrentDirectory("C:/kavita/");+ fileSystem.AddDirectory("C:/kavita/config/");+ fileSystem.AddDirectory(CacheDirectory);+ fileSystem.AddDirectory(CoverImageDirectory);+ fileSystem.AddDirectory(BackupDirectory);+ fileSystem.AddDirectory(LogDirectory);+ fileSystem.AddDirectory("C:/data/");++ return fileSystem;+ }++ #endregion++++ #region GetLogFiles++ public void GetLogFiles_ExpectAllFiles_NoRollingFiles()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddFile($"{LogDirectory}kavita.log", new MockFileData(""));+ filesystem.AddFile($"{LogDirectory}kavita1.log", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ // You can't mock _config extensions because they are static+ _config.GetMaxRollingFiles().Returns(1);+ _config.GetLoggingFileName().Returns(ds.FileSystem.Path.Join(LogDirectory, "kavita.log"));++ var backupService = new BackupService(_logger, _unitOfWork, ds, _config, _messageHub);++ Assert.Single(backupService.GetLogFiles(1, LogDirectory));+ }+++ #endregion++}diff --git a/API.Tests/Services/BookServiceTests.cs b/API.Tests/Services/BookServiceTests.csindex d0cc29040..07fa2936d 100644--- a/API.Tests/Services/BookServiceTests.cs+++ b/API.Tests/Services/BookServiceTests.cs@@ -1,5 +1,5 @@using System.IO;-using API.Interfaces.Services;+using System.IO.Abstractions;using API.Services;using Microsoft.Extensions.Logging;using NSubstitute;@@ -14,7 +14,8 @@ namespace API.Tests.Servicespublic BookServiceTests(){- _bookService = new BookService(_logger);+ var directoryService = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), new FileSystem());+ _bookService = new BookService(_logger, directoryService, new ImageService(Substitute.For<ILogger<ImageService>>(), directoryService));}[Theory]@@ -27,5 +28,40 @@ namespace API.Tests.ServicesAssert.Equal(expectedPages, _bookService.GetNumberOfPages(Path.Join(testDirectory, filePath)));}+ [Fact]+ public void ShouldHaveComicInfo()+ {+ var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BookService/EPUB");+ var archive = Path.Join(testDirectory, "The Golden Harpoon; Or, Lost Among the Floes A Story of the Whaling Grounds.epub");+ const string summaryInfo = "Book Description";++ var comicInfo = _bookService.GetComicInfo(archive);+ Assert.NotNull(comicInfo);+ Assert.Equal(summaryInfo, comicInfo.Summary);+ Assert.Equal("genre1, genre2", comicInfo.Genre);+ }++ [Fact]+ public void ShouldHaveComicInfo_WithAuthors()+ {+ var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BookService/EPUB");+ var archive = Path.Join(testDirectory, "The Golden Harpoon; Or, Lost Among the Floes A Story of the Whaling Grounds.epub");++ var comicInfo = _bookService.GetComicInfo(archive);+ Assert.NotNull(comicInfo);+ Assert.Equal("Roger Starbuck,Junya Inoue", comicInfo.Writer);+ }+++ #region BookEscaping++ [Fact]+ public void EscapeCSSImportReferencesTest()+ {++ }++ #endregion+}}diff --git a/API.Tests/Services/CacheServiceTests.cs b/API.Tests/Services/CacheServiceTests.csindex 410c43ade..7a2cbada8 100644--- a/API.Tests/Services/CacheServiceTests.cs+++ b/API.Tests/Services/CacheServiceTests.cs@@ -1,115 +1,508 @@-namespace API.Tests.Services+using System.Collections.Generic;+using System.Data.Common;+using System.IO;+using System.IO.Abstractions.TestingHelpers;+using System.Linq;+using System.Threading.Tasks;+using API.Data;+using API.Data.Metadata;+using API.Entities;+using API.Entities.Enums;+using API.Parser;+using API.Services;+using API.SignalR;+using AutoMapper;+using Microsoft.AspNetCore.SignalR;+using Microsoft.Data.Sqlite;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.Extensions.Logging;+using NSubstitute;+using Xunit;++namespace API.Tests.Services{+ internal class MockReadingItemServiceForCacheService : IReadingItemService+ {+ private readonly DirectoryService _directoryService;++ public MockReadingItemServiceForCacheService(DirectoryService directoryService)+ {+ _directoryService = directoryService;+ }++ public ComicInfo GetComicInfo(string filePath)+ {+ return null;+ }++ public int GetNumberOfPages(string filePath, MangaFormat format)+ {+ return 1;+ }++ public string GetCoverImage(string fileFilePath, string fileName, MangaFormat format)+ {+ return string.Empty;+ }++ public void Extract(string fileFilePath, string targetDirectory, MangaFormat format, int imageCount = 1)+ {+ throw new System.NotImplementedException();+ }++ public ParserInfo Parse(string path, string rootPath, LibraryType type)+ {+ throw new System.NotImplementedException();+ }+ }public class CacheServiceTests{- // private readonly CacheService _cacheService;- // private readonly ILogger<CacheService> _logger = Substitute.For<ILogger<CacheService>>();- // private readonly IUnitOfWork _unitOfWork = Substitute.For<IUnitOfWork>();- // private readonly IArchiveService _archiveService = Substitute.For<IArchiveService>();- // private readonly IDirectoryService _directoryService = Substitute.For<DirectoryService>();- //- // public CacheServiceTests()- // {- // _cacheService = new CacheService(_logger, _unitOfWork, _archiveService, _directoryService);- // }-+ private readonly ILogger<CacheService> _logger = Substitute.For<ILogger<CacheService>>();+ private readonly IUnitOfWork _unitOfWork;+ private readonly IHubContext<MessageHub> _messageHub = Substitute.For<IHubContext<MessageHub>>();++ private readonly DbConnection _connection;+ private readonly DataContext _context;++ private const string CacheDirectory = "C:/kavita/config/cache/";+ private const string CoverImageDirectory = "C:/kavita/config/covers/";+ private const string BackupDirectory = "C:/kavita/config/backups/";+ private const string DataDirectory = "C:/data/";++ public CacheServiceTests()+ {+ var contextOptions = new DbContextOptionsBuilder()+ .UseSqlite(CreateInMemoryDatabase())+ .Options;+ _connection = RelationalOptionsExtension.Extract(contextOptions).Connection;++ _context = new DataContext(contextOptions);+ Task.Run(SeedDb).GetAwaiter().GetResult();++ _unitOfWork = new UnitOfWork(_context, Substitute.For<IMapper>(), null);+ }++ #region Setup++ private static DbConnection CreateInMemoryDatabase()+ {+ var connection = new SqliteConnection("Filename=:memory:");++ connection.Open();++ return connection;+ }++ public void Dispose() => _connection.Dispose();++ private async Task<bool> SeedDb()+ {+ await _context.Database.MigrateAsync();+ var filesystem = CreateFileSystem();++ await Seed.SeedSettings(_context, new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem));++ var setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.CacheDirectory).SingleAsync();+ setting.Value = CacheDirectory;++ setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.BackupDirectory).SingleAsync();+ setting.Value = BackupDirectory;++ _context.ServerSetting.Update(setting);++ _context.Library.Add(new Library()+ {+ Name = "Manga",+ Folders = new List<FolderPath>()+ {+ new FolderPath()+ {+ Path = "C:/data/"+ }+ }+ });+ return await _context.SaveChangesAsync() > 0;+ }++ private async Task ResetDB()+ {+ _context.Series.RemoveRange(_context.Series.ToList());++ await _context.SaveChangesAsync();+ }++ private static MockFileSystem CreateFileSystem()+ {+ var fileSystem = new MockFileSystem();+ fileSystem.Directory.SetCurrentDirectory("C:/kavita/");+ fileSystem.AddDirectory("C:/kavita/config/");+ fileSystem.AddDirectory(CacheDirectory);+ fileSystem.AddDirectory(CoverImageDirectory);+ fileSystem.AddDirectory(BackupDirectory);+ fileSystem.AddDirectory(DataDirectory);++ return fileSystem;+ }++ #endregion++ #region Ensure++ [Fact]+ public async Task Ensure_DirectoryAlreadyExists_DontExtractAnything()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddFile($"{DataDirectory}Test v1.zip", new MockFileData(""));+ filesystem.AddDirectory($"{CacheDirectory}1/");+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CacheService(_logger, _unitOfWork, ds,+ new ReadingItemService(Substitute.For<IArchiveService>(), Substitute.For<IBookService>(), Substitute.For<IImageService>(), ds));++ await ResetDB();+ var s = DbFactory.Series("Test");+ var v = DbFactory.Volume("1");+ var c = new Chapter()+ {+ Number = "1",+ Files = new List<MangaFile>()+ {+ new MangaFile()+ {+ Format = MangaFormat.Archive,+ FilePath = $"{DataDirectory}Test v1.zip",+ }+ }+ };+ v.Chapters.Add(c);+ s.Volumes.Add(v);+ s.LibraryId = 1;+ _context.Series.Add(s);++ await _context.SaveChangesAsync();++ await cleanupService.Ensure(1);+ Assert.Empty(ds.GetFiles(filesystem.Path.Join(CacheDirectory, "1"), searchOption:SearchOption.AllDirectories));+ }+// [Fact]- // public async void Ensure_ShouldExtractArchive(int chapterId)+ // public async Task Ensure_DirectoryAlreadyExists_ExtractsImages()// {- //- // // CacheDirectory needs to be customized.- // _unitOfWork.VolumeRepository.GetChapterAsync(chapterId).Returns(new Chapter+ // // TODO: Figure out a way to test this+ // var filesystem = CreateFileSystem();+ // filesystem.AddFile($"{DataDirectory}Test v1.zip", new MockFileData(""));+ // filesystem.AddDirectory($"{CacheDirectory}1/");+ // var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ // var archiveService = Substitute.For<IArchiveService>();+ // archiveService.ExtractArchive($"{DataDirectory}Test v1.zip",+ // filesystem.Path.Join(CacheDirectory, "1"));+ // var cleanupService = new CacheService(_logger, _unitOfWork, ds,+ // new ReadingItemService(archiveService, Substitute.For<IBookService>(), Substitute.For<IImageService>(), ds));+ //+ // await ResetDB();+ // var s = DbFactory.Series("Test");+ // var v = DbFactory.Volume("1");+ // var c = new Chapter()// {- // Id = 1,+ // Number = "1",// Files = new List<MangaFile>()// {// new MangaFile()// {- // FilePath = ""+ // Format = MangaFormat.Archive,+ // FilePath = $"{DataDirectory}Test v1.zip",// }// }- // });- //- // await _cacheService.Ensure(1);- //- // var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/CacheService/Archives");+ // };+ // v.Chapters.Add(c);+ // s.Volumes.Add(v);+ // s.LibraryId = 1;+ // _context.Series.Add(s);+ //+ // await _context.SaveChangesAsync();//+ // await cleanupService.Ensure(1);+ // Assert.Empty(ds.GetFiles(filesystem.Path.Join(CacheDirectory, "1"), searchOption:SearchOption.AllDirectories));// }-- //string GetCachedPagePath(Volume volume, int page)+++ #endregion++ #region CleanupChapters++ [Fact]+ public void CleanupChapters_AllFilesShouldBeDeleted()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddDirectory($"{CacheDirectory}1/");+ filesystem.AddFile($"{CacheDirectory}1/001.jpg", new MockFileData(""));+ filesystem.AddFile($"{CacheDirectory}1/002.jpg", new MockFileData(""));+ filesystem.AddFile($"{CacheDirectory}3/003.jpg", new MockFileData(""));+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CacheService(_logger, _unitOfWork, ds,+ new ReadingItemService(Substitute.For<IArchiveService>(), Substitute.For<IBookService>(), Substitute.For<IImageService>(), ds));++ cleanupService.CleanupChapters(new []{1, 3});+ Assert.Empty(ds.GetFiles(CacheDirectory, searchOption:SearchOption.AllDirectories));+ }+++ #endregion++ #region GetCachedEpubFile++ [Fact]+ public void GetCachedEpubFile_ShouldReturnFirstEpub()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddDirectory($"{CacheDirectory}1/");+ filesystem.AddFile($"{DataDirectory}1.epub", new MockFileData(""));+ filesystem.AddFile($"{DataDirectory}2.epub", new MockFileData(""));+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cs = new CacheService(_logger, _unitOfWork, ds,+ new ReadingItemService(Substitute.For<IArchiveService>(), Substitute.For<IBookService>(), Substitute.For<IImageService>(), ds));++ var c = new Chapter()+ {+ Files = new List<MangaFile>()+ {+ new MangaFile()+ {+ FilePath = $"{DataDirectory}1.epub"+ },+ new MangaFile()+ {+ FilePath = $"{DataDirectory}2.epub"+ }+ }+ };+ cs.GetCachedEpubFile(1, c);+ Assert.Same($"{DataDirectory}1.epub", cs.GetCachedEpubFile(1, c));+ }++ #endregion++ #region GetCachedPagePath++ [Fact]+ public void GetCachedPagePath_ReturnNullIfNoFiles()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddDirectory($"{CacheDirectory}1/");+ filesystem.AddFile($"{DataDirectory}1.zip", new MockFileData(""));+ filesystem.AddFile($"{DataDirectory}2.zip", new MockFileData(""));++ var c = new Chapter()+ {+ Id = 1,+ Files = new List<MangaFile>()+ };++ var fileIndex = 0;+ foreach (var file in c.Files)+ {+ for (var i = 0; i < file.Pages - 1; i++)+ {+ filesystem.AddFile($"{CacheDirectory}1/{fileIndex}/{i+1}.jpg", new MockFileData(""));+ }++ fileIndex++;+ }++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cs = new CacheService(_logger, _unitOfWork, ds,+ new ReadingItemService(Substitute.For<IArchiveService>(), Substitute.For<IBookService>(), Substitute.For<IImageService>(), ds));++ // Flatten to prepare for how GetFullPath expects+ ds.Flatten($"{CacheDirectory}1/");++ var path = cs.GetCachedPagePath(c, 11);+ Assert.Equal(string.Empty, path);+ }++ [Fact]+ public void GetCachedPagePath_GetFileFromFirstFile()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddDirectory($"{CacheDirectory}1/");+ filesystem.AddFile($"{DataDirectory}1.zip", new MockFileData(""));+ filesystem.AddFile($"{DataDirectory}2.zip", new MockFileData(""));++ var c = new Chapter()+ {+ Id = 1,+ Files = new List<MangaFile>()+ {+ new MangaFile()+ {+ Id = 1,+ FilePath = $"{DataDirectory}1.zip",+ Pages = 10++ },+ new MangaFile()+ {+ Id = 2,+ FilePath = $"{DataDirectory}2.zip",+ Pages = 5+ }+ }+ };++ var fileIndex = 0;+ foreach (var file in c.Files)+ {+ for (var i = 0; i < file.Pages; i++)+ {+ filesystem.AddFile($"{CacheDirectory}1/00{fileIndex}_00{i+1}.jpg", new MockFileData(""));+ }++ fileIndex++;+ }++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cs = new CacheService(_logger, _unitOfWork, ds,+ new ReadingItemService(Substitute.For<IArchiveService>(), Substitute.For<IBookService>(), Substitute.For<IImageService>(), ds));++ // Flatten to prepare for how GetFullPath expects+ ds.Flatten($"{CacheDirectory}1/");++ Assert.Equal(ds.FileSystem.Path.GetFullPath($"{CacheDirectory}/1/000_001.jpg"), ds.FileSystem.Path.GetFullPath(cs.GetCachedPagePath(c, 0)));++ }+++ [Fact]+ public void GetCachedPagePath_GetLastPageFromSingleFile()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddDirectory($"{CacheDirectory}1/");+ filesystem.AddFile($"{DataDirectory}1.zip", new MockFileData(""));++ var c = new Chapter()+ {+ Id = 1,+ Files = new List<MangaFile>()+ {+ new MangaFile()+ {+ Id = 1,+ FilePath = $"{DataDirectory}1.zip",+ Pages = 10++ }+ }+ };+ c.Pages = c.Files.Sum(f => f.Pages);++ var fileIndex = 0;+ foreach (var file in c.Files)+ {+ for (var i = 0; i < file.Pages; i++)+ {+ filesystem.AddFile($"{CacheDirectory}1/{fileIndex}/{i+1}.jpg", new MockFileData(""));+ }++ fileIndex++;+ }++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cs = new CacheService(_logger, _unitOfWork, ds,+ new ReadingItemService(Substitute.For<IArchiveService>(), Substitute.For<IBookService>(), Substitute.For<IImageService>(), ds));++ // Flatten to prepare for how GetFullPath expects+ ds.Flatten($"{CacheDirectory}1/");++ // Remember that we start at 0, so this is the 10th file+ var path = cs.GetCachedPagePath(c, c.Pages);+ Assert.Equal(ds.FileSystem.Path.GetFullPath($"{CacheDirectory}/1/000_0{c.Pages}.jpg"), ds.FileSystem.Path.GetFullPath(path));+ }++ [Fact]+ public void GetCachedPagePath_GetFileFromSecondFile()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddDirectory($"{CacheDirectory}1/");+ filesystem.AddFile($"{DataDirectory}1.zip", new MockFileData(""));+ filesystem.AddFile($"{DataDirectory}2.zip", new MockFileData(""));++ var c = new Chapter()+ {+ Id = 1,+ Files = new List<MangaFile>()+ {+ new MangaFile()+ {+ Id = 1,+ FilePath = $"{DataDirectory}1.zip",+ Pages = 10++ },+ new MangaFile()+ {+ Id = 2,+ FilePath = $"{DataDirectory}2.zip",+ Pages = 5+ }+ }+ };++ var fileIndex = 0;+ foreach (var file in c.Files)+ {+ for (var i = 0; i < file.Pages; i++)+ {+ filesystem.AddFile($"{CacheDirectory}1/{fileIndex}/{i+1}.jpg", new MockFileData(""));+ }++ fileIndex++;+ }++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cs = new CacheService(_logger, _unitOfWork, ds,+ new ReadingItemService(Substitute.For<IArchiveService>(), Substitute.For<IBookService>(), Substitute.For<IImageService>(), ds));++ // Flatten to prepare for how GetFullPath expects+ ds.Flatten($"{CacheDirectory}1/");++ // Remember that we start at 0, so this is the page + 1 file+ var path = cs.GetCachedPagePath(c, 10);+ Assert.Equal(ds.FileSystem.Path.GetFullPath($"{CacheDirectory}/1/001_001.jpg"), ds.FileSystem.Path.GetFullPath(path));+ }++ #endregion++ #region ExtractChapterFiles+// [Fact]- // //[InlineData("", 0, "")]- // public void GetCachedPagePathTest_Should()+ // public void ExtractChapterFiles_ShouldExtractOnlyImages()// {- //- // // string archivePath = "flat file.zip";- // // int pageNum = 0;- // // string expected = "cache/1/pexels-photo-6551949.jpg";- // //- // // var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives");- // // var file = Path.Join(testDirectory, archivePath);- // // var volume = new Volume- // // {- // // Id = 1,- // // Files = new List<MangaFile>()- // // {- // // new()- // // {- // // Id = 1,- // // Chapter = 0,- // // FilePath = archivePath,- // // Format = MangaFormat.Archive,- // // Pages = 1,- // // }- // // },- // // Name = "1",- // // Number = 1- // // };- // //- // // var cacheService = Substitute.ForPartsOf<CacheService>();- // // cacheService.Configure().CacheDirectoryIsAccessible().Returns(true);- // // cacheService.Configure().GetVolumeCachePath(1, volume.Files.ElementAt(0)).Returns("cache/1/");- // // _directoryService.Configure().GetFilesWithExtension("cache/1/").Returns(new string[] {"pexels-photo-6551949.jpg"});- // // Assert.Equal(expected, _cacheService.GetCachedPagePath(volume, pageNum));- // //Assert.True(true);- // }- //- // [Fact]- // public void GetOrderedChaptersTest()+ // const string testDirectory = "/manga/";+ // var fileSystem = new MockFileSystem();+ // for (var i = 0; i < 10; i++)// {- // // var files = new List<Chapter>()- // // {- // // new()- // // {- // // Number = "1"- // // },- // // new()- // // {- // // Chapter = 2- // // },- // // new()- // // {- // // Chapter = 0- // // },- // // };- // // var expected = new List<MangaFile>()- // // {- // // new()- // // {- // // Chapter = 1- // // },- // // new()- // // {- // // Chapter = 2- // // },- // // new()- // // {- // // Chapter = 0- // // },- // // };- // // Assert.NotStrictEqual(expected, _cacheService.GetOrderedChapters(files));+ // fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));// }//-+ // fileSystem.AddDirectory(CacheDirectory);+ //+ // var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ // var cs = new CacheService(_logger, _unitOfWork, ds,+ // new MockReadingItemServiceForCacheService(ds));+ //+ //+ // cs.ExtractChapterFiles(CacheDirectory, new List<MangaFile>()+ // {+ // new MangaFile()+ // {+ // ChapterId = 1,+ // Format = MangaFormat.Archive,+ // Pages = 2,+ // FilePath =+ // }+ // })+ // }++ #endregion}-}\ No newline at end of file+}diff --git a/API.Tests/Services/CleanupServiceTests.cs b/API.Tests/Services/CleanupServiceTests.csnew file mode 100644index 000000000..419dd4126--- /dev/null+++ b/API.Tests/Services/CleanupServiceTests.cs@@ -0,0 +1,433 @@+using System;+using System.Collections.Generic;+using System.Data.Common;+using System.IO;+using System.IO.Abstractions.TestingHelpers;+using System.Linq;+using System.Threading.Tasks;+using API.Data;+using API.Entities;+using API.Entities.Enums;+using API.Services;+using API.Services.Tasks;+using API.SignalR;+using AutoMapper;+using Microsoft.AspNetCore.SignalR;+using Microsoft.Data.Sqlite;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.Extensions.Logging;+using NSubstitute;+using Xunit;++namespace API.Tests.Services;++public class CleanupServiceTests+{+ private readonly ILogger<CleanupService> _logger = Substitute.For<ILogger<CleanupService>>();+ private readonly IUnitOfWork _unitOfWork;+ private readonly IHubContext<MessageHub> _messageHub = Substitute.For<IHubContext<MessageHub>>();++ private readonly DbConnection _connection;+ private readonly DataContext _context;++ private const string CacheDirectory = "C:/kavita/config/cache/";+ private const string CoverImageDirectory = "C:/kavita/config/covers/";+ private const string BackupDirectory = "C:/kavita/config/backups/";+ private const string BookmarkDirectory = "C:/kavita/config/bookmarks/";+++ public CleanupServiceTests()+ {+ var contextOptions = new DbContextOptionsBuilder()+ .UseSqlite(CreateInMemoryDatabase())+ .Options;+ _connection = RelationalOptionsExtension.Extract(contextOptions).Connection;++ _context = new DataContext(contextOptions);+ Task.Run(SeedDb).GetAwaiter().GetResult();++ _unitOfWork = new UnitOfWork(_context, Substitute.For<IMapper>(), null);+ }++ #region Setup++ private static DbConnection CreateInMemoryDatabase()+ {+ var connection = new SqliteConnection("Filename=:memory:");++ connection.Open();++ return connection;+ }++ public void Dispose() => _connection.Dispose();++ private async Task<bool> SeedDb()+ {+ await _context.Database.MigrateAsync();+ var filesystem = CreateFileSystem();++ await Seed.SeedSettings(_context, new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem));++ var setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.CacheDirectory).SingleAsync();+ setting.Value = CacheDirectory;++ setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.BackupDirectory).SingleAsync();+ setting.Value = BackupDirectory;++ setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.BookmarkDirectory).SingleAsync();+ setting.Value = BookmarkDirectory;++ _context.ServerSetting.Update(setting);++ _context.Library.Add(new Library()+ {+ Name = "Manga",+ Folders = new List<FolderPath>()+ {+ new FolderPath()+ {+ Path = "C:/data/"+ }+ }+ });+ return await _context.SaveChangesAsync() > 0;+ }++ private async Task ResetDB()+ {+ _context.Series.RemoveRange(_context.Series.ToList());+ _context.Users.RemoveRange(_context.Users.ToList());+ _context.AppUserBookmark.RemoveRange(_context.AppUserBookmark.ToList());++ await _context.SaveChangesAsync();+ }++ private static MockFileSystem CreateFileSystem()+ {+ var fileSystem = new MockFileSystem();+ fileSystem.Directory.SetCurrentDirectory("C:/kavita/");+ fileSystem.AddDirectory("C:/kavita/config/");+ fileSystem.AddDirectory(CacheDirectory);+ fileSystem.AddDirectory(CoverImageDirectory);+ fileSystem.AddDirectory(BackupDirectory);+ fileSystem.AddDirectory(BookmarkDirectory);+ fileSystem.AddDirectory("C:/data/");++ return fileSystem;+ }++ #endregion+++ #region DeleteSeriesCoverImages++ [Fact]+ public async Task DeleteSeriesCoverImages_ShouldDeleteAll()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddFile($"{CoverImageDirectory}series_01.jpg", new MockFileData(""));+ filesystem.AddFile($"{CoverImageDirectory}series_03.jpg", new MockFileData(""));+ filesystem.AddFile($"{CoverImageDirectory}series_1000.jpg", new MockFileData(""));++ // Delete all Series to reset state+ await ResetDB();++ var s = DbFactory.Series("Test 1");+ s.CoverImage = "series_01.jpg";+ s.LibraryId = 1;+ _context.Series.Add(s);+ s = DbFactory.Series("Test 2");+ s.CoverImage = "series_03.jpg";+ s.LibraryId = 1;+ _context.Series.Add(s);+ s = DbFactory.Series("Test 3");+ s.CoverImage = "series_1000.jpg";+ s.LibraryId = 1;+ _context.Series.Add(s);++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,+ ds);++ await cleanupService.DeleteSeriesCoverImages();++ Assert.Empty(ds.GetFiles(CoverImageDirectory));+ }++ [Fact]+ public async Task DeleteSeriesCoverImages_ShouldNotDeleteLinkedFiles()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddFile($"{CoverImageDirectory}series_01.jpg", new MockFileData(""));+ filesystem.AddFile($"{CoverImageDirectory}series_03.jpg", new MockFileData(""));+ filesystem.AddFile($"{CoverImageDirectory}series_1000.jpg", new MockFileData(""));++ // Delete all Series to reset state+ await ResetDB();++ // Add 2 series with cover images+ var s = DbFactory.Series("Test 1");+ s.CoverImage = "series_01.jpg";+ s.LibraryId = 1;+ _context.Series.Add(s);+ s = DbFactory.Series("Test 2");+ s.CoverImage = "series_03.jpg";+ s.LibraryId = 1;+ _context.Series.Add(s);+++ await _context.SaveChangesAsync();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,+ ds);++ await cleanupService.DeleteSeriesCoverImages();++ Assert.Equal(2, ds.GetFiles(CoverImageDirectory).Count());+ }+ #endregion++ #region DeleteChapterCoverImages+ [Fact]+ public async Task DeleteChapterCoverImages_ShouldNotDeleteLinkedFiles()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddFile($"{CoverImageDirectory}v01_c01.jpg", new MockFileData(""));+ filesystem.AddFile($"{CoverImageDirectory}v01_c03.jpg", new MockFileData(""));+ filesystem.AddFile($"{CoverImageDirectory}v01_c1000.jpg", new MockFileData(""));++ // Delete all Series to reset state+ await ResetDB();++ // Add 2 series with cover images+ var s = DbFactory.Series("Test 1");+ var v = DbFactory.Volume("1");+ v.Chapters.Add(new Chapter()+ {+ CoverImage = "v01_c01.jpg"+ });+ v.CoverImage = "v01_c01.jpg";+ s.Volumes.Add(v);+ s.CoverImage = "series_01.jpg";+ s.LibraryId = 1;+ _context.Series.Add(s);++ s = DbFactory.Series("Test 2");+ v = DbFactory.Volume("1");+ v.Chapters.Add(new Chapter()+ {+ CoverImage = "v01_c03.jpg"+ });+ v.CoverImage = "v01_c03jpg";+ s.Volumes.Add(v);+ s.CoverImage = "series_03.jpg";+ s.LibraryId = 1;+ _context.Series.Add(s);+++ await _context.SaveChangesAsync();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,+ ds);++ await cleanupService.DeleteChapterCoverImages();++ Assert.Equal(2, ds.GetFiles(CoverImageDirectory).Count());+ }+ #endregion++ #region DeleteTagCoverImages++ [Fact]+ public async Task DeleteTagCoverImages_ShouldNotDeleteLinkedFiles()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddFile($"{CoverImageDirectory}tag_01.jpg", new MockFileData(""));+ filesystem.AddFile($"{CoverImageDirectory}tag_02.jpg", new MockFileData(""));+ filesystem.AddFile($"{CoverImageDirectory}tag_1000.jpg", new MockFileData(""));++ // Delete all Series to reset state+ await ResetDB();++ // Add 2 series with cover images+ var s = DbFactory.Series("Test 1");+ s.Metadata.CollectionTags = new List<CollectionTag>();+ s.Metadata.CollectionTags.Add(new CollectionTag()+ {+ Title = "Something",+ CoverImage ="tag_01.jpg"+ });+ s.CoverImage = "series_01.jpg";+ s.LibraryId = 1;+ _context.Series.Add(s);++ s = DbFactory.Series("Test 2");+ s.Metadata.CollectionTags = new List<CollectionTag>();+ s.Metadata.CollectionTags.Add(new CollectionTag()+ {+ Title = "Something 2",+ CoverImage ="tag_02.jpg"+ });+ s.CoverImage = "series_03.jpg";+ s.LibraryId = 1;+ _context.Series.Add(s);+++ await _context.SaveChangesAsync();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,+ ds);++ await cleanupService.DeleteTagCoverImages();++ Assert.Equal(2, ds.GetFiles(CoverImageDirectory).Count());+ }++ #endregion++ #region CleanupCacheDirectory++ [Fact]+ public void CleanupCacheDirectory_ClearAllFiles()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddFile($"{CacheDirectory}01.jpg", new MockFileData(""));+ filesystem.AddFile($"{CacheDirectory}02.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,+ ds);+ cleanupService.CleanupCacheDirectory();+ Assert.Empty(ds.GetFiles(CacheDirectory, searchOption: SearchOption.AllDirectories));+ }++ [Fact]+ public void CleanupCacheDirectory_ClearAllFilesInSubDirectory()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddFile($"{CacheDirectory}01.jpg", new MockFileData(""));+ filesystem.AddFile($"{CacheDirectory}subdir/02.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,+ ds);+ cleanupService.CleanupCacheDirectory();+ Assert.Empty(ds.GetFiles(CacheDirectory, searchOption: SearchOption.AllDirectories));+ }++ #endregion++ #region CleanupBackups++ [Fact]+ public void CleanupBackups_LeaveOneFile_SinceAllAreExpired()+ {+ var filesystem = CreateFileSystem();+ var filesystemFile = new MockFileData("")+ {+ CreationTime = DateTimeOffset.Now.Subtract(TimeSpan.FromDays(31))+ };+ filesystem.AddFile($"{BackupDirectory}kavita_backup_11_29_2021_12_00_13 AM.zip", filesystemFile);+ filesystem.AddFile($"{BackupDirectory}kavita_backup_12_3_2021_9_27_58 AM.zip", filesystemFile);+ filesystem.AddFile($"{BackupDirectory}randomfile.zip", filesystemFile);++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,+ ds);+ cleanupService.CleanupBackups();+ Assert.Single(ds.GetFiles(BackupDirectory, searchOption: SearchOption.AllDirectories));+ }++ [Fact]+ public void CleanupBackups_LeaveLestExpired()+ {+ var filesystem = CreateFileSystem();+ var filesystemFile = new MockFileData("")+ {+ CreationTime = DateTimeOffset.Now.Subtract(TimeSpan.FromDays(31))+ };+ filesystem.AddFile($"{BackupDirectory}kavita_backup_11_29_2021_12_00_13 AM.zip", filesystemFile);+ filesystem.AddFile($"{BackupDirectory}kavita_backup_12_3_2021_9_27_58 AM.zip", filesystemFile);+ filesystem.AddFile($"{BackupDirectory}randomfile.zip", new MockFileData("")+ {+ CreationTime = DateTimeOffset.Now.Subtract(TimeSpan.FromDays(14))+ });++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,+ ds);+ cleanupService.CleanupBackups();+ Assert.True(filesystem.File.Exists($"{BackupDirectory}randomfile.zip"));+ }++ #endregion++ #region CleanupBookmarks++ [Fact]+ public async Task CleanupBookmarks_LeaveAllFiles()+ {+ var filesystem = CreateFileSystem();+ filesystem.AddFile($"{BookmarkDirectory}1/1/1/0001.jpg", new MockFileData(""));+ filesystem.AddFile($"{BookmarkDirectory}1/1/1/0002.jpg", new MockFileData(""));++ // Delete all Series to reset state+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ new Volume()+ {+ Chapters = new List<Chapter>()+ {+ new Chapter()+ {++ }+ }+ }+ }+ });++ await _context.SaveChangesAsync();++ _context.AppUser.Add(new AppUser()+ {+ Bookmarks = new List<AppUserBookmark>()+ {+ new AppUserBookmark()+ {+ AppUserId = 1,+ ChapterId = 1,+ Page = 1,+ FileName = "1/1/1/0001.jpg",+ SeriesId = 1,+ VolumeId = 1+ }+ }+ });++ await _context.SaveChangesAsync();+++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);+ var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,+ ds);++ await cleanupService.CleanupBookmarks();++ Assert.Equal(1, ds.GetFiles(BookmarkDirectory, searchOption:SearchOption.AllDirectories).Count());++ }++ #endregion+}diff --git a/API.Tests/Services/DirectoryServiceTests.cs b/API.Tests/Services/DirectoryServiceTests.csindex d64df0d82..bdbb7a238 100644--- a/API.Tests/Services/DirectoryServiceTests.cs+++ b/API.Tests/Services/DirectoryServiceTests.cs@@ -1,7 +1,11 @@-using System;+using System;using System.Collections.Generic;using System.IO;+using System.IO.Abstractions;+using System.IO.Abstractions.TestingHelpers;using System.Linq;+using System.Text;+using System.Threading.Tasks;using API.Services;using Microsoft.Extensions.Logging;using NSubstitute;@@ -12,92 +16,658 @@ namespace API.Tests.Servicespublic class DirectoryServiceTests{- private readonly DirectoryService _directoryService;private readonly ILogger<DirectoryService> _logger = Substitute.For<ILogger<DirectoryService>>();- public DirectoryServiceTests()+ #region TraverseTreeParallelForEach+ [Fact]+ public void TraverseTreeParallelForEach_JustArchives_ShouldBe28(){- _directoryService = new DirectoryService(_logger);+ var testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 28; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ fileSystem.AddFile($"{testDirectory}file_{29}.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = new List<string>();+ var fileCount = ds.TraverseTreeParallelForEach(testDirectory, s => files.Add(s),+ API.Parser.Parser.ArchiveFileExtensions, _logger);++ Assert.Equal(28, fileCount);+ Assert.Equal(28, files.Count);+ }++ [Fact]+ public void TraverseTreeParallelForEach_LongDirectory_ShouldBe1()+ {+ var fileSystem = new MockFileSystem();+ // Create a super long path+ var testDirectory = "/manga/";+ for (var i = 0; i < 200; i++)+ {+ testDirectory = fileSystem.FileSystem.Path.Join(testDirectory, "supercalifragilisticexpialidocious");+ }+++ fileSystem.AddFile(fileSystem.FileSystem.Path.Join(testDirectory, "file_29.jpg"), new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = new List<string>();+ try+ {+ var fileCount = ds.TraverseTreeParallelForEach("/manga/", s => files.Add(s),+ API.Parser.Parser.ImageFileExtensions, _logger);+ Assert.Equal(1, fileCount);+ }+ catch (Exception ex)+ {+ Assert.False(true);+ }+++ Assert.Equal(1, files.Count);}++[Fact]- public void GetFilesTest_Should_Be28()+ public void TraverseTreeParallelForEach_DontCountExcludedDirectories_ShouldBe28(){- var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ScannerService/Manga");- // ReSharper disable once CollectionNeverQueried.Local+ var testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 28; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ fileSystem.AddFile($"{Path.Join(testDirectory, "@eaDir")}file_{29}.jpg", new MockFileData(""));+ fileSystem.AddFile($"{Path.Join(testDirectory, ".DS_Store")}file_{30}.jpg", new MockFileData(""));+ fileSystem.AddFile($"{Path.Join(testDirectory, ".qpkg")}file_{30}.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);var files = new List<string>();- var fileCount = DirectoryService.TraverseTreeParallelForEach(testDirectory, s => files.Add(s),+ var fileCount = ds.TraverseTreeParallelForEach(testDirectory, s => files.Add(s),API.Parser.Parser.ArchiveFileExtensions, _logger);Assert.Equal(28, fileCount);+ Assert.Equal(28, files.Count);+ }+ #endregion++ #region GetFilesWithCertainExtensions+ [Fact]+ public void GetFilesWithCertainExtensions_ShouldBe10()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ fileSystem.AddFile($"{testDirectory}file_{29}.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = ds.GetFilesWithExtension(testDirectory, API.Parser.Parser.ArchiveFileExtensions);++ Assert.Equal(10, files.Length);+ Assert.All(files, s => fileSystem.Path.GetExtension(s).Equals(".zip"));+ }++ [Fact]+ public void GetFilesWithCertainExtensions_OnlyArchives()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ fileSystem.AddFile($"{testDirectory}file_{29}.rar", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = ds.GetFilesWithExtension(testDirectory, ".zip|.rar");++ Assert.Equal(11, files.Length);+ }+ #endregion++ #region GetFiles+ [Fact]+ public void GetFiles_ArchiveOnly_ShouldBe10()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ fileSystem.AddFile($"{testDirectory}file_{29}.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = ds.GetFiles(testDirectory, API.Parser.Parser.ArchiveFileExtensions).ToList();++ Assert.Equal(10, files.Count());+ Assert.All(files, s => fileSystem.Path.GetExtension(s).Equals(".zip"));+ }++ [Fact]+ public void GetFiles_All_ShouldBe11()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ fileSystem.AddFile($"{testDirectory}file_{29}.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = ds.GetFiles(testDirectory).ToList();++ Assert.Equal(11, files.Count());+ }++ [Fact]+ public void GetFiles_All_MixedPathSeparators()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ fileSystem.AddFile($"/manga\\file_{29}.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = ds.GetFiles(testDirectory).ToList();++ Assert.Equal(11, files.Count());+ }++ [Fact]+ public void GetFiles_All_TopDirectoryOnly_ShouldBe10()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ fileSystem.AddFile($"{testDirectory}/SubDir/file_{29}.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = ds.GetFiles(testDirectory).ToList();++ Assert.Equal(10, files.Count());+ }++ [Fact]+ public void GetFiles_WithSubDirectories_ShouldCountOnlyTopLevel()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ fileSystem.AddFile($"{testDirectory}/SubDir/file_{29}.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = ds.GetFiles(testDirectory).ToList();++ Assert.Equal(10, files.Count());+ }++ [Fact]+ public void GetFiles_ShouldNotReturnFilesThatAreExcluded()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ fileSystem.AddFile($"{testDirectory}/._file_{29}.jpg", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = ds.GetFiles(testDirectory).ToList();++ Assert.Equal(10, files.Count());+ }++ [Fact]+ public void GetFiles_WithCustomRegex_ShouldBe10()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}data-{i}.txt", new MockFileData(""));+ }+ fileSystem.AddFile($"{testDirectory}joe.txt", new MockFileData(""));+ fileSystem.AddFile($"{testDirectory}0d.txt", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = ds.GetFiles(testDirectory, @".*d.*\.txt");+ Assert.Equal(11, files.Count());+ }++ [Fact]+ public void GetFiles_WithCustomRegexThatContainsFolder_ShouldBe10()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file/data-{i}.txt", new MockFileData(""));+ }+ fileSystem.AddFile($"{testDirectory}joe.txt", new MockFileData(""));+ fileSystem.AddFile($"{testDirectory}0d.txt", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var files = ds.GetFiles(testDirectory, @".*d.*\.txt", SearchOption.AllDirectories);+ Assert.Equal(11, files.Count());+ }+ #endregion++ #region GetTotalSize+ [Fact]+ public void GetTotalSize_ShouldBeGreaterThan0()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file/data-{i}.txt", new MockFileData("abc"));+ }+ fileSystem.AddFile($"{testDirectory}joe.txt", new MockFileData(""));+++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var fileSize = ds.GetTotalSize(fileSystem.AllFiles);+ Assert.True(fileSize > 0);+ }+ #endregion++ #region CopyFileToDirectory+ [Fact]+ public void CopyFileToDirectory_ShouldCopyFileToNonExistentDirectory()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}file/data-0.txt", new MockFileData("abc"));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.CopyFileToDirectory($"{testDirectory}file/data-0.txt", "/manga/output/");+ Assert.True(fileSystem.FileExists("manga/output/data-0.txt"));+ Assert.True(fileSystem.FileExists("manga/file/data-0.txt"));+ }+ [Fact]+ public void CopyFileToDirectory_ShouldCopyFileToExistingDirectoryAndOverwrite()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}file/data-0.txt", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}output/data-0.txt", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.CopyFileToDirectory($"{testDirectory}file/data-0.txt", "/manga/output/");+ Assert.True(fileSystem.FileExists("/manga/output/data-0.txt"));+ Assert.True(fileSystem.FileExists("/manga/file/data-0.txt"));+ Assert.True(fileSystem.FileInfo.FromFileName("/manga/file/data-0.txt").Length == fileSystem.FileInfo.FromFileName("/manga/output/data-0.txt").Length);+ }+ #endregion++ #region CopyDirectoryToDirectory+ [Fact]+ public void CopyDirectoryToDirectory_ShouldThrowWhenSourceDestinationDoesntExist()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}file/data-0.txt", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}output/data-0.txt", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var ex = Assert.Throws<DirectoryNotFoundException>(() => ds.CopyDirectoryToDirectory("/comics/", "/manga/output/"));+ Assert.Equal(ex.Message, "Source directory does not exist or could not be found: " + "/comics/");+ }++ [Fact]+ public void CopyDirectoryToDirectory_ShouldCopyEmptyDirectory()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}file/data-0.txt", new MockFileData("abc"));+ fileSystem.AddDirectory($"{testDirectory}empty/");++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.CopyDirectoryToDirectory($"{testDirectory}empty/", "/manga/output/");+ Assert.Empty(fileSystem.DirectoryInfo.FromDirectoryName("/manga/output/").GetFiles());+ }++ [Fact]+ public void CopyDirectoryToDirectory_ShouldCopyAllFileAndNestedDirectoriesOver()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}file/data-0.txt", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}data-1.txt", new MockFileData("abc"));+ fileSystem.AddDirectory($"{testDirectory}empty/");++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.CopyDirectoryToDirectory($"{testDirectory}", "/manga/output/");+ Assert.Equal(2, ds.GetFiles("/manga/output/", searchOption: SearchOption.AllDirectories).Count());+ }+ #endregion++ #region IsDriveMounted+ [Fact]+ public void IsDriveMounted_DriveIsNotMounted()+ {+ const string testDirectory = "c:/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}data-0.txt", new MockFileData("abc"));+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);++ Assert.False(ds.IsDriveMounted("d:/manga/"));+ }++ [Fact]+ public void IsDriveMounted_DriveIsMounted()+ {+ const string testDirectory = "c:/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}data-0.txt", new MockFileData("abc"));+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);++ Assert.True(ds.IsDriveMounted("c:/manga/file"));+ }+ #endregion++ #region IsDirectoryEmpty+ [Fact]+ public void IsDirectoryEmpty_DirectoryIsEmpty()+ {+ const string testDirectory = "c:/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddDirectory(testDirectory);+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);++ Assert.True(ds.IsDirectoryEmpty("c:/manga/"));+ }++ [Fact]+ public void IsDirectoryEmpty_DirectoryIsNotEmpty()+ {+ const string testDirectory = "c:/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}data-0.txt", new MockFileData("abc"));+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);++ Assert.False(ds.IsDirectoryEmpty("c:/manga/"));}+ #endregion+ #region ExistOrCreate[Fact]- public void GetFiles_WithCustomRegex_ShouldPass_Test()+ public void ExistOrCreate_ShouldCreate(){- var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService/regex");- var files = DirectoryService.GetFiles(testDirectory, @"file\d*.txt");- Assert.Equal(2, files.Count());+ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.ExistOrCreate("c:/manga/output/");++ Assert.True(ds.FileSystem.DirectoryInfo.FromDirectoryName("c:/manga/output/").Exists);}+ #endregion+ #region ClearAndDeleteDirectory[Fact]- public void GetFiles_TopLevel_ShouldBeEmpty_Test()+ public void ClearAndDeleteDirectory_ShouldDeleteSelfAndAllFilesAndFolders(){- var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService");- var files = DirectoryService.GetFiles(testDirectory);- Assert.Empty(files);+ const string testDirectory = "/manga/base/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file/data-{i}.txt", new MockFileData("abc"));+ }+ fileSystem.AddFile($"{testDirectory}data-a.txt", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}data-b.txt", new MockFileData("abc"));+ fileSystem.AddDirectory($"{testDirectory}empty/");++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.ClearAndDeleteDirectory($"{testDirectory}");+ Assert.Empty(ds.GetFiles("/manga/", searchOption: SearchOption.AllDirectories));+ Assert.Empty(ds.FileSystem.DirectoryInfo.FromDirectoryName("/manga/").GetDirectories());+ Assert.True(ds.FileSystem.DirectoryInfo.FromDirectoryName("/manga/").Exists);+ Assert.False(ds.FileSystem.DirectoryInfo.FromDirectoryName("/manga/base").Exists);+ }+ #endregion++ #region ClearDirectory+ [Fact]+ public void ClearDirectory_ShouldDeleteAllFilesAndFolders_LeaveSelf()+ {+ const string testDirectory = "/manga/base/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file/data-{i}.txt", new MockFileData("abc"));+ }+ fileSystem.AddFile($"{testDirectory}data-a.txt", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}data-b.txt", new MockFileData("abc"));+ fileSystem.AddDirectory($"{testDirectory}file/empty/");++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.ClearDirectory($"{testDirectory}file/");+ Assert.Empty(ds.FileSystem.DirectoryInfo.FromDirectoryName($"{testDirectory}file/").GetDirectories());+ Assert.True(ds.FileSystem.DirectoryInfo.FromDirectoryName("/manga/").Exists);+ Assert.True(ds.FileSystem.DirectoryInfo.FromDirectoryName($"{testDirectory}file/").Exists);+ }++ [Fact]+ public void ClearDirectory_ShouldDeleteFoldersWithOneFileInside()+ {+ const string testDirectory = "/manga/base/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file/data-{i}.txt", new MockFileData("abc"));+ }++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.ClearDirectory($"{testDirectory}");+ Assert.Empty(ds.FileSystem.DirectoryInfo.FromDirectoryName($"{testDirectory}").GetDirectories());+ Assert.True(ds.FileSystem.DirectoryInfo.FromDirectoryName(testDirectory).Exists);+ Assert.False(ds.FileSystem.DirectoryInfo.FromDirectoryName($"{testDirectory}file/").Exists);}+ #endregion+ #region CopyFilesToDirectory[Fact]- public void GetFilesWithExtensions_ShouldBeEmpty_Test()+ public void CopyFilesToDirectory_ShouldMoveAllFiles(){- var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService/extensions");- var files = DirectoryService.GetFiles(testDirectory, "*.txt");- Assert.Empty(files);+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.CopyFilesToDirectory(new []{$"{testDirectory}file_{0}.zip", $"{testDirectory}file_{1}.zip"}, "/manga/output/");+ Assert.Equal(2, ds.GetFiles("/manga/output/").Count());}[Fact]- public void GetFilesWithExtensions_Test()+ public void CopyFilesToDirectory_ShouldMoveAllFiles_InclFilesInNestedFolders(){- var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService/extension");- var files = DirectoryService.GetFiles(testDirectory, ".cbz|.rar");- Assert.Equal(3, files.Count());+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }+ fileSystem.AddFile($"{testDirectory}nested/file_11.zip", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.CopyFilesToDirectory(new []{$"{testDirectory}file_{0}.zip", $"{testDirectory}file_{1}.zip", $"{testDirectory}nested/file_11.zip"}, "/manga/output/");+ Assert.Equal(3, ds.GetFiles("/manga/output/").Count());}[Fact]- public void GetFilesWithExtensions_BadDirectory_ShouldBeEmpty_Test()+ public void CopyFilesToDirectory_ShouldMoveAllFiles_WithPrepend(){- var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService/doesntexist");- var files = DirectoryService.GetFiles(testDirectory, ".cbz|.rar");- Assert.Empty(files);+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.CopyFilesToDirectory(new []{$"{testDirectory}file_{0}.zip", $"{testDirectory}file_{1}.zip", $"{testDirectory}nested/file_11.zip"},+ "/manga/output/", "mangarocks_");+ Assert.Equal(2, ds.GetFiles("/manga/output/").Count());+ Assert.All(ds.GetFiles("/manga/output/"), filepath => ds.FileSystem.Path.GetFileName(filepath).StartsWith("mangarocks_"));}[Fact]- public void ListDirectory_SubDirectory_Test()+ public void CopyFilesToDirectory_ShouldMoveOnlyFilesThatExist(){- var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService/");- var dirs = _directoryService.ListDirectory(testDirectory);- Assert.Contains(dirs, s => s.Contains("regex"));+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ for (var i = 0; i < 10; i++)+ {+ fileSystem.AddFile($"{testDirectory}file_{i}.zip", new MockFileData(""));+ }+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.CopyFilesToDirectory(new []{$"{testDirectory}file_{0}.zip", $"{testDirectory}file_{1}.zip", $"{testDirectory}nested/file_11.zip"},+ "/manga/output/");+ Assert.Equal(2, ds.GetFiles("/manga/output/").Count());}+ #endregion++ #region ListDirectory[Fact]- public void ListDirectory_NoSubDirectory_Test()+ public void ListDirectory_EmptyForNonExistent(){- var dirs = _directoryService.ListDirectory("");- Assert.DoesNotContain(dirs, s => s.Contains("regex"));+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}file_0.zip", new MockFileData(""));+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ Assert.Empty(ds.ListDirectory("/comics/"));}+ [Fact]+ public void ListDirectory_ListsAllDirectories()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddDirectory($"{testDirectory}dir1");+ fileSystem.AddDirectory($"{testDirectory}dir2");+ fileSystem.AddDirectory($"{testDirectory}dir3");+ fileSystem.AddFile($"{testDirectory}file_0.zip", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ Assert.Equal(3, ds.ListDirectory(testDirectory).Count());+ }++ [Fact]+ public void ListDirectory_ListsOnlyNonSystemAndHiddenOnly()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddDirectory($"{testDirectory}dir1");+ var di = fileSystem.DirectoryInfo.FromDirectoryName($"{testDirectory}dir1");+ di.Attributes |= FileAttributes.System;+ fileSystem.AddDirectory($"{testDirectory}dir2");+ di = fileSystem.DirectoryInfo.FromDirectoryName($"{testDirectory}dir2");+ di.Attributes |= FileAttributes.Hidden;+ fileSystem.AddDirectory($"{testDirectory}dir3");+ fileSystem.AddFile($"{testDirectory}file_0.zip", new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ Assert.Equal(1, ds.ListDirectory(testDirectory).Count());+ }++ #endregion++ #region ReadFileAsync++ [Fact]+ public async Task ReadFileAsync_ShouldGetBytes()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}file_1.zip", new MockFileData("Hello"));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var bytes = await ds.ReadFileAsync($"{testDirectory}file_1.zip");+ Assert.Equal(Encoding.UTF8.GetBytes("Hello"), bytes);+ }++ [Fact]+ public async Task ReadFileAsync_ShouldReadNothingFromNonExistent()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile($"{testDirectory}file_1.zip", new MockFileData("Hello"));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var bytes = await ds.ReadFileAsync($"{testDirectory}file_32123.zip");+ Assert.Empty(bytes);+ }+++ #endregion++ #region FindHighestDirectoriesFromFiles+[Theory][InlineData(new [] {"C:/Manga/"}, new [] {"C:/Manga/Love Hina/Vol. 01.cbz"}, "C:/Manga/Love Hina")]- public void FindHighestDirectoriesFromFilesTest(string[] rootDirectories, string[] folders, string expectedDirectory)+ [InlineData(new [] {"C:/Manga/Dir 1/", "c://Manga/Dir 2/"}, new [] {"C:/Manga/Dir 1/Love Hina/Vol. 01.cbz"}, "C:/Manga/Dir 1/Love Hina")]+ [InlineData(new [] {"C:/Manga/Dir 1/", "c://Manga/"}, new [] {"D:/Manga/Love Hina/Vol. 01.cbz", "D:/Manga/Vol. 01.cbz"}, "")]+ public void FindHighestDirectoriesFromFilesTest(string[] rootDirectories, string[] files, string expectedDirectory){- var actual = DirectoryService.FindHighestDirectoriesFromFiles(rootDirectories, folders);- var expected = new Dictionary<string, string> {{expectedDirectory, ""}};+ var fileSystem = new MockFileSystem();+ foreach (var directory in rootDirectories)+ {+ fileSystem.AddDirectory(directory);+ }+ foreach (var f in files)+ {+ fileSystem.AddFile(f, new MockFileData(""));+ }+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);++ var actual = ds.FindHighestDirectoriesFromFiles(rootDirectories, files);+ var expected = new Dictionary<string, string>();+ if (!string.IsNullOrEmpty(expectedDirectory))+ {+ expected = new Dictionary<string, string> {{expectedDirectory, ""}};+ }+Assert.Equal(expected, actual);}+ #endregion++ #region GetFoldersTillRoot+[Theory][InlineData("C:/Manga/", "C:/Manga/Love Hina/Specials/Omake/", "Omake,Specials,Love Hina")][InlineData("C:/Manga/", "C:/Manga/Love Hina/Specials/Omake", "Omake,Specials,Love Hina")]@@ -114,12 +684,110 @@ namespace API.Tests.Services[InlineData(@"M:\", @"M:\Toukyou Akazukin\Vol. 01 Ch. 005.cbz", @"Toukyou Akazukin")]public void GetFoldersTillRoot_Test(string rootPath, string fullpath, string expectedArray){+ var fileSystem = new MockFileSystem();+ fileSystem.AddDirectory(rootPath);+ fileSystem.AddFile(fullpath, new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+var expected = expectedArray.Split(",");if (expectedArray.Equals(string.Empty)){- expected = Array.Empty<string>();+ expected = Array.Empty<string>();}- Assert.Equal(expected, DirectoryService.GetFoldersTillRoot(rootPath, fullpath));+ Assert.Equal(expected, ds.GetFoldersTillRoot(rootPath, fullpath));+ }++ #endregion++ #region RemoveNonImages++ [Fact]+ public void RemoveNonImages()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddDirectory(testDirectory);+ fileSystem.AddFile($"{testDirectory}file/data-0.txt", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}data-1.jpg", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}data-2.png", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}data-3.webp", new MockFileData("abc"));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.RemoveNonImages($"{testDirectory}");+ Assert.False(fileSystem.FileExists($"{testDirectory}file/data-0.txt"));+ Assert.Equal(3, ds.GetFiles($"{testDirectory}", searchOption:SearchOption.AllDirectories).Count());+ }++ #endregion++ #region Flatten++ [Fact]+ public void Flatten_ShouldDoNothing()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddDirectory(testDirectory);+ fileSystem.AddFile($"{testDirectory}data-1.jpg", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}data-2.png", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}data-3.webp", new MockFileData("abc"));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.Flatten($"{testDirectory}");+ Assert.True(fileSystem.FileExists($"{testDirectory}data-1.jpg"));+ Assert.True(fileSystem.FileExists($"{testDirectory}data-2.png"));+ Assert.True(fileSystem.FileExists($"{testDirectory}data-3.webp"));+ }++ [Fact]+ public void Flatten_ShouldFlatten()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddDirectory(testDirectory);+ fileSystem.AddFile($"{testDirectory}data-1.jpg", new MockFileData("abc"));+ fileSystem.AddFile($"{testDirectory}subdir/data-3.webp", new MockFileData("abc"));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.Flatten($"{testDirectory}");+ Assert.Equal(2, ds.GetFiles(testDirectory).Count());+ Assert.False(fileSystem.FileExists($"{testDirectory}subdir/data-3.webp"));+ Assert.True(fileSystem.Directory.Exists($"{testDirectory}subdir/"));+ }++ #endregion++ #region CheckWriteAccess++ [Fact]+ public async Task CheckWriteAccess_ShouldHaveAccess()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var hasAccess = await ds.CheckWriteAccess(ds.FileSystem.Path.Join(testDirectory, "bookmarks"));+ Assert.True(hasAccess);++ Assert.False(ds.FileSystem.Directory.Exists(ds.FileSystem.Path.Join(testDirectory, "bookmarks")));+ Assert.False(ds.FileSystem.File.Exists(ds.FileSystem.Path.Join(testDirectory, "bookmarks", "test.txt")));+ }+++ #endregion++ #region GetHumanReadableBytes++ [Theory]+ [InlineData(1200, "1.17 KB")]+ [InlineData(1, "1 B")]+ [InlineData(10000000, "9.54 MB")]+ [InlineData(10000000000, "9.31 GB")]+ public void GetHumanReadableBytesTest(long bytes, string expected)+ {+ Assert.Equal(expected, DirectoryService.GetHumanReadableBytes(bytes));}+ #endregion}}diff --git a/API.Tests/Services/FileSystemTests.cs b/API.Tests/Services/FileSystemTests.csnew file mode 100644index 000000000..97250ea45--- /dev/null+++ b/API.Tests/Services/FileSystemTests.cs@@ -0,0 +1,44 @@+using System;+using System.Collections.Generic;+using System.IO.Abstractions.TestingHelpers;+using API.Services;+using Xunit;++namespace API.Tests.Services;++public class FileSystemTests+{+ [Fact]+ public void FileHasNotBeenModifiedSinceCreation()+ {+ var file = new MockFileData("Testing is meh.")+ {+ LastWriteTime = DateTimeOffset.Now.Subtract(TimeSpan.FromMinutes(1))+ };+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>+ {+ { @"c:\myfile.txt", file }+ });++ var fileService = new FileService(fileSystem);++ Assert.False(fileService.HasFileBeenModifiedSince(@"c:\myfile.txt", DateTime.Now));+ }++ [Fact]+ public void FileHasBeenModifiedSinceCreation()+ {+ var file = new MockFileData("Testing is meh.")+ {+ LastWriteTime = DateTimeOffset.Now+ };+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>+ {+ { @"c:\myfile.txt", file }+ });++ var fileService = new FileService(fileSystem);++ Assert.True(fileService.HasFileBeenModifiedSince(@"c:\myfile.txt", DateTime.Now.Subtract(TimeSpan.FromMinutes(1))));+ }+}diff --git a/API.Tests/Services/MetadataServiceTests.cs b/API.Tests/Services/MetadataServiceTests.csindex 5d61ee249..60a1bd0bd 100644--- a/API.Tests/Services/MetadataServiceTests.cs+++ b/API.Tests/Services/MetadataServiceTests.cs@@ -1,8 +1,9 @@using System;+using System.Collections.Generic;using System.IO;-using API.Entities;+using System.IO.Abstractions.TestingHelpers;+using API.Helpers;using API.Services;-using Xunit;namespace API.Tests.Services{@@ -10,6 +11,7 @@ namespace API.Tests.Services{private readonly string _testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives");private const string TestCoverImageFile = "thumbnail.jpg";+ private const string TestCoverArchive = @"c:\file in folder.zip";private readonly string _testCoverImageDirectory = Path.Join(Directory.GetCurrentDirectory(), @"../../../Services/Test Data/ArchiveService/CoverImages");//private readonly MetadataService _metadataService;// private readonly IUnitOfWork _unitOfWork = Substitute.For<IUnitOfWork>();@@ -18,116 +20,23 @@ namespace API.Tests.Services// private readonly IArchiveService _archiveService = Substitute.For<IArchiveService>();// private readonly ILogger<MetadataService> _logger = Substitute.For<ILogger<MetadataService>>();// private readonly IHubContext<MessageHub> _messageHub = Substitute.For<IHubContext<MessageHub>>();+ private readonly ICacheHelper _cacheHelper;+public MetadataServiceTests(){//_metadataService = new MetadataService(_unitOfWork, _logger, _archiveService, _bookService, _imageService, _messageHub);- }-- [Fact]- public void ShouldUpdateCoverImage_OnFirstRun()- {- // Represents first run- Assert.True(MetadataService.ShouldUpdateCoverImage(null, new MangaFile()- {- FilePath = Path.Join(_testDirectory, "file in folder.zip"),- LastModified = DateTime.Now- }, false, false));- }-- [Fact]- public void ShouldUpdateCoverImage_OnFirstRunSeries()- {- // Represents first run- Assert.True(MetadataService.ShouldUpdateCoverImage(null,null, false, false));- }-- [Fact]- public void ShouldUpdateCoverImage_OnFirstRun_FileModified()- {- // Represents first run- Assert.True(MetadataService.ShouldUpdateCoverImage(null, new MangaFile()- {- FilePath = Path.Join(_testDirectory, "file in folder.zip"),- LastModified = new FileInfo(Path.Join(_testDirectory, "file in folder.zip")).LastWriteTime.Subtract(TimeSpan.FromDays(1))- }, false, false));- }-- [Fact]- public void ShouldUpdateCoverImage_OnFirstRun_CoverImageLocked()- {- // Represents first run- Assert.True(MetadataService.ShouldUpdateCoverImage(null, new MangaFile()+ var file = new MockFileData(""){- FilePath = Path.Join(_testDirectory, "file in folder.zip"),- LastModified = new FileInfo(Path.Join(_testDirectory, "file in folder.zip")).LastWriteTime- }, false, true));- }-- [Fact]- public void ShouldUpdateCoverImage_OnSecondRun_ForceUpdate()- {- // Represents first run- Assert.True(MetadataService.ShouldUpdateCoverImage(null, new MangaFile()+ LastWriteTime = DateTimeOffset.Now.Subtract(TimeSpan.FromMinutes(1))+ };+ var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>{- FilePath = Path.Join(_testDirectory, "file in folder.zip"),- LastModified = new FileInfo(Path.Join(_testDirectory, "file in folder.zip")).LastWriteTime- }, true, false));- }+ { TestCoverArchive, file }+ });- [Fact]- public void ShouldUpdateCoverImage_OnSecondRun_NoFileChangeButNoCoverImage()- {- // Represents first run- Assert.True(MetadataService.ShouldUpdateCoverImage(null, new MangaFile()- {- FilePath = Path.Join(_testDirectory, "file in folder.zip"),- LastModified = new FileInfo(Path.Join(_testDirectory, "file in folder.zip")).LastWriteTime- }, false, false));- }-- [Fact]- public void ShouldUpdateCoverImage_OnSecondRun_FileChangeButNoCoverImage()- {- // Represents first run- Assert.True(MetadataService.ShouldUpdateCoverImage(null, new MangaFile()- {- FilePath = Path.Join(_testDirectory, "file in folder.zip"),- LastModified = new FileInfo(Path.Join(_testDirectory, "file in folder.zip")).LastWriteTime + TimeSpan.FromDays(1)- }, false, false));- }-- [Fact]- public void ShouldNotUpdateCoverImage_OnSecondRun_CoverImageSet()- {- // Represents first run- Assert.False(MetadataService.ShouldUpdateCoverImage(TestCoverImageFile, new MangaFile()- {- FilePath = Path.Join(_testDirectory, "file in folder.zip"),- LastModified = new FileInfo(Path.Join(_testDirectory, "file in folder.zip")).LastWriteTime- }, false, false, _testCoverImageDirectory));- }-- [Fact]- public void ShouldNotUpdateCoverImage_OnSecondRun_HasCoverImage_NoForceUpdate_NoLock()- {-- Assert.False(MetadataService.ShouldUpdateCoverImage(TestCoverImageFile, new MangaFile()- {- FilePath = Path.Join(_testDirectory, "file in folder.zip"),- LastModified = DateTime.Now- }, false, false, _testCoverImageDirectory));- }-- [Fact]- public void ShouldUpdateCoverImage_OnSecondRun_HasCoverImage_NoForceUpdate_HasLock_CoverImageDoesntExist()- {-- Assert.True(MetadataService.ShouldUpdateCoverImage(@"doesn't_exist.jpg", new MangaFile()- {- FilePath = Path.Join(_testDirectory, "file in folder.zip"),- LastModified = DateTime.Now- }, false, true, _testCoverImageDirectory));+ var fileService = new FileService(fileSystem);+ _cacheHelper = new CacheHelper(fileService);}}}diff --git a/API.Tests/Services/ParseScannedFilesTests.cs b/API.Tests/Services/ParseScannedFilesTests.csnew file mode 100644index 000000000..fd55143a1--- /dev/null+++ b/API.Tests/Services/ParseScannedFilesTests.cs@@ -0,0 +1,314 @@+using System.Collections.Generic;+using System.Data.Common;+using System.IO.Abstractions.TestingHelpers;+using System.Linq;+using System.Threading.Tasks;+using API.Data;+using API.Data.Metadata;+using API.Entities;+using API.Entities.Enums;+using API.Parser;+using API.Services;+using API.Services.Tasks.Scanner;+using API.SignalR;+using API.Tests.Helpers;+using AutoMapper;+using Microsoft.AspNetCore.SignalR;+using Microsoft.Data.Sqlite;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.Extensions.Logging;+using NSubstitute;+using Xunit;++namespace API.Tests.Services;++internal class MockReadingItemService : IReadingItemService+{+ private readonly DefaultParser _defaultParser;++ public MockReadingItemService(DefaultParser defaultParser)+ {+ _defaultParser = defaultParser;+ }++ public ComicInfo GetComicInfo(string filePath)+ {+ return null;+ }++ public int GetNumberOfPages(string filePath, MangaFormat format)+ {+ return 1;+ }++ public string GetCoverImage(string fileFilePath, string fileName, MangaFormat format)+ {+ return string.Empty;+ }++ public void Extract(string fileFilePath, string targetDirectory, MangaFormat format, int imageCount = 1)+ {+ throw new System.NotImplementedException();+ }++ public ParserInfo Parse(string path, string rootPath, LibraryType type)+ {+ return _defaultParser.Parse(path, rootPath, type);+ }+}++public class ParseScannedFilesTests+{+ private readonly ILogger<ParseScannedFiles> _logger = Substitute.For<ILogger<ParseScannedFiles>>();+ private readonly IUnitOfWork _unitOfWork;++ private readonly DbConnection _connection;+ private readonly DataContext _context;++ private const string CacheDirectory = "C:/kavita/config/cache/";+ private const string CoverImageDirectory = "C:/kavita/config/covers/";+ private const string BackupDirectory = "C:/kavita/config/backups/";+ private const string DataDirectory = "C:/data/";++ public ParseScannedFilesTests()+ {+ var contextOptions = new DbContextOptionsBuilder()+ .UseSqlite(CreateInMemoryDatabase())+ .Options;+ _connection = RelationalOptionsExtension.Extract(contextOptions).Connection;++ _context = new DataContext(contextOptions);+ Task.Run(SeedDb).GetAwaiter().GetResult();++ _unitOfWork = new UnitOfWork(_context, Substitute.For<IMapper>(), null);++ // Since ProcessFile relies on _readingItemService, we can implement our own versions of _readingItemService so we have control over how the calls work+ }++ #region Setup++ private static DbConnection CreateInMemoryDatabase()+ {+ var connection = new SqliteConnection("Filename=:memory:");++ connection.Open();++ return connection;+ }++ public void Dispose() => _connection.Dispose();++ private async Task<bool> SeedDb()+ {+ await _context.Database.MigrateAsync();+ var filesystem = CreateFileSystem();++ await Seed.SeedSettings(_context, new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem));++ var setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.CacheDirectory).SingleAsync();+ setting.Value = CacheDirectory;++ setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.BackupDirectory).SingleAsync();+ setting.Value = BackupDirectory;++ _context.ServerSetting.Update(setting);++ _context.Library.Add(new Library()+ {+ Name = "Manga",+ Folders = new List<FolderPath>()+ {+ new FolderPath()+ {+ Path = DataDirectory+ }+ }+ });+ return await _context.SaveChangesAsync() > 0;+ }++ private async Task ResetDB()+ {+ _context.Series.RemoveRange(_context.Series.ToList());++ await _context.SaveChangesAsync();+ }++ private static MockFileSystem CreateFileSystem()+ {+ var fileSystem = new MockFileSystem();+ fileSystem.Directory.SetCurrentDirectory("C:/kavita/");+ fileSystem.AddDirectory("C:/kavita/config/");+ fileSystem.AddDirectory(CacheDirectory);+ fileSystem.AddDirectory(CoverImageDirectory);+ fileSystem.AddDirectory(BackupDirectory);+ fileSystem.AddDirectory(DataDirectory);++ return fileSystem;+ }++ #endregion++ #region GetInfosByName++ [Fact]+ public void GetInfosByName_ShouldReturnGivenMatchingSeriesName()+ {+ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var psf = new ParseScannedFiles(Substitute.For<ILogger<ParseScannedFiles>>(), ds,+ new MockReadingItemService(new DefaultParser(ds)));++ var infos = new List<ParserInfo>()+ {+ ParserInfoFactory.CreateParsedInfo("Accel World", "1", "0", "Accel World v1.cbz", false),+ ParserInfoFactory.CreateParsedInfo("Accel World", "2", "0", "Accel World v2.cbz", false)+ };+ var parsedSeries = new Dictionary<ParsedSeries, List<ParserInfo>>+ {+ {+ new ParsedSeries()+ {+ Format = MangaFormat.Archive,+ Name = "Accel World",+ NormalizedName = API.Parser.Parser.Normalize("Accel World")+ },+ infos+ },+ {+ new ParsedSeries()+ {+ Format = MangaFormat.Pdf,+ Name = "Accel World",+ NormalizedName = API.Parser.Parser.Normalize("Accel World")+ },+ new List<ParserInfo>()+ }+ };++ var series = DbFactory.Series("Accel World");+ series.Format = MangaFormat.Pdf;++ Assert.Empty(ParseScannedFiles.GetInfosByName(parsedSeries, series));++ series.Format = MangaFormat.Archive;+ Assert.Equal(2, ParseScannedFiles.GetInfosByName(parsedSeries, series).Count());++ }++ [Fact]+ public void GetInfosByName_ShouldReturnGivenMatchingNormalizedSeriesName()+ {+ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var psf = new ParseScannedFiles(Substitute.For<ILogger<ParseScannedFiles>>(), ds,+ new MockReadingItemService(new DefaultParser(ds)));++ var infos = new List<ParserInfo>()+ {+ ParserInfoFactory.CreateParsedInfo("Accel World", "1", "0", "Accel World v1.cbz", false),+ ParserInfoFactory.CreateParsedInfo("Accel World", "2", "0", "Accel World v2.cbz", false)+ };+ var parsedSeries = new Dictionary<ParsedSeries, List<ParserInfo>>+ {+ {+ new ParsedSeries()+ {+ Format = MangaFormat.Archive,+ Name = "Accel World",+ NormalizedName = API.Parser.Parser.Normalize("Accel World")+ },+ infos+ },+ {+ new ParsedSeries()+ {+ Format = MangaFormat.Pdf,+ Name = "Accel World",+ NormalizedName = API.Parser.Parser.Normalize("Accel World")+ },+ new List<ParserInfo>()+ }+ };++ var series = DbFactory.Series("accel world");+ series.Format = MangaFormat.Archive;+ Assert.Equal(2, ParseScannedFiles.GetInfosByName(parsedSeries, series).Count());++ }++ #endregion++ #region MergeName++ [Fact]+ public void MergeName_ShouldMergeMatchingFormatAndName()+ {+ var fileSystem = new MockFileSystem();+ fileSystem.AddDirectory("C:/Data/");+ fileSystem.AddFile("C:/Data/Accel World v1.cbz", new MockFileData(string.Empty));+ fileSystem.AddFile("C:/Data/Accel World v2.cbz", new MockFileData(string.Empty));+ fileSystem.AddFile("C:/Data/Accel World v2.pdf", new MockFileData(string.Empty));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var psf = new ParseScannedFiles(Substitute.For<ILogger<ParseScannedFiles>>(), ds,+ new MockReadingItemService(new DefaultParser(ds)));+++ psf.ScanLibrariesForSeries(LibraryType.Manga, new List<string>() {"C:/Data/"}, out _, out _);++ Assert.Equal("Accel World", psf.MergeName(ParserInfoFactory.CreateParsedInfo("Accel World", "1", "0", "Accel World v1.cbz", false)));+ Assert.Equal("Accel World", psf.MergeName(ParserInfoFactory.CreateParsedInfo("accel_world", "1", "0", "Accel World v1.cbz", false)));+ Assert.Equal("Accel World", psf.MergeName(ParserInfoFactory.CreateParsedInfo("accelworld", "1", "0", "Accel World v1.cbz", false)));+ }++ [Fact]+ public void MergeName_ShouldMerge_MismatchedFormatSameName()+ {+ var fileSystem = new MockFileSystem();+ fileSystem.AddDirectory("C:/Data/");+ fileSystem.AddFile("C:/Data/Accel World v1.cbz", new MockFileData(string.Empty));+ fileSystem.AddFile("C:/Data/Accel World v2.cbz", new MockFileData(string.Empty));+ fileSystem.AddFile("C:/Data/Accel World v2.pdf", new MockFileData(string.Empty));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var psf = new ParseScannedFiles(Substitute.For<ILogger<ParseScannedFiles>>(), ds,+ new MockReadingItemService(new DefaultParser(ds)));+++ psf.ScanLibrariesForSeries(LibraryType.Manga, new List<string>() {"C:/Data/"}, out _, out _);++ Assert.Equal("Accel World", psf.MergeName(ParserInfoFactory.CreateParsedInfo("Accel World", "1", "0", "Accel World v1.epub", false)));+ Assert.Equal("Accel World", psf.MergeName(ParserInfoFactory.CreateParsedInfo("accel_world", "1", "0", "Accel World v1.epub", false)));+ }++ #endregion++ #region ScanLibrariesForSeries++ [Fact]+ public void ScanLibrariesForSeries_ShouldFindFiles()+ {+ var fileSystem = new MockFileSystem();+ fileSystem.AddDirectory("C:/Data/");+ fileSystem.AddFile("C:/Data/Accel World v1.cbz", new MockFileData(string.Empty));+ fileSystem.AddFile("C:/Data/Accel World v2.cbz", new MockFileData(string.Empty));+ fileSystem.AddFile("C:/Data/Accel World v2.pdf", new MockFileData(string.Empty));+ fileSystem.AddFile("C:/Data/Nothing.pdf", new MockFileData(string.Empty));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var psf = new ParseScannedFiles(Substitute.For<ILogger<ParseScannedFiles>>(), ds,+ new MockReadingItemService(new DefaultParser(ds)));+++ var parsedSeries = psf.ScanLibrariesForSeries(LibraryType.Manga, new List<string>() {"C:/Data/"}, out _, out _);++ Assert.Equal(3, parsedSeries.Values.Count);+ Assert.NotEmpty(parsedSeries.Keys.Where(p => p.Format == MangaFormat.Archive && p.Name.Equals("Accel World")));++ }+++ #endregion+}diff --git a/API.Tests/Services/ReaderServiceTests.cs b/API.Tests/Services/ReaderServiceTests.csnew file mode 100644index 000000000..940bc2ebe--- /dev/null+++ b/API.Tests/Services/ReaderServiceTests.cs@@ -0,0 +1,814 @@+using System.Collections.Generic;+using System.Data.Common;+using System.IO;+using System.IO.Abstractions.TestingHelpers;+using System.Linq;+using System.Threading.Tasks;+using API.Data;+using API.Data.Repositories;+using API.DTOs;+using API.Entities;+using API.Entities.Enums;+using API.Helpers;+using API.Services;+using API.SignalR;+using API.Tests.Helpers;+using AutoMapper;+using Microsoft.AspNetCore.SignalR;+using Microsoft.Data.Sqlite;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.Extensions.Logging;+using NSubstitute;+using Xunit;++namespace API.Tests.Services;++public class ReaderServiceTests+{+ private readonly ILogger<CacheService> _logger = Substitute.For<ILogger<CacheService>>();+ private readonly IUnitOfWork _unitOfWork;+ private readonly IHubContext<MessageHub> _messageHub = Substitute.For<IHubContext<MessageHub>>();++ private readonly DbConnection _connection;+ private readonly DataContext _context;++ private const string CacheDirectory = "C:/kavita/config/cache/";+ private const string CoverImageDirectory = "C:/kavita/config/covers/";+ private const string BackupDirectory = "C:/kavita/config/backups/";+ private const string DataDirectory = "C:/data/";++ public ReaderServiceTests()+ {+ var contextOptions = new DbContextOptionsBuilder().UseSqlite(CreateInMemoryDatabase()).Options;+ _connection = RelationalOptionsExtension.Extract(contextOptions).Connection;++ _context = new DataContext(contextOptions);+ Task.Run(SeedDb).GetAwaiter().GetResult();++ var config = new MapperConfiguration(cfg => cfg.AddProfile<AutoMapperProfiles>());+ var mapper = config.CreateMapper();+ _unitOfWork = new UnitOfWork(_context, mapper, null);+ }++ #region Setup++ private static DbConnection CreateInMemoryDatabase()+ {+ var connection = new SqliteConnection("Filename=:memory:");++ connection.Open();++ return connection;+ }++ public void Dispose() => _connection.Dispose();++ private async Task<bool> SeedDb()+ {+ await _context.Database.MigrateAsync();+ var filesystem = CreateFileSystem();++ await Seed.SeedSettings(_context,+ new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem));++ var setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.CacheDirectory).SingleAsync();+ setting.Value = CacheDirectory;++ setting = await _context.ServerSetting.Where(s => s.Key == ServerSettingKey.BackupDirectory).SingleAsync();+ setting.Value = BackupDirectory;++ _context.ServerSetting.Update(setting);++ _context.Library.Add(new Library()+ {+ Name = "Manga", Folders = new List<FolderPath>() {new FolderPath() {Path = "C:/data/"}}+ });+ return await _context.SaveChangesAsync() > 0;+ }++ private async Task ResetDB()+ {+ _context.Series.RemoveRange(_context.Series.ToList());++ await _context.SaveChangesAsync();+ }++ private static MockFileSystem CreateFileSystem()+ {+ var fileSystem = new MockFileSystem();+ fileSystem.Directory.SetCurrentDirectory("C:/kavita/");+ fileSystem.AddDirectory("C:/kavita/config/");+ fileSystem.AddDirectory(CacheDirectory);+ fileSystem.AddDirectory(CoverImageDirectory);+ fileSystem.AddDirectory(BackupDirectory);+ fileSystem.AddDirectory(DataDirectory);++ return fileSystem;+ }++ #endregion++ #region FormatBookmarkFolderPath++ [Theory]+ [InlineData("/manga/", 1, 1, 1, "/manga/1/1/1")]+ [InlineData("C:/manga/", 1, 1, 10001, "C:/manga/1/1/10001")]+ public void FormatBookmarkFolderPathTest(string baseDir, int userId, int seriesId, int chapterId, string expected)+ {+ Assert.Equal(expected, ReaderService.FormatBookmarkFolderPath(baseDir, userId, seriesId, chapterId));+ }++ #endregion++ #region CapPageToChapter++ [Fact]+ public async Task CapPageToChapterTest()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ new Volume()+ {+ Chapters = new List<Chapter>()+ {+ new Chapter()+ {+ Pages = 1+ }+ }+ }+ }+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ Assert.Equal(0, await readerService.CapPageToChapter(1, -1));+ Assert.Equal(1, await readerService.CapPageToChapter(1, 10));+ }++ #endregion++ #region SaveReadingProgress++ [Fact]+ public async Task SaveReadingProgress_ShouldCreateNewEntity()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ new Volume()+ {+ Chapters = new List<Chapter>()+ {+ new Chapter()+ {+ Pages = 1+ }+ }+ }+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var successful = await readerService.SaveReadingProgress(new ProgressDto()+ {+ ChapterId = 1,+ PageNum = 1,+ SeriesId = 1,+ VolumeId = 1,+ BookScrollId = null+ }, 1);++ Assert.True(successful);+ Assert.NotNull(await _unitOfWork.AppUserProgressRepository.GetUserProgressAsync(1, 1));+ }++ [Fact]+ public async Task SaveReadingProgress_ShouldUpdateExisting()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ new Volume()+ {+ Chapters = new List<Chapter>()+ {+ new Chapter()+ {+ Pages = 1+ }+ }+ }+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var successful = await readerService.SaveReadingProgress(new ProgressDto()+ {+ ChapterId = 1,+ PageNum = 1,+ SeriesId = 1,+ VolumeId = 1,+ BookScrollId = null+ }, 1);++ Assert.True(successful);+ Assert.NotNull(await _unitOfWork.AppUserProgressRepository.GetUserProgressAsync(1, 1));++ Assert.True(await readerService.SaveReadingProgress(new ProgressDto()+ {+ ChapterId = 1,+ PageNum = 1,+ SeriesId = 1,+ VolumeId = 1,+ BookScrollId = "/h1/"+ }, 1));++ Assert.Equal("/h1/", (await _unitOfWork.AppUserProgressRepository.GetUserProgressAsync(1, 1)).BookScrollId);++ }+++ #endregion++ #region MarkChaptersAsRead++ [Fact]+ public async Task MarkChaptersAsReadTest()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ new Volume()+ {+ Chapters = new List<Chapter>()+ {+ new Chapter()+ {+ Pages = 1+ },+ new Chapter()+ {+ Pages = 2+ }+ }+ }+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var volumes = await _unitOfWork.VolumeRepository.GetVolumes(1);+ readerService.MarkChaptersAsRead(await _unitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.Progress), 1, volumes.First().Chapters);+ await _context.SaveChangesAsync();++ Assert.Equal(2, (await _unitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.Progress)).Progresses.Count);+ }+ #endregion++ #region MarkChapterAsUnread++ [Fact]+ public async Task MarkChapterAsUnreadTest()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ new Volume()+ {+ Chapters = new List<Chapter>()+ {+ new Chapter()+ {+ Pages = 1+ },+ new Chapter()+ {+ Pages = 2+ }+ }+ }+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var volumes = (await _unitOfWork.VolumeRepository.GetVolumes(1)).ToList();+ readerService.MarkChaptersAsRead(await _unitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.Progress), 1, volumes.First().Chapters);++ await _context.SaveChangesAsync();+ Assert.Equal(2, (await _unitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.Progress)).Progresses.Count);++ readerService.MarkChaptersAsUnread(await _unitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.Progress), 1, volumes.First().Chapters);+ await _context.SaveChangesAsync();++ var progresses = (await _unitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.Progress)).Progresses;+ Assert.Equal(0, progresses.Max(p => p.PagesRead));+ Assert.Equal(2, progresses.Count);+ }++ #endregion++ #region GetNextChapterIdAsync++ [Fact]+ public async Task GetNextChapterIdAsync_ShouldGetNextVolume()+ {+ // V1 -> V2+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("2", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("2", new List<Chapter>()+ {+ EntityFactory.CreateChapter("21", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("22", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("3", new List<Chapter>()+ {+ EntityFactory.CreateChapter("31", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("32", false, new List<MangaFile>()),+ }),+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var nextChapter = await readerService.GetNextChapterIdAsync(1, 1, 1, 1);+ var actualChapter = await _unitOfWork.ChapterRepository.GetChapterAsync(nextChapter);+ Assert.Equal("2", actualChapter.Range);+ }++ [Fact]+ public async Task GetNextChapterIdAsync_ShouldRollIntoNextVolume()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("2", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("2", new List<Chapter>()+ {+ EntityFactory.CreateChapter("21", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("22", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("3", new List<Chapter>()+ {+ EntityFactory.CreateChapter("31", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("32", false, new List<MangaFile>()),+ }),+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);+++ var nextChapter = await readerService.GetNextChapterIdAsync(1, 1, 2, 1);+ var actualChapter = await _unitOfWork.ChapterRepository.GetChapterAsync(nextChapter);+ Assert.Equal("21", actualChapter.Range);+ }++ [Fact]+ public async Task GetNextChapterIdAsync_ShouldNotMoveFromVolumeToSpecial()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("2", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("0", new List<Chapter>()+ {+ EntityFactory.CreateChapter("A.cbz", true, new List<MangaFile>()),+ EntityFactory.CreateChapter("B.cbz", true, new List<MangaFile>()),+ }),+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);+++ var nextChapter = await readerService.GetNextChapterIdAsync(1, 1, 2, 1);+ Assert.Equal(-1, nextChapter);+ }++ [Fact]+ public async Task GetNextChapterIdAsync_ShouldMoveFromSpecialToSpecial()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("2", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("0", new List<Chapter>()+ {+ EntityFactory.CreateChapter("A.cbz", true, new List<MangaFile>()),+ EntityFactory.CreateChapter("B.cbz", true, new List<MangaFile>()),+ }),+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);+++ var nextChapter = await readerService.GetNextChapterIdAsync(1, 2, 3, 1);+ Assert.NotEqual(-1, nextChapter);+ var actualChapter = await _unitOfWork.ChapterRepository.GetChapterAsync(nextChapter);+ Assert.Equal("B.cbz", actualChapter.Range);+ }++ #endregion++ #region GetPrevChapterIdAsync++ [Fact]+ public async Task GetPrevChapterIdAsync_ShouldGetPrevVolume()+ {+ // V1 -> V2+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("2", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("2", new List<Chapter>()+ {+ EntityFactory.CreateChapter("21", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("22", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("3", new List<Chapter>()+ {+ EntityFactory.CreateChapter("31", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("32", false, new List<MangaFile>()),+ }),+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);++ var prevChapter = await readerService.GetPrevChapterIdAsync(1, 1, 2, 1);+ var actualChapter = await _unitOfWork.ChapterRepository.GetChapterAsync(prevChapter);+ Assert.Equal("1", actualChapter.Range);+ }++ [Fact]+ public async Task GetPrevChapterIdAsync_ShouldRollIntoPrevVolume()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("2", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("2", new List<Chapter>()+ {+ EntityFactory.CreateChapter("21", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("22", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("3", new List<Chapter>()+ {+ EntityFactory.CreateChapter("31", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("32", false, new List<MangaFile>()),+ }),+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);+++ var prevChapter = await readerService.GetPrevChapterIdAsync(1, 2, 3, 1);+ var actualChapter = await _unitOfWork.ChapterRepository.GetChapterAsync(prevChapter);+ Assert.Equal("2", actualChapter.Range);+ }++ [Fact]+ public async Task GetPrevChapterIdAsync_ShouldMoveFromVolumeToSpecial()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("2", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("0", new List<Chapter>()+ {+ EntityFactory.CreateChapter("A.cbz", true, new List<MangaFile>()),+ EntityFactory.CreateChapter("B.cbz", true, new List<MangaFile>()),+ }),+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);+++ var prevChapter = await readerService.GetPrevChapterIdAsync(1, 1, 1, 1);+ Assert.NotEqual(-1, prevChapter);+ var actualChapter = await _unitOfWork.ChapterRepository.GetChapterAsync(prevChapter);+ Assert.Equal("B.cbz", actualChapter.Range);+ }++ [Fact]+ public async Task GetPrevChapterIdAsync_ShouldMoveFromSpecialToSpecial()+ {+ await ResetDB();++ _context.Series.Add(new Series()+ {+ Name = "Test",+ Library = new Library() {+ Name = "Test LIb",+ Type = LibraryType.Manga,+ },+ Volumes = new List<Volume>()+ {+ EntityFactory.CreateVolume("1", new List<Chapter>()+ {+ EntityFactory.CreateChapter("1", false, new List<MangaFile>()),+ EntityFactory.CreateChapter("2", false, new List<MangaFile>()),+ }),+ EntityFactory.CreateVolume("0", new List<Chapter>()+ {+ EntityFactory.CreateChapter("A.cbz", true, new List<MangaFile>()),+ EntityFactory.CreateChapter("B.cbz", true, new List<MangaFile>()),+ }),+ }+ });++ _context.AppUser.Add(new AppUser()+ {+ UserName = "majora2007"+ });++ await _context.SaveChangesAsync();++ var fileSystem = new MockFileSystem();+ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);+++ var prevChapter = await readerService.GetPrevChapterIdAsync(1, 2, 4, 1);+ Assert.NotEqual(-1, prevChapter);+ var actualChapter = await _unitOfWork.ChapterRepository.GetChapterAsync(prevChapter);+ Assert.Equal("A.cbz", actualChapter.Range);+ }++ #endregion++ // #region GetNumberOfPages+ //+ // [Fact]+ // public void GetNumberOfPages_EPUB()+ // {+ // const string testDirectory = "/manga/";+ // var fileSystem = new MockFileSystem();+ //+ // var actualFile = Path.Join(Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BookService/EPUB"), "The Golden Harpoon; Or, Lost Among the Floes A Story of the Whaling Grounds.epub")+ // fileSystem.File.WriteAllBytes("${testDirectory}test.epub", File.ReadAllBytes(actualFile));+ //+ // fileSystem.AddDirectory(CacheDirectory);+ //+ // var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ // var cs = new CacheService(_logger, _unitOfWork, ds, new MockReadingItemServiceForCacheService(ds));+ // var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>(), ds, cs);+ //+ //+ // }+ //+ //+ // #endregion++}diff --git a/API.Tests/Services/ScannerServiceTests.cs b/API.Tests/Services/ScannerServiceTests.csindex 0253ccef6..b78c6be35 100644--- a/API.Tests/Services/ScannerServiceTests.cs+++ b/API.Tests/Services/ScannerServiceTests.cs@@ -3,13 +3,14 @@ using System.Collections.Concurrent;using System.Collections.Generic;using System.Data.Common;using System.IO;+using System.IO.Abstractions.TestingHelpers;using System.Linq;using System.Threading.Tasks;using API.Data;using API.Entities;using API.Entities.Enums;-using API.Interfaces;-using API.Interfaces.Services;+using API.Entities.Metadata;+using API.Helpers;using API.Parser;using API.Services;using API.Services.Tasks;@@ -27,55 +28,38 @@ using Xunit;namespace API.Tests.Services{- public class ScannerServiceTests : IDisposable+ public class ScannerServiceTests{- private readonly ScannerService _scannerService;- private readonly ILogger<ScannerService> _logger = Substitute.For<ILogger<ScannerService>>();- private readonly IArchiveService _archiveService = Substitute.For<IArchiveService>();- private readonly IBookService _bookService = Substitute.For<IBookService>();- private readonly IImageService _imageService = Substitute.For<IImageService>();- private readonly ILogger<MetadataService> _metadataLogger = Substitute.For<ILogger<MetadataService>>();- private readonly ICacheService _cacheService = Substitute.For<ICacheService>();- private readonly IHubContext<MessageHub> _messageHub = Substitute.For<IHubContext<MessageHub>>();-- private readonly DbConnection _connection;- private readonly DataContext _context;--- public ScannerServiceTests()+ [Fact]+ public void FindSeriesNotOnDisk_Should_Remove1(){- var contextOptions = new DbContextOptionsBuilder()- .UseSqlite(CreateInMemoryDatabase())- .Options;- _connection = RelationalOptionsExtension.Extract(contextOptions).Connection;-- _context = new DataContext(contextOptions);- Task.Run(SeedDb).GetAwaiter().GetResult();-- IUnitOfWork unitOfWork = new UnitOfWork(_context, Substitute.For<IMapper>(), null);--- IMetadataService metadataService = Substitute.For<MetadataService>(unitOfWork, _metadataLogger, _archiveService, _bookService, _imageService, _messageHub);- _scannerService = new ScannerService(unitOfWork, _logger, _archiveService, metadataService, _bookService, _cacheService, _messageHub);- }+ var infos = new Dictionary<ParsedSeries, List<ParserInfo>>();- private async Task<bool> SeedDb()- {- await _context.Database.MigrateAsync();- await Seed.SeedSettings(_context);+ ParserInfoFactory.AddToParsedInfo(infos, new ParserInfo() {Series = "Darker than Black", Volumes = "1", Format = MangaFormat.Archive});+ //AddToParsedInfo(infos, new ParserInfo() {Series = "Darker than Black", Volumes = "1", Format = MangaFormat.Epub});- _context.Library.Add(new Library()+ var existingSeries = new List<Series>{- Name = "Manga",- Folders = new List<FolderPath>()+ new Series(){- new FolderPath()+ Name = "Darker Than Black",+ LocalizedName = "Darker Than Black",+ OriginalName = "Darker Than Black",+ Volumes = new List<Volume>(){- Path = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ScannerService/Manga")- }+ new Volume()+ {+ Number = 1,+ Name = "1"+ }+ },+ NormalizedName = API.Parser.Parser.Normalize("Darker Than Black"),+ Metadata = new SeriesMetadata(),+ Format = MangaFormat.Epub}- });- return await _context.SaveChangesAsync() > 0;+ };++ Assert.Equal(1, ScannerService.FindSeriesNotOnDisk(existingSeries, infos).Count());}[Fact]@@ -83,9 +67,9 @@ namespace API.Tests.Services{var infos = new Dictionary<ParsedSeries, List<ParserInfo>>();- AddToParsedInfo(infos, new ParserInfo() {Series = "Darker than Black", Format = MangaFormat.Archive});- AddToParsedInfo(infos, new ParserInfo() {Series = "Cage of Eden", Volumes = "1", Format = MangaFormat.Archive});- AddToParsedInfo(infos, new ParserInfo() {Series = "Cage of Eden", Volumes = "10", Format = MangaFormat.Archive});+ ParserInfoFactory.AddToParsedInfo(infos, new ParserInfo() {Series = "Darker than Black", Format = MangaFormat.Archive});+ ParserInfoFactory.AddToParsedInfo(infos, new ParserInfo() {Series = "Cage of Eden", Volumes = "1", Format = MangaFormat.Archive});+ ParserInfoFactory.AddToParsedInfo(infos, new ParserInfo() {Series = "Cage of Eden", Volumes = "10", Format = MangaFormat.Archive});var existingSeries = new List<Series>{@@ -138,78 +122,25 @@ namespace API.Tests.Services// Assert.Equal(expected, actualName);// }- [Fact]- public void RemoveMissingSeries_Should_RemoveSeries()- {- var existingSeries = new List<Series>()- {- EntityFactory.CreateSeries("Darker than Black Vol 1"),- EntityFactory.CreateSeries("Darker than Black"),- EntityFactory.CreateSeries("Beastars"),- };- var missingSeries = new List<Series>()- {- EntityFactory.CreateSeries("Darker than Black Vol 1"),- };- existingSeries = ScannerService.RemoveMissingSeries(existingSeries, missingSeries, out var removeCount).ToList();-- Assert.DoesNotContain(missingSeries[0].Name, existingSeries.Select(s => s.Name));- Assert.Equal(missingSeries.Count, removeCount);- }-- private void AddToParsedInfo(IDictionary<ParsedSeries, List<ParserInfo>> collectedSeries, ParserInfo info)- {- var existingKey = collectedSeries.Keys.FirstOrDefault(ps =>- ps.Format == info.Format && ps.NormalizedName == API.Parser.Parser.Normalize(info.Series));- existingKey ??= new ParsedSeries()- {- Format = info.Format,- Name = info.Series,- NormalizedName = API.Parser.Parser.Normalize(info.Series)- };- if (collectedSeries.GetType() == typeof(ConcurrentDictionary<,>))- {- ((ConcurrentDictionary<ParsedSeries, List<ParserInfo>>) collectedSeries).AddOrUpdate(existingKey, new List<ParserInfo>() {info}, (_, oldValue) =>- {- oldValue ??= new List<ParserInfo>();- if (!oldValue.Contains(info))- {- oldValue.Add(info);- }-- return oldValue;- });- }- else- {- if (!collectedSeries.ContainsKey(existingKey))- {- collectedSeries.Add(existingKey, new List<ParserInfo>() {info});- }- else- {- var list = collectedSeries[existingKey];- if (!list.Contains(info))- {- list.Add(info);- }-- collectedSeries[existingKey] = list;- }-- }-- }-- private static DbConnection CreateInMemoryDatabase()- {- var connection = new SqliteConnection("Filename=:memory:");-- connection.Open();+ // [Fact]+ // public void RemoveMissingSeries_Should_RemoveSeries()+ // {+ // var existingSeries = new List<Series>()+ // {+ // EntityFactory.CreateSeries("Darker than Black Vol 1"),+ // EntityFactory.CreateSeries("Darker than Black"),+ // EntityFactory.CreateSeries("Beastars"),+ // };+ // var missingSeries = new List<Series>()+ // {+ // EntityFactory.CreateSeries("Darker than Black Vol 1"),+ // };+ // existingSeries = ScannerService.RemoveMissingSeries(existingSeries, missingSeries, out var removeCount).ToList();+ //+ // Assert.DoesNotContain(missingSeries[0].Name, existingSeries.Select(s => s.Name));+ // Assert.Equal(missingSeries.Count, removeCount);+ // }- return connection;- }- public void Dispose() => _connection.Dispose();}}diff --git a/API.Tests/Services/Test Data/ArchiveService/ComicInfos/ComicInfo_authors.zip b/API.Tests/Services/Test Data/ArchiveService/ComicInfos/ComicInfo_authors.zipnew file mode 100644index 000000000..e44b8aa5aBinary files /dev/null and b/API.Tests/Services/Test Data/ArchiveService/ComicInfos/ComicInfo_authors.zip differdiff --git a/API.Tests/Services/Test Data/ArchiveService/CoverImages/output/test2_output.png b/API.Tests/Services/Test Data/ArchiveService/CoverImages/output/test2_output.pngnew file mode 100644index 000000000..faa1b5d21Binary files /dev/null and b/API.Tests/Services/Test Data/ArchiveService/CoverImages/output/test2_output.png differdiff --git a/API.Tests/Services/Test Data/ArchiveService/CoverImages/test.expected.jpg b/API.Tests/Services/Test Data/ArchiveService/CoverImages/test.expected.jpgnew file mode 100644index 000000000..e3f368eb3Binary files /dev/null and b/API.Tests/Services/Test Data/ArchiveService/CoverImages/test.expected.jpg differdiff --git a/API.Tests/Services/Test Data/ArchiveService/CoverImages/test.zip b/API.Tests/Services/Test Data/ArchiveService/CoverImages/test.zipnew file mode 100644index 000000000..3d318ac6cBinary files /dev/null and b/API.Tests/Services/Test Data/ArchiveService/CoverImages/test.zip differdiff --git a/API.Tests/Services/Test Data/BookService/EPUB/The Golden Harpoon; Or, Lost Among the Floes A Story of the Whaling Grounds.epub b/API.Tests/Services/Test Data/BookService/EPUB/The Golden Harpoon; Or, Lost Among the Floes A Story of the Whaling Grounds.epubindex 7388bc85e..99d4e3bbf 100644Binary files a/API.Tests/Services/Test Data/BookService/EPUB/The Golden Harpoon; Or, Lost Among the Floes A Story of the Whaling Grounds.epub and b/API.Tests/Services/Test Data/BookService/EPUB/The Golden Harpoon; Or, Lost Among the Floes A Story of the Whaling Grounds.epub differdiff --git a/API.Tests/Services/Test Data/BookService/EPUB/content.opf b/API.Tests/Services/Test Data/BookService/EPUB/content.opfnew file mode 100644index 000000000..74e62677a--- /dev/null+++ b/API.Tests/Services/Test Data/BookService/EPUB/content.opf@@ -0,0 +1,81 @@+<?xml version='1.0' encoding='UTF-8'?>++<package xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="id">+ <metadata>+ <dc:rights>Public domain in the USA.</dc:rights>+ <dc:identifier opf:scheme="URI" id="id">http://www.gutenberg.org/64999</dc:identifier>+ <dc:creator opf:file-as="Starbuck, Roger">Roger Starbuck</dc:creator>+ <dc:title>The Golden Harpoon / Lost Among the Floes</dc:title>+ <dc:language xsi:type="dcterms:RFC4646">en</dc:language>+ <dc:date opf:event="publication">2021-04-05</dc:date>+ <dc:date opf:event="conversion">2021-04-05T23:00:07.039989+00:00</dc:date>+ <dc:source>https://www.gutenberg.org/files/64999/64999-h/64999-h.htm</dc:source>+ <dc:description>Book Description</dc:description>+ <dc:subject>Genre1, Genre2</dc:subject>+ <dc:creator id="creator">Junya Inoue</dc:creator>+ <meta refines="#creator" property="file-as">Inoue, Junya</meta>+ <meta refines="#creator" property="role" scheme="marc:relators">aut</meta>+ <meta name="cover" content="item1"/>+ </metadata>+ <manifest>+ <!--Image: 1000 x 1572 size=145584 -->+ <item href="@public@vhost@g@gutenberg@html@files@64999@64999-h@[email protected]" id="item1" media-type="image/jpeg"/>+ <item href="pgepub.css" id="item2" media-type="text/css"/>+ <item href="0.css" id="item3" media-type="text/css"/>+ <item href="1.css" id="item4" media-type="text/css"/>+ <!--Chunk: size=3477 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="cover" media-type="application/xhtml+xml"/>+ <!--Chunk: size=3242 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item5" media-type="application/xhtml+xml"/>+ <!--Chunk: size=27802 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item6" media-type="application/xhtml+xml"/>+ <!--Chunk: size=13387 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item7" media-type="application/xhtml+xml"/>+ <!--Chunk: size=25774 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item8" media-type="application/xhtml+xml"/>+ <!--Chunk: size=17053 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item9" media-type="application/xhtml+xml"/>+ <!--Chunk: size=19590 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item10" media-type="application/xhtml+xml"/>+ <!--Chunk: size=16645 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item11" media-type="application/xhtml+xml"/>+ <!--Chunk: size=19768 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item12" media-type="application/xhtml+xml"/>+ <!--Chunk: size=30397 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item13" media-type="application/xhtml+xml"/>+ <!--Chunk: size=41064 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item14" media-type="application/xhtml+xml"/>+ <!--Chunk: size=35745 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item15" media-type="application/xhtml+xml"/>+ <!--Chunk: size=3277 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item16" media-type="application/xhtml+xml"/>+ <!--Chunk: size=5983 Split on div.chapter-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item17" media-type="application/xhtml+xml"/>+ <!--Chunk: size=22066-->+ <item href="@public@vhost@g@gutenberg@html@files@64999@[email protected]" id="item18" media-type="application/xhtml+xml"/>+ <item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml"/>+ <item href="wrap0000.html" id="coverpage-wrapper" media-type="application/xhtml+xml"/>+ </manifest>+ <spine toc="ncx">+ <itemref idref="coverpage-wrapper" linear="yes"/>+ <itemref idref="cover" linear="yes"/>+ <itemref idref="item5" linear="yes"/>+ <itemref idref="item6" linear="yes"/>+ <itemref idref="item7" linear="yes"/>+ <itemref idref="item8" linear="yes"/>+ <itemref idref="item9" linear="yes"/>+ <itemref idref="item10" linear="yes"/>+ <itemref idref="item11" linear="yes"/>+ <itemref idref="item12" linear="yes"/>+ <itemref idref="item13" linear="yes"/>+ <itemref idref="item14" linear="yes"/>+ <itemref idref="item15" linear="yes"/>+ <itemref idref="item16" linear="yes"/>+ <itemref idref="item17" linear="yes"/>+ <itemref idref="item18" linear="yes"/>+ </spine>+ <guide>+ <reference type="toc" title="CONTENTS" href="@public@vhost@g@gutenberg@html@files@64999@[email protected]#pgepubid00001"/>+ <reference type="cover" title="Cover" href="wrap0000.html"/>+ </guide>+</package>diff --git a/API.Tests/generate_test_data.py b/API.Tests/generate_test_data.pydeleted file mode 100644index 69652969a..000000000--- a/API.Tests/generate_test_data.py+++ /dev/null@@ -1,80 +0,0 @@-""" This script should be run on a directory which will generate a test case file- that can be loaded into the renametest.py"""-import os-from pathlib import Path-import shutil--verbose = False--def print_log(val):- if verbose:- print(val)---def create_test_base(file, root_dir):- """ Creates and returns a new base directory for data creation for a given testcase."""- base_dir = os.path.split(file.split('-testcase.txt')[0])[-1]- print_log('base_dir: {0}'.format(base_dir))- new_dir = os.path.join(root_dir, base_dir)- print_log('new dir: {0}'.format(new_dir))- p = Path(new_dir)- if not p.exists():- os.mkdir(new_dir)-- return new_dir----def generate_data(file, root_dir):- ''' Generates directories and fake files for testing against '''-- base_dir = ''- if file.endswith('-testcase.txt'):- base_dir = create_test_base(file, root_dir)-- files_to_create = []- with open(file, 'r') as in_file:- files_to_create = in_file.read().splitlines()-- for filepath in files_to_create:- for part in os.path.split(filepath):- part_path = os.path.join(base_dir, part)- print_log('Checking if {0} exists '.format(part_path))- p = Path(part_path)-- if not p.exists():- print_log('Creating: {0}'.format(part))-- if p.suffix != '':- with open(os.path.join(root_dir, base_dir + '/' + filepath), 'w+') as f:- f.write('')- else:- os.mkdir(part_path)--def clean_up_generated_data(root_dir):- for root, dirs, files in os.walk(root_dir):- for dir in dirs:- shutil.rmtree(os.path.join(root, dir))- for file in files:- if not file.endswith('-testcase.txt'):- print_log('Removing {0}'.format(os.path.join(root, file)))- os.remove(os.path.join(root, file))---def generate_test_file():- root_dir = os.path.abspath('.')- current_folder = os.path.split(root_dir)[-1]- out_files = []- for root, _, files in os.walk(root_dir):- for file in files:- if not file.endswith('-testcase.txt'):- filename = os.path.join(root.replace(root_dir, ''), file) # root_dir or root_dir + '//'?- out_files.append(filename)-- with open(os.path.join(root_dir, current_folder + '-testcase.txt'), 'w+') as f:- for filename in out_files:- f.write(filename + '\n')--if __name__ == '__main__':- verbose = True- generate_test_file()\ No newline at end of filediff --git a/API/API.csproj b/API/API.csprojindex d6f059830..fbf15067e 100644--- a/API/API.csproj+++ b/API/API.csproj@@ -2,7 +2,7 @@<PropertyGroup><AnalysisMode>Default</AnalysisMode>- <TargetFramework>net5.0</TargetFramework>+ <TargetFramework>net6.0</TargetFramework><EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild><DockerDefaultTargetOS>Linux</DockerDefaultTargetOS></PropertyGroup>@@ -36,39 +36,41 @@</PropertyGroup><ItemGroup>- <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />- <PackageReference Include="Docnet.Core" Version="2.4.0-alpha.1" />+ <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />+ <PackageReference Include="Docnet.Core" Version="2.4.0-alpha.2" /><PackageReference Include="ExCSS" Version="4.1.0" /><PackageReference Include="Flurl" Version="3.0.2" /><PackageReference Include="Flurl.Http" Version="3.2.0" />- <PackageReference Include="Hangfire" Version="1.7.25" />- <PackageReference Include="Hangfire.AspNetCore" Version="1.7.25" />+ <PackageReference Include="Hangfire" Version="1.7.27" />+ <PackageReference Include="Hangfire.AspNetCore" Version="1.7.27" /><PackageReference Include="Hangfire.MaximumConcurrentExecutions" Version="1.1.0" /><PackageReference Include="Hangfire.MemoryStorage.Core" Version="1.4.0" />- <PackageReference Include="HtmlAgilityPack" Version="1.11.37" />+ <PackageReference Include="HtmlAgilityPack" Version="1.11.38" /><PackageReference Include="MarkdownDeep.NET.Core" Version="1.5.0.4" />- <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.10" />- <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.10" />- <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.10" />+ <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />+ <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.1" />+ <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0" /><PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />- <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.10">+ <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0"><PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets></PackageReference>- <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.10" />- <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />- <PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.1.3" />- <PackageReference Include="NetVips" Version="2.0.1" />- <PackageReference Include="NetVips.Native" Version="8.11.4" />+ <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />+ <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />+ <PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.2.0" />+ <PackageReference Include="NetVips" Version="2.1.0" />+ <PackageReference Include="NetVips.Native" Version="8.12.1" /><PackageReference Include="NReco.Logging.File" Version="1.1.2" />- <PackageReference Include="SharpCompress" Version="0.30.0" />- <PackageReference Include="SonarAnalyzer.CSharp" Version="8.29.0.36737">+ <PackageReference Include="SharpCompress" Version="0.30.1" />+ <PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />+ <PackageReference Include="SonarAnalyzer.CSharp" Version="8.33.0.40503"><PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets></PackageReference>- <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.2" />- <PackageReference Include="System.Drawing.Common" Version="5.0.2" />- <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.2" />+ <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />+ <PackageReference Include="System.Drawing.Common" Version="6.0.0" />+ <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.0" />+ <PackageReference Include="System.IO.Abstractions" Version="16.1.2" /><PackageReference Include="VersOne.Epub" Version="3.0.3.1" /></ItemGroup>diff --git a/API/API.csproj.DotSettings b/API/API.csproj.DotSettingsindex 80aad93c5..c7410bba2 100644--- a/API/API.csproj.DotSettings+++ b/API/API.csproj.DotSettings@@ -1,2 +1,3 @@<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">- <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=covers/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>\ No newline at end of file+ <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=covers/@EntryIndexedValue">True</s:Boolean>+ <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=wwwroot/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>\ No newline at end of filediff --git a/API/Comparators/ChapterSortComparer.cs b/API/Comparators/ChapterSortComparer.csindex 3791e05ff..189919a33 100644--- a/API/Comparators/ChapterSortComparer.cs+++ b/API/Comparators/ChapterSortComparer.cs@@ -8,7 +8,7 @@ namespace API.Comparatorspublic class ChapterSortComparer : IComparer<double>{/// <summary>- /// Normal sort for 2 doubles. 0 always comes before anything else+ /// Normal sort for 2 doubles. 0 always comes last/// </summary>/// <param name="x"></param>/// <param name="y"></param>diff --git a/API/Comparators/NaturalSortComparer.cs b/API/Comparators/NaturalSortComparer.csdeleted file mode 100644index 8fb0a74a5..000000000--- a/API/Comparators/NaturalSortComparer.cs+++ /dev/null@@ -1,106 +0,0 @@-using System;-using System.Collections.Generic;-using System.Text.RegularExpressions;-using static System.GC;-using static System.String;--namespace API.Comparators-{- /// <summary>- /// Attempts to emulate Windows explorer sorting- /// </summary>- /// <remarks>This is not thread-safe</remarks>- public sealed class NaturalSortComparer : IComparer<string>, IDisposable- {- private readonly bool _isAscending;- private Dictionary<string, string[]> _table = new();-- private bool _disposed;--- public NaturalSortComparer(bool inAscendingOrder = true)- {- _isAscending = inAscendingOrder;- }-- int IComparer<string>.Compare(string x, string y)- {- if (x == y) return 0;-- if (!_table.TryGetValue(x ?? Empty, out var x1))- {- x1 = Regex.Split(x ?? Empty, "([0-9]+)");- _table.Add(x ?? Empty, x1);- }-- if (!_table.TryGetValue(y ?? Empty, out var y1))- {- y1 = Regex.Split(y ?? Empty, "([0-9]+)");- _table.Add(y ?? Empty, y1);- }-- int returnVal;-- for (var i = 0; i < x1.Length && i < y1.Length; i++)- {- if (x1[i] == y1[i]) continue;- returnVal = PartCompare(x1[i], y1[i]);- return _isAscending ? returnVal : -returnVal;- }-- if (y1.Length > x1.Length)- {- returnVal = 1;- }- else if (x1.Length > y1.Length)- {- returnVal = -1;- }- else- {- returnVal = 0;- }--- return _isAscending ? returnVal : -returnVal;- }-- private static int PartCompare(string left, string right)- {- if (!int.TryParse(left, out var x))- return Compare(left, right, StringComparison.Ordinal);-- if (!int.TryParse(right, out var y))- return Compare(left, right, StringComparison.Ordinal);-- return x.CompareTo(y);- }-- private void Dispose(bool disposing)- {- if (!_disposed)- {- if (disposing)- {- // called via myClass.Dispose().- _table.Clear();- _table = null;- }- // Release unmanaged resources.- // Set large fields to null.- _disposed = true;- }- }-- public void Dispose()- {- Dispose(true);- SuppressFinalize(this);- }-- ~NaturalSortComparer() // the finalizer- {- Dispose(false);- }- }-}diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.csindex 415b51f59..3d3a93f85 100644--- a/API/Controllers/AccountController.cs+++ b/API/Controllers/AccountController.cs@@ -4,12 +4,11 @@ using System.Linq;using System.Reflection;using System.Threading.Tasks;using API.Constants;+using API.Data;using API.DTOs;using API.DTOs.Account;using API.Entities;using API.Extensions;-using API.Interfaces;-using API.Interfaces.Services;using API.Services;using AutoMapper;using Kavita.Common;@@ -92,7 +91,7 @@ namespace API.Controllersif (registerDto.IsAdmin){var firstTimeFlow = !(await _userManager.GetUsersInRoleAsync("Admin")).Any();- if (!firstTimeFlow && !await _unitOfWork.UserRepository.IsUserAdmin(+ if (!firstTimeFlow && !await _unitOfWork.UserRepository.IsUserAdminAsync(await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername()))){return BadRequest("You are not permitted to create an admin account");@@ -167,7 +166,7 @@ namespace API.Controllersif (user == null) return Unauthorized("Invalid username");- var isAdmin = await _unitOfWork.UserRepository.IsUserAdmin(user);+ var isAdmin = await _unitOfWork.UserRepository.IsUserAdminAsync(user);var settings = await _unitOfWork.SettingsRepository.GetSettingsDtoAsync();if (!settings.EnableAuthentication && !isAdmin){diff --git a/API/Controllers/BookController.cs b/API/Controllers/BookController.csindex cf5e66e22..473640df7 100644--- a/API/Controllers/BookController.cs+++ b/API/Controllers/BookController.cs@@ -1,15 +1,16 @@-using System.Collections.Generic;+using System;+using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;+using API.Data;using API.DTOs;using API.DTOs.Reader;using API.Entities.Enums;using API.Extensions;-using API.Interfaces;-using API.Interfaces.Services;using API.Services;using HtmlAgilityPack;using Microsoft.AspNetCore.Mvc;+using Microsoft.Extensions.Hosting;using Microsoft.Extensions.Logging;using VersOne.Epub;@@ -21,10 +22,11 @@ namespace API.Controllersprivate readonly IBookService _bookService;private readonly IUnitOfWork _unitOfWork;private readonly ICacheService _cacheService;- private static readonly string BookApiUrl = "book-resources?file=";+ private const string BookApiUrl = "book-resources?file=";- public BookController(ILogger<BookController> logger, IBookService bookService, IUnitOfWork unitOfWork, ICacheService cacheService)+ public BookController(ILogger<BookController> logger, IBookService bookService,+ IUnitOfWork unitOfWork, ICacheService cacheService){_logger = logger;_bookService = bookService;@@ -110,32 +112,12 @@ namespace API.Controllers}}- if (navigationItem.Link == null)- {- var item = new BookChapterItem()- {- Title = navigationItem.Title,- Children = nestedChapters- };- if (nestedChapters.Count > 0)- {- item.Page = nestedChapters[0].Page;- }- chaptersList.Add(item);- }- else- {- var groupKey = BookService.CleanContentKeys(navigationItem.Link.ContentFileName);- if (mappings.ContainsKey(groupKey))- {- chaptersList.Add(new BookChapterItem()- {- Title = navigationItem.Title,- Page = mappings[groupKey],- Children = nestedChapters- });- }- }+ CreateToCChapter(navigationItem, nestedChapters, chaptersList, mappings);+ }++ if (navigationItem.NestedItems.Count == 0)+ {+ CreateToCChapter(navigationItem, Array.Empty<BookChapterItem>(), chaptersList, mappings);}}@@ -188,6 +170,38 @@ namespace API.Controllersreturn Ok(chaptersList);}+ private static void CreateToCChapter(EpubNavigationItemRef navigationItem, IList<BookChapterItem> nestedChapters, IList<BookChapterItem> chaptersList,+ IReadOnlyDictionary<string, int> mappings)+ {+ if (navigationItem.Link == null)+ {+ var item = new BookChapterItem()+ {+ Title = navigationItem.Title,+ Children = nestedChapters+ };+ if (nestedChapters.Count > 0)+ {+ item.Page = nestedChapters[0].Page;+ }++ chaptersList.Add(item);+ }+ else+ {+ var groupKey = BookService.CleanContentKeys(navigationItem.Link.ContentFileName);+ if (mappings.ContainsKey(groupKey))+ {+ chaptersList.Add(new BookChapterItem()+ {+ Title = navigationItem.Title,+ Page = mappings[groupKey],+ Children = nestedChapters+ });+ }+ }+ }+[HttpGet("{chapterId}/book-page")]public async Task<ActionResult<string>> GetBookPage(int chapterId, [FromQuery] int page){@@ -200,146 +214,40 @@ namespace API.Controllersvar counter = 0;var doc = new HtmlDocument {OptionFixNestedTags = true};- var baseUrl = Request.Scheme + "://" + Request.Host + Request.PathBase + "/api/";++ var baseUrl = "//" + Request.Host + Request.PathBase + "/api/";var apiBase = baseUrl + "book/" + chapterId + "/" + BookApiUrl;var bookPages = await book.GetReadingOrderAsync();foreach (var contentFileRef in bookPages){- if (page == counter)+ if (page != counter){- var content = await contentFileRef.ReadContentAsync();- if (contentFileRef.ContentType != EpubContentType.XHTML_1_1) return Ok(content);-- // In more cases than not, due to this being XML not HTML, we need to escape the script tags.- content = BookService.EscapeTags(content);-- doc.LoadHtml(content);- var body = doc.DocumentNode.SelectSingleNode("//body");-- if (body == null)- {- if (doc.ParseErrors.Any())- {- LogBookErrors(book, contentFileRef, doc);- return BadRequest("The file is malformed! Cannot read.");- }- _logger.LogError("{FilePath} has no body tag! Generating one for support. Book may be skewed", book.FilePath);- doc.DocumentNode.SelectSingleNode("/html").AppendChild(HtmlNode.CreateNode("<body></body>"));- body = doc.DocumentNode.SelectSingleNode("/html/body");- }-- var inlineStyles = doc.DocumentNode.SelectNodes("//style");- if (inlineStyles != null)- {- foreach (var inlineStyle in inlineStyles)- {- var styleContent = await _bookService.ScopeStyles(inlineStyle.InnerHtml, apiBase, "", book);- body.PrependChild(HtmlNode.CreateNode($"<style>{styleContent}</style>"));- }- }-- var styleNodes = doc.DocumentNode.SelectNodes("/html/head/link");- if (styleNodes != null)- {- foreach (var styleLinks in styleNodes)- {- var key = BookService.CleanContentKeys(styleLinks.Attributes["href"].Value);- // Some epubs are malformed the key in content.opf might be: content/resources/filelist_0_0.xml but the actual html links to resources/filelist_0_0.xml- // In this case, we will do a search for the key that ends with- if (!book.Content.Css.ContainsKey(key))- {- var correctedKey = book.Content.Css.Keys.SingleOrDefault(s => s.EndsWith(key));- if (correctedKey == null)- {- _logger.LogError("Epub is Malformed, key: {Key} is not matching OPF file", key);- continue;- }-- key = correctedKey;- }-- var styleContent = await _bookService.ScopeStyles(await book.Content.Css[key].ReadContentAsync(), apiBase, book.Content.Css[key].FileName, book);- if (styleContent != null)- {- body.PrependChild(HtmlNode.CreateNode($"<style>{styleContent}</style>"));- }- }- }-- var anchors = doc.DocumentNode.SelectNodes("//a");- if (anchors != null)- {- foreach (var anchor in anchors)- {- BookService.UpdateLinks(anchor, mappings, page);- }- }+ counter++;+ continue;+ }- var images = doc.DocumentNode.SelectNodes("//img");- if (images != null)- {- foreach (var image in images)- {- if (image.Name != "img") continue;+ var content = await contentFileRef.ReadContentAsync();+ if (contentFileRef.ContentType != EpubContentType.XHTML_1_1) return Ok(content);- // Need to do for xlink:href- if (image.Attributes["src"] != null)- {- var imageFile = image.Attributes["src"].Value;- if (!book.Content.Images.ContainsKey(imageFile))- {- var correctedKey = book.Content.Images.Keys.SingleOrDefault(s => s.EndsWith(imageFile));- if (correctedKey != null)- {- imageFile = correctedKey;- }- }- image.Attributes.Remove("src");- image.Attributes.Add("src", $"{apiBase}" + imageFile);- }- }- }+ // In more cases than not, due to this being XML not HTML, we need to escape the script tags.+ content = BookService.EscapeTags(content);- images = doc.DocumentNode.SelectNodes("//image");- if (images != null)- {- foreach (var image in images)- {- if (image.Name != "image") continue;-- if (image.Attributes["xlink:href"] != null)- {- var imageFile = image.Attributes["xlink:href"].Value;- if (!book.Content.Images.ContainsKey(imageFile))- {- var correctedKey = book.Content.Images.Keys.SingleOrDefault(s => s.EndsWith(imageFile));- if (correctedKey != null)- {- imageFile = correctedKey;- }- }- image.Attributes.Remove("xlink:href");- image.Attributes.Add("xlink:href", $"{apiBase}" + imageFile);- }- }- }+ doc.LoadHtml(content);+ var body = doc.DocumentNode.SelectSingleNode("//body");- // Check if any classes on the html node (some r2l books do this) and move them to body tag for scoping- var htmlNode = doc.DocumentNode.SelectSingleNode("//html");- if (htmlNode != null && htmlNode.Attributes.Contains("class"))+ if (body == null)+ {+ if (doc.ParseErrors.Any()){- var bodyClasses = body.Attributes.Contains("class") ? body.Attributes["class"].Value : string.Empty;- var classes = htmlNode.Attributes["class"].Value + " " + bodyClasses;- body.Attributes.Add("class", $"{classes}");- // I actually need the body tag itself for the classes, so i will create a div and put the body stuff there.- return Ok($"<div class=\"{body.Attributes["class"].Value}\">{body.InnerHtml}</div>");+ LogBookErrors(book, contentFileRef, doc);+ return BadRequest("The file is malformed! Cannot read.");}--- return Ok(body.InnerHtml);+ _logger.LogError("{FilePath} has no body tag! Generating one for support. Book may be skewed", book.FilePath);+ doc.DocumentNode.SelectSingleNode("/html").AppendChild(HtmlNode.CreateNode("<body></body>"));+ body = doc.DocumentNode.SelectSingleNode("/html/body");}- counter++;+ return Ok(await _bookService.ScopePage(doc, book, apiBase, body, mappings, page));}return BadRequest("Could not find the appropriate html for that page");diff --git a/API/Controllers/CollectionController.cs b/API/Controllers/CollectionController.csindex 681a962d0..9f297273f 100644--- a/API/Controllers/CollectionController.cs+++ b/API/Controllers/CollectionController.cs@@ -3,11 +3,9 @@ using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using API.Data;-using API.DTOs;using API.DTOs.CollectionTags;-using API.Entities;+using API.Entities.Metadata;using API.Extensions;-using API.Interfaces;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;@@ -34,7 +32,7 @@ namespace API.Controllerspublic async Task<IEnumerable<CollectionTagDto>> GetAllTags(){var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());- var isAdmin = await _unitOfWork.UserRepository.IsUserAdmin(user);+ var isAdmin = await _unitOfWork.UserRepository.IsUserAdminAsync(user);if (isAdmin){return await _unitOfWork.CollectionTagRepository.GetAllTagDtosAsync();diff --git a/API/Controllers/DownloadController.cs b/API/Controllers/DownloadController.csindex d1ea4e8fb..c253fb9ee 100644--- a/API/Controllers/DownloadController.cs+++ b/API/Controllers/DownloadController.cs@@ -4,16 +4,17 @@ using System.IO;using System.Linq;using System.Threading.Tasks;using API.Comparators;+using API.Data;using API.DTOs.Downloads;using API.Entities;using API.Entities.Enums;using API.Extensions;-using API.Interfaces;-using API.Interfaces.Services;using API.Services;+using API.SignalR;using Kavita.Common;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.SignalR;namespace API.Controllers{@@ -25,16 +26,19 @@ namespace API.Controllersprivate readonly IDirectoryService _directoryService;private readonly ICacheService _cacheService;private readonly IDownloadService _downloadService;+ private readonly IHubContext<MessageHub> _messageHub;private readonly NumericComparer _numericComparer;private const string DefaultContentType = "application/octet-stream";- public DownloadController(IUnitOfWork unitOfWork, IArchiveService archiveService, IDirectoryService directoryService, ICacheService cacheService, IDownloadService downloadService)+ public DownloadController(IUnitOfWork unitOfWork, IArchiveService archiveService, IDirectoryService directoryService,+ ICacheService cacheService, IDownloadService downloadService, IHubContext<MessageHub> messageHub){_unitOfWork = unitOfWork;_archiveService = archiveService;_directoryService = directoryService;_cacheService = cacheService;_downloadService = downloadService;+ _messageHub = messageHub;_numericComparer = new NumericComparer();}@@ -42,21 +46,21 @@ namespace API.Controllerspublic async Task<ActionResult<long>> GetVolumeSize(int volumeId){var files = await _unitOfWork.VolumeRepository.GetFilesForVolume(volumeId);- return Ok(DirectoryService.GetTotalSize(files.Select(c => c.FilePath)));+ return Ok(_directoryService.GetTotalSize(files.Select(c => c.FilePath)));}[HttpGet("chapter-size")]public async Task<ActionResult<long>> GetChapterSize(int chapterId){var files = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId);- return Ok(DirectoryService.GetTotalSize(files.Select(c => c.FilePath)));+ return Ok(_directoryService.GetTotalSize(files.Select(c => c.FilePath)));}[HttpGet("series-size")]public async Task<ActionResult<long>> GetSeriesSize(int seriesId){var files = await _unitOfWork.SeriesRepository.GetFilesForSeries(seriesId);- return Ok(DirectoryService.GetTotalSize(files.Select(c => c.FilePath)));+ return Ok(_directoryService.GetTotalSize(files.Select(c => c.FilePath)));}[HttpGet("volume")]@@ -67,13 +71,7 @@ namespace API.Controllersvar series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(volume.SeriesId);try{- if (files.Count == 1)- {- return await GetFirstFileDownload(files);- }- var (fileBytes, _) = await _archiveService.CreateZipForDownload(files.Select(c => c.FilePath),- $"download_{User.GetUsername()}_v{volumeId}");- return File(fileBytes, DefaultContentType, $"{series.Name} - Volume {volume.Number}.zip");+ return await DownloadFiles(files, $"download_{User.GetUsername()}_v{volumeId}", $"{series.Name} - Volume {volume.Number}.zip");}catch (KavitaException ex){@@ -96,13 +94,7 @@ namespace API.Controllersvar series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(volume.SeriesId);try{- if (files.Count == 1)- {- return await GetFirstFileDownload(files);- }- var (fileBytes, _) = await _archiveService.CreateZipForDownload(files.Select(c => c.FilePath),- $"download_{User.GetUsername()}_c{chapterId}");- return File(fileBytes, DefaultContentType, $"{series.Name} - Chapter {chapter.Number}.zip");+ return await DownloadFiles(files, $"download_{User.GetUsername()}_c{chapterId}", $"{series.Name} - Chapter {chapter.Number}.zip");}catch (KavitaException ex){@@ -110,6 +102,21 @@ namespace API.Controllers}}+ private async Task<ActionResult> DownloadFiles(ICollection<MangaFile> files, string tempFolder, string downloadName)+ {+ await _messageHub.Clients.All.SendAsync(SignalREvents.DownloadProgress,+ MessageFactory.DownloadProgressEvent(User.GetUsername(), Path.GetFileNameWithoutExtension(downloadName), 0F));+ if (files.Count == 1)+ {+ return await GetFirstFileDownload(files);+ }+ var (fileBytes, _) = await _archiveService.CreateZipForDownload(files.Select(c => c.FilePath),+ tempFolder);+ await _messageHub.Clients.All.SendAsync(SignalREvents.DownloadProgress,+ MessageFactory.DownloadProgressEvent(User.GetUsername(), Path.GetFileNameWithoutExtension(downloadName), 1F));+ return File(fileBytes, DefaultContentType, downloadName);+ }+[HttpGet("series")]public async Task<ActionResult> DownloadSeries(int seriesId){@@ -117,13 +124,7 @@ namespace API.Controllersvar series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId);try{- if (files.Count == 1)- {- return await GetFirstFileDownload(files);- }- var (fileBytes, _) = await _archiveService.CreateZipForDownload(files.Select(c => c.FilePath),- $"download_{User.GetUsername()}_s{seriesId}");- return File(fileBytes, DefaultContentType, $"{series.Name}.zip");+ return await DownloadFiles(files, $"download_{User.GetUsername()}_s{seriesId}", $"{series.Name}.zip");}catch (KavitaException ex){@@ -135,57 +136,20 @@ namespace API.Controllerspublic async Task<ActionResult> DownloadBookmarkPages(DownloadBookmarkDto downloadBookmarkDto){// We know that all bookmarks will be for one single seriesId+ var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(downloadBookmarkDto.Bookmarks.First().SeriesId);- var totalFilePaths = new List<string>();-- var tempFolder = $"download_{series.Id}_bookmarks";- var fullExtractPath = Path.Join(DirectoryService.TempDirectory, tempFolder);- if (new DirectoryInfo(fullExtractPath).Exists)- {- return BadRequest(- "Server is currently processing this exact download. Please try again in a few minutes.");- }- DirectoryService.ExistOrCreate(fullExtractPath);-- var uniqueChapterIds = downloadBookmarkDto.Bookmarks.Select(b => b.ChapterId).Distinct().ToList();-- foreach (var chapterId in uniqueChapterIds)- {- var chapterExtractPath = Path.Join(fullExtractPath, $"{series.Id}_bookmark_{chapterId}");- var chapterPages = downloadBookmarkDto.Bookmarks.Where(b => b.ChapterId == chapterId)- .Select(b => b.Page).ToList();- var mangaFiles = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId);- switch (series.Format)- {- case MangaFormat.Image:- DirectoryService.ExistOrCreate(chapterExtractPath);- _directoryService.CopyFilesToDirectory(mangaFiles.Select(f => f.FilePath), chapterExtractPath, $"{chapterId}_");- break;- case MangaFormat.Archive:- case MangaFormat.Pdf:- _cacheService.ExtractChapterFiles(chapterExtractPath, mangaFiles.ToList());- var originalFiles = DirectoryService.GetFilesWithExtension(chapterExtractPath,- Parser.Parser.ImageFileExtensions);- _directoryService.CopyFilesToDirectory(originalFiles, chapterExtractPath, $"{chapterId}_");- DirectoryService.DeleteFiles(originalFiles);- break;- case MangaFormat.Epub:- return BadRequest("Series is not in a valid format.");- default:- return BadRequest("Series is not in a valid format. Please rescan series and try again.");- }-- var files = DirectoryService.GetFilesWithExtension(chapterExtractPath, Parser.Parser.ImageFileExtensions);- // Filter out images that aren't in bookmarks- Array.Sort(files, _numericComparer);- totalFilePaths.AddRange(files.Where((_, i) => chapterPages.Contains(i)));- }+ var bookmarkDirectory =+ (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BookmarkDirectory)).Value;+ var files = (await _unitOfWork.UserRepository.GetAllBookmarksByIds(downloadBookmarkDto.Bookmarks+ .Select(b => b.Id)+ .ToList()))+ .Select(b => Parser.Parser.NormalizePath(_directoryService.FileSystem.Path.Join(bookmarkDirectory, b.FileName)));- var (fileBytes, _) = await _archiveService.CreateZipForDownload(totalFilePaths,- tempFolder);- DirectoryService.ClearAndDeleteDirectory(fullExtractPath);+ var (fileBytes, _) = await _archiveService.CreateZipForDownload(files,+ $"download_{user.Id}_{series.Id}_bookmarks");return File(fileBytes, DefaultContentType, $"{series.Name} - Bookmarks.zip");}+}}diff --git a/API/Controllers/FallbackController.cs b/API/Controllers/FallbackController.csindex ecd0315e2..ae8bad21f 100644--- a/API/Controllers/FallbackController.cs+++ b/API/Controllers/FallbackController.cs@@ -1,5 +1,5 @@using System.IO;-using API.Interfaces;+using API.Services;using Microsoft.AspNetCore.Mvc;namespace API.Controllers@@ -12,7 +12,7 @@ namespace API.Controllerspublic FallbackController(ITaskScheduler taskScheduler){- // This is used to load TaskScheduler on startup without having to navigate to a Controller that uses.+ // This is used to load TaskScheduler on startup without having to navigate to a Controller that uses._taskScheduler = taskScheduler;}@@ -21,4 +21,4 @@ namespace API.Controllersreturn PhysicalFile(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "index.html"), "text/HTML");}}-}\ No newline at end of file+}diff --git a/API/Controllers/ImageController.cs b/API/Controllers/ImageController.csindex 88bafcff7..a875be14e 100644--- a/API/Controllers/ImageController.cs+++ b/API/Controllers/ImageController.cs@@ -1,7 +1,8 @@using System.IO;using System.Threading.Tasks;+using API.Data;+using API.Entities.Enums;using API.Extensions;-using API.Interfaces;using API.Services;using Microsoft.AspNetCore.Mvc;@@ -13,11 +14,13 @@ namespace API.Controllerspublic class ImageController : BaseApiController{private readonly IUnitOfWork _unitOfWork;+ private readonly IDirectoryService _directoryService;/// <inheritdoc />- public ImageController(IUnitOfWork unitOfWork)+ public ImageController(IUnitOfWork unitOfWork, IDirectoryService directoryService){_unitOfWork = unitOfWork;+ _directoryService = directoryService;}/// <summary>@@ -28,12 +31,12 @@ namespace API.Controllers[HttpGet("chapter-cover")]public async Task<ActionResult> GetChapterCoverImage(int chapterId){- var path = Path.Join(DirectoryService.CoverImageDirectory, await _unitOfWork.ChapterRepository.GetChapterCoverImageAsync(chapterId));- if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No cover image");- var format = Path.GetExtension(path).Replace(".", "");+ var path = Path.Join(_directoryService.CoverImageDirectory, await _unitOfWork.ChapterRepository.GetChapterCoverImageAsync(chapterId));+ if (string.IsNullOrEmpty(path) || !_directoryService.FileSystem.File.Exists(path)) return BadRequest($"No cover image");+ var format = _directoryService.FileSystem.Path.GetExtension(path).Replace(".", "");Response.AddCacheHeader(path);- return PhysicalFile(path, "image/" + format, Path.GetFileName(path));+ return PhysicalFile(path, "image/" + format, _directoryService.FileSystem.Path.GetFileName(path));}/// <summary>@@ -44,12 +47,12 @@ namespace API.Controllers[HttpGet("volume-cover")]public async Task<ActionResult> GetVolumeCoverImage(int volumeId){- var path = Path.Join(DirectoryService.CoverImageDirectory, await _unitOfWork.VolumeRepository.GetVolumeCoverImageAsync(volumeId));- if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No cover image");- var format = Path.GetExtension(path).Replace(".", "");+ var path = Path.Join(_directoryService.CoverImageDirectory, await _unitOfWork.VolumeRepository.GetVolumeCoverImageAsync(volumeId));+ if (string.IsNullOrEmpty(path) || !_directoryService.FileSystem.File.Exists(path)) return BadRequest($"No cover image");+ var format = _directoryService.FileSystem.Path.GetExtension(path).Replace(".", "");Response.AddCacheHeader(path);- return PhysicalFile(path, "image/" + format, Path.GetFileName(path));+ return PhysicalFile(path, "image/" + format, _directoryService.FileSystem.Path.GetFileName(path));}/// <summary>@@ -60,12 +63,12 @@ namespace API.Controllers[HttpGet("series-cover")]public async Task<ActionResult> GetSeriesCoverImage(int seriesId){- var path = Path.Join(DirectoryService.CoverImageDirectory, await _unitOfWork.SeriesRepository.GetSeriesCoverImageAsync(seriesId));- if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No cover image");- var format = Path.GetExtension(path).Replace(".", "");+ var path = Path.Join(_directoryService.CoverImageDirectory, await _unitOfWork.SeriesRepository.GetSeriesCoverImageAsync(seriesId));+ if (string.IsNullOrEmpty(path) || !_directoryService.FileSystem.File.Exists(path)) return BadRequest($"No cover image");+ var format = _directoryService.FileSystem.Path.GetExtension(path).Replace(".", "");Response.AddCacheHeader(path);- return PhysicalFile(path, "image/" + format, Path.GetFileName(path));+ return PhysicalFile(path, "image/" + format, _directoryService.FileSystem.Path.GetFileName(path));}/// <summary>@@ -76,12 +79,34 @@ namespace API.Controllers[HttpGet("collection-cover")]public async Task<ActionResult> GetCollectionCoverImage(int collectionTagId){- var path = Path.Join(DirectoryService.CoverImageDirectory, await _unitOfWork.CollectionTagRepository.GetCoverImageAsync(collectionTagId));- if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No cover image");- var format = Path.GetExtension(path).Replace(".", "");+ var path = Path.Join(_directoryService.CoverImageDirectory, await _unitOfWork.CollectionTagRepository.GetCoverImageAsync(collectionTagId));+ if (string.IsNullOrEmpty(path) || !_directoryService.FileSystem.File.Exists(path)) return BadRequest($"No cover image");+ var format = _directoryService.FileSystem.Path.GetExtension(path).Replace(".", "");Response.AddCacheHeader(path);- return PhysicalFile(path, "image/" + format, Path.GetFileName(path));+ return PhysicalFile(path, "image/" + format, _directoryService.FileSystem.Path.GetFileName(path));+ }++ /// <summary>+ /// Returns image for a given bookmark page+ /// </summary>+ /// <remarks>This request is served unauthenticated, but user must be passed via api key to validate</remarks>+ /// <param name="chapterId"></param>+ /// <param name="pageNum">Starts at 0</param>+ /// <param name="apiKey">API Key for user. Needed to authenticate request</param>+ /// <returns></returns>+ [HttpGet("bookmark")]+ public async Task<ActionResult> GetBookmarkImage(int chapterId, int pageNum, string apiKey)+ {+ var userId = await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey);+ var bookmark = await _unitOfWork.UserRepository.GetBookmarkForPage(pageNum, chapterId, userId);+ if (bookmark == null) return BadRequest("Bookmark does not exist");++ var bookmarkDirectory =+ (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BookmarkDirectory)).Value;+ var file = new FileInfo(Path.Join(bookmarkDirectory, bookmark.FileName));+ var format = Path.GetExtension(file.FullName).Replace(".", "");+ return PhysicalFile(file.FullName, "image/" + format, Path.GetFileName(file.FullName));}}}diff --git a/API/Controllers/LibraryController.cs b/API/Controllers/LibraryController.csindex 15a8d1166..9cdd06158 100644--- a/API/Controllers/LibraryController.cs+++ b/API/Controllers/LibraryController.cs@@ -3,13 +3,13 @@ using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading.Tasks;+using API.Data;using API.Data.Repositories;using API.DTOs;using API.Entities;using API.Entities.Enums;using API.Extensions;-using API.Interfaces;-using API.Interfaces.Services;+using API.Services;using AutoMapper;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;diff --git a/API/Controllers/MetadataController.cs b/API/Controllers/MetadataController.csnew file mode 100644index 000000000..4aa13691f--- /dev/null+++ b/API/Controllers/MetadataController.cs@@ -0,0 +1,140 @@+using System;+using System.Collections.Generic;+using System.Globalization;+using System.Linq;+using System.Threading.Tasks;+using API.Data;+using API.DTOs;+using API.DTOs.Filtering;+using API.DTOs.Metadata;+using API.Entities.Enums;+using Kavita.Common.Extensions;+using Microsoft.AspNetCore.Mvc;++namespace API.Controllers;+++public class MetadataController : BaseApiController+{+ private readonly IUnitOfWork _unitOfWork;++ public MetadataController(IUnitOfWork unitOfWork)+ {+ _unitOfWork = unitOfWork;+ }++ /// <summary>+ /// Fetches genres from the instance+ /// </summary>+ /// <param name="libraryIds">String separated libraryIds or null for all genres</param>+ /// <returns></returns>+ [HttpGet("genres")]+ public async Task<ActionResult<IList<GenreTagDto>>> GetAllGenres(string? libraryIds)+ {+ var ids = libraryIds?.Split(",").Select(int.Parse).ToList();+ if (ids != null && ids.Count > 0)+ {+ return Ok(await _unitOfWork.GenreRepository.GetAllGenreDtosForLibrariesAsync(ids));+ }++ return Ok(await _unitOfWork.GenreRepository.GetAllGenreDtosAsync());+ }++ /// <summary>+ /// Fetches people from the instance+ /// </summary>+ /// <param name="libraryIds">String separated libraryIds or null for all people</param>+ /// <returns></returns>+ [HttpGet("people")]+ public async Task<ActionResult<IList<PersonDto>>> GetAllPeople(string? libraryIds)+ {+ var ids = libraryIds?.Split(",").Select(int.Parse).ToList();+ if (ids != null && ids.Count > 0)+ {+ return Ok(await _unitOfWork.PersonRepository.GetAllPeopleDtosForLibrariesAsync(ids));+ }+ return Ok(await _unitOfWork.PersonRepository.GetAllPeople());+ }++ /// <summary>+ /// Fetches all tags from the instance+ /// </summary>+ /// <param name="libraryIds">String separated libraryIds or null for all tags</param>+ /// <returns></returns>+ [HttpGet("tags")]+ public async Task<ActionResult<IList<TagDto>>> GetAllTags(string? libraryIds)+ {+ var ids = libraryIds?.Split(",").Select(int.Parse).ToList();+ if (ids != null && ids.Count > 0)+ {+ return Ok(await _unitOfWork.TagRepository.GetAllTagDtosForLibrariesAsync(ids));+ }+ return Ok(await _unitOfWork.TagRepository.GetAllTagDtosAsync());+ }++ /// <summary>+ /// Fetches all age ratings from the instance+ /// </summary>+ /// <param name="libraryIds">String separated libraryIds or null for all ratings</param>+ /// <returns></returns>+ [HttpGet("age-ratings")]+ public async Task<ActionResult<IList<AgeRatingDto>>> GetAllAgeRatings(string? libraryIds)+ {+ var ids = libraryIds?.Split(",").Select(int.Parse).ToList();+ if (ids != null && ids.Count > 0)+ {+ return Ok(await _unitOfWork.SeriesRepository.GetAllAgeRatingsDtosForLibrariesAsync(ids));+ }++ return Ok(Enum.GetValues<AgeRating>().Select(t => new AgeRatingDto()+ {+ Title = t.ToDescription(),+ Value = t+ }));+ }++ /// <summary>+ /// Fetches all publication status' from the instance+ /// </summary>+ /// <param name="libraryIds">String separated libraryIds or null for all publication status</param>+ /// <returns></returns>+ [HttpGet("publication-status")]+ public async Task<ActionResult<IList<AgeRatingDto>>> GetAllPublicationStatus(string? libraryIds)+ {+ var ids = libraryIds?.Split(",").Select(int.Parse).ToList();+ if (ids != null && ids.Count > 0)+ {+ return Ok(await _unitOfWork.SeriesRepository.GetAllPublicationStatusesDtosForLibrariesAsync(ids));+ }++ return Ok(Enum.GetValues<PublicationStatus>().Select(t => new PublicationStatusDto()+ {+ Title = t.ToDescription(),+ Value = t+ }));+ }++ /// <summary>+ /// Fetches all age ratings from the instance+ /// </summary>+ /// <param name="libraryIds">String separated libraryIds or null for all ratings</param>+ /// <returns></returns>+ [HttpGet("languages")]+ public async Task<ActionResult<IList<LanguageDto>>> GetAllLanguages(string? libraryIds)+ {+ var ids = libraryIds?.Split(",").Select(int.Parse).ToList();+ if (ids != null && ids.Count > 0)+ {+ return Ok(await _unitOfWork.SeriesRepository.GetAllLanguagesForLibrariesAsync(ids));+ }++ return Ok(new List<LanguageDto>()+ {+ new ()+ {+ Title = CultureInfo.GetCultureInfo("en").DisplayName,+ IsoCode = "en"+ }+ });+ }+}diff --git a/API/Controllers/OPDSController.cs b/API/Controllers/OPDSController.csindex 49a70d90d..9b7e87d62 100644--- a/API/Controllers/OPDSController.cs+++ b/API/Controllers/OPDSController.cs@@ -5,789 +5,800 @@ using System.Linq;using System.Threading.Tasks;using System.Xml.Serialization;using API.Comparators;+using API.Data;using API.DTOs;using API.DTOs.CollectionTags;using API.DTOs.Filtering;using API.DTOs.OPDS;using API.Entities;+using API.Entities.Enums;using API.Extensions;using API.Helpers;-using API.Interfaces;-using API.Interfaces.Services;using API.Services;using Kavita.Common;using Microsoft.AspNetCore.Mvc;-using Microsoft.Extensions.Logging;-namespace API.Controllers-{- public class OpdsController : BaseApiController- {- private readonly IUnitOfWork _unitOfWork;- private readonly IDownloadService _downloadService;- private readonly IDirectoryService _directoryService;- private readonly ICacheService _cacheService;- private readonly IReaderService _readerService;+namespace API.Controllers;+public class OpdsController : BaseApiController+{+ private readonly IUnitOfWork _unitOfWork;+ private readonly IDownloadService _downloadService;+ private readonly IDirectoryService _directoryService;+ private readonly ICacheService _cacheService;+ private readonly IReaderService _readerService;- private readonly XmlSerializer _xmlSerializer;- private readonly XmlSerializer _xmlOpenSearchSerializer;- private const string Prefix = "/api/opds/";- private readonly FilterDto _filterDto = new FilterDto()- {- MangaFormat = null- };- private readonly ChapterSortComparer _chapterSortComparer = new ChapterSortComparer();- public OpdsController(IUnitOfWork unitOfWork, IDownloadService downloadService,- IDirectoryService directoryService, ICacheService cacheService,- IReaderService readerService)- {- _unitOfWork = unitOfWork;- _downloadService = downloadService;- _directoryService = directoryService;- _cacheService = cacheService;- _readerService = readerService;+ private readonly XmlSerializer _xmlSerializer;+ private readonly XmlSerializer _xmlOpenSearchSerializer;+ private const string Prefix = "/api/opds/";+ private readonly FilterDto _filterDto = new FilterDto()+ {+ Formats = new List<MangaFormat>(),+ Character = new List<int>(),+ Colorist = new List<int>(),+ Editor = new List<int>(),+ Genres = new List<int>(),+ Inker = new List<int>(),+ Languages = new List<string>(),+ Letterer = new List<int>(),+ Penciller = new List<int>(),+ Libraries = new List<int>(),+ Publisher = new List<int>(),+ Rating = 0,+ Tags = new List<int>(),+ Translators = new List<int>(),+ Writers = new List<int>(),+ AgeRating = new List<AgeRating>(),+ CollectionTags = new List<int>(),+ CoverArtist = new List<int>(),+ ReadStatus = new ReadStatus(),+ SortOptions = null,+ PublicationStatus = new List<PublicationStatus>()+ };+ private readonly ChapterSortComparer _chapterSortComparer = new ChapterSortComparer();++ public OpdsController(IUnitOfWork unitOfWork, IDownloadService downloadService,+ IDirectoryService directoryService, ICacheService cacheService,+ IReaderService readerService)+ {+ _unitOfWork = unitOfWork;+ _downloadService = downloadService;+ _directoryService = directoryService;+ _cacheService = cacheService;+ _readerService = readerService;- _xmlSerializer = new XmlSerializer(typeof(Feed));- _xmlOpenSearchSerializer = new XmlSerializer(typeof(OpenSearchDescription));+ _xmlSerializer = new XmlSerializer(typeof(Feed));+ _xmlOpenSearchSerializer = new XmlSerializer(typeof(OpenSearchDescription));- }+ }- [HttpPost("{apiKey}")]- [HttpGet("{apiKey}")]- [Produces("application/xml")]- public async Task<IActionResult> Get(string apiKey)+ [HttpPost("{apiKey}")]+ [HttpGet("{apiKey}")]+ [Produces("application/xml")]+ public async Task<IActionResult> Get(string apiKey)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var feed = CreateFeed("Kavita", string.Empty, apiKey);+ SetFeedId(feed, "root");+ feed.Entries.Add(new FeedEntry(){- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var feed = CreateFeed("Kavita", string.Empty, apiKey);- SetFeedId(feed, "root");- feed.Entries.Add(new FeedEntry()+ Id = "onDeck",+ Title = "On Deck",+ Content = new FeedEntryContent(){- Id = "onDeck",- Title = "On Deck",- Content = new FeedEntryContent()- {- Text = "Browse by On Deck"- },- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/on-deck"),- }- });- feed.Entries.Add(new FeedEntry()+ Text = "Browse by On Deck"+ },+ Links = new List<FeedLink>(){- Id = "recentlyAdded",- Title = "Recently Added",- Content = new FeedEntryContent()- {- Text = "Browse by Recently Added"- },- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/recently-added"),- }- });- feed.Entries.Add(new FeedEntry()- {- Id = "readingList",- Title = "Reading Lists",- Content = new FeedEntryContent()- {- Text = "Browse by Reading Lists"- },- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/reading-list"),- }- });- feed.Entries.Add(new FeedEntry()- {- Id = "allLibraries",- Title = "All Libraries",- Content = new FeedEntryContent()- {- Text = "Browse by Libraries"- },- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/libraries"),- }- });- feed.Entries.Add(new FeedEntry()- {- Id = "allCollections",- Title = "All Collections",- Content = new FeedEntryContent()- {- Text = "Browse by Collections"- },- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/collections"),- }- });- return CreateXmlResult(SerializeXml(feed));- }--- [HttpGet("{apiKey}/libraries")]- [Produces("application/xml")]- public async Task<IActionResult> GetLibraries(string apiKey)+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/on-deck"),+ }+ });+ feed.Entries.Add(new FeedEntry(){- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- var libraries = await _unitOfWork.LibraryRepository.GetLibrariesForUserIdAsync(userId);- var feed = CreateFeed("All Libraries", $"{apiKey}/libraries", apiKey);- SetFeedId(feed, "libraries");- foreach (var library in libraries)+ Id = "recentlyAdded",+ Title = "Recently Added",+ Content = new FeedEntryContent(){- feed.Entries.Add(new FeedEntry()- {- Id = library.Id.ToString(),- Title = library.Name,- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/libraries/{library.Id}"),- }- });+ Text = "Browse by Recently Added"+ },+ Links = new List<FeedLink>()+ {+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/recently-added"),}-- return CreateXmlResult(SerializeXml(feed));- }-- [HttpGet("{apiKey}/collections")]- [Produces("application/xml")]- public async Task<IActionResult> GetCollections(string apiKey)+ });+ feed.Entries.Add(new FeedEntry(){- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);- var isAdmin = await _unitOfWork.UserRepository.IsUserAdmin(user);-- IList<CollectionTagDto> tags;- if (isAdmin)+ Id = "readingList",+ Title = "Reading Lists",+ Content = new FeedEntryContent(){- tags = (await _unitOfWork.CollectionTagRepository.GetAllTagDtosAsync()).ToList();- }- else+ Text = "Browse by Reading Lists"+ },+ Links = new List<FeedLink>(){- tags = (await _unitOfWork.CollectionTagRepository.GetAllPromotedTagDtosAsync()).ToList();+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/reading-list"),}--- var feed = CreateFeed("All Collections", $"{apiKey}/collections", apiKey);- SetFeedId(feed, "collections");- foreach (var tag in tags)+ });+ feed.Entries.Add(new FeedEntry()+ {+ Id = "allLibraries",+ Title = "All Libraries",+ Content = new FeedEntryContent(){- feed.Entries.Add(new FeedEntry()- {- Id = tag.Id.ToString(),- Title = tag.Title,- Summary = tag.Summary,- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/collections/{tag.Id}"),- CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/collection-cover?collectionId={tag.Id}"),- CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"/api/image/collection-cover?collectionId={tag.Id}")- }- });+ Text = "Browse by Libraries"+ },+ Links = new List<FeedLink>()+ {+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/libraries"),}-- return CreateXmlResult(SerializeXml(feed));- }--- [HttpGet("{apiKey}/collections/{collectionId}")]- [Produces("application/xml")]- public async Task<IActionResult> GetCollection(int collectionId, string apiKey, [FromQuery] int pageNumber = 0)+ });+ feed.Entries.Add(new FeedEntry(){- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);- var isAdmin = await _unitOfWork.UserRepository.IsUserAdmin(user);-- IEnumerable <CollectionTagDto> tags;- if (isAdmin)+ Id = "allCollections",+ Title = "All Collections",+ Content = new FeedEntryContent(){- tags = await _unitOfWork.CollectionTagRepository.GetAllTagDtosAsync();- }- else+ Text = "Browse by Collections"+ },+ Links = new List<FeedLink>(){- tags = await _unitOfWork.CollectionTagRepository.GetAllPromotedTagDtosAsync();+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/collections"),}+ });+ return CreateXmlResult(SerializeXml(feed));+ }- var tag = tags.SingleOrDefault(t => t.Id == collectionId);- if (tag == null)- {- return BadRequest("Collection does not exist or you don't have access");- }- var series = await _unitOfWork.SeriesRepository.GetSeriesDtoForCollectionAsync(collectionId, userId, new UserParams()+ [HttpGet("{apiKey}/libraries")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetLibraries(string apiKey)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ var libraries = await _unitOfWork.LibraryRepository.GetLibrariesForUserIdAsync(userId);+ var feed = CreateFeed("All Libraries", $"{apiKey}/libraries", apiKey);+ SetFeedId(feed, "libraries");+ foreach (var library in libraries)+ {+ feed.Entries.Add(new FeedEntry(){- PageNumber = pageNumber,- PageSize = 20+ Id = library.Id.ToString(),+ Title = library.Name,+ Links = new List<FeedLink>()+ {+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/libraries/{library.Id}"),+ }});+ }- var feed = CreateFeed(tag.Title + " Collection", $"{apiKey}/collections/{collectionId}", apiKey);- SetFeedId(feed, $"collections-{collectionId}");- AddPagination(feed, series, $"{Prefix}{apiKey}/collections/{collectionId}");+ return CreateXmlResult(SerializeXml(feed));+ }- foreach (var seriesDto in series)- {- feed.Entries.Add(CreateSeries(seriesDto, apiKey));- }+ [HttpGet("{apiKey}/collections")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetCollections(string apiKey)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);+ var isAdmin = await _unitOfWork.UserRepository.IsUserAdminAsync(user);+ IList<CollectionTagDto> tags = isAdmin ? (await _unitOfWork.CollectionTagRepository.GetAllTagDtosAsync()).ToList()+ : (await _unitOfWork.CollectionTagRepository.GetAllPromotedTagDtosAsync()).ToList();- return CreateXmlResult(SerializeXml(feed));- }- [HttpGet("{apiKey}/reading-list")]- [Produces("application/xml")]- public async Task<IActionResult> GetReadingLists(string apiKey, [FromQuery] int pageNumber = 0)+ var feed = CreateFeed("All Collections", $"{apiKey}/collections", apiKey);+ SetFeedId(feed, "collections");+ foreach (var tag in tags){- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);-- var readingLists = await _unitOfWork.ReadingListRepository.GetReadingListDtosForUserAsync(userId, true, new UserParams()+ feed.Entries.Add(new FeedEntry(){- PageNumber = pageNumber+ Id = tag.Id.ToString(),+ Title = tag.Title,+ Summary = tag.Summary,+ Links = new List<FeedLink>()+ {+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/collections/{tag.Id}"),+ CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/collection-cover?collectionId={tag.Id}"),+ CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"/api/image/collection-cover?collectionId={tag.Id}")+ }});+ }+ return CreateXmlResult(SerializeXml(feed));+ }- var feed = CreateFeed("All Reading Lists", $"{apiKey}/reading-list", apiKey);- SetFeedId(feed, "reading-list");- foreach (var readingListDto in readingLists)- {- feed.Entries.Add(new FeedEntry()- {- Id = readingListDto.Id.ToString(),- Title = readingListDto.Title,- Summary = readingListDto.Summary,- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/reading-list/{readingListDto.Id}"),- }- });- }- return CreateXmlResult(SerializeXml(feed));+ [HttpGet("{apiKey}/collections/{collectionId}")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetCollection(int collectionId, string apiKey, [FromQuery] int pageNumber = 0)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);+ var isAdmin = await _unitOfWork.UserRepository.IsUserAdminAsync(user);++ IEnumerable <CollectionTagDto> tags;+ if (isAdmin)+ {+ tags = await _unitOfWork.CollectionTagRepository.GetAllTagDtosAsync();}-- [HttpGet("{apiKey}/reading-list/{readingListId}")]- [Produces("application/xml")]- public async Task<IActionResult> GetReadingListItems(int readingListId, string apiKey)+ else{- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);+ tags = await _unitOfWork.CollectionTagRepository.GetAllPromotedTagDtosAsync();+ }- var userWithLists = await _unitOfWork.UserRepository.GetUserWithReadingListsByUsernameAsync(user.UserName);- var readingList = userWithLists.ReadingLists.SingleOrDefault(t => t.Id == readingListId);- if (readingList == null)- {- return BadRequest("Reading list does not exist or you don't have access");- }+ var tag = tags.SingleOrDefault(t => t.Id == collectionId);+ if (tag == null)+ {+ return BadRequest("Collection does not exist or you don't have access");+ }- var feed = CreateFeed(readingList.Title + " Reading List", $"{apiKey}/reading-list/{readingListId}", apiKey);- SetFeedId(feed, $"reading-list-{readingListId}");+ var series = await _unitOfWork.SeriesRepository.GetSeriesDtoForCollectionAsync(collectionId, userId, new UserParams()+ {+ PageNumber = pageNumber,+ PageSize = 20+ });- var items = (await _unitOfWork.ReadingListRepository.GetReadingListItemDtosByIdAsync(readingListId, userId)).ToList();- foreach (var item in items)- {- feed.Entries.Add(new FeedEntry()- {- Id = item.ChapterId.ToString(),- Title = $"{item.SeriesName} Chapter {item.ChapterNumber}",- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/series/{item.SeriesId}/volume/{item.VolumeId}/chapter/{item.ChapterId}"),- CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/chapter-cover?chapterId={item.ChapterId}")- }- });- }+ var feed = CreateFeed(tag.Title + " Collection", $"{apiKey}/collections/{collectionId}", apiKey);+ SetFeedId(feed, $"collections-{collectionId}");+ AddPagination(feed, series, $"{Prefix}{apiKey}/collections/{collectionId}");- return CreateXmlResult(SerializeXml(feed));+ foreach (var seriesDto in series)+ {+ feed.Entries.Add(CreateSeries(seriesDto, apiKey));}- [HttpGet("{apiKey}/libraries/{libraryId}")]- [Produces("application/xml")]- public async Task<IActionResult> GetSeriesForLibrary(int libraryId, string apiKey, [FromQuery] int pageNumber = 0)- {- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- var library =- (await _unitOfWork.LibraryRepository.GetLibrariesForUserIdAsync(userId)).SingleOrDefault(l =>- l.Id == libraryId);- if (library == null)- {- return BadRequest("User does not have access to this library");- }- var series = await _unitOfWork.SeriesRepository.GetSeriesDtoForLibraryIdAsync(libraryId, userId, new UserParams()- {- PageNumber = pageNumber,- PageSize = 20- }, _filterDto);+ return CreateXmlResult(SerializeXml(feed));+ }- var feed = CreateFeed(library.Name, $"{apiKey}/libraries/{libraryId}", apiKey);- SetFeedId(feed, $"library-{library.Name}");- AddPagination(feed, series, $"{Prefix}{apiKey}/libraries/{libraryId}");+ [HttpGet("{apiKey}/reading-list")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetReadingLists(string apiKey, [FromQuery] int pageNumber = 0)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);- foreach (var seriesDto in series)- {- feed.Entries.Add(CreateSeries(seriesDto, apiKey));- }+ var readingLists = await _unitOfWork.ReadingListRepository.GetReadingListDtosForUserAsync(userId, true, new UserParams()+ {+ PageNumber = pageNumber+ });- return CreateXmlResult(SerializeXml(feed));- }- [HttpGet("{apiKey}/recently-added")]- [Produces("application/xml")]- public async Task<IActionResult> GetRecentlyAdded(string apiKey, [FromQuery] int pageNumber = 1)+ var feed = CreateFeed("All Reading Lists", $"{apiKey}/reading-list", apiKey);+ SetFeedId(feed, "reading-list");+ foreach (var readingListDto in readingLists){- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- var recentlyAdded = await _unitOfWork.SeriesRepository.GetRecentlyAdded(0, userId, new UserParams()+ feed.Entries.Add(new FeedEntry(){- PageNumber = pageNumber,- PageSize = 20- }, _filterDto);-- var feed = CreateFeed("Recently Added", $"{apiKey}/recently-added", apiKey);- SetFeedId(feed, "recently-added");- AddPagination(feed, recentlyAdded, $"{Prefix}{apiKey}/recently-added");+ Id = readingListDto.Id.ToString(),+ Title = readingListDto.Title,+ Summary = readingListDto.Summary,+ Links = new List<FeedLink>()+ {+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/reading-list/{readingListDto.Id}"),+ }+ });+ }- foreach (var seriesDto in recentlyAdded)- {- feed.Entries.Add(CreateSeries(seriesDto, apiKey));- }+ return CreateXmlResult(SerializeXml(feed));+ }- return CreateXmlResult(SerializeXml(feed));+ [HttpGet("{apiKey}/reading-list/{readingListId}")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetReadingListItems(int readingListId, string apiKey)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);++ var userWithLists = await _unitOfWork.UserRepository.GetUserWithReadingListsByUsernameAsync(user.UserName);+ var readingList = userWithLists.ReadingLists.SingleOrDefault(t => t.Id == readingListId);+ if (readingList == null)+ {+ return BadRequest("Reading list does not exist or you don't have access");}- [HttpGet("{apiKey}/on-deck")]- [Produces("application/xml")]- public async Task<IActionResult> GetOnDeck(string apiKey, [FromQuery] int pageNumber = 1)+ var feed = CreateFeed(readingList.Title + " Reading List", $"{apiKey}/reading-list/{readingListId}", apiKey);+ SetFeedId(feed, $"reading-list-{readingListId}");++ var items = (await _unitOfWork.ReadingListRepository.GetReadingListItemDtosByIdAsync(readingListId, userId)).ToList();+ foreach (var item in items){- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- var userParams = new UserParams()+ feed.Entries.Add(new FeedEntry(){- PageNumber = pageNumber,- PageSize = 20- };- var results = await _unitOfWork.SeriesRepository.GetOnDeck(userId, 0, userParams, _filterDto);- var listResults = results.DistinctBy(s => s.Name).Skip((userParams.PageNumber - 1) * userParams.PageSize)- .Take(userParams.PageSize).ToList();- var pagedList = new PagedList<SeriesDto>(listResults, listResults.Count, userParams.PageNumber, userParams.PageSize);-- Response.AddPaginationHeader(pagedList.CurrentPage, pagedList.PageSize, pagedList.TotalCount, pagedList.TotalPages);-- var feed = CreateFeed("On Deck", $"{apiKey}/on-deck", apiKey);- SetFeedId(feed, "on-deck");- AddPagination(feed, pagedList, $"{Prefix}{apiKey}/on-deck");+ Id = item.ChapterId.ToString(),+ Title = $"{item.SeriesName} Chapter {item.ChapterNumber}",+ Links = new List<FeedLink>()+ {+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/series/{item.SeriesId}/volume/{item.VolumeId}/chapter/{item.ChapterId}"),+ CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/chapter-cover?chapterId={item.ChapterId}")+ }+ });+ }- foreach (var seriesDto in pagedList)- {- feed.Entries.Add(CreateSeries(seriesDto, apiKey));- }+ return CreateXmlResult(SerializeXml(feed));+ }- return CreateXmlResult(SerializeXml(feed));+ [HttpGet("{apiKey}/libraries/{libraryId}")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetSeriesForLibrary(int libraryId, string apiKey, [FromQuery] int pageNumber = 0)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ var library =+ (await _unitOfWork.LibraryRepository.GetLibrariesForUserIdAsync(userId)).SingleOrDefault(l =>+ l.Id == libraryId);+ if (library == null)+ {+ return BadRequest("User does not have access to this library");}- [HttpGet("{apiKey}/series")]- [Produces("application/xml")]- public async Task<IActionResult> SearchSeries(string apiKey, [FromQuery] string query)+ var series = await _unitOfWork.SeriesRepository.GetSeriesDtoForLibraryIdAsync(libraryId, userId, new UserParams(){- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- if (string.IsNullOrEmpty(query))- {- return BadRequest("You must pass a query parameter");- }- query = query.Replace(@"%", "");- // Get libraries user has access to- var libraries = (await _unitOfWork.LibraryRepository.GetLibrariesForUserIdAsync(userId)).ToList();-- if (!libraries.Any()) return BadRequest("User does not have access to any libraries");-- var series = await _unitOfWork.SeriesRepository.SearchSeries(libraries.Select(l => l.Id).ToArray(), query);-- var feed = CreateFeed(query, $"{apiKey}/series?query=" + query, apiKey);- SetFeedId(feed, "search-series");- foreach (var seriesDto in series)- {- feed.Entries.Add(CreateSeries(seriesDto, apiKey));- }+ PageNumber = pageNumber,+ PageSize = 20+ }, _filterDto);- return CreateXmlResult(SerializeXml(feed));- }+ var feed = CreateFeed(library.Name, $"{apiKey}/libraries/{libraryId}", apiKey);+ SetFeedId(feed, $"library-{library.Name}");+ AddPagination(feed, series, $"{Prefix}{apiKey}/libraries/{libraryId}");- private static void SetFeedId(Feed feed, string id)+ foreach (var seriesDto in series){- feed.Id = id;+ feed.Entries.Add(CreateSeries(seriesDto, apiKey));}- [HttpGet("{apiKey}/search")]- [Produces("application/xml")]- public async Task<IActionResult> GetSearchDescriptor(string apiKey)+ return CreateXmlResult(SerializeXml(feed));+ }++ [HttpGet("{apiKey}/recently-added")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetRecentlyAdded(string apiKey, [FromQuery] int pageNumber = 1)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ var recentlyAdded = await _unitOfWork.SeriesRepository.GetRecentlyAdded(0, userId, new UserParams(){- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var feed = new OpenSearchDescription()- {- ShortName = "Search",- Description = "Search for Series",- Url = new SearchLink()- {- Type = FeedLinkType.AtomAcquisition,- Template = $"{Prefix}{apiKey}/series?query=" + "{searchTerms}"- }- };+ PageNumber = pageNumber,+ PageSize = 20+ }, _filterDto);- await using var sm = new StringWriter();- _xmlOpenSearchSerializer.Serialize(sm, feed);+ var feed = CreateFeed("Recently Added", $"{apiKey}/recently-added", apiKey);+ SetFeedId(feed, "recently-added");+ AddPagination(feed, recentlyAdded, $"{Prefix}{apiKey}/recently-added");- return CreateXmlResult(sm.ToString().Replace("utf-16", "utf-8"));+ foreach (var seriesDto in recentlyAdded)+ {+ feed.Entries.Add(CreateSeries(seriesDto, apiKey));}- [HttpGet("{apiKey}/series/{seriesId}")]- [Produces("application/xml")]- public async Task<IActionResult> GetSeries(string apiKey, int seriesId)- {- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- var series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);- var volumes = await _unitOfWork.VolumeRepository.GetVolumesDtoAsync(seriesId, userId);- var feed = CreateFeed(series.Name + " - Volumes", $"{apiKey}/series/{series.Id}", apiKey);- SetFeedId(feed, $"series-{series.Id}");- feed.Links.Add(CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/series-cover?seriesId={seriesId}"));- foreach (var volumeDto in volumes)- {- feed.Entries.Add(CreateVolume(volumeDto, seriesId, apiKey));- }+ return CreateXmlResult(SerializeXml(feed));+ }- return CreateXmlResult(SerializeXml(feed));- }+ [HttpGet("{apiKey}/on-deck")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetOnDeck(string apiKey, [FromQuery] int pageNumber = 1)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ var userParams = new UserParams()+ {+ PageNumber = pageNumber,+ PageSize = 20+ };+ var results = await _unitOfWork.SeriesRepository.GetOnDeck(userId, 0, userParams, _filterDto);+ var listResults = results.DistinctBy(s => s.Name).Skip((userParams.PageNumber - 1) * userParams.PageSize)+ .Take(userParams.PageSize).ToList();+ var pagedList = new PagedList<SeriesDto>(listResults, listResults.Count, userParams.PageNumber, userParams.PageSize);- [HttpGet("{apiKey}/series/{seriesId}/volume/{volumeId}")]- [Produces("application/xml")]- public async Task<IActionResult> GetVolume(string apiKey, int seriesId, int volumeId)- {- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- var series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);- var volume = await _unitOfWork.VolumeRepository.GetVolumeAsync(volumeId);- var chapters =- (await _unitOfWork.ChapterRepository.GetChaptersAsync(volumeId)).OrderBy(x => double.Parse(x.Number),- _chapterSortComparer);-- var feed = CreateFeed(series.Name + " - Volume " + volume.Name + " - Chapters ", $"{apiKey}/series/{seriesId}/volume/{volumeId}", apiKey);- SetFeedId(feed, $"series-{series.Id}-volume-{volume.Id}-chapters");- foreach (var chapter in chapters)- {- feed.Entries.Add(new FeedEntry()- {- Id = chapter.Id.ToString(),- Title = "Chapter " + chapter.Number,- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapter.Id}"),- CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/chapter-cover?chapterId={chapter.Id}")- }- });- }+ Response.AddPaginationHeader(pagedList.CurrentPage, pagedList.PageSize, pagedList.TotalCount, pagedList.TotalPages);- return CreateXmlResult(SerializeXml(feed));- }+ var feed = CreateFeed("On Deck", $"{apiKey}/on-deck", apiKey);+ SetFeedId(feed, "on-deck");+ AddPagination(feed, pagedList, $"{Prefix}{apiKey}/on-deck");- [HttpGet("{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapterId}")]- [Produces("application/xml")]- public async Task<IActionResult> GetChapter(string apiKey, int seriesId, int volumeId, int chapterId)- {- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var userId = await GetUser(apiKey);- var series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);- var volume = await _unitOfWork.VolumeRepository.GetVolumeAsync(volumeId);- var chapter = await _unitOfWork.ChapterRepository.GetChapterDtoAsync(chapterId);- var files = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId);-- var feed = CreateFeed(series.Name + " - Volume " + volume.Name + " - Chapters ", $"{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapterId}", apiKey);- SetFeedId(feed, $"series-{series.Id}-volume-{volume.Id}-chapter-{chapter.Id}-files");- foreach (var mangaFile in files)- {- feed.Entries.Add(CreateChapter(seriesId, volumeId, chapterId, mangaFile, series, volume, chapter, apiKey));- }-- return CreateXmlResult(SerializeXml(feed));+ foreach (var seriesDto in pagedList)+ {+ feed.Entries.Add(CreateSeries(seriesDto, apiKey));}- /// <summary>- /// Downloads a file- /// </summary>- /// <param name="seriesId"></param>- /// <param name="volumeId"></param>- /// <param name="chapterId"></param>- /// <param name="filename">Not used. Only for Chunky to allow download links</param>- /// <returns></returns>- [HttpGet("{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapterId}/download/{filename}")]- public async Task<ActionResult> DownloadFile(string apiKey, int seriesId, int volumeId, int chapterId, string filename)- {- if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)- return BadRequest("OPDS is not enabled on this server");- var files = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId);- var (bytes, contentType, fileDownloadName) = await _downloadService.GetFirstFileDownload(files);- return File(bytes, contentType, fileDownloadName);- }+ return CreateXmlResult(SerializeXml(feed));+ }- private static ContentResult CreateXmlResult(string xml)+ [HttpGet("{apiKey}/series")]+ [Produces("application/xml")]+ public async Task<IActionResult> SearchSeries(string apiKey, [FromQuery] string query)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ if (string.IsNullOrEmpty(query)){- return new ContentResult- {- ContentType = "application/xml",- Content = xml,- StatusCode = 200- };+ return BadRequest("You must pass a query parameter");}+ query = query.Replace(@"%", "");+ // Get libraries user has access to+ var libraries = (await _unitOfWork.LibraryRepository.GetLibrariesForUserIdAsync(userId)).ToList();++ if (!libraries.Any()) return BadRequest("User does not have access to any libraries");- private static void AddPagination(Feed feed, PagedList<SeriesDto> list, string href)+ var series = await _unitOfWork.SeriesRepository.SearchSeries(libraries.Select(l => l.Id).ToArray(), query);++ var feed = CreateFeed(query, $"{apiKey}/series?query=" + query, apiKey);+ SetFeedId(feed, "search-series");+ foreach (var seriesDto in series){- var url = href;- if (href.Contains("?"))- {- url += "&";- }- else- {- url += "?";- }+ feed.Entries.Add(CreateSeries(seriesDto, apiKey));+ }- var pageNumber = Math.Max(list.CurrentPage, 1);+ return CreateXmlResult(SerializeXml(feed));+ }- if (pageNumber > 1)- {- feed.Links.Add(CreateLink(FeedLinkRelation.Prev, FeedLinkType.AtomNavigation, url + "pageNumber=" + (pageNumber - 1)));- }+ private static void SetFeedId(Feed feed, string id)+ {+ feed.Id = id;+ }- if (pageNumber + 1 < list.TotalPages)+ [HttpGet("{apiKey}/search")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetSearchDescriptor(string apiKey)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var feed = new OpenSearchDescription()+ {+ ShortName = "Search",+ Description = "Search for Series",+ Url = new SearchLink(){- feed.Links.Add(CreateLink(FeedLinkRelation.Next, FeedLinkType.AtomNavigation, url + "pageNumber=" + (pageNumber + 1)));+ Type = FeedLinkType.AtomAcquisition,+ Template = $"{Prefix}{apiKey}/series?query=" + "{searchTerms}"}+ };- // Update self to point to current page- var selfLink = feed.Links.SingleOrDefault(l => l.Rel == FeedLinkRelation.Self);- if (selfLink != null)- {- selfLink.Href = url + "pageNumber=" + pageNumber;- }+ await using var sm = new StringWriter();+ _xmlOpenSearchSerializer.Serialize(sm, feed);+ return CreateXmlResult(sm.ToString().Replace("utf-16", "utf-8"));+ }- feed.Total = list.TotalPages * list.PageSize;- feed.ItemsPerPage = list.PageSize;- feed.StartIndex = (Math.Max(list.CurrentPage - 1, 0) * list.PageSize) + 1;+ [HttpGet("{apiKey}/series/{seriesId}")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetSeries(string apiKey, int seriesId)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ var series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);+ var volumes = await _unitOfWork.VolumeRepository.GetVolumesDtoAsync(seriesId, userId);+ var feed = CreateFeed(series.Name + " - Volumes", $"{apiKey}/series/{series.Id}", apiKey);+ SetFeedId(feed, $"series-{series.Id}");+ feed.Links.Add(CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/series-cover?seriesId={seriesId}"));+ foreach (var volumeDto in volumes)+ {+ feed.Entries.Add(CreateVolume(volumeDto, seriesId, apiKey));}- private static FeedEntry CreateSeries(SeriesDto seriesDto, string apiKey)+ return CreateXmlResult(SerializeXml(feed));+ }++ [HttpGet("{apiKey}/series/{seriesId}/volume/{volumeId}")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetVolume(string apiKey, int seriesId, int volumeId)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ var series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);+ var volume = await _unitOfWork.VolumeRepository.GetVolumeAsync(volumeId);+ var chapters =+ (await _unitOfWork.ChapterRepository.GetChaptersAsync(volumeId)).OrderBy(x => double.Parse(x.Number),+ _chapterSortComparer);++ var feed = CreateFeed(series.Name + " - Volume " + volume.Name + " - Chapters ", $"{apiKey}/series/{seriesId}/volume/{volumeId}", apiKey);+ SetFeedId(feed, $"series-{series.Id}-volume-{volume.Id}-chapters");+ foreach (var chapter in chapters){- return new FeedEntry()+ feed.Entries.Add(new FeedEntry(){- Id = seriesDto.Id.ToString(),- Title = $"{seriesDto.Name} ({seriesDto.Format})",- Summary = seriesDto.Summary,+ Id = chapter.Id.ToString(),+ Title = "Chapter " + chapter.Number,Links = new List<FeedLink>(){- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/series/{seriesDto.Id}"),- CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/series-cover?seriesId={seriesDto.Id}"),- CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"/api/image/series-cover?seriesId={seriesDto.Id}")+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapter.Id}"),+ CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/chapter-cover?chapterId={chapter.Id}")}- };+ });}- private static FeedEntry CreateSeries(SearchResultDto searchResultDto, string apiKey)+ return CreateXmlResult(SerializeXml(feed));+ }++ [HttpGet("{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapterId}")]+ [Produces("application/xml")]+ public async Task<IActionResult> GetChapter(string apiKey, int seriesId, int volumeId, int chapterId)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var userId = await GetUser(apiKey);+ var series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);+ var volume = await _unitOfWork.VolumeRepository.GetVolumeAsync(volumeId);+ var chapter = await _unitOfWork.ChapterRepository.GetChapterDtoAsync(chapterId);+ var files = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId);++ var feed = CreateFeed(series.Name + " - Volume " + volume.Name + " - Chapters ", $"{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapterId}", apiKey);+ SetFeedId(feed, $"series-{series.Id}-volume-{volume.Id}-chapter-{chapter.Id}-files");+ foreach (var mangaFile in files){- return new FeedEntry()- {- Id = searchResultDto.SeriesId.ToString(),- Title = $"{searchResultDto.Name} ({searchResultDto.Format})",- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/series/{searchResultDto.SeriesId}"),- CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/series-cover?seriesId={searchResultDto.SeriesId}"),- CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"/api/image/series-cover?seriesId={searchResultDto.SeriesId}")- }- };+ feed.Entries.Add(CreateChapter(seriesId, volumeId, chapterId, mangaFile, series, volume, chapter, apiKey));}- private static FeedEntry CreateVolume(VolumeDto volumeDto, int seriesId, string apiKey)+ return CreateXmlResult(SerializeXml(feed));+ }++ /// <summary>+ /// Downloads a file+ /// </summary>+ /// <param name="seriesId"></param>+ /// <param name="volumeId"></param>+ /// <param name="chapterId"></param>+ /// <param name="filename">Not used. Only for Chunky to allow download links</param>+ /// <returns></returns>+ [HttpGet("{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapterId}/download/{filename}")]+ public async Task<ActionResult> DownloadFile(string apiKey, int seriesId, int volumeId, int chapterId, string filename)+ {+ if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)+ return BadRequest("OPDS is not enabled on this server");+ var files = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId);+ var (bytes, contentType, fileDownloadName) = await _downloadService.GetFirstFileDownload(files);+ return File(bytes, contentType, fileDownloadName);+ }++ private static ContentResult CreateXmlResult(string xml)+ {+ return new ContentResult{- return new FeedEntry()- {- Id = volumeDto.Id.ToString(),- Title = "Volume " + volumeDto.Name,- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/series/{seriesId}/volume/{volumeDto.Id}"),- CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/volume-cover?volumeId={volumeDto.Id}"),- CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"/api/image/volume-cover?volumeId={volumeDto.Id}")- }- };+ ContentType = "application/xml",+ Content = xml,+ StatusCode = 200+ };+ }++ private static void AddPagination(Feed feed, PagedList<SeriesDto> list, string href)+ {+ var url = href;+ if (href.Contains("?"))+ {+ url += "&";+ }+ else+ {+ url += "?";}- private FeedEntry CreateChapter(int seriesId, int volumeId, int chapterId, MangaFile mangaFile, SeriesDto series, Volume volume, ChapterDto chapter, string apiKey)+ var pageNumber = Math.Max(list.CurrentPage, 1);++ if (pageNumber > 1){- var fileSize =- DirectoryService.GetHumanReadableBytes(DirectoryService.GetTotalSize(new List<string>()- {mangaFile.FilePath}));- var fileType = _downloadService.GetContentTypeFromFile(mangaFile.FilePath);- var filename = Uri.EscapeUriString(Path.GetFileName(mangaFile.FilePath) ?? string.Empty);- return new FeedEntry()- {- Id = mangaFile.Id.ToString(),- Title = $"{series.Name} - Volume {volume.Name} - Chapter {chapter.Number}",- Extent = fileSize,- Summary = $"{fileType.Split("/")[1]} - {fileSize}",- Format = mangaFile.Format.ToString(),- Links = new List<FeedLink>()- {- CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/chapter-cover?chapterId={chapterId}"),- CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"/api/image/chapter-cover?chapterId={chapterId}"),- // Chunky requires a file at the end. Our API ignores this- CreateLink(FeedLinkRelation.Acquisition, fileType, $"{Prefix}{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapterId}/download/{filename}"),- CreatePageStreamLink(seriesId, volumeId, chapterId, mangaFile, apiKey)- },- Content = new FeedEntryContent()- {- Text = fileType,- Type = "text"- }- };+ feed.Links.Add(CreateLink(FeedLinkRelation.Prev, FeedLinkType.AtomNavigation, url + "pageNumber=" + (pageNumber - 1)));}- [HttpGet("{apiKey}/image")]- public async Task<ActionResult> GetPageStreamedImage(string apiKey, [FromQuery] int seriesId, [FromQuery] int volumeId,[FromQuery] int chapterId, [FromQuery] int pageNumber)+ if (pageNumber + 1 <= list.TotalPages){- if (pageNumber < 0) return BadRequest("Page cannot be less than 0");- var chapter = await _cacheService.Ensure(chapterId);- if (chapter == null) return BadRequest("There was an issue finding image file for reading");+ feed.Links.Add(CreateLink(FeedLinkRelation.Next, FeedLinkType.AtomNavigation, url + "pageNumber=" + (pageNumber + 1)));+ }- try- {- var (path, _) = await _cacheService.GetCachedPagePath(chapter, pageNumber);- if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No such image for page {pageNumber}");+ // Update self to point to current page+ var selfLink = feed.Links.SingleOrDefault(l => l.Rel == FeedLinkRelation.Self);+ if (selfLink != null)+ {+ selfLink.Href = url + "pageNumber=" + pageNumber;+ }- var content = await _directoryService.ReadFileAsync(path);- var format = Path.GetExtension(path).Replace(".", "");- // Calculates SHA1 Hash for byte[]- Response.AddCacheHeader(content);+ feed.Total = list.TotalCount;+ feed.ItemsPerPage = list.PageSize;+ feed.StartIndex = (Math.Max(list.CurrentPage - 1, 0) * list.PageSize) + 1;+ }- // Save progress for the user- await _readerService.SaveReadingProgress(new ProgressDto()- {- ChapterId = chapterId,- PageNum = pageNumber,- SeriesId = seriesId,- VolumeId = volumeId- }, await GetUser(apiKey));+ private static FeedEntry CreateSeries(SeriesDto seriesDto, string apiKey)+ {+ return new FeedEntry()+ {+ Id = seriesDto.Id.ToString(),+ Title = $"{seriesDto.Name} ({seriesDto.Format})",+ Summary = seriesDto.Summary,+ Links = new List<FeedLink>()+ {+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/series/{seriesDto.Id}"),+ CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/series-cover?seriesId={seriesDto.Id}"),+ CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"/api/image/series-cover?seriesId={seriesDto.Id}")+ }+ };+ }- return File(content, "image/" + format);+ private static FeedEntry CreateSeries(SearchResultDto searchResultDto, string apiKey)+ {+ return new FeedEntry()+ {+ Id = searchResultDto.SeriesId.ToString(),+ Title = $"{searchResultDto.Name} ({searchResultDto.Format})",+ Links = new List<FeedLink>()+ {+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/series/{searchResultDto.SeriesId}"),+ CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/series-cover?seriesId={searchResultDto.SeriesId}"),+ CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"/api/image/series-cover?seriesId={searchResultDto.SeriesId}")}- catch (Exception)+ };+ }++ private static FeedEntry CreateVolume(VolumeDto volumeDto, int seriesId, string apiKey)+ {+ return new FeedEntry()+ {+ Id = volumeDto.Id.ToString(),+ Title = "Volume " + volumeDto.Name,+ Links = new List<FeedLink>(){- _cacheService.CleanupChapters(new []{ chapterId });- throw;+ CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, Prefix + $"{apiKey}/series/{seriesId}/volume/{volumeDto.Id}"),+ CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/volume-cover?volumeId={volumeDto.Id}"),+ CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"/api/image/volume-cover?volumeId={volumeDto.Id}")}- }+ };+ }- [HttpGet("{apiKey}/favicon")]- public async Task<ActionResult> GetFavicon(string apiKey)+ private FeedEntry CreateChapter(int seriesId, int volumeId, int chapterId, MangaFile mangaFile, SeriesDto series, Volume volume, ChapterDto chapter, string apiKey)+ {+ var fileSize =+ DirectoryService.GetHumanReadableBytes(_directoryService.GetTotalSize(new List<string>()+ {mangaFile.FilePath}));+ var fileType = _downloadService.GetContentTypeFromFile(mangaFile.FilePath);+ var filename = Uri.EscapeDataString(Path.GetFileName(mangaFile.FilePath) ?? string.Empty);+ return new FeedEntry(){- var files = DirectoryService.GetFilesWithExtension(Path.Join(Directory.GetCurrentDirectory(), ".."), @"\.ico");- if (files.Length == 0) return BadRequest("Cannot find icon");- var path = files[0];+ Id = mangaFile.Id.ToString(),+ Title = $"{series.Name} - Volume {volume.Name} - Chapter {chapter.Number}",+ Extent = fileSize,+ Summary = $"{fileType.Split("/")[1]} - {fileSize}",+ Format = mangaFile.Format.ToString(),+ Links = new List<FeedLink>()+ {+ CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/chapter-cover?chapterId={chapterId}"),+ CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"/api/image/chapter-cover?chapterId={chapterId}"),+ // Chunky requires a file at the end. Our API ignores this+ CreateLink(FeedLinkRelation.Acquisition, fileType, $"{Prefix}{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapterId}/download/{filename}"),+ CreatePageStreamLink(seriesId, volumeId, chapterId, mangaFile, apiKey)+ },+ Content = new FeedEntryContent()+ {+ Text = fileType,+ Type = "text"+ }+ };+ }++ [HttpGet("{apiKey}/image")]+ public async Task<ActionResult> GetPageStreamedImage(string apiKey, [FromQuery] int seriesId, [FromQuery] int volumeId,[FromQuery] int chapterId, [FromQuery] int pageNumber)+ {+ if (pageNumber < 0) return BadRequest("Page cannot be less than 0");+ var chapter = await _cacheService.Ensure(chapterId);+ if (chapter == null) return BadRequest("There was an issue finding image file for reading");++ try+ {+ var path = _cacheService.GetCachedPagePath(chapter, pageNumber);+ if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No such image for page {pageNumber}");+var content = await _directoryService.ReadFileAsync(path);var format = Path.GetExtension(path).Replace(".", "");// Calculates SHA1 Hash for byte[]Response.AddCacheHeader(content);+ // Save progress for the user+ await _readerService.SaveReadingProgress(new ProgressDto()+ {+ ChapterId = chapterId,+ PageNum = pageNumber,+ SeriesId = seriesId,+ VolumeId = volumeId+ }, await GetUser(apiKey));+return File(content, "image/" + format);}-- /// <summary>- /// Gets the user from the API key- /// </summary>- /// <returns></returns>- private async Task<int> GetUser(string apiKey)+ catch (Exception){- try- {- var user = await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey);- return user;- }- catch- {- /* Do nothing */- }- throw new KavitaException("User does not exist");+ _cacheService.CleanupChapters(new []{ chapterId });+ throw;}+ }++ [HttpGet("{apiKey}/favicon")]+ public async Task<ActionResult> GetFavicon(string apiKey)+ {+ var files = _directoryService.GetFilesWithExtension(Path.Join(Directory.GetCurrentDirectory(), ".."), @"\.ico");+ if (files.Length == 0) return BadRequest("Cannot find icon");+ var path = files[0];+ var content = await _directoryService.ReadFileAsync(path);+ var format = Path.GetExtension(path).Replace(".", "");++ // Calculates SHA1 Hash for byte[]+ Response.AddCacheHeader(content);- private static FeedLink CreatePageStreamLink(int seriesId, int volumeId, int chapterId, MangaFile mangaFile, string apiKey)+ return File(content, "image/" + format);+ }++ /// <summary>+ /// Gets the user from the API key+ /// </summary>+ /// <returns></returns>+ private async Task<int> GetUser(string apiKey)+ {+ try{- var link = CreateLink(FeedLinkRelation.Stream, "image/jpeg", $"{Prefix}{apiKey}/image?seriesId={seriesId}&volumeId={volumeId}&chapterId={chapterId}&pageNumber=" + "{pageNumber}");- link.TotalPages = mangaFile.Pages;- return link;+ var user = await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey);+ return user;}-- private static FeedLink CreateLink(string rel, string type, string href)+ catch{- return new FeedLink()- {- Rel = rel,- Href = href,- Type = type- };+ /* Do nothing */}+ throw new KavitaException("User does not exist");+ }++ private static FeedLink CreatePageStreamLink(int seriesId, int volumeId, int chapterId, MangaFile mangaFile, string apiKey)+ {+ var link = CreateLink(FeedLinkRelation.Stream, "image/jpeg", $"{Prefix}{apiKey}/image?seriesId={seriesId}&volumeId={volumeId}&chapterId={chapterId}&pageNumber=" + "{pageNumber}");+ link.TotalPages = mangaFile.Pages;+ return link;+ }- private static Feed CreateFeed(string title, string href, string apiKey)+ private static FeedLink CreateLink(string rel, string type, string href)+ {+ return new FeedLink(){- var link = CreateLink(FeedLinkRelation.Self, string.IsNullOrEmpty(href) ?- FeedLinkType.AtomNavigation :- FeedLinkType.AtomAcquisition, Prefix + href);+ Rel = rel,+ Href = href,+ Type = type+ };+ }- return new Feed()- {- Title = title,- Icon = Prefix + $"{apiKey}/favicon",- Links = new List<FeedLink>()- {- link,- CreateLink(FeedLinkRelation.Start, FeedLinkType.AtomNavigation, Prefix + apiKey),- CreateLink(FeedLinkRelation.Search, FeedLinkType.AtomSearch, Prefix + $"{apiKey}/search")- },- };- }+ private static Feed CreateFeed(string title, string href, string apiKey)+ {+ var link = CreateLink(FeedLinkRelation.Self, string.IsNullOrEmpty(href) ?+ FeedLinkType.AtomNavigation :+ FeedLinkType.AtomAcquisition, Prefix + href);- private string SerializeXml(Feed feed)+ return new Feed(){- if (feed == null) return string.Empty;- using var sm = new StringWriter();- _xmlSerializer.Serialize(sm, feed);- return sm.ToString().Replace("utf-16", "utf-8"); // Chunky cannot accept UTF-16 feeds- }+ Title = title,+ Icon = Prefix + $"{apiKey}/favicon",+ Links = new List<FeedLink>()+ {+ link,+ CreateLink(FeedLinkRelation.Start, FeedLinkType.AtomNavigation, Prefix + apiKey),+ CreateLink(FeedLinkRelation.Search, FeedLinkType.AtomSearch, Prefix + $"{apiKey}/search")+ },+ };+ }++ private string SerializeXml(Feed feed)+ {+ if (feed == null) return string.Empty;+ using var sm = new StringWriter();+ _xmlSerializer.Serialize(sm, feed);+ return sm.ToString().Replace("utf-16", "utf-8"); // Chunky cannot accept UTF-16 feeds}}diff --git a/API/Controllers/PluginController.cs b/API/Controllers/PluginController.csindex b176c0628..5f2d99ba3 100644--- a/API/Controllers/PluginController.cs+++ b/API/Controllers/PluginController.cs@@ -1,7 +1,7 @@using System.Threading.Tasks;+using API.Data;using API.DTOs;-using API.Interfaces;-using API.Interfaces.Services;+using API.Services;using Microsoft.AspNetCore.Mvc;using Microsoft.Extensions.Logging;diff --git a/API/Controllers/ReaderController.cs b/API/Controllers/ReaderController.csindex 5b18cfb98..3028d1fee 100644--- a/API/Controllers/ReaderController.cs+++ b/API/Controllers/ReaderController.cs@@ -3,13 +3,15 @@ using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading.Tasks;+using API.Data;using API.Data.Repositories;using API.DTOs;using API.DTOs.Reader;using API.Entities;+using API.Entities.Enums;using API.Extensions;-using API.Interfaces;-using API.Interfaces.Services;+using API.Services;+using API.Services.Tasks;using Microsoft.AspNetCore.Mvc;using Microsoft.Extensions.Logging;@@ -24,15 +26,21 @@ namespace API.Controllersprivate readonly IUnitOfWork _unitOfWork;private readonly ILogger<ReaderController> _logger;private readonly IReaderService _readerService;+ private readonly IDirectoryService _directoryService;+ private readonly ICleanupService _cleanupService;/// <inheritdoc />public ReaderController(ICacheService cacheService,- IUnitOfWork unitOfWork, ILogger<ReaderController> logger, IReaderService readerService)+ IUnitOfWork unitOfWork, ILogger<ReaderController> logger,+ IReaderService readerService, IDirectoryService directoryService,+ ICleanupService cleanupService){_cacheService = cacheService;_unitOfWork = unitOfWork;_logger = logger;_readerService = readerService;+ _directoryService = directoryService;+ _cleanupService = cleanupService;}/// <summary>@@ -50,7 +58,7 @@ namespace API.Controllerstry{- var (path, _) = await _cacheService.GetCachedPagePath(chapter, page);+ var path = _cacheService.GetCachedPagePath(chapter, page);if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No such image for page {page}");var format = Path.GetExtension(path).Replace(".", "");@@ -75,6 +83,7 @@ namespace API.Controllersif (chapter == null) return BadRequest("Could not find Chapter");var dto = await _unitOfWork.ChapterRepository.GetChapterInfoDtoAsync(chapterId);+ if (dto == null) return BadRequest("Please perform a scan on this series or library and try again");var mangaFile = (await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId)).First();return Ok(new ChapterInfoDto()@@ -89,6 +98,7 @@ namespace API.ControllersLibraryId = dto.LibraryId,IsSpecial = dto.IsSpecial,Pages = dto.Pages,+ ChapterTitle = dto.ChapterTitle ?? string.Empty});}@@ -129,15 +139,7 @@ namespace API.Controllersuser.Progresses ??= new List<AppUserProgress>();foreach (var volume in volumes){- foreach (var chapter in volume.Chapters)- {- var userProgress = ReaderService.GetUserProgressForChapter(user, chapter);-- if (userProgress == null) continue;- userProgress.PagesRead = 0;- userProgress.SeriesId = markReadDto.SeriesId;- userProgress.VolumeId = volume.Id;- }+ _readerService.MarkChaptersAsUnread(user, markReadDto.SeriesId, volume.Chapters);}_unitOfWork.UserRepository.Update(user);@@ -396,6 +398,14 @@ namespace API.Controllersif (await _unitOfWork.CommitAsync()){+ try+ {+ await _cleanupService.CleanupBookmarks();+ }+ catch (Exception ex)+ {+ _logger.LogError(ex, "There was an issue cleaning up old bookmarks");+ }return Ok();}}@@ -453,6 +463,18 @@ namespace API.Controllersvar userBookmark =await _unitOfWork.UserRepository.GetBookmarkForPage(bookmarkDto.Page, bookmarkDto.ChapterId, user.Id);+ // We need to get the image+ var chapter = await _cacheService.Ensure(bookmarkDto.ChapterId);+ if (chapter == null) return BadRequest("There was an issue finding image file for reading");+ var path = _cacheService.GetCachedPagePath(chapter, bookmarkDto.Page);+ var fileInfo = new FileInfo(path);++ var bookmarkDirectory =+ (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BookmarkDirectory)).Value;+ _directoryService.CopyFileToDirectory(path, Path.Join(bookmarkDirectory,+ $"{user.Id}", $"{bookmarkDto.SeriesId}", $"{bookmarkDto.ChapterId}"));++if (userBookmark == null){user.Bookmarks ??= new List<AppUserBookmark>();@@ -462,22 +484,21 @@ namespace API.ControllersVolumeId = bookmarkDto.VolumeId,SeriesId = bookmarkDto.SeriesId,ChapterId = bookmarkDto.ChapterId,+ FileName = Path.Join($"{user.Id}", $"{bookmarkDto.SeriesId}", $"{bookmarkDto.ChapterId}", fileInfo.Name)+});_unitOfWork.UserRepository.Update(user);}-- if (await _unitOfWork.CommitAsync())- {- return Ok();- }+ await _unitOfWork.CommitAsync();}catch (Exception){await _unitOfWork.RollbackAsync();+ return BadRequest("Could not save bookmark");}- return BadRequest("Could not save bookmark");+ return Ok();}/// <summary>diff --git a/API/Controllers/ReadingListController.cs b/API/Controllers/ReadingListController.csindex 19e4a4b49..9391105cb 100644--- a/API/Controllers/ReadingListController.cs+++ b/API/Controllers/ReadingListController.cs@@ -1,13 +1,12 @@-using System;-using System.Collections.Generic;+using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using API.Comparators;+using API.Data;using API.DTOs.ReadingLists;using API.Entities;using API.Extensions;using API.Helpers;-using API.Interfaces;using Microsoft.AspNetCore.Mvc;namespace API.Controllersdiff --git a/API/Controllers/SeriesController.cs b/API/Controllers/SeriesController.csindex ba0571ec3..ad2faeb0f 100644--- a/API/Controllers/SeriesController.cs+++ b/API/Controllers/SeriesController.cs@@ -3,15 +3,18 @@ using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using API.Data;+using API.Data.Metadata;using API.Data.Repositories;using API.DTOs;using API.DTOs.Filtering;using API.Entities;+using API.Entities.Enums;using API.Extensions;using API.Helpers;-using API.Interfaces;+using API.Services;using API.SignalR;using Kavita.Common;+using Kavita.Common.Extensions;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.SignalR;@@ -80,6 +83,8 @@ namespace API.Controllersvar username = User.GetUsername();_logger.LogInformation("Series {SeriesId} is being deleted by {UserName}", seriesId, username);+ var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId);+var chapterIds = (await _unitOfWork.SeriesRepository.GetChapterIdsForSeriesAsync(new []{seriesId}));var result = await _unitOfWork.SeriesRepository.DeleteSeriesAsync(seriesId);@@ -89,6 +94,8 @@ namespace API.Controllersawait _unitOfWork.CollectionTagRepository.RemoveTagsWithoutSeries();await _unitOfWork.CommitAsync();_taskScheduler.CleanupChapters(chapterIds);+ await _messageHub.Clients.All.SendAsync(SignalREvents.SeriesRemoved,+ MessageFactory.SeriesRemovedEvent(seriesId, series.Name, series.LibraryId));}return Ok(result);}@@ -151,7 +158,7 @@ namespace API.Controllerspublic async Task<ActionResult> UpdateSeriesRating(UpdateSeriesRatingDto updateSeriesRatingDto){var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Ratings);- var userRating = await _unitOfWork.UserRepository.GetUserRating(updateSeriesRatingDto.SeriesId, user.Id) ??+ var userRating = await _unitOfWork.UserRepository.GetUserRatingAsync(updateSeriesRatingDto.SeriesId, user.Id) ??new AppUserRating();userRating.Rating = updateSeriesRatingDto.UserRating;@@ -187,7 +194,7 @@ namespace API.Controllersseries.Name = updateSeries.Name.Trim();series.LocalizedName = updateSeries.LocalizedName.Trim();series.SortName = updateSeries.SortName?.Trim();- series.Summary = updateSeries.Summary?.Trim();+ series.Metadata.Summary = updateSeries.Summary?.Trim();var needsRefreshMetadata = false;// This is when you hit Reset@@ -230,6 +237,23 @@ namespace API.Controllersreturn Ok(series);}+ [HttpPost("all")]+ public async Task<ActionResult<IEnumerable<SeriesDto>>> GetAllSeries(FilterDto filterDto, [FromQuery] UserParams userParams, [FromQuery] int libraryId = 0)+ {+ var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());+ var series =+ await _unitOfWork.SeriesRepository.GetSeriesDtoForLibraryIdAsync(libraryId, userId, userParams, filterDto);++ // Apply progress/rating information (I can't work out how to do this in initial query)+ if (series == null) return BadRequest("Could not get series");++ await _unitOfWork.SeriesRepository.AddSeriesModifiers(userId, series);++ Response.AddPaginationHeader(series.CurrentPage, series.PageSize, series.TotalCount, series.TotalPages);++ return Ok(series);+ }+/// <summary>/// Fetches series that are on deck aka have progress on them./// </summary>@@ -294,6 +318,7 @@ namespace API.Controllerselse{series.Metadata.CollectionTags ??= new List<CollectionTag>();+ // TODO: Move this merging logic into a reusable code as it can be used for any Tagvar newTags = new List<CollectionTag>();// I want a union of these 2 lists. Return only elements that are in both lists, but the list types are different@@ -313,7 +338,7 @@ namespace API.Controllersvar existingTag = allTags.SingleOrDefault(t => t.Title == tag.Title);if (existingTag != null){- if (!series.Metadata.CollectionTags.Any(t => t.Title == tag.Title))+ if (series.Metadata.CollectionTags.All(t => t.Title != tag.Title)){newTags.Add(existingTag);}@@ -392,6 +417,12 @@ namespace API.Controllersreturn Ok(await _unitOfWork.SeriesRepository.GetSeriesDtoForIdsAsync(dto.SeriesIds, userId));}+ [HttpGet("age-rating")]+ public ActionResult<string> GetAgeRating(int ageRating)+ {+ var val = (AgeRating) ageRating;+ return Ok(val.ToDescription());+ }}}diff --git a/API/Controllers/ServerController.cs b/API/Controllers/ServerController.csindex 04ffa3428..45fb22ce5 100644--- a/API/Controllers/ServerController.cs+++ b/API/Controllers/ServerController.cs@@ -5,7 +5,7 @@ using System.Threading.Tasks;using API.DTOs.Stats;using API.DTOs.Update;using API.Extensions;-using API.Interfaces.Services;+using API.Services;using API.Services.Tasks;using Kavita.Common;using Microsoft.AspNetCore.Authorization;@@ -27,10 +27,11 @@ namespace API.Controllersprivate readonly ICacheService _cacheService;private readonly IVersionUpdaterService _versionUpdaterService;private readonly IStatsService _statsService;+ private readonly ICleanupService _cleanupService;public ServerController(IHostApplicationLifetime applicationLifetime, ILogger<ServerController> logger, IConfiguration config,IBackupService backupService, IArchiveService archiveService, ICacheService cacheService,- IVersionUpdaterService versionUpdaterService, IStatsService statsService)+ IVersionUpdaterService versionUpdaterService, IStatsService statsService, ICleanupService cleanupService){_applicationLifetime = applicationLifetime;_logger = logger;@@ -40,6 +41,7 @@ namespace API.Controllers_cacheService = cacheService;_versionUpdaterService = versionUpdaterService;_statsService = statsService;+ _cleanupService = cleanupService;}/// <summary>@@ -63,7 +65,7 @@ namespace API.Controllerspublic ActionResult ClearCache(){_logger.LogInformation("{UserName} is clearing cache of server from admin dashboard", User.GetUsername());- _cacheService.Cleanup();+ _cleanupService.CleanupCacheDirectory();return Ok();}@@ -94,7 +96,7 @@ namespace API.Controllers[HttpGet("logs")]public async Task<ActionResult> GetLogs(){- var files = _backupService.LogFiles(_config.GetMaxRollingFiles(), _config.GetLoggingFileName());+ var files = _backupService.GetLogFiles(_config.GetMaxRollingFiles(), _config.GetLoggingFileName());try{var (fileBytes, zipPath) = await _archiveService.CreateZipForDownload(files, "logs");diff --git a/API/Controllers/SettingsController.cs b/API/Controllers/SettingsController.csindex c8b3248ba..76b30acf8 100644--- a/API/Controllers/SettingsController.cs+++ b/API/Controllers/SettingsController.cs@@ -3,13 +3,13 @@ using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading.Tasks;+using API.Data;using API.DTOs.Settings;using API.Entities.Enums;using API.Extensions;using API.Helpers.Converters;-using API.Interfaces;-using API.Interfaces.Services;using API.Services;+using AutoMapper;using Kavita.Common;using Kavita.Common.Extensions;using Microsoft.AspNetCore.Authorization;@@ -24,13 +24,18 @@ namespace API.Controllersprivate readonly IUnitOfWork _unitOfWork;private readonly ITaskScheduler _taskScheduler;private readonly IAccountService _accountService;+ private readonly IDirectoryService _directoryService;+ private readonly IMapper _mapper;- public SettingsController(ILogger<SettingsController> logger, IUnitOfWork unitOfWork, ITaskScheduler taskScheduler, IAccountService accountService)+ public SettingsController(ILogger<SettingsController> logger, IUnitOfWork unitOfWork, ITaskScheduler taskScheduler,+ IAccountService accountService, IDirectoryService directoryService, IMapper mapper){_logger = logger;_unitOfWork = unitOfWork;_taskScheduler = taskScheduler;_accountService = accountService;+ _directoryService = directoryService;+ _mapper = mapper;}[AllowAnonymous]@@ -46,11 +51,21 @@ namespace API.Controllerspublic async Task<ActionResult<ServerSettingDto>> GetSettings(){var settingsDto = await _unitOfWork.SettingsRepository.GetSettingsDtoAsync();+ // TODO: Is this needed as it gets updated in the DB on startupsettingsDto.Port = Configuration.Port;settingsDto.LoggingLevel = Configuration.LogLevel;return Ok(settingsDto);}+ [Authorize(Policy = "RequireAdminRole")]+ [HttpPost("reset")]+ public async Task<ActionResult<ServerSettingDto>> ResetSettings()+ {+ _logger.LogInformation("{UserName} is resetting Server Settings", User.GetUsername());++ return await UpdateSettings(_mapper.Map<ServerSettingDto>(Seed.DefaultSettings));+ }+[Authorize(Policy = "RequireAdminRole")][HttpPost]public async Task<ActionResult<ServerSettingDto>> UpdateSettings(ServerSettingDto updateSettingsDto)@@ -70,6 +85,20 @@ namespace API.Controllers// We do not allow CacheDirectory changes, so we will ignore.var currentSettings = await _unitOfWork.SettingsRepository.GetSettingsAsync();var updateAuthentication = false;+ var updateBookmarks = false;+ var originalBookmarkDirectory = _directoryService.BookmarkDirectory;++ var bookmarkDirectory = updateSettingsDto.BookmarksDirectory;+ if (!updateSettingsDto.BookmarksDirectory.EndsWith("bookmarks") &&+ !updateSettingsDto.BookmarksDirectory.EndsWith("bookmarks/"))+ {+ bookmarkDirectory = _directoryService.FileSystem.Path.Join(updateSettingsDto.BookmarksDirectory, "bookmarks");+ }++ if (string.IsNullOrEmpty(updateSettingsDto.BookmarksDirectory))+ {+ bookmarkDirectory = _directoryService.BookmarkDirectory;+ }foreach (var setting in currentSettings){@@ -118,6 +147,22 @@ namespace API.Controllers_unitOfWork.SettingsRepository.Update(setting);}+ if (setting.Key == ServerSettingKey.BookmarkDirectory && bookmarkDirectory != setting.Value)+ {+ // Validate new directory can be used+ if (!await _directoryService.CheckWriteAccess(bookmarkDirectory))+ {+ return BadRequest("Bookmark Directory does not have correct permissions for Kavita to use");+ }++ originalBookmarkDirectory = setting.Value;+ // Normalize the path deliminators. Just to look nice in DB, no functionality+ setting.Value = _directoryService.FileSystem.Path.GetFullPath(bookmarkDirectory);+ _unitOfWork.SettingsRepository.Update(setting);+ updateBookmarks = true;++ }+if (setting.Key == ServerSettingKey.EnableAuthentication && updateSettingsDto.EnableAuthentication + string.Empty != setting.Value){setting.Value = updateSettingsDto.EnableAuthentication + string.Empty;@@ -160,6 +205,13 @@ namespace API.Controllers_logger.LogInformation("Server authentication changed. Updated all non-admins to default password");}++ if (updateBookmarks)+ {+ _directoryService.ExistOrCreate(bookmarkDirectory);+ _directoryService.CopyDirectoryToDirectory(originalBookmarkDirectory, bookmarkDirectory);+ _directoryService.ClearAndDeleteDirectory(originalBookmarkDirectory);+ }}catch (Exception ex){@@ -170,7 +222,7 @@ namespace API.Controllers_logger.LogInformation("Server Settings updated");- _taskScheduler.ScheduleTasks();+ await _taskScheduler.ScheduleTasks();return Ok(updateSettingsDto);}diff --git a/API/Controllers/UploadController.cs b/API/Controllers/UploadController.csindex 43c9b8d09..b383021e2 100644--- a/API/Controllers/UploadController.cs+++ b/API/Controllers/UploadController.cs@@ -1,8 +1,7 @@using System;using System.Threading.Tasks;+using API.Data;using API.DTOs.Uploads;-using API.Interfaces;-using API.Interfaces.Services;using API.Services;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;diff --git a/API/Controllers/UsersController.cs b/API/Controllers/UsersController.csindex f5171b819..7662fdf95 100644--- a/API/Controllers/UsersController.cs+++ b/API/Controllers/UsersController.cs@@ -1,10 +1,10 @@using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;+using API.Data;using API.Data.Repositories;using API.DTOs;using API.Extensions;-using API.Interfaces;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;diff --git a/API/DTOs/ChapterDto.cs b/API/DTOs/ChapterDto.csindex 8c791a395..6a4effe16 100644--- a/API/DTOs/ChapterDto.cs+++ b/API/DTOs/ChapterDto.cs@@ -1,5 +1,7 @@using System;using System.Collections.Generic;+using API.DTOs.Metadata;+using API.Entities;namespace API.DTOs{@@ -50,5 +52,41 @@ namespace API.DTOs/// When chapter was created/// </summary>public DateTime Created { get; init; }+ /// <summary>+ /// When the chapter was released.+ /// </summary>+ /// <remarks>Metadata field</remarks>+ public DateTime ReleaseDate { get; init; }+ /// <summary>+ /// Title of the Chapter/Issue+ /// </summary>+ /// <remarks>Metadata field</remarks>+ public string TitleName { get; set; }+ /// <summary>+ /// Summary for the Chapter/Issue+ /// </summary>+ public string Summary { get; set; }+ /// <summary>+ /// Language for the Chapter/Issue+ /// </summary>+ public string Language { get; set; }+ /// <summary>+ /// Number in the TotalCount of issues+ /// </summary>+ public int Count { get; set; }+ /// <summary>+ /// Total number of issues for the series+ /// </summary>+ public int TotalCount { get; set; }+ public ICollection<PersonDto> Writers { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Penciller { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Inker { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Colorist { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Letterer { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> CoverArtist { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Editor { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Publisher { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Translators { get; set; } = new List<PersonDto>();+ public ICollection<TagDto> Tags { get; set; } = new List<TagDto>();}}diff --git a/API/DTOs/Filtering/FilterDto.cs b/API/DTOs/Filtering/FilterDto.csindex c5956f17d..863e66e6e 100644--- a/API/DTOs/Filtering/FilterDto.cs+++ b/API/DTOs/Filtering/FilterDto.cs@@ -1,13 +1,98 @@-using API.Entities.Enums;+using System.Collections.Generic;+using API.Entities;+using API.Entities.Enums;namespace API.DTOs.Filtering{public class FilterDto{/// <summary>- /// Pass null if you want all formats+ /// The type of Formats you want to be returned. An empty list will return all formats back/// </summary>- public MangaFormat? MangaFormat { get; init; } = null;+ public IList<MangaFormat> Formats { get; init; } = new List<MangaFormat>();++ /// <summary>+ /// The progress you want to be returned. This can be bitwise manipulated. Defaults to all applicable states.+ /// </summary>+ public ReadStatus ReadStatus { get; init; } = new ReadStatus();++ /// <summary>+ /// A list of library ids to restrict search to. Defaults to all libraries by passing empty list+ /// </summary>+ public IList<int> Libraries { get; init; } = new List<int>();+ /// <summary>+ /// A list of Genre ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Genres { get; init; } = new List<int>();+ /// <summary>+ /// A list of Writers to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Writers { get; init; } = new List<int>();+ /// <summary>+ /// A list of Penciller ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Penciller { get; init; } = new List<int>();+ /// <summary>+ /// A list of Inker ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Inker { get; init; } = new List<int>();+ /// <summary>+ /// A list of Colorist ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Colorist { get; init; } = new List<int>();+ /// <summary>+ /// A list of Letterer ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Letterer { get; init; } = new List<int>();+ /// <summary>+ /// A list of CoverArtist ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> CoverArtist { get; init; } = new List<int>();+ /// <summary>+ /// A list of Editor ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Editor { get; init; } = new List<int>();+ /// <summary>+ /// A list of Publisher ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Publisher { get; init; } = new List<int>();+ /// <summary>+ /// A list of Character ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Character { get; init; } = new List<int>();+ /// <summary>+ /// A list of Translator ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Translators { get; init; } = new List<int>();+ /// <summary>+ /// A list of Collection Tag ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> CollectionTags { get; init; } = new List<int>();+ /// <summary>+ /// A list of Tag ids to restrict search to. Defaults to all genres by passing an empty list+ /// </summary>+ public IList<int> Tags { get; init; } = new List<int>();+ /// <summary>+ /// Will return back everything with the rating and above+ /// <see cref="AppUserRating.Rating"/>+ /// </summary>+ public int Rating { get; init; }+ /// <summary>+ /// Sorting Options for a query. Defaults to null, which uses the queries natural sorting order+ /// </summary>+ public SortOptions SortOptions { get; init; } = null;+ /// <summary>+ /// Age Ratings. Empty list will return everything back+ /// </summary>+ public IList<AgeRating> AgeRating { get; init; } = new List<AgeRating>();+ /// <summary>+ /// Languages (ISO 639-1 code) to filter by. Empty list will return everything back+ /// </summary>+ public IList<string> Languages { get; init; } = new List<string>();+ /// <summary>+ /// Publication statuses to filter by. Empty list will return everything back+ /// </summary>+ public IList<PublicationStatus> PublicationStatus { get; init; } = new List<PublicationStatus>();}}diff --git a/API/DTOs/Filtering/LanguageDto.cs b/API/DTOs/Filtering/LanguageDto.csnew file mode 100644index 000000000..b09aed5d1--- /dev/null+++ b/API/DTOs/Filtering/LanguageDto.cs@@ -0,0 +1,7 @@+namespace API.DTOs.Filtering;++public class LanguageDto+{+ public string IsoCode { get; set; }+ public string Title { get; set; }+}diff --git a/API/DTOs/Filtering/ReadStatus.cs b/API/DTOs/Filtering/ReadStatus.csnew file mode 100644index 000000000..e2452fdc1--- /dev/null+++ b/API/DTOs/Filtering/ReadStatus.cs@@ -0,0 +1,13 @@+using System;++namespace API.DTOs.Filtering;++/// <summary>+/// Represents the Reading Status. This is a flag and allows multiple statues+/// </summary>+public class ReadStatus+{+ public bool NotRead { get; set; } = true;+ public bool InProgress { get; set; } = true;+ public bool Read { get; set; } = true;+}diff --git a/API/DTOs/Filtering/SortField.cs b/API/DTOs/Filtering/SortField.csnew file mode 100644index 000000000..0e465f6aa--- /dev/null+++ b/API/DTOs/Filtering/SortField.cs@@ -0,0 +1,8 @@+namespace API.DTOs.Filtering;++public enum SortField+{+ SortName = 1,+ CreatedDate = 2,+ LastModifiedDate = 3,+}diff --git a/API/DTOs/Filtering/SortOptions.cs b/API/DTOs/Filtering/SortOptions.csnew file mode 100644index 000000000..00bf91675--- /dev/null+++ b/API/DTOs/Filtering/SortOptions.cs@@ -0,0 +1,10 @@+namespace API.DTOs.Filtering;++/// <summary>+/// Sorting Options for a query+/// </summary>+public class SortOptions+{+ public SortField SortField { get; set; }+ public bool IsAscending { get; set; } = true;+}diff --git a/API/DTOs/Metadata/AgeRatingDto.cs b/API/DTOs/Metadata/AgeRatingDto.csnew file mode 100644index 000000000..cbeb44e33--- /dev/null+++ b/API/DTOs/Metadata/AgeRatingDto.cs@@ -0,0 +1,9 @@+using API.Entities.Enums;++namespace API.DTOs.Metadata;++public class AgeRatingDto+{+ public AgeRating Value { get; set; }+ public string Title { get; set; }+}diff --git a/API/DTOs/Metadata/ChapterMetadataDto.cs b/API/DTOs/Metadata/ChapterMetadataDto.csnew file mode 100644index 000000000..77b89fe94--- /dev/null+++ b/API/DTOs/Metadata/ChapterMetadataDto.cs@@ -0,0 +1,19 @@+using System.Collections.Generic;++namespace API.DTOs.Metadata+{+ public class ChapterMetadataDto+ {+ public int Id { get; set; }+ public string Title { get; set; }+ public ICollection<PersonDto> Writers { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Penciller { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Inker { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Colorist { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Letterer { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> CoverArtist { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Editor { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Publisher { get; set; } = new List<PersonDto>();+ public int ChapterId { get; set; }+ }+}diff --git a/API/DTOs/Metadata/GenreTagDto.cs b/API/DTOs/Metadata/GenreTagDto.csnew file mode 100644index 000000000..e6ea03130--- /dev/null+++ b/API/DTOs/Metadata/GenreTagDto.cs@@ -0,0 +1,8 @@+namespace API.DTOs.Metadata+{+ public class GenreTagDto+ {+ public int Id { get; set; }+ public string Title { get; set; }+ }+}diff --git a/API/DTOs/Metadata/PublicationStatusDto.cs b/API/DTOs/Metadata/PublicationStatusDto.csnew file mode 100644index 000000000..332223428--- /dev/null+++ b/API/DTOs/Metadata/PublicationStatusDto.cs@@ -0,0 +1,9 @@+using API.Entities.Enums;++namespace API.DTOs.Metadata;++public class PublicationStatusDto+{+ public PublicationStatus Value { get; set; }+ public string Title { get; set; }+}diff --git a/API/DTOs/Metadata/TagDto.cs b/API/DTOs/Metadata/TagDto.csnew file mode 100644index 000000000..6e9b2f71e--- /dev/null+++ b/API/DTOs/Metadata/TagDto.cs@@ -0,0 +1,7 @@+namespace API.DTOs.Metadata;++public class TagDto+{+ public int Id { get; set; }+ public string Title { get; set; }+}diff --git a/API/DTOs/OPDS/Feed.cs b/API/DTOs/OPDS/Feed.csindex 95f08448e..efbffe8ac 100644--- a/API/DTOs/OPDS/Feed.cs+++ b/API/DTOs/OPDS/Feed.cs@@ -23,7 +23,7 @@ namespace API.DTOs.OPDSpublic string Icon { get; set; } = "/favicon.ico";[XmlElement("author")]- public Author Author { get; set; } = new Author()+ public FeedAuthor Author { get; set; } = new FeedAuthor(){Name = "Kavita",Uri = "https://kavitareader.com"diff --git a/API/DTOs/OPDS/Author.cs b/API/DTOs/OPDS/FeedAuthor.cssimilarity index 88%rename from API/DTOs/OPDS/Author.csrename to API/DTOs/OPDS/FeedAuthor.csindex 1758a037e..ec0446d73 100644--- a/API/DTOs/OPDS/Author.cs+++ b/API/DTOs/OPDS/FeedAuthor.cs@@ -2,7 +2,7 @@namespace API.DTOs.OPDS{- public class Author+ public class FeedAuthor{[XmlElement("name")]public string Name { get; set; }diff --git a/API/DTOs/PersonDto.cs b/API/DTOs/PersonDto.csindex 646817c1d..0ab7a4076 100644--- a/API/DTOs/PersonDto.cs+++ b/API/DTOs/PersonDto.cs@@ -4,7 +4,8 @@ namespace API.DTOs{public class PersonDto{+ public int Id { get; set; }public string Name { get; set; }public PersonRole Role { get; set; }}-}\ No newline at end of file+}diff --git a/API/DTOs/Reader/BookInfoDto.cs b/API/DTOs/Reader/BookInfoDto.csindex 6705c9647..b881c1b10 100644--- a/API/DTOs/Reader/BookInfoDto.cs+++ b/API/DTOs/Reader/BookInfoDto.cs@@ -14,5 +14,6 @@ namespace API.DTOs.Readerpublic int LibraryId { get; set; }public int Pages { get; set; }public bool IsSpecial { get; set; }+ public string ChapterTitle { get; set; }}}diff --git a/API/DTOs/Reader/ChapterInfoDto.cs b/API/DTOs/Reader/ChapterInfoDto.csindex ec512670d..e29f3798c 100644--- a/API/DTOs/Reader/ChapterInfoDto.cs+++ b/API/DTOs/Reader/ChapterInfoDto.cs@@ -1,4 +1,5 @@-using API.Entities.Enums;+using System;+using API.Entities.Enums;namespace API.DTOs.Reader{@@ -12,7 +13,7 @@ namespace API.DTOs.Readerpublic MangaFormat SeriesFormat { get; set; }public int SeriesId { get; set; }public int LibraryId { get; set; }- public string ChapterTitle { get; set; } = "";+ public string ChapterTitle { get; set; } = string.Empty;public int Pages { get; set; }public string FileName { get; set; }public bool IsSpecial { get; set; }diff --git a/API/DTOs/Reader/IChapterInfoDto.cs b/API/DTOs/Reader/IChapterInfoDto.csindex 67aa6caf6..e448e5e13 100644--- a/API/DTOs/Reader/IChapterInfoDto.cs+++ b/API/DTOs/Reader/IChapterInfoDto.cs@@ -13,6 +13,7 @@ namespace API.DTOs.Readerpublic int LibraryId { get; set; }public int Pages { get; set; }public bool IsSpecial { get; set; }+ public string ChapterTitle { get; set; }}}diff --git a/API/DTOs/SeriesMetadataDto.cs b/API/DTOs/SeriesMetadataDto.csindex 69dcae2d9..fbee305ac 100644--- a/API/DTOs/SeriesMetadataDto.cs+++ b/API/DTOs/SeriesMetadataDto.cs@@ -1,16 +1,61 @@using System.Collections.Generic;using API.DTOs.CollectionTags;-using API.Entities;+using API.DTOs.Metadata;+using API.Entities.Enums;namespace API.DTOs{public class SeriesMetadataDto{public int Id { get; set; }- public ICollection<string> Genres { get; set; }- public ICollection<CollectionTagDto> Tags { get; set; }- public ICollection<Person> Persons { get; set; }- public string Publisher { get; set; }+ public string Summary { get; set; }+ /// <summary>+ /// Collections the Series belongs to+ /// </summary>+ public ICollection<CollectionTagDto> CollectionTags { get; set; }+ /// <summary>+ /// Genres for the Series+ /// </summary>+ public ICollection<GenreTagDto> Genres { get; set; }+ /// <summary>+ /// Collection of all Tags from underlying chapters for a Series+ /// </summary>+ public ICollection<TagDto> Tags { get; set; }+ public ICollection<PersonDto> Writers { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> CoverArtists { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Publishers { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Characters { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Pencillers { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Inkers { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Colorists { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Letterers { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Editors { get; set; } = new List<PersonDto>();+ public ICollection<PersonDto> Translators { get; set; } = new List<PersonDto>();+ /// <summary>+ /// Highest Age Rating from all Chapters+ /// </summary>+ public AgeRating AgeRating { get; set; } = AgeRating.Unknown;+ /// <summary>+ /// Earliest Year from all chapters+ /// </summary>+ public int ReleaseYear { get; set; }+ /// <summary>+ /// Language of the content (BCP-47 code)+ /// </summary>+ public string Language { get; set; } = string.Empty;+ /// <summary>+ /// Number in the TotalCount of issues+ /// </summary>+ public int Count { get; set; }+ /// <summary>+ /// Total number of issues for the series+ /// </summary>+ public int TotalCount { get; set; }+ /// <summary>+ /// Publication status of the Series+ /// </summary>+ public PublicationStatus PublicationStatus { get; set; }+public int SeriesId { get; set; }}-}\ No newline at end of file+}diff --git a/API/DTOs/Settings/ServerSettingDTO.cs b/API/DTOs/Settings/ServerSettingDTO.csindex aace57127..4004c65b1 100644--- a/API/DTOs/Settings/ServerSettingDTO.cs+++ b/API/DTOs/Settings/ServerSettingDTO.cs@@ -1,4 +1,6 @@-namespace API.DTOs.Settings+using API.Services;++namespace API.DTOs.Settings{public class ServerSettingDto{@@ -30,5 +32,10 @@/// Base Url for the kavita. Requires restart to take effect./// </summary>public string BaseUrl { get; set; }+ /// <summary>+ /// Where Bookmarks are stored.+ /// </summary>+ /// <remarks>If null or empty string, will default back to default install setting aka <see cref="DirectoryService.BookmarkDirectory"/></remarks>+ public string BookmarksDirectory { get; set; }}}diff --git a/API/DTOs/Update/UpdateNotificationDto.cs b/API/DTOs/Update/UpdateNotificationDto.csindex 03c56c567..66c979cc4 100644--- a/API/DTOs/Update/UpdateNotificationDto.cs+++ b/API/DTOs/Update/UpdateNotificationDto.cs@@ -1,6 +1,4 @@-using System;--namespace API.DTOs.Update+namespace API.DTOs.Update{/// <summary>/// Update Notification denoting a new release available for user to update todiff --git a/API/DTOs/UserPreferencesDto.cs b/API/DTOs/UserPreferencesDto.csindex 03dbeaa5e..c36c9d146 100644--- a/API/DTOs/UserPreferencesDto.cs+++ b/API/DTOs/UserPreferencesDto.cs@@ -18,4 +18,4 @@ namespace API.DTOspublic ReadingDirection BookReaderReadingDirection { get; set; }public bool SiteDarkMode { get; set; }}-}\ No newline at end of file+}diff --git a/API/Data/DataContext.cs b/API/Data/DataContext.csindex 8e4dc263e..c1e100d48 100644--- a/API/Data/DataContext.cs+++ b/API/Data/DataContext.cs@@ -4,6 +4,7 @@ using System.Threading;using System.Threading.Tasks;using API.Entities;using API.Entities.Interfaces;+using API.Entities.Metadata;using Microsoft.AspNetCore.Identity;using Microsoft.AspNetCore.Identity.EntityFrameworkCore;using Microsoft.EntityFrameworkCore;@@ -23,7 +24,6 @@ namespace API.Datapublic DbSet<Library> Library { get; set; }public DbSet<Series> Series { get; set; }-public DbSet<Chapter> Chapter { get; set; }public DbSet<Volume> Volume { get; set; }public DbSet<AppUser> AppUser { get; set; }@@ -37,6 +37,9 @@ namespace API.Datapublic DbSet<AppUserBookmark> AppUserBookmark { get; set; }public DbSet<ReadingList> ReadingList { get; set; }public DbSet<ReadingListItem> ReadingListItem { get; set; }+ public DbSet<Person> Person { get; set; }+ public DbSet<Genre> Genre { get; set; }+ public DbSet<Tag> Tag { get; set; }protected override void OnModelCreating(ModelBuilder builder)diff --git a/API/Data/DbFactory.cs b/API/Data/DbFactory.csindex a57ba4037..d5b3434f7 100644--- a/API/Data/DbFactory.cs+++ b/API/Data/DbFactory.cs@@ -1,7 +1,11 @@using System;using System.Collections.Generic;+using System.IO;+using API.Data.Metadata;using API.Entities;using API.Entities.Enums;+using API.Entities.Metadata;+using API.Extensions;using API.Parser;using API.Services.Tasks;@@ -21,12 +25,16 @@ namespace API.DataLocalizedName = name,NormalizedName = Parser.Parser.Normalize(name),SortName = name,- Summary = string.Empty,Volumes = new List<Volume>(),Metadata = SeriesMetadata(Array.Empty<CollectionTag>())};}+ public static SeriesMetadata SeriesMetadata(ComicInfo info)+ {+ return SeriesMetadata(Array.Empty<CollectionTag>());+ }+public static Volume Volume(string volumeNumber){return new Volume()@@ -57,7 +65,8 @@ namespace API.Data{return new SeriesMetadata(){- CollectionTags = collectionTags+ CollectionTags = collectionTags,+ Summary = string.Empty};}@@ -72,5 +81,47 @@ namespace API.DataPromoted = promoted};}++ public static Genre Genre(string name, bool external)+ {+ return new Genre()+ {+ Title = name.Trim().SentenceCase(),+ NormalizedTitle = Parser.Parser.Normalize(name),+ ExternalTag = external+ };+ }++ public static Tag Tag(string name, bool external)+ {+ return new Tag()+ {+ Title = name.Trim().SentenceCase(),+ NormalizedTitle = Parser.Parser.Normalize(name),+ ExternalTag = external+ };+ }++ public static Person Person(string name, PersonRole role)+ {+ return new Person()+ {+ Name = name.Trim(),+ NormalizedName = Parser.Parser.Normalize(name),+ Role = role+ };+ }++ public static MangaFile MangaFile(string filePath, MangaFormat format, int pages)+ {+ return new MangaFile()+ {+ FilePath = filePath,+ Format = format,+ Pages = pages,+ LastModified = File.GetLastWriteTime(filePath) // NOTE: Changed this from DateTime.Now+ };+ }+}}diff --git a/API/Data/Metadata/ComicInfo.cs b/API/Data/Metadata/ComicInfo.csindex 9f846ea42..cc7154f93 100644--- a/API/Data/Metadata/ComicInfo.cs+++ b/API/Data/Metadata/ComicInfo.cs@@ -1,51 +1,121 @@-namespace API.Data.Metadata+using System;+using System.Linq;+using API.Entities.Enums;+using Kavita.Common.Extensions;++namespace API.Data.Metadata{/// <summary>/// A representation of a ComicInfo.xml file/// </summary>- /// <remarks>See reference of the loose spec here: https://github.com/Kussie/ComicInfoStandard/blob/main/ComicInfo.xsd</remarks>+ /// <remarks>See reference of the loose spec here: https://anansi-project.github.io/docs/comicinfo/documentation</remarks>public class ComicInfo{- public string Summary { get; set; }- public string Title { get; set; }- public string Series { get; set; }- public string Number { get; set; }- public string Volume { get; set; }- public string Notes { get; set; }- public string Genre { get; set; }+ public string Summary { get; set; } = string.Empty;+ public string Title { get; set; } = string.Empty;+ public string Series { get; set; } = string.Empty;+ public string Number { get; set; } = string.Empty;+ /// <summary>+ /// The total number of items in the series.+ /// </summary>+ public int Count { get; set; } = 0;+ public string Volume { get; set; } = string.Empty;+ public string Notes { get; set; } = string.Empty;+ public string Genre { get; set; } = string.Empty;public int PageCount { get; set; }// ReSharper disable once InconsistentNaming- public string LanguageISO { get; set; }- public string Web { get; set; }- public int Month { get; set; }- public int Year { get; set; }/// <summary>- /// Rating based on the content. Think PG-13, R for movies+ /// ISO 639-1 Code to represent the language of the content/// </summary>- public string AgeRating { get; set; }+ public string LanguageISO { get; set; } = string.Empty;+ /// <summary>+ /// This is the link to where the data was scraped from+ /// </summary>+ public string Web { get; set; } = string.Empty;+ public int Day { get; set; } = 0;+ public int Month { get; set; } = 0;+ public int Year { get; set; } = 0;+++ /// <summary>+ /// Rating based on the content. Think PG-13, R for movies. See <see cref="AgeRating"/> for valid types+ /// </summary>+ public string AgeRating { get; set; } = string.Empty;/// <summary>/// User's rating of the content/// </summary>public float UserRating { get; set; }- public string AlternateSeries { get; set; }- public string StoryArc { get; set; }- public string SeriesGroup { get; set; }- public string AlternativeSeries { get; set; }- public string AlternativeNumber { get; set; }+ public string AlternateSeries { get; set; } = string.Empty;+ public string StoryArc { get; set; } = string.Empty;+ public string SeriesGroup { get; set; } = string.Empty;+ public string AlternativeSeries { get; set; } = string.Empty;+ public string AlternativeNumber { get; set; } = string.Empty;++ /// <summary>+ /// This is Epub only: calibre:title_sort+ /// Represents the sort order for the title+ /// </summary>+ public string TitleSort { get; set; } = string.Empty;+ /// <summary>+ /// The translator, can be comma separated. This is part of ComicInfo.xml draft v2.1+ /// </summary>+ /// See https://github.com/anansi-project/comicinfo/issues/2 for information about this tag+ public string Translator { get; set; } = string.Empty;+ /// <summary>+ /// Misc tags. This is part of ComicInfo.xml draft v2.1+ /// </summary>+ /// See https://github.com/anansi-project/comicinfo/issues/1 for information about this tag+ public string Tags { get; set; } = string.Empty;/// <summary>/// This is the Author. For Books, we map creator tag in OPF to this field. Comma separated if multiple./// </summary>- public string Writer { get; set; } // TODO: Validate if we should make this a list of writers- public string Penciller { get; set; }- public string Inker { get; set; }- public string Colorist { get; set; }- public string Letterer { get; set; }- public string CoverArtist { get; set; }- public string Editor { get; set; }- public string Publisher { get; set; }+ public string Writer { get; set; } = string.Empty;+ public string Penciller { get; set; } = string.Empty;+ public string Inker { get; set; } = string.Empty;+ public string Colorist { get; set; } = string.Empty;+ public string Letterer { get; set; } = string.Empty;+ public string CoverArtist { get; set; } = string.Empty;+ public string Editor { get; set; } = string.Empty;+ public string Publisher { get; set; } = string.Empty;+ public string Characters { get; set; } = string.Empty;++ public static AgeRating ConvertAgeRatingToEnum(string value)+ {+ if (string.IsNullOrEmpty(value)) return Entities.Enums.AgeRating.Unknown;+ return Enum.GetValues<AgeRating>()+ .SingleOrDefault(t => t.ToDescription().ToUpperInvariant().Equals(value.ToUpperInvariant()), Entities.Enums.AgeRating.Unknown);+ }++ public static void CleanComicInfo(ComicInfo info)+ {+ if (info == null) return;++ info.Writer = Parser.Parser.CleanAuthor(info.Writer);+ info.Colorist = Parser.Parser.CleanAuthor(info.Colorist);+ info.Editor = Parser.Parser.CleanAuthor(info.Editor);+ info.Inker = Parser.Parser.CleanAuthor(info.Inker);+ info.Letterer = Parser.Parser.CleanAuthor(info.Letterer);+ info.Penciller = Parser.Parser.CleanAuthor(info.Penciller);+ info.Publisher = Parser.Parser.CleanAuthor(info.Publisher);+ info.Characters = Parser.Parser.CleanAuthor(info.Characters);+ info.Translator = Parser.Parser.CleanAuthor(info.Translator);+ info.CoverArtist = Parser.Parser.CleanAuthor(info.CoverArtist);+++ // if (!string.IsNullOrEmpty(info.Web))+ // {+ // // ComicVine stores the Issue number in Number field and does not use Volume.+ // if (!info.Web.Contains("https://comicvine.gamespot.com/")) return;+ // if (info.Volume.Equals("1"))+ // {+ // info.Volume = Parser.Parser.DefaultVolume;+ // }+ // }+ }+}}diff --git a/API/Data/MigrateBookmarks.cs b/API/Data/MigrateBookmarks.csnew file mode 100644index 000000000..043b3e0a4--- /dev/null+++ b/API/Data/MigrateBookmarks.cs@@ -0,0 +1,102 @@+using System;+using System.Linq;+using System.Threading.Tasks;+using API.Comparators;+using API.Entities.Enums;+using API.Services;+using Microsoft.Extensions.Logging;++namespace API.Data;++/// <summary>+/// Responsible to migrate existing bookmarks to files+/// </summary>+public static class MigrateBookmarks+{+ private static readonly Version VersionBookmarksChanged = new Version(0, 4, 9, 27);+ /// <summary>+ /// This will migrate existing bookmarks to bookmark folder based+ /// </summary>+ /// <remarks>Bookmark directory is configurable. This will always use the default bookmark directory.</remarks>+ /// <param name="directoryService"></param>+ /// <returns></returns>+ public static async Task Migrate(IDirectoryService directoryService, IUnitOfWork unitOfWork,+ ILogger<Program> logger, ICacheService cacheService)+ {+ var bookmarkDirectory = (await unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BookmarkDirectory))+ .Value;+ if (string.IsNullOrEmpty(bookmarkDirectory))+ {+ bookmarkDirectory = directoryService.BookmarkDirectory;+ }++ if (directoryService.Exists(bookmarkDirectory)) return;++ logger.LogInformation("Bookmark migration is needed....This may take some time");++ var allBookmarks = (await unitOfWork.UserRepository.GetAllBookmarksAsync()).ToList();++ var uniqueChapterIds = allBookmarks.Select(b => b.ChapterId).Distinct().ToList();+ var uniqueUserIds = allBookmarks.Select(b => b.AppUserId).Distinct().ToList();+ foreach (var userId in uniqueUserIds)+ {+ foreach (var chapterId in uniqueChapterIds)+ {+ var chapterBookmarks = allBookmarks.Where(b => b.ChapterId == chapterId).ToList();+ var chapterPages = chapterBookmarks+ .Select(b => b.Page).ToList();+ var seriesId = chapterBookmarks+ .Select(b => b.SeriesId).First();+ var mangaFiles = await unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId);+ var chapterExtractPath = directoryService.FileSystem.Path.Join(directoryService.TempDirectory, $"bookmark_c{chapterId}_u{userId}_s{seriesId}");++ var numericComparer = new NumericComparer();+ if (!mangaFiles.Any()) continue;++ switch (mangaFiles.First().Format)+ {+ case MangaFormat.Image:+ directoryService.ExistOrCreate(chapterExtractPath);+ directoryService.CopyFilesToDirectory(mangaFiles.Select(f => f.FilePath), chapterExtractPath);+ break;+ case MangaFormat.Archive:+ case MangaFormat.Pdf:+ cacheService.ExtractChapterFiles(chapterExtractPath, mangaFiles.ToList());+ break;+ case MangaFormat.Epub:+ continue;+ default:+ continue;+ }++ var files = directoryService.GetFilesWithExtension(chapterExtractPath, Parser.Parser.ImageFileExtensions);+ // Filter out images that aren't in bookmarks+ Array.Sort(files, numericComparer);+ foreach (var chapterPage in chapterPages)+ {+ var file = files.ElementAt(chapterPage);+ var bookmark = allBookmarks.FirstOrDefault(b =>+ b.ChapterId == chapterId && b.SeriesId == seriesId && b.AppUserId == userId &&+ b.Page == chapterPage);+ if (bookmark == null) continue;++ var filename = directoryService.FileSystem.Path.GetFileName(file);+ var newLocation = directoryService.FileSystem.Path.Join(+ ReaderService.FormatBookmarkFolderPath(String.Empty, userId, seriesId, chapterId),+ filename);+ bookmark.FileName = newLocation;+ directoryService.CopyFileToDirectory(file,+ ReaderService.FormatBookmarkFolderPath(bookmarkDirectory, userId, seriesId, chapterId));+ unitOfWork.UserRepository.Update(bookmark);+ }+ }+ // Clear temp after each user to avoid too much space being eaten+ directoryService.ClearDirectory(directoryService.TempDirectory);+ }++ await unitOfWork.CommitAsync();+ // Run CleanupService as we cache a ton of files+ directoryService.ClearDirectory(directoryService.TempDirectory);++ }+}diff --git a/API/Data/MigrateConfigFiles.cs b/API/Data/MigrateConfigFiles.csindex 752b03192..51ee37167 100644--- a/API/Data/MigrateConfigFiles.cs+++ b/API/Data/MigrateConfigFiles.cs@@ -1,12 +1,16 @@using System;using System.Collections.Generic;using System.IO;+using System.IO.Abstractions;using System.Linq;using API.Services;using Kavita.Common;namespace API.Data{+ /// <summary>+ /// A Migration to migrate config related files to the config/ directory for installs prior to v0.4.9.+ /// </summary>public static class MigrateConfigFiles{private static readonly List<string> LooseLeafFiles = new List<string>()@@ -31,7 +35,7 @@ namespace API.Data/// In v0.4.8 we moved all config files to config/ to match with how docker was setup. This will move all config files from current directory/// to config//// </summary>- public static void Migrate(bool isDocker)+ public static void Migrate(bool isDocker, IDirectoryService directoryService){Console.WriteLine("Checking if migration to config/ is needed");@@ -46,8 +50,8 @@ namespace API.DataConsole.WriteLine("Migrating files from pre-v0.4.8. All Kavita config files are now located in config/");- CopyAppFolders();- DeleteAppFolders();+ CopyAppFolders(directoryService);+ DeleteAppFolders(directoryService);UpdateConfiguration();@@ -64,14 +68,14 @@ namespace API.DataConsole.WriteLine("Migrating files from pre-v0.4.8. All Kavita config files are now located in config/");- Console.WriteLine($"Creating {DirectoryService.ConfigDirectory}");- DirectoryService.ExistOrCreate(DirectoryService.ConfigDirectory);+ Console.WriteLine($"Creating {directoryService.ConfigDirectory}");+ directoryService.ExistOrCreate(directoryService.ConfigDirectory);try{- CopyLooseLeafFiles();+ CopyLooseLeafFiles(directoryService);- CopyAppFolders();+ CopyAppFolders(directoryService);// Then we need to update the config file to point to the new DB fileUpdateConfiguration();@@ -84,43 +88,43 @@ namespace API.Data// Finally delete everything in the source directoryConsole.WriteLine("Removing old files");- DeleteLooseFiles();- DeleteAppFolders();+ DeleteLooseFiles(directoryService);+ DeleteAppFolders(directoryService);Console.WriteLine("Removing old files...DONE");Console.WriteLine("Migration complete. All config files are now in config/ directory");}- private static void DeleteAppFolders()+ private static void DeleteAppFolders(IDirectoryService directoryService){foreach (var folderToDelete in AppFolders){if (!new DirectoryInfo(Path.Join(Directory.GetCurrentDirectory(), folderToDelete)).Exists) continue;- DirectoryService.ClearAndDeleteDirectory(Path.Join(Directory.GetCurrentDirectory(), folderToDelete));+ directoryService.ClearAndDeleteDirectory(Path.Join(Directory.GetCurrentDirectory(), folderToDelete));}}- private static void DeleteLooseFiles()+ private static void DeleteLooseFiles(IDirectoryService directoryService){var configFiles = LooseLeafFiles.Select(file => new FileInfo(Path.Join(Directory.GetCurrentDirectory(), file))).Where(f => f.Exists);- DirectoryService.DeleteFiles(configFiles.Select(f => f.FullName));+ directoryService.DeleteFiles(configFiles.Select(f => f.FullName));}- private static void CopyAppFolders()+ private static void CopyAppFolders(IDirectoryService directoryService){Console.WriteLine("Moving folders to config");foreach (var folderToMove in AppFolders){- if (new DirectoryInfo(Path.Join(DirectoryService.ConfigDirectory, folderToMove)).Exists) continue;+ if (new DirectoryInfo(Path.Join(directoryService.ConfigDirectory, folderToMove)).Exists) continue;try{- DirectoryService.CopyDirectoryToDirectory(- Path.Join(Directory.GetCurrentDirectory(), folderToMove),- Path.Join(DirectoryService.ConfigDirectory, folderToMove));+ directoryService.CopyDirectoryToDirectory(+ Path.Join(directoryService.FileSystem.Directory.GetCurrentDirectory(), folderToMove),+ Path.Join(directoryService.ConfigDirectory, folderToMove));}catch (Exception){@@ -132,9 +136,9 @@ namespace API.DataConsole.WriteLine("Moving folders to config...DONE");}- private static void CopyLooseLeafFiles()+ private static void CopyLooseLeafFiles(IDirectoryService directoryService){- var configFiles = LooseLeafFiles.Select(file => new FileInfo(Path.Join(Directory.GetCurrentDirectory(), file)))+ var configFiles = LooseLeafFiles.Select(file => new FileInfo(Path.Join(directoryService.FileSystem.Directory.GetCurrentDirectory(), file))).Where(f => f.Exists);// First step is to move all the filesConsole.WriteLine("Moving files to config/");@@ -142,7 +146,7 @@ namespace API.Data{try{- fileInfo.CopyTo(Path.Join(DirectoryService.ConfigDirectory, fileInfo.Name));+ fileInfo.CopyTo(Path.Join(directoryService.ConfigDirectory, fileInfo.Name));}catch (Exception){diff --git a/API/Data/MigrateCoverImages.cs b/API/Data/MigrateCoverImages.csindex 87e65cb81..b5839509a 100644--- a/API/Data/MigrateCoverImages.cs+++ b/API/Data/MigrateCoverImages.cs@@ -29,10 +29,10 @@ namespace API.Data/// <summary>/// Run first. Will extract byte[]s from DB and write them to the cover directory./// </summary>- public static void ExtractToImages(DbContext context)+ public static void ExtractToImages(DbContext context, IDirectoryService directoryService, IImageService imageService){Console.WriteLine("Migrating Cover Images to disk. Expect delay.");- DirectoryService.ExistOrCreate(DirectoryService.CoverImageDirectory);+ directoryService.ExistOrCreate(directoryService.CoverImageDirectory);Console.WriteLine("Extracting cover images for Series");var lockedSeries = SqlHelper.RawSqlQuery(context, "Select Id, CoverImage From Series Where CoverImage IS NOT NULL", x =>@@ -45,14 +45,14 @@ namespace API.Dataforeach (var series in lockedSeries){if (series.CoverImage == null || !series.CoverImage.Any()) continue;- if (File.Exists(Path.Join(DirectoryService.CoverImageDirectory,+ if (File.Exists(directoryService.FileSystem.Path.Join(directoryService.CoverImageDirectory,$"{ImageService.GetSeriesFormat(int.Parse(series.Id))}.png"))) continue;try{var stream = new MemoryStream(series.CoverImage);stream.Position = 0;- ImageService.WriteCoverThumbnail(stream, ImageService.GetSeriesFormat(int.Parse(series.Id)));+ imageService.WriteCoverThumbnail(stream, ImageService.GetSeriesFormat(int.Parse(series.Id)), directoryService.CoverImageDirectory);}catch (Exception e){@@ -71,14 +71,14 @@ namespace API.Dataforeach (var chapter in chapters){if (chapter.CoverImage == null || !chapter.CoverImage.Any()) continue;- if (File.Exists(Path.Join(DirectoryService.CoverImageDirectory,+ if (directoryService.FileSystem.File.Exists(directoryService.FileSystem.Path.Join(directoryService.CoverImageDirectory,$"{ImageService.GetChapterFormat(int.Parse(chapter.Id), int.Parse(chapter.ParentId))}.png"))) continue;try{var stream = new MemoryStream(chapter.CoverImage);stream.Position = 0;- ImageService.WriteCoverThumbnail(stream, $"{ImageService.GetChapterFormat(int.Parse(chapter.Id), int.Parse(chapter.ParentId))}");+ imageService.WriteCoverThumbnail(stream, $"{ImageService.GetChapterFormat(int.Parse(chapter.Id), int.Parse(chapter.ParentId))}", directoryService.CoverImageDirectory);}catch (Exception e){@@ -97,13 +97,13 @@ namespace API.Dataforeach (var tag in tags){if (tag.CoverImage == null || !tag.CoverImage.Any()) continue;- if (File.Exists(Path.Join(DirectoryService.CoverImageDirectory,+ if (directoryService.FileSystem.File.Exists(Path.Join(directoryService.CoverImageDirectory,$"{ImageService.GetCollectionTagFormat(int.Parse(tag.Id))}.png"))) continue;try{var stream = new MemoryStream(tag.CoverImage);stream.Position = 0;- ImageService.WriteCoverThumbnail(stream, $"{ImageService.GetCollectionTagFormat(int.Parse(tag.Id))}");+ imageService.WriteCoverThumbnail(stream, $"{ImageService.GetCollectionTagFormat(int.Parse(tag.Id))}", directoryService.CoverImageDirectory);}catch (Exception e){@@ -116,13 +116,13 @@ namespace API.Data/// Run after <see cref="ExtractToImages"/>. Will update the DB with names of files that were extracted./// </summary>/// <param name="context"></param>- public static async Task UpdateDatabaseWithImages(DataContext context)+ public static async Task UpdateDatabaseWithImages(DataContext context, IDirectoryService directoryService){Console.WriteLine("Updating Series entities");var seriesCovers = await context.Series.Where(s => !string.IsNullOrEmpty(s.CoverImage)).ToListAsync();foreach (var series in seriesCovers){- if (!File.Exists(Path.Join(DirectoryService.CoverImageDirectory,+ if (!directoryService.FileSystem.File.Exists(directoryService.FileSystem.Path.Join(directoryService.CoverImageDirectory,$"{ImageService.GetSeriesFormat(series.Id)}.png"))) continue;series.CoverImage = $"{ImageService.GetSeriesFormat(series.Id)}.png";}@@ -131,9 +131,10 @@ namespace API.DataConsole.WriteLine("Updating Chapter entities");var chapters = await context.Chapter.ToListAsync();+ // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumeratorforeach (var chapter in chapters){- if (File.Exists(Path.Join(DirectoryService.CoverImageDirectory,+ if (directoryService.FileSystem.File.Exists(directoryService.FileSystem.Path.Join(directoryService.CoverImageDirectory,$"{ImageService.GetChapterFormat(chapter.Id, chapter.VolumeId)}.png"))){chapter.CoverImage = $"{ImageService.GetChapterFormat(chapter.Id, chapter.VolumeId)}.png";@@ -149,7 +150,7 @@ namespace API.Data{var firstChapter = volume.Chapters.OrderBy(x => double.Parse(x.Number), ChapterSortComparerForInChapterSorting).FirstOrDefault();if (firstChapter == null) continue;- if (File.Exists(Path.Join(DirectoryService.CoverImageDirectory,+ if (directoryService.FileSystem.File.Exists(directoryService.FileSystem.Path.Join(directoryService.CoverImageDirectory,$"{ImageService.GetChapterFormat(firstChapter.Id, firstChapter.VolumeId)}.png"))){volume.CoverImage = $"{ImageService.GetChapterFormat(firstChapter.Id, firstChapter.VolumeId)}.png";@@ -161,9 +162,10 @@ namespace API.DataConsole.WriteLine("Updating Collection Tag entities");var tags = await context.CollectionTag.ToListAsync();+ // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumeratorforeach (var tag in tags){- if (File.Exists(Path.Join(DirectoryService.CoverImageDirectory,+ if (directoryService.FileSystem.File.Exists(directoryService.FileSystem.Path.Join(directoryService.CoverImageDirectory,$"{ImageService.GetCollectionTagFormat(tag.Id)}.png"))){tag.CoverImage = $"{ImageService.GetCollectionTagFormat(tag.Id)}.png";diff --git a/API/Data/Migrations/20211127200244_MetadataFoundation.Designer.cs b/API/Data/Migrations/20211127200244_MetadataFoundation.Designer.csnew file mode 100644index 000000000..32408164b--- /dev/null+++ b/API/Data/Migrations/20211127200244_MetadataFoundation.Designer.cs@@ -0,0 +1,1215 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20211127200244_MetadataFoundation")]+ partial class MetadataFoundation+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.ChapterMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("StoryArc")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("Year")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("ChapterId")+ .IsUnique();++ b.ToTable("ChapterMetadata");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterMetadataPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterMetadataPerson");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.ChapterMetadata", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithOne("ChapterMetadata")+ .HasForeignKey("API.Entities.ChapterMetadata", "ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterMetadataPerson", b =>+ {+ b.HasOne("API.Entities.ChapterMetadata", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("ChapterMetadata");++ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20211127200244_MetadataFoundation.cs b/API/Data/Migrations/20211127200244_MetadataFoundation.csnew file mode 100644index 000000000..f2ea2c9c1--- /dev/null+++ b/API/Data/Migrations/20211127200244_MetadataFoundation.cs@@ -0,0 +1,203 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class MetadataFoundation : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropColumn(+ name: "Summary",+ table: "Series");++ migrationBuilder.AddColumn<string>(+ name: "Summary",+ table: "SeriesMetadata",+ type: "TEXT",+ nullable: true);++ migrationBuilder.CreateTable(+ name: "ChapterMetadata",+ columns: table => new+ {+ Id = table.Column<int>(type: "INTEGER", nullable: false)+ .Annotation("Sqlite:Autoincrement", true),+ Title = table.Column<string>(type: "TEXT", nullable: true),+ Year = table.Column<string>(type: "TEXT", nullable: true),+ StoryArc = table.Column<string>(type: "TEXT", nullable: true),+ ChapterId = table.Column<int>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_ChapterMetadata", x => x.Id);+ table.ForeignKey(+ name: "FK_ChapterMetadata_Chapter_ChapterId",+ column: x => x.ChapterId,+ principalTable: "Chapter",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateTable(+ name: "Genre",+ columns: table => new+ {+ Id = table.Column<int>(type: "INTEGER", nullable: false)+ .Annotation("Sqlite:Autoincrement", true),+ Name = table.Column<string>(type: "TEXT", nullable: true),+ NormalizedName = table.Column<string>(type: "TEXT", nullable: true)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_Genre", x => x.Id);+ });++ migrationBuilder.CreateTable(+ name: "Person",+ columns: table => new+ {+ Id = table.Column<int>(type: "INTEGER", nullable: false)+ .Annotation("Sqlite:Autoincrement", true),+ Name = table.Column<string>(type: "TEXT", nullable: true),+ NormalizedName = table.Column<string>(type: "TEXT", nullable: true),+ Role = table.Column<int>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_Person", x => x.Id);+ });++ migrationBuilder.CreateTable(+ name: "GenreSeriesMetadata",+ columns: table => new+ {+ GenresId = table.Column<int>(type: "INTEGER", nullable: false),+ SeriesMetadatasId = table.Column<int>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_GenreSeriesMetadata", x => new { x.GenresId, x.SeriesMetadatasId });+ table.ForeignKey(+ name: "FK_GenreSeriesMetadata_Genre_GenresId",+ column: x => x.GenresId,+ principalTable: "Genre",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ table.ForeignKey(+ name: "FK_GenreSeriesMetadata_SeriesMetadata_SeriesMetadatasId",+ column: x => x.SeriesMetadatasId,+ principalTable: "SeriesMetadata",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateTable(+ name: "ChapterMetadataPerson",+ columns: table => new+ {+ ChapterMetadatasId = table.Column<int>(type: "INTEGER", nullable: false),+ PeopleId = table.Column<int>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_ChapterMetadataPerson", x => new { x.ChapterMetadatasId, x.PeopleId });+ table.ForeignKey(+ name: "FK_ChapterMetadataPerson_ChapterMetadata_ChapterMetadatasId",+ column: x => x.ChapterMetadatasId,+ principalTable: "ChapterMetadata",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ table.ForeignKey(+ name: "FK_ChapterMetadataPerson_Person_PeopleId",+ column: x => x.PeopleId,+ principalTable: "Person",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateTable(+ name: "PersonSeriesMetadata",+ columns: table => new+ {+ PeopleId = table.Column<int>(type: "INTEGER", nullable: false),+ SeriesMetadatasId = table.Column<int>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_PersonSeriesMetadata", x => new { x.PeopleId, x.SeriesMetadatasId });+ table.ForeignKey(+ name: "FK_PersonSeriesMetadata_Person_PeopleId",+ column: x => x.PeopleId,+ principalTable: "Person",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ table.ForeignKey(+ name: "FK_PersonSeriesMetadata_SeriesMetadata_SeriesMetadatasId",+ column: x => x.SeriesMetadatasId,+ principalTable: "SeriesMetadata",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateIndex(+ name: "IX_ChapterMetadata_ChapterId",+ table: "ChapterMetadata",+ column: "ChapterId",+ unique: true);++ migrationBuilder.CreateIndex(+ name: "IX_ChapterMetadataPerson_PeopleId",+ table: "ChapterMetadataPerson",+ column: "PeopleId");++ migrationBuilder.CreateIndex(+ name: "IX_Genre_NormalizedName",+ table: "Genre",+ column: "NormalizedName",+ unique: true);++ migrationBuilder.CreateIndex(+ name: "IX_GenreSeriesMetadata_SeriesMetadatasId",+ table: "GenreSeriesMetadata",+ column: "SeriesMetadatasId");++ migrationBuilder.CreateIndex(+ name: "IX_PersonSeriesMetadata_SeriesMetadatasId",+ table: "PersonSeriesMetadata",+ column: "SeriesMetadatasId");+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropTable(+ name: "ChapterMetadataPerson");++ migrationBuilder.DropTable(+ name: "GenreSeriesMetadata");++ migrationBuilder.DropTable(+ name: "PersonSeriesMetadata");++ migrationBuilder.DropTable(+ name: "ChapterMetadata");++ migrationBuilder.DropTable(+ name: "Genre");++ migrationBuilder.DropTable(+ name: "Person");++ migrationBuilder.DropColumn(+ name: "Summary",+ table: "SeriesMetadata");++ migrationBuilder.AddColumn<string>(+ name: "Summary",+ table: "Series",+ type: "TEXT",+ nullable: true);+ }+ }+}diff --git a/API/Data/Migrations/20211129231007_RemoveChapterMetadata.Designer.cs b/API/Data/Migrations/20211129231007_RemoveChapterMetadata.Designer.csnew file mode 100644index 000000000..27436b91f--- /dev/null+++ b/API/Data/Migrations/20211129231007_RemoveChapterMetadata.Designer.cs@@ -0,0 +1,1232 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20211129231007_RemoveChapterMetadata")]+ partial class RemoveChapterMetadata+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.ChapterMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("StoryArc")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("Year")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("ChapterMetadata");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int?>("ChapterMetadataId")+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterMetadataId");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.ChapterMetadata", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.HasOne("API.Entities.Metadata.ChapterMetadata", null)+ .WithMany("People")+ .HasForeignKey("ChapterMetadataId");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.Metadata.ChapterMetadata", b =>+ {+ b.Navigation("People");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20211129231007_RemoveChapterMetadata.cs b/API/Data/Migrations/20211129231007_RemoveChapterMetadata.csnew file mode 100644index 000000000..c50578ff9--- /dev/null+++ b/API/Data/Migrations/20211129231007_RemoveChapterMetadata.cs@@ -0,0 +1,138 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class RemoveChapterMetadata : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropTable(+ name: "ChapterMetadataPerson");++ migrationBuilder.DropIndex(+ name: "IX_ChapterMetadata_ChapterId",+ table: "ChapterMetadata");++ migrationBuilder.AddColumn<int>(+ name: "ChapterMetadataId",+ table: "Person",+ type: "INTEGER",+ nullable: true);++ migrationBuilder.AddColumn<string>(+ name: "TitleName",+ table: "Chapter",+ type: "TEXT",+ nullable: true);++ migrationBuilder.CreateTable(+ name: "ChapterPerson",+ columns: table => new+ {+ ChapterMetadatasId = table.Column<int>(type: "INTEGER", nullable: false),+ PeopleId = table.Column<int>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_ChapterPerson", x => new { x.ChapterMetadatasId, x.PeopleId });+ table.ForeignKey(+ name: "FK_ChapterPerson_Chapter_ChapterMetadatasId",+ column: x => x.ChapterMetadatasId,+ principalTable: "Chapter",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ table.ForeignKey(+ name: "FK_ChapterPerson_Person_PeopleId",+ column: x => x.PeopleId,+ principalTable: "Person",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateIndex(+ name: "IX_Person_ChapterMetadataId",+ table: "Person",+ column: "ChapterMetadataId");++ migrationBuilder.CreateIndex(+ name: "IX_ChapterMetadata_ChapterId",+ table: "ChapterMetadata",+ column: "ChapterId");++ migrationBuilder.CreateIndex(+ name: "IX_ChapterPerson_PeopleId",+ table: "ChapterPerson",+ column: "PeopleId");++ migrationBuilder.AddForeignKey(+ name: "FK_Person_ChapterMetadata_ChapterMetadataId",+ table: "Person",+ column: "ChapterMetadataId",+ principalTable: "ChapterMetadata",+ principalColumn: "Id");+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropForeignKey(+ name: "FK_Person_ChapterMetadata_ChapterMetadataId",+ table: "Person");++ migrationBuilder.DropTable(+ name: "ChapterPerson");++ migrationBuilder.DropIndex(+ name: "IX_Person_ChapterMetadataId",+ table: "Person");++ migrationBuilder.DropIndex(+ name: "IX_ChapterMetadata_ChapterId",+ table: "ChapterMetadata");++ migrationBuilder.DropColumn(+ name: "ChapterMetadataId",+ table: "Person");++ migrationBuilder.DropColumn(+ name: "TitleName",+ table: "Chapter");++ migrationBuilder.CreateTable(+ name: "ChapterMetadataPerson",+ columns: table => new+ {+ ChapterMetadatasId = table.Column<int>(type: "INTEGER", nullable: false),+ PeopleId = table.Column<int>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_ChapterMetadataPerson", x => new { x.ChapterMetadatasId, x.PeopleId });+ table.ForeignKey(+ name: "FK_ChapterMetadataPerson_ChapterMetadata_ChapterMetadatasId",+ column: x => x.ChapterMetadatasId,+ principalTable: "ChapterMetadata",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ table.ForeignKey(+ name: "FK_ChapterMetadataPerson_Person_PeopleId",+ column: x => x.PeopleId,+ principalTable: "Person",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateIndex(+ name: "IX_ChapterMetadata_ChapterId",+ table: "ChapterMetadata",+ column: "ChapterId",+ unique: true);++ migrationBuilder.CreateIndex(+ name: "IX_ChapterMetadataPerson_PeopleId",+ table: "ChapterMetadataPerson",+ column: "PeopleId");+ }+ }+}diff --git a/API/Data/Migrations/20211130134642_GenreProvider.Designer.cs b/API/Data/Migrations/20211130134642_GenreProvider.Designer.csnew file mode 100644index 000000000..4b90e75ba--- /dev/null+++ b/API/Data/Migrations/20211130134642_GenreProvider.Designer.cs@@ -0,0 +1,1182 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20211130134642_GenreProvider")]+ partial class GenreProvider+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20211130134642_GenreProvider.cs b/API/Data/Migrations/20211130134642_GenreProvider.csnew file mode 100644index 000000000..260210d54--- /dev/null+++ b/API/Data/Migrations/20211130134642_GenreProvider.cs@@ -0,0 +1,86 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class GenreProvider : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropForeignKey(+ name: "FK_Person_ChapterMetadata_ChapterMetadataId",+ table: "Person");++ migrationBuilder.DropTable(+ name: "ChapterMetadata");++ migrationBuilder.DropIndex(+ name: "IX_Person_ChapterMetadataId",+ table: "Person");++ migrationBuilder.DropColumn(+ name: "ChapterMetadataId",+ table: "Person");++ migrationBuilder.AddColumn<bool>(+ name: "ExternalTag",+ table: "Genre",+ type: "INTEGER",+ nullable: false,+ defaultValue: false);+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropColumn(+ name: "ExternalTag",+ table: "Genre");++ migrationBuilder.AddColumn<int>(+ name: "ChapterMetadataId",+ table: "Person",+ type: "INTEGER",+ nullable: true);++ migrationBuilder.CreateTable(+ name: "ChapterMetadata",+ columns: table => new+ {+ Id = table.Column<int>(type: "INTEGER", nullable: false)+ .Annotation("Sqlite:Autoincrement", true),+ ChapterId = table.Column<int>(type: "INTEGER", nullable: false),+ StoryArc = table.Column<string>(type: "TEXT", nullable: true),+ Title = table.Column<string>(type: "TEXT", nullable: true),+ Year = table.Column<string>(type: "TEXT", nullable: true)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_ChapterMetadata", x => x.Id);+ table.ForeignKey(+ name: "FK_ChapterMetadata_Chapter_ChapterId",+ column: x => x.ChapterId,+ principalTable: "Chapter",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateIndex(+ name: "IX_Person_ChapterMetadataId",+ table: "Person",+ column: "ChapterMetadataId");++ migrationBuilder.CreateIndex(+ name: "IX_ChapterMetadata_ChapterId",+ table: "ChapterMetadata",+ column: "ChapterId");++ migrationBuilder.AddForeignKey(+ name: "FK_Person_ChapterMetadata_ChapterMetadataId",+ table: "Person",+ column: "ChapterMetadataId",+ principalTable: "ChapterMetadata",+ principalColumn: "Id");+ }+ }+}diff --git a/API/Data/Migrations/20211201230003_GenreTitle.Designer.cs b/API/Data/Migrations/20211201230003_GenreTitle.Designer.csnew file mode 100644index 000000000..81f69b5a0--- /dev/null+++ b/API/Data/Migrations/20211201230003_GenreTitle.Designer.cs@@ -0,0 +1,1196 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20211201230003_GenreTitle")]+ partial class GenreTitle+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int?>("GenreId")+ .HasColumnType("INTEGER");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("GenreId");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany("Chapters")+ .HasForeignKey("GenreId");++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Navigation("Chapters");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20211201230003_GenreTitle.cs b/API/Data/Migrations/20211201230003_GenreTitle.csnew file mode 100644index 000000000..ab3e65daf--- /dev/null+++ b/API/Data/Migrations/20211201230003_GenreTitle.cs@@ -0,0 +1,85 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class GenreTitle : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropIndex(+ name: "IX_Genre_NormalizedName",+ table: "Genre");++ migrationBuilder.RenameColumn(+ name: "NormalizedName",+ table: "Genre",+ newName: "Title");++ migrationBuilder.RenameColumn(+ name: "Name",+ table: "Genre",+ newName: "NormalizedTitle");++ migrationBuilder.AddColumn<int>(+ name: "GenreId",+ table: "Chapter",+ type: "INTEGER",+ nullable: true);++ migrationBuilder.CreateIndex(+ name: "IX_Genre_NormalizedTitle_ExternalTag",+ table: "Genre",+ columns: new[] { "NormalizedTitle", "ExternalTag" },+ unique: true);++ migrationBuilder.CreateIndex(+ name: "IX_Chapter_GenreId",+ table: "Chapter",+ column: "GenreId");++ migrationBuilder.AddForeignKey(+ name: "FK_Chapter_Genre_GenreId",+ table: "Chapter",+ column: "GenreId",+ principalTable: "Genre",+ principalColumn: "Id");+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropForeignKey(+ name: "FK_Chapter_Genre_GenreId",+ table: "Chapter");++ migrationBuilder.DropIndex(+ name: "IX_Genre_NormalizedTitle_ExternalTag",+ table: "Genre");++ migrationBuilder.DropIndex(+ name: "IX_Chapter_GenreId",+ table: "Chapter");++ migrationBuilder.DropColumn(+ name: "GenreId",+ table: "Chapter");++ migrationBuilder.RenameColumn(+ name: "Title",+ table: "Genre",+ newName: "NormalizedName");++ migrationBuilder.RenameColumn(+ name: "NormalizedTitle",+ table: "Genre",+ newName: "Name");++ migrationBuilder.CreateIndex(+ name: "IX_Genre_NormalizedName",+ table: "Genre",+ column: "NormalizedName",+ unique: true);+ }+ }+}diff --git a/API/Data/Migrations/20211205185207_MetadataAgeRating.Designer.cs b/API/Data/Migrations/20211205185207_MetadataAgeRating.Designer.csnew file mode 100644index 000000000..58704e29d--- /dev/null+++ b/API/Data/Migrations/20211205185207_MetadataAgeRating.Designer.cs@@ -0,0 +1,1199 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20211205185207_MetadataAgeRating")]+ partial class MetadataAgeRating+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int?>("GenreId")+ .HasColumnType("INTEGER");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("GenreId");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany("Chapters")+ .HasForeignKey("GenreId");++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Navigation("Chapters");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20211205185207_MetadataAgeRating.cs b/API/Data/Migrations/20211205185207_MetadataAgeRating.csnew file mode 100644index 000000000..8f03753f6--- /dev/null+++ b/API/Data/Migrations/20211205185207_MetadataAgeRating.cs@@ -0,0 +1,26 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class MetadataAgeRating : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.AddColumn<int>(+ name: "AgeRating",+ table: "SeriesMetadata",+ type: "INTEGER",+ nullable: false,+ defaultValue: 0);+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropColumn(+ name: "AgeRating",+ table: "SeriesMetadata");+ }+ }+}diff --git a/API/Data/Migrations/20211206193225_AgeRatingAndReleaseDate.Designer.cs b/API/Data/Migrations/20211206193225_AgeRatingAndReleaseDate.Designer.csnew file mode 100644index 000000000..eade9e871--- /dev/null+++ b/API/Data/Migrations/20211206193225_AgeRatingAndReleaseDate.Designer.cs@@ -0,0 +1,1208 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20211206193225_AgeRatingAndReleaseDate")]+ partial class AgeRatingAndReleaseDate+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int?>("GenreId")+ .HasColumnType("INTEGER");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<DateTime>("ReleaseDate")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("GenreId");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<int>("ReleaseYear")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany("Chapters")+ .HasForeignKey("GenreId");++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Navigation("Chapters");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20211206193225_AgeRatingAndReleaseDate.cs b/API/Data/Migrations/20211206193225_AgeRatingAndReleaseDate.csnew file mode 100644index 000000000..76a7f05c6--- /dev/null+++ b/API/Data/Migrations/20211206193225_AgeRatingAndReleaseDate.cs@@ -0,0 +1,49 @@+using System;+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class AgeRatingAndReleaseDate : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.AddColumn<int>(+ name: "ReleaseYear",+ table: "SeriesMetadata",+ type: "INTEGER",+ nullable: false,+ defaultValue: 0);++ migrationBuilder.AddColumn<int>(+ name: "AgeRating",+ table: "Chapter",+ type: "INTEGER",+ nullable: false,+ defaultValue: 0);++ migrationBuilder.AddColumn<DateTime>(+ name: "ReleaseDate",+ table: "Chapter",+ type: "TEXT",+ nullable: false,+ defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropColumn(+ name: "ReleaseYear",+ table: "SeriesMetadata");++ migrationBuilder.DropColumn(+ name: "AgeRating",+ table: "Chapter");++ migrationBuilder.DropColumn(+ name: "ReleaseDate",+ table: "Chapter");+ }+ }+}diff --git a/API/Data/Migrations/20211217013734_BookmarkRefactor.Designer.cs b/API/Data/Migrations/20211217013734_BookmarkRefactor.Designer.csnew file mode 100644index 000000000..5db4111f6--- /dev/null+++ b/API/Data/Migrations/20211217013734_BookmarkRefactor.Designer.cs@@ -0,0 +1,1317 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20211217013734_BookmarkRefactor")]+ partial class BookmarkRefactor+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.1");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FileName")+ .HasColumnType("TEXT");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int?>("GenreId")+ .HasColumnType("INTEGER");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<DateTime>("ReleaseDate")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("GenreId");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<string>("Language")+ .HasColumnType("TEXT");++ b.Property<int>("ReleaseYear")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Tag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Tag");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("ChapterTag");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("SeriesMetadatasId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("SeriesMetadataTag");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Progress")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Ratings")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany("Chapters")+ .HasForeignKey("GenreId");++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Navigation("Chapters");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Progress");++ b.Navigation("Ratings");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20211217013734_BookmarkRefactor.cs b/API/Data/Migrations/20211217013734_BookmarkRefactor.csnew file mode 100644index 000000000..7ac831e07--- /dev/null+++ b/API/Data/Migrations/20211217013734_BookmarkRefactor.cs@@ -0,0 +1,25 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class BookmarkRefactor : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.AddColumn<string>(+ name: "FileName",+ table: "AppUserBookmark",+ type: "TEXT",+ nullable: true);+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropColumn(+ name: "FileName",+ table: "AppUserBookmark");+ }+ }+}diff --git a/API/Data/Migrations/20211217180457_filteringChanges.Designer.cs b/API/Data/Migrations/20211217180457_filteringChanges.Designer.csnew file mode 100644index 000000000..39377a6c3--- /dev/null+++ b/API/Data/Migrations/20211217180457_filteringChanges.Designer.cs@@ -0,0 +1,1314 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20211217180457_filteringChanges")]+ partial class filteringChanges+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int?>("GenreId")+ .HasColumnType("INTEGER");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<DateTime>("ReleaseDate")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("GenreId");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<string>("Language")+ .HasColumnType("TEXT");++ b.Property<int>("ReleaseYear")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Tag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Tag");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("ChapterTag");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("SeriesMetadatasId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("SeriesMetadataTag");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Progress")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Ratings")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany("Chapters")+ .HasForeignKey("GenreId");++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Navigation("Chapters");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Progress");++ b.Navigation("Ratings");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20211217180457_filteringChanges.cs b/API/Data/Migrations/20211217180457_filteringChanges.csnew file mode 100644index 000000000..28c4d00b3--- /dev/null+++ b/API/Data/Migrations/20211217180457_filteringChanges.cs@@ -0,0 +1,155 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class filteringChanges : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.AddColumn<string>(+ name: "Language",+ table: "SeriesMetadata",+ type: "TEXT",+ nullable: true);++ migrationBuilder.CreateTable(+ name: "Tag",+ columns: table => new+ {+ Id = table.Column<int>(type: "INTEGER", nullable: false)+ .Annotation("Sqlite:Autoincrement", true),+ Title = table.Column<string>(type: "TEXT", nullable: true),+ NormalizedTitle = table.Column<string>(type: "TEXT", nullable: true),+ ExternalTag = table.Column<bool>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_Tag", x => x.Id);+ });++ migrationBuilder.CreateTable(+ name: "ChapterTag",+ columns: table => new+ {+ ChaptersId = table.Column<int>(type: "INTEGER", nullable: false),+ TagsId = table.Column<int>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_ChapterTag", x => new { x.ChaptersId, x.TagsId });+ table.ForeignKey(+ name: "FK_ChapterTag_Chapter_ChaptersId",+ column: x => x.ChaptersId,+ principalTable: "Chapter",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ table.ForeignKey(+ name: "FK_ChapterTag_Tag_TagsId",+ column: x => x.TagsId,+ principalTable: "Tag",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateTable(+ name: "SeriesMetadataTag",+ columns: table => new+ {+ SeriesMetadatasId = table.Column<int>(type: "INTEGER", nullable: false),+ TagsId = table.Column<int>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_SeriesMetadataTag", x => new { x.SeriesMetadatasId, x.TagsId });+ table.ForeignKey(+ name: "FK_SeriesMetadataTag_SeriesMetadata_SeriesMetadatasId",+ column: x => x.SeriesMetadatasId,+ principalTable: "SeriesMetadata",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ table.ForeignKey(+ name: "FK_SeriesMetadataTag_Tag_TagsId",+ column: x => x.TagsId,+ principalTable: "Tag",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateIndex(+ name: "IX_AppUserRating_SeriesId",+ table: "AppUserRating",+ column: "SeriesId");++ migrationBuilder.CreateIndex(+ name: "IX_AppUserProgresses_SeriesId",+ table: "AppUserProgresses",+ column: "SeriesId");++ migrationBuilder.CreateIndex(+ name: "IX_ChapterTag_TagsId",+ table: "ChapterTag",+ column: "TagsId");++ migrationBuilder.CreateIndex(+ name: "IX_SeriesMetadataTag_TagsId",+ table: "SeriesMetadataTag",+ column: "TagsId");++ migrationBuilder.CreateIndex(+ name: "IX_Tag_NormalizedTitle_ExternalTag",+ table: "Tag",+ columns: new[] { "NormalizedTitle", "ExternalTag" },+ unique: true);++ migrationBuilder.AddForeignKey(+ name: "FK_AppUserProgresses_Series_SeriesId",+ table: "AppUserProgresses",+ column: "SeriesId",+ principalTable: "Series",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);++ migrationBuilder.AddForeignKey(+ name: "FK_AppUserRating_Series_SeriesId",+ table: "AppUserRating",+ column: "SeriesId",+ principalTable: "Series",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropForeignKey(+ name: "FK_AppUserProgresses_Series_SeriesId",+ table: "AppUserProgresses");++ migrationBuilder.DropForeignKey(+ name: "FK_AppUserRating_Series_SeriesId",+ table: "AppUserRating");++ migrationBuilder.DropTable(+ name: "ChapterTag");++ migrationBuilder.DropTable(+ name: "SeriesMetadataTag");++ migrationBuilder.DropTable(+ name: "Tag");++ migrationBuilder.DropIndex(+ name: "IX_AppUserRating_SeriesId",+ table: "AppUserRating");++ migrationBuilder.DropIndex(+ name: "IX_AppUserProgresses_SeriesId",+ table: "AppUserProgresses");++ migrationBuilder.DropColumn(+ name: "Language",+ table: "SeriesMetadata");+ }+ }+}diff --git a/API/Data/Migrations/20211227180752_FullscreenPref.Designer.cs b/API/Data/Migrations/20211227180752_FullscreenPref.Designer.csnew file mode 100644index 000000000..b649b12b6--- /dev/null+++ b/API/Data/Migrations/20211227180752_FullscreenPref.Designer.cs@@ -0,0 +1,1317 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20211227180752_FullscreenPref")]+ partial class FullscreenPref+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("FullscreenMode")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int?>("GenreId")+ .HasColumnType("INTEGER");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<DateTime>("ReleaseDate")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("GenreId");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<string>("Language")+ .HasColumnType("TEXT");++ b.Property<int>("ReleaseYear")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Tag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Tag");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("ChapterTag");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("SeriesMetadatasId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("SeriesMetadataTag");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Progress")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Ratings")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany("Chapters")+ .HasForeignKey("GenreId");++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Navigation("Chapters");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Progress");++ b.Navigation("Ratings");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20211227180752_FullscreenPref.cs b/API/Data/Migrations/20211227180752_FullscreenPref.csnew file mode 100644index 000000000..ab6cbc8a8--- /dev/null+++ b/API/Data/Migrations/20211227180752_FullscreenPref.cs@@ -0,0 +1,26 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class FullscreenPref : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.AddColumn<int>(+ name: "FullscreenMode",+ table: "AppUserPreferences",+ type: "INTEGER",+ nullable: false,+ defaultValue: 0);+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropColumn(+ name: "FullscreenMode",+ table: "AppUserPreferences");+ }+ }+}diff --git a/API/Data/Migrations/20220107232822_ChapterMetadataOptimization.Designer.cs b/API/Data/Migrations/20220107232822_ChapterMetadataOptimization.Designer.csnew file mode 100644index 000000000..9df425dbd--- /dev/null+++ b/API/Data/Migrations/20220107232822_ChapterMetadataOptimization.Designer.cs@@ -0,0 +1,1339 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20220107232822_ChapterMetadataOptimization")]+ partial class ChapterMetadataOptimization+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FileName")+ .HasColumnType("TEXT");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<string>("Language")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<DateTime>("ReleaseDate")+ .HasColumnType("TEXT");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<string>("Language")+ .HasColumnType("TEXT");++ b.Property<int>("ReleaseYear")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Tag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Tag");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterGenre", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "GenresId");++ b.HasIndex("GenresId");++ b.ToTable("ChapterGenre");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("ChapterTag");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("SeriesMetadatasId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("SeriesMetadataTag");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Progress")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Ratings")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterGenre", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Progress");++ b.Navigation("Ratings");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20220107232822_ChapterMetadataOptimization.cs b/API/Data/Migrations/20220107232822_ChapterMetadataOptimization.csnew file mode 100644index 000000000..28e874f03--- /dev/null+++ b/API/Data/Migrations/20220107232822_ChapterMetadataOptimization.cs@@ -0,0 +1,108 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class ChapterMetadataOptimization : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropForeignKey(+ name: "FK_Chapter_Genre_GenreId",+ table: "Chapter");++ migrationBuilder.DropIndex(+ name: "IX_Chapter_GenreId",+ table: "Chapter");++ migrationBuilder.DropColumn(+ name: "GenreId",+ table: "Chapter");++ migrationBuilder.DropColumn(+ name: "FullscreenMode",+ table: "AppUserPreferences");++ migrationBuilder.AddColumn<string>(+ name: "Language",+ table: "Chapter",+ type: "TEXT",+ nullable: true);++ migrationBuilder.AddColumn<string>(+ name: "Summary",+ table: "Chapter",+ type: "TEXT",+ nullable: true);++ migrationBuilder.CreateTable(+ name: "ChapterGenre",+ columns: table => new+ {+ ChaptersId = table.Column<int>(type: "INTEGER", nullable: false),+ GenresId = table.Column<int>(type: "INTEGER", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_ChapterGenre", x => new { x.ChaptersId, x.GenresId });+ table.ForeignKey(+ name: "FK_ChapterGenre_Chapter_ChaptersId",+ column: x => x.ChaptersId,+ principalTable: "Chapter",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ table.ForeignKey(+ name: "FK_ChapterGenre_Genre_GenresId",+ column: x => x.GenresId,+ principalTable: "Genre",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateIndex(+ name: "IX_ChapterGenre_GenresId",+ table: "ChapterGenre",+ column: "GenresId");+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropTable(+ name: "ChapterGenre");++ migrationBuilder.DropColumn(+ name: "Language",+ table: "Chapter");++ migrationBuilder.DropColumn(+ name: "Summary",+ table: "Chapter");++ migrationBuilder.AddColumn<int>(+ name: "GenreId",+ table: "Chapter",+ type: "INTEGER",+ nullable: true);++ migrationBuilder.AddColumn<int>(+ name: "FullscreenMode",+ table: "AppUserPreferences",+ type: "INTEGER",+ nullable: false,+ defaultValue: 0);++ migrationBuilder.CreateIndex(+ name: "IX_Chapter_GenreId",+ table: "Chapter",+ column: "GenreId");++ migrationBuilder.AddForeignKey(+ name: "FK_Chapter_Genre_GenreId",+ table: "Chapter",+ column: "GenreId",+ principalTable: "Genre",+ principalColumn: "Id");+ }+ }+}diff --git a/API/Data/Migrations/20220108200822_CountMetadata.Designer.cs b/API/Data/Migrations/20220108200822_CountMetadata.Designer.csnew file mode 100644index 000000000..1866b6e58--- /dev/null+++ b/API/Data/Migrations/20220108200822_CountMetadata.Designer.cs@@ -0,0 +1,1345 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20220108200822_CountMetadata")]+ partial class CountMetadata+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FileName")+ .HasColumnType("TEXT");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<int>("Count")+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<string>("Language")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<DateTime>("ReleaseDate")+ .HasColumnType("TEXT");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<int>("Count")+ .HasColumnType("INTEGER");++ b.Property<string>("Language")+ .HasColumnType("TEXT");++ b.Property<int>("ReleaseYear")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Tag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Tag");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterGenre", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "GenresId");++ b.HasIndex("GenresId");++ b.ToTable("ChapterGenre");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("ChapterTag");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("SeriesMetadatasId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("SeriesMetadataTag");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Progress")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Ratings")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterGenre", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Progress");++ b.Navigation("Ratings");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20220108200822_CountMetadata.cs b/API/Data/Migrations/20220108200822_CountMetadata.csnew file mode 100644index 000000000..98a7f7e11--- /dev/null+++ b/API/Data/Migrations/20220108200822_CountMetadata.cs@@ -0,0 +1,37 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class CountMetadata : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.AddColumn<int>(+ name: "Count",+ table: "SeriesMetadata",+ type: "INTEGER",+ nullable: false,+ defaultValue: 0);++ migrationBuilder.AddColumn<int>(+ name: "Count",+ table: "Chapter",+ type: "INTEGER",+ nullable: false,+ defaultValue: 0);+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropColumn(+ name: "Count",+ table: "SeriesMetadata");++ migrationBuilder.DropColumn(+ name: "Count",+ table: "Chapter");+ }+ }+}diff --git a/API/Data/Migrations/20220108202027_PublicationStatus.Designer.cs b/API/Data/Migrations/20220108202027_PublicationStatus.Designer.csnew file mode 100644index 000000000..8479775bf--- /dev/null+++ b/API/Data/Migrations/20220108202027_PublicationStatus.Designer.cs@@ -0,0 +1,1351 @@+// <auto-generated />+using System;+using API.Data;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace API.Data.Migrations+{+ [DbContext(typeof(DataContext))]+ [Migration("20220108202027_PublicationStatus")]+ partial class PublicationStatus+ {+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedName")+ .IsUnique()+ .HasDatabaseName("RoleNameIndex");++ b.ToTable("AspNetRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ApiKey")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .IsConcurrencyToken()+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastActive")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasMaxLength(256)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedEmail")+ .HasDatabaseName("EmailIndex");++ b.HasIndex("NormalizedUserName")+ .IsUnique()+ .HasDatabaseName("UserNameIndex");++ b.ToTable("AspNetUsers", (string)null);+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FileName")+ .HasColumnType("TEXT");++ b.Property<int>("Page")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("AppUserBookmark");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<bool>("AutoCloseMenu")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderDarkMode")+ .HasColumnType("INTEGER");++ b.Property<string>("BookReaderFontFamily")+ .HasColumnType("TEXT");++ b.Property<int>("BookReaderFontSize")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderLineSpacing")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderMargin")+ .HasColumnType("INTEGER");++ b.Property<int>("BookReaderReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<bool>("BookReaderTapToPaginate")+ .HasColumnType("INTEGER");++ b.Property<int>("PageSplitOption")+ .HasColumnType("INTEGER");++ b.Property<int>("ReaderMode")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingDirection")+ .HasColumnType("INTEGER");++ b.Property<int>("ScalingOption")+ .HasColumnType("INTEGER");++ b.Property<bool>("SiteDarkMode")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId")+ .IsUnique();++ b.ToTable("AppUserPreferences");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<string>("BookScrollId")+ .HasColumnType("TEXT");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("PagesRead")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserProgresses");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<int>("Rating")+ .HasColumnType("INTEGER");++ b.Property<string>("Review")+ .HasColumnType("TEXT");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.HasIndex("SeriesId");++ b.ToTable("AppUserRating");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("UserId", "RoleId");++ b.HasIndex("RoleId");++ b.ToTable("AspNetUserRoles", (string)null);+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<int>("Count")+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<bool>("IsSpecial")+ .HasColumnType("INTEGER");++ b.Property<string>("Language")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Number")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("Range")+ .HasColumnType("TEXT");++ b.Property<DateTime>("ReleaseDate")+ .HasColumnType("TEXT");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("TotalCount")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("VolumeId");++ b.ToTable("Chapter");+ });++ modelBuilder.Entity("API.Entities.CollectionTag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Id", "Promoted")+ .IsUnique();++ b.ToTable("CollectionTag");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("Path")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.ToTable("FolderPath");+ });++ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Genre");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastScanned")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<string>("FilePath")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.ToTable("MangaFile");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<int>("Count")+ .HasColumnType("INTEGER");++ b.Property<string>("Language")+ .HasColumnType("TEXT");++ b.Property<int>("PublicationStatus")+ .HasColumnType("INTEGER");++ b.Property<int>("ReleaseYear")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AppUserId")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<bool>("Promoted")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("AppUserId");++ b.ToTable("ReadingList");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("ChapterId")+ .HasColumnType("INTEGER");++ b.Property<int>("Order")+ .HasColumnType("INTEGER");++ b.Property<int>("ReadingListId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<int>("VolumeId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("ChapterId");++ b.HasIndex("ReadingListId");++ b.HasIndex("SeriesId");++ b.HasIndex("VolumeId");++ b.ToTable("ReadingListItem");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<bool>("CoverImageLocked")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<int>("Format")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<int>("LibraryId")+ .HasColumnType("INTEGER");++ b.Property<string>("LocalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<string>("OriginalName")+ .HasColumnType("TEXT");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<string>("SortName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("LibraryId");++ b.HasIndex("Name", "NormalizedName", "LocalizedName", "LibraryId", "Format")+ .IsUnique();++ b.ToTable("Series");+ });++ modelBuilder.Entity("API.Entities.ServerSetting", b =>+ {+ b.Property<int>("Key")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSetting");+ });++ modelBuilder.Entity("API.Entities.Tag", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Tag");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CoverImage")+ .HasColumnType("TEXT");++ b.Property<DateTime>("Created")+ .HasColumnType("TEXT");++ b.Property<DateTime>("LastModified")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<int>("Number")+ .HasColumnType("INTEGER");++ b.Property<int>("Pages")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("SeriesId");++ b.ToTable("Volume");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.Property<int>("AppUsersId")+ .HasColumnType("INTEGER");++ b.Property<int>("LibrariesId")+ .HasColumnType("INTEGER");++ b.HasKey("AppUsersId", "LibrariesId");++ b.HasIndex("LibrariesId");++ b.ToTable("AppUserLibrary");+ });++ modelBuilder.Entity("ChapterGenre", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "GenresId");++ b.HasIndex("GenresId");++ b.ToTable("ChapterGenre");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("ChapterTag");+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.Property<int>("CollectionTagsId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("CollectionTagsId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("CollectionTagSeriesMetadata");+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("RoleId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("RoleId");++ b.ToTable("AspNetRoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.HasKey("LoginProvider", "ProviderKey");++ b.HasIndex("UserId");++ b.ToTable("AspNetUserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.Property<int>("UserId")+ .HasColumnType("INTEGER");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("SeriesMetadatasId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("SeriesMetadataTag");+ });++ modelBuilder.Entity("API.Entities.AppUserBookmark", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Bookmarks")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithOne("UserPreferences")+ .HasForeignKey("API.Entities.AppUserPreferences", "AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserProgress", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Progresses")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Progress")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRating", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("Ratings")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", null)+ .WithMany("Ratings")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.AppUserRole", b =>+ {+ b.HasOne("API.Entities.AppRole", "Role")+ .WithMany("UserRoles")+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.AppUser", "User")+ .WithMany("UserRoles")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Role");++ b.Navigation("User");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany("Chapters")+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.FolderPath", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Folders")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.MangaFile", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany("Files")+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");+ });++ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.HasOne("API.Entities.AppUser", "AppUser")+ .WithMany("ReadingLists")+ .HasForeignKey("AppUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("AppUser");+ });++ modelBuilder.Entity("API.Entities.ReadingListItem", b =>+ {+ b.HasOne("API.Entities.Chapter", "Chapter")+ .WithMany()+ .HasForeignKey("ChapterId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.ReadingList", "ReadingList")+ .WithMany("Items")+ .HasForeignKey("ReadingListId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Series", "Series")+ .WithMany()+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Volume", "Volume")+ .WithMany()+ .HasForeignKey("VolumeId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Chapter");++ b.Navigation("ReadingList");++ b.Navigation("Series");++ b.Navigation("Volume");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.HasOne("API.Entities.Library", "Library")+ .WithMany("Series")+ .HasForeignKey("LibraryId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Library");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithMany("Volumes")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });++ modelBuilder.Entity("AppUserLibrary", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("AppUsersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Library", null)+ .WithMany()+ .HasForeignKey("LibrariesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterGenre", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("CollectionTagSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.CollectionTag", null)+ .WithMany()+ .HasForeignKey("CollectionTagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppRole", null)+ .WithMany()+ .HasForeignKey("RoleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>+ {+ b.HasOne("API.Entities.AppUser", null)+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("API.Entities.AppRole", b =>+ {+ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.AppUser", b =>+ {+ b.Navigation("Bookmarks");++ b.Navigation("Progresses");++ b.Navigation("Ratings");++ b.Navigation("ReadingLists");++ b.Navigation("UserPreferences");++ b.Navigation("UserRoles");+ });++ modelBuilder.Entity("API.Entities.Chapter", b =>+ {+ b.Navigation("Files");+ });++ modelBuilder.Entity("API.Entities.Library", b =>+ {+ b.Navigation("Folders");++ b.Navigation("Series");+ });++ modelBuilder.Entity("API.Entities.ReadingList", b =>+ {+ b.Navigation("Items");+ });++ modelBuilder.Entity("API.Entities.Series", b =>+ {+ b.Navigation("Metadata");++ b.Navigation("Progress");++ b.Navigation("Ratings");++ b.Navigation("Volumes");+ });++ modelBuilder.Entity("API.Entities.Volume", b =>+ {+ b.Navigation("Chapters");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/API/Data/Migrations/20220108202027_PublicationStatus.cs b/API/Data/Migrations/20220108202027_PublicationStatus.csnew file mode 100644index 000000000..a8d676ed0--- /dev/null+++ b/API/Data/Migrations/20220108202027_PublicationStatus.cs@@ -0,0 +1,37 @@+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace API.Data.Migrations+{+ public partial class PublicationStatus : Migration+ {+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.AddColumn<int>(+ name: "PublicationStatus",+ table: "SeriesMetadata",+ type: "INTEGER",+ nullable: false,+ defaultValue: 0);++ migrationBuilder.AddColumn<int>(+ name: "TotalCount",+ table: "Chapter",+ type: "INTEGER",+ nullable: false,+ defaultValue: 0);+ }++ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropColumn(+ name: "PublicationStatus",+ table: "SeriesMetadata");++ migrationBuilder.DropColumn(+ name: "TotalCount",+ table: "Chapter");+ }+ }+}diff --git a/API/Data/Migrations/DataContextModelSnapshot.cs b/API/Data/Migrations/DataContextModelSnapshot.csindex 21a9d930a..c0aefbcd2 100644--- a/API/Data/Migrations/DataContextModelSnapshot.cs+++ b/API/Data/Migrations/DataContextModelSnapshot.cs@@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore;using Microsoft.EntityFrameworkCore.Infrastructure;using Microsoft.EntityFrameworkCore.Storage.ValueConversion;+#nullable disable+namespace API.Data.Migrations{[DbContext(typeof(DataContext))]@@ -13,8 +15,7 @@ namespace API.Data.Migrationsprotected override void BuildModel(ModelBuilder modelBuilder){#pragma warning disable 612, 618- modelBuilder- .HasAnnotation("ProductVersion", "5.0.8");+ modelBuilder.HasAnnotation("ProductVersion", "6.0.0");modelBuilder.Entity("API.Entities.AppRole", b =>{@@ -40,7 +41,7 @@ namespace API.Data.Migrations.IsUnique().HasDatabaseName("RoleNameIndex");- b.ToTable("AspNetRoles");+ b.ToTable("AspNetRoles", (string)null);});modelBuilder.Entity("API.Entities.AppUser", b =>@@ -118,7 +119,7 @@ namespace API.Data.Migrations.IsUnique().HasDatabaseName("UserNameIndex");- b.ToTable("AspNetUsers");+ b.ToTable("AspNetUsers", (string)null);});modelBuilder.Entity("API.Entities.AppUserBookmark", b =>@@ -133,6 +134,9 @@ namespace API.Data.Migrationsb.Property<int>("ChapterId").HasColumnType("INTEGER");+ b.Property<string>("FileName")+ .HasColumnType("TEXT");+b.Property<int>("Page").HasColumnType("INTEGER");@@ -239,6 +243,8 @@ namespace API.Data.Migrationsb.HasIndex("AppUserId");+ b.HasIndex("SeriesId");+b.ToTable("AppUserProgresses");});@@ -264,6 +270,8 @@ namespace API.Data.Migrationsb.HasIndex("AppUserId");+ b.HasIndex("SeriesId");+b.ToTable("AppUserRating");});@@ -279,7 +287,7 @@ namespace API.Data.Migrationsb.HasIndex("RoleId");- b.ToTable("AspNetUserRoles");+ b.ToTable("AspNetUserRoles", (string)null);});modelBuilder.Entity("API.Entities.Chapter", b =>@@ -288,6 +296,12 @@ namespace API.Data.Migrations.ValueGeneratedOnAdd().HasColumnType("INTEGER");+ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<int>("Count")+ .HasColumnType("INTEGER");+b.Property<string>("CoverImage").HasColumnType("TEXT");@@ -300,6 +314,9 @@ namespace API.Data.Migrationsb.Property<bool>("IsSpecial").HasColumnType("INTEGER");+ b.Property<string>("Language")+ .HasColumnType("TEXT");+b.Property<DateTime>("LastModified").HasColumnType("TEXT");@@ -312,9 +329,21 @@ namespace API.Data.Migrationsb.Property<string>("Range").HasColumnType("TEXT");+ b.Property<DateTime>("ReleaseDate")+ .HasColumnType("TEXT");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");+b.Property<string>("Title").HasColumnType("TEXT");+ b.Property<string>("TitleName")+ .HasColumnType("TEXT");++ b.Property<int>("TotalCount")+ .HasColumnType("INTEGER");+b.Property<int>("VolumeId").HasColumnType("INTEGER");@@ -382,6 +411,29 @@ namespace API.Data.Migrationsb.ToTable("FolderPath");});+ modelBuilder.Entity("API.Entities.Genre", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<bool>("ExternalTag")+ .HasColumnType("INTEGER");++ b.Property<string>("NormalizedTitle")+ .HasColumnType("TEXT");++ b.Property<string>("Title")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Genre");+ });+modelBuilder.Entity("API.Entities.Library", b =>{b.Property<int>("Id")@@ -439,6 +491,68 @@ namespace API.Data.Migrationsb.ToTable("MangaFile");});+ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<int>("AgeRating")+ .HasColumnType("INTEGER");++ b.Property<int>("Count")+ .HasColumnType("INTEGER");++ b.Property<string>("Language")+ .HasColumnType("TEXT");++ b.Property<int>("PublicationStatus")+ .HasColumnType("INTEGER");++ b.Property<int>("ReleaseYear")+ .HasColumnType("INTEGER");++ b.Property<uint>("RowVersion")+ .IsConcurrencyToken()+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesId")+ .HasColumnType("INTEGER");++ b.Property<string>("Summary")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("SeriesId")+ .IsUnique();++ b.HasIndex("Id", "SeriesId")+ .IsUnique();++ b.ToTable("SeriesMetadata");+ });++ modelBuilder.Entity("API.Entities.Person", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.Property<int>("Role")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.ToTable("Person");+ });+modelBuilder.Entity("API.Entities.ReadingList", b =>{b.Property<int>("Id")@@ -546,9 +660,6 @@ namespace API.Data.Migrationsb.Property<string>("SortName").HasColumnType("TEXT");- b.Property<string>("Summary")- .HasColumnType("TEXT");-b.HasKey("Id");b.HasIndex("LibraryId");@@ -559,45 +670,44 @@ namespace API.Data.Migrationsb.ToTable("Series");});- modelBuilder.Entity("API.Entities.SeriesMetadata", b =>+ modelBuilder.Entity("API.Entities.ServerSetting", b =>{- b.Property<int>("Id")- .ValueGeneratedOnAdd()+ b.Property<int>("Key").HasColumnType("INTEGER");b.Property<uint>("RowVersion").IsConcurrencyToken().HasColumnType("INTEGER");- b.Property<int>("SeriesId")- .HasColumnType("INTEGER");-- b.HasKey("Id");-- b.HasIndex("SeriesId")- .IsUnique();+ b.Property<string>("Value")+ .HasColumnType("TEXT");- b.HasIndex("Id", "SeriesId")- .IsUnique();+ b.HasKey("Key");- b.ToTable("SeriesMetadata");+ b.ToTable("ServerSetting");});- modelBuilder.Entity("API.Entities.ServerSetting", b =>+ modelBuilder.Entity("API.Entities.Tag", b =>{- b.Property<int>("Key")+ b.Property<int>("Id")+ .ValueGeneratedOnAdd().HasColumnType("INTEGER");- b.Property<uint>("RowVersion")- .IsConcurrencyToken()+ b.Property<bool>("ExternalTag").HasColumnType("INTEGER");- b.Property<string>("Value")+ b.Property<string>("NormalizedTitle").HasColumnType("TEXT");- b.HasKey("Key");+ b.Property<string>("Title")+ .HasColumnType("TEXT");- b.ToTable("ServerSetting");+ b.HasKey("Id");++ b.HasIndex("NormalizedTitle", "ExternalTag")+ .IsUnique();++ b.ToTable("Tag");});modelBuilder.Entity("API.Entities.Volume", b =>@@ -649,6 +759,51 @@ namespace API.Data.Migrationsb.ToTable("AppUserLibrary");});+ modelBuilder.Entity("ChapterGenre", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "GenresId");++ b.HasIndex("GenresId");++ b.ToTable("ChapterGenre");+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.Property<int>("ChapterMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.HasKey("ChapterMetadatasId", "PeopleId");++ b.HasIndex("PeopleId");++ b.ToTable("ChapterPerson");+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.Property<int>("ChaptersId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("ChaptersId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("ChapterTag");+ });+modelBuilder.Entity("CollectionTagSeriesMetadata", b =>{b.Property<int>("CollectionTagsId")@@ -664,6 +819,21 @@ namespace API.Data.Migrationsb.ToTable("CollectionTagSeriesMetadata");});+ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.Property<int>("GenresId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("GenresId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("GenreSeriesMetadata");+ });+modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>{b.Property<int>("Id")@@ -683,7 +853,7 @@ namespace API.Data.Migrationsb.HasIndex("RoleId");- b.ToTable("AspNetRoleClaims");+ b.ToTable("AspNetRoleClaims", (string)null);});modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>@@ -705,7 +875,7 @@ namespace API.Data.Migrationsb.HasIndex("UserId");- b.ToTable("AspNetUserClaims");+ b.ToTable("AspNetUserClaims", (string)null);});modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>@@ -726,7 +896,7 @@ namespace API.Data.Migrationsb.HasIndex("UserId");- b.ToTable("AspNetUserLogins");+ b.ToTable("AspNetUserLogins", (string)null);});modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>@@ -745,7 +915,37 @@ namespace API.Data.Migrationsb.HasKey("UserId", "LoginProvider", "Name");- b.ToTable("AspNetUserTokens");+ b.ToTable("AspNetUserTokens", (string)null);+ });++ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.Property<int>("PeopleId")+ .HasColumnType("INTEGER");++ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.HasKey("PeopleId", "SeriesMetadatasId");++ b.HasIndex("SeriesMetadatasId");++ b.ToTable("PersonSeriesMetadata");+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.Property<int>("SeriesMetadatasId")+ .HasColumnType("INTEGER");++ b.Property<int>("TagsId")+ .HasColumnType("INTEGER");++ b.HasKey("SeriesMetadatasId", "TagsId");++ b.HasIndex("TagsId");++ b.ToTable("SeriesMetadataTag");});modelBuilder.Entity("API.Entities.AppUserBookmark", b =>@@ -778,6 +978,12 @@ namespace API.Data.Migrations.OnDelete(DeleteBehavior.Cascade).IsRequired();+ b.HasOne("API.Entities.Series", null)+ .WithMany("Progress")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+b.Navigation("AppUser");});@@ -789,6 +995,12 @@ namespace API.Data.Migrations.OnDelete(DeleteBehavior.Cascade).IsRequired();+ b.HasOne("API.Entities.Series", null)+ .WithMany("Ratings")+ .HasForeignKey("SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+b.Navigation("AppUser");});@@ -844,6 +1056,17 @@ namespace API.Data.Migrationsb.Navigation("Chapter");});+ modelBuilder.Entity("API.Entities.Metadata.SeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Series", "Series")+ .WithOne("Metadata")+ .HasForeignKey("API.Entities.Metadata.SeriesMetadata", "SeriesId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Series");+ });+modelBuilder.Entity("API.Entities.ReadingList", b =>{b.HasOne("API.Entities.AppUser", "AppUser")@@ -901,17 +1124,6 @@ namespace API.Data.Migrationsb.Navigation("Library");});- modelBuilder.Entity("API.Entities.SeriesMetadata", b =>- {- b.HasOne("API.Entities.Series", "Series")- .WithOne("Metadata")- .HasForeignKey("API.Entities.SeriesMetadata", "SeriesId")- .OnDelete(DeleteBehavior.Cascade)- .IsRequired();-- b.Navigation("Series");- });-modelBuilder.Entity("API.Entities.Volume", b =>{b.HasOne("API.Entities.Series", "Series")@@ -938,6 +1150,51 @@ namespace API.Data.Migrations.IsRequired();});+ modelBuilder.Entity("ChapterGenre", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterPerson", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChapterMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("ChapterTag", b =>+ {+ b.HasOne("API.Entities.Chapter", null)+ .WithMany()+ .HasForeignKey("ChaptersId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });+modelBuilder.Entity("CollectionTagSeriesMetadata", b =>{b.HasOne("API.Entities.CollectionTag", null)@@ -946,7 +1203,22 @@ namespace API.Data.Migrations.OnDelete(DeleteBehavior.Cascade).IsRequired();- b.HasOne("API.Entities.SeriesMetadata", null)+ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("GenreSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Genre", null)+ .WithMany()+ .HasForeignKey("GenresId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null).WithMany().HasForeignKey("SeriesMetadatasId").OnDelete(DeleteBehavior.Cascade)@@ -989,6 +1261,36 @@ namespace API.Data.Migrations.IsRequired();});+ modelBuilder.Entity("PersonSeriesMetadata", b =>+ {+ b.HasOne("API.Entities.Person", null)+ .WithMany()+ .HasForeignKey("PeopleId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });++ modelBuilder.Entity("SeriesMetadataTag", b =>+ {+ b.HasOne("API.Entities.Metadata.SeriesMetadata", null)+ .WithMany()+ .HasForeignKey("SeriesMetadatasId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("API.Entities.Tag", null)+ .WithMany()+ .HasForeignKey("TagsId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();+ });+modelBuilder.Entity("API.Entities.AppRole", b =>{b.Navigation("UserRoles");@@ -1030,6 +1332,10 @@ namespace API.Data.Migrations{b.Navigation("Metadata");+ b.Navigation("Progress");++ b.Navigation("Ratings");+b.Navigation("Volumes");});diff --git a/API/Data/Repositories/AppUserProgressRepository.cs b/API/Data/Repositories/AppUserProgressRepository.csindex c91e61cd0..37fc68693 100644--- a/API/Data/Repositories/AppUserProgressRepository.cs+++ b/API/Data/Repositories/AppUserProgressRepository.cs@@ -2,78 +2,84 @@using System.Threading.Tasks;using API.Entities;using API.Entities.Enums;-using API.Interfaces.Repositories;using Microsoft.EntityFrameworkCore;-namespace API.Data.Repositories+namespace API.Data.Repositories;++public interface IAppUserProgressRepository{- public class AppUserProgressRepository : IAppUserProgressRepository- {- private readonly DataContext _context;+ void Update(AppUserProgress userProgress);+ Task<int> CleanupAbandonedChapters();+ Task<bool> UserHasProgress(LibraryType libraryType, int userId);+ Task<AppUserProgress> GetUserProgressAsync(int chapterId, int userId);+}- public AppUserProgressRepository(DataContext context)- {- _context = context;- }+public class AppUserProgressRepository : IAppUserProgressRepository+{+ private readonly DataContext _context;++ public AppUserProgressRepository(DataContext context)+ {+ _context = context;+ }- public void Update(AppUserProgress userProgress)- {- _context.Entry(userProgress).State = EntityState.Modified;- }+ public void Update(AppUserProgress userProgress)+ {+ _context.Entry(userProgress).State = EntityState.Modified;+ }- /// <summary>- /// This will remove any entries that have chapterIds that no longer exists. This will execute the save as well.- /// </summary>- public async Task<int> CleanupAbandonedChapters()- {- var chapterIds = _context.Chapter.Select(c => c.Id);+ /// <summary>+ /// This will remove any entries that have chapterIds that no longer exists. This will execute the save as well.+ /// </summary>+ public async Task<int> CleanupAbandonedChapters()+ {+ var chapterIds = _context.Chapter.Select(c => c.Id);- var rowsToRemove = await _context.AppUserProgresses- .Where(progress => !chapterIds.Contains(progress.ChapterId))- .ToListAsync();+ var rowsToRemove = await _context.AppUserProgresses+ .Where(progress => !chapterIds.Contains(progress.ChapterId))+ .ToListAsync();- var rowsToRemoveBookmarks = await _context.AppUserBookmark- .Where(progress => !chapterIds.Contains(progress.ChapterId))- .ToListAsync();+ var rowsToRemoveBookmarks = await _context.AppUserBookmark+ .Where(progress => !chapterIds.Contains(progress.ChapterId))+ .ToListAsync();- var rowsToRemoveReadingLists = await _context.ReadingListItem- .Where(item => !chapterIds.Contains(item.ChapterId))- .ToListAsync();+ var rowsToRemoveReadingLists = await _context.ReadingListItem+ .Where(item => !chapterIds.Contains(item.ChapterId))+ .ToListAsync();- _context.RemoveRange(rowsToRemove);- _context.RemoveRange(rowsToRemoveBookmarks);- _context.RemoveRange(rowsToRemoveReadingLists);- return await _context.SaveChangesAsync() > 0 ? rowsToRemove.Count : 0;- }+ _context.RemoveRange(rowsToRemove);+ _context.RemoveRange(rowsToRemoveBookmarks);+ _context.RemoveRange(rowsToRemoveReadingLists);+ return await _context.SaveChangesAsync() > 0 ? rowsToRemove.Count : 0;+ }- /// <summary>- /// Checks if user has any progress against a library of passed type- /// </summary>- /// <param name="libraryType"></param>- /// <param name="userId"></param>- /// <returns></returns>- public async Task<bool> UserHasProgress(LibraryType libraryType, int userId)- {- var seriesIds = await _context.AppUserProgresses- .Where(aup => aup.PagesRead > 0 && aup.AppUserId == userId)- .AsNoTracking()- .Select(aup => aup.SeriesId)- .ToListAsync();+ /// <summary>+ /// Checks if user has any progress against a library of passed type+ /// </summary>+ /// <param name="libraryType"></param>+ /// <param name="userId"></param>+ /// <returns></returns>+ public async Task<bool> UserHasProgress(LibraryType libraryType, int userId)+ {+ var seriesIds = await _context.AppUserProgresses+ .Where(aup => aup.PagesRead > 0 && aup.AppUserId == userId)+ .AsNoTracking()+ .Select(aup => aup.SeriesId)+ .ToListAsync();- if (seriesIds.Count == 0) return false;+ if (seriesIds.Count == 0) return false;- return await _context.Series- .Include(s => s.Library)- .Where(s => seriesIds.Contains(s.Id) && s.Library.Type == libraryType)- .AsNoTracking()- .AnyAsync();- }+ return await _context.Series+ .Include(s => s.Library)+ .Where(s => seriesIds.Contains(s.Id) && s.Library.Type == libraryType)+ .AsNoTracking()+ .AnyAsync();+ }- public async Task<AppUserProgress> GetUserProgressAsync(int chapterId, int userId)- {- return await _context.AppUserProgresses- .Where(p => p.ChapterId == chapterId && p.AppUserId == userId)- .FirstOrDefaultAsync();- }+ public async Task<AppUserProgress> GetUserProgressAsync(int chapterId, int userId)+ {+ return await _context.AppUserProgresses+ .Where(p => p.ChapterId == chapterId && p.AppUserId == userId)+ .FirstOrDefaultAsync();}}diff --git a/API/Data/Repositories/ChapterRepository.cs b/API/Data/Repositories/ChapterRepository.csindex 54c808d9c..f89304f74 100644--- a/API/Data/Repositories/ChapterRepository.cs+++ b/API/Data/Repositories/ChapterRepository.cs@@ -4,186 +4,205 @@ using System.Threading.Tasks;using API.DTOs;using API.DTOs.Reader;using API.Entities;-using API.Interfaces.Repositories;using AutoMapper;using AutoMapper.QueryableExtensions;using Microsoft.EntityFrameworkCore;-namespace API.Data.Repositories+namespace API.Data.Repositories;++public interface IChapterRepository+{+ void Update(Chapter chapter);+ Task<IEnumerable<Chapter>> GetChaptersByIdsAsync(IList<int> chapterIds);+ Task<IChapterInfoDto> GetChapterInfoDtoAsync(int chapterId);+ Task<int> GetChapterTotalPagesAsync(int chapterId);+ Task<Chapter> GetChapterAsync(int chapterId);+ Task<ChapterDto> GetChapterDtoAsync(int chapterId);+ Task<IList<MangaFile>> GetFilesForChapterAsync(int chapterId);+ Task<IList<Chapter>> GetChaptersAsync(int volumeId);+ Task<IList<MangaFile>> GetFilesForChaptersAsync(IReadOnlyList<int> chapterIds);+ Task<string> GetChapterCoverImageAsync(int chapterId);+ Task<IList<string>> GetAllCoverImagesAsync();+ Task<IEnumerable<string>> GetCoverImagesForLockedChaptersAsync();+}+public class ChapterRepository : IChapterRepository{- public class ChapterRepository : IChapterRepository+ private readonly DataContext _context;+ private readonly IMapper _mapper;++ public ChapterRepository(DataContext context, IMapper mapper)+ {+ _context = context;+ _mapper = mapper;+ }++ public void Update(Chapter chapter)+ {+ _context.Entry(chapter).State = EntityState.Modified;+ }++ public async Task<IEnumerable<Chapter>> GetChaptersByIdsAsync(IList<int> chapterIds)+ {+ return await _context.Chapter+ .Where(c => chapterIds.Contains(c.Id))+ .Include(c => c.Volume)+ .ToListAsync();+ }++ /// <summary>+ /// Populates a partial IChapterInfoDto+ /// </summary>+ /// <returns></returns>+ public async Task<IChapterInfoDto> GetChapterInfoDtoAsync(int chapterId)+ {+ var chapterInfo = await _context.Chapter+ .Where(c => c.Id == chapterId)+ .Join(_context.Volume, c => c.VolumeId, v => v.Id, (chapter, volume) => new+ {+ ChapterNumber = chapter.Range,+ VolumeNumber = volume.Number,+ VolumeId = volume.Id,+ chapter.IsSpecial,+ chapter.TitleName,+ volume.SeriesId,+ chapter.Pages,+ })+ .Join(_context.Series, data => data.SeriesId, series => series.Id, (data, series) => new+ {+ data.ChapterNumber,+ data.VolumeNumber,+ data.VolumeId,+ data.IsSpecial,+ data.SeriesId,+ data.Pages,+ data.TitleName,+ SeriesFormat = series.Format,+ SeriesName = series.Name,+ series.LibraryId+ })+ .Select(data => new ChapterInfoDto()+ {+ ChapterNumber = data.ChapterNumber,+ VolumeNumber = data.VolumeNumber + string.Empty,+ VolumeId = data.VolumeId,+ IsSpecial = data.IsSpecial,+ SeriesId =data.SeriesId,+ SeriesFormat = data.SeriesFormat,+ SeriesName = data.SeriesName,+ LibraryId = data.LibraryId,+ Pages = data.Pages,+ ChapterTitle = data.TitleName+ })+ .AsNoTracking()+ .AsSplitQuery()+ .SingleOrDefaultAsync();++ return chapterInfo;+ }++ public Task<int> GetChapterTotalPagesAsync(int chapterId)+ {+ return _context.Chapter+ .Where(c => c.Id == chapterId)+ .Select(c => c.Pages)+ .SingleOrDefaultAsync();+ }+ public async Task<ChapterDto> GetChapterDtoAsync(int chapterId)+ {+ var chapter = await _context.Chapter+ .Include(c => c.Files)+ .ProjectTo<ChapterDto>(_mapper.ConfigurationProvider)+ .AsNoTracking()+ .SingleOrDefaultAsync(c => c.Id == chapterId);++ return chapter;+ }++ /// <summary>+ /// Returns non-tracked files for a given chapterId+ /// </summary>+ /// <param name="chapterId"></param>+ /// <returns></returns>+ public async Task<IList<MangaFile>> GetFilesForChapterAsync(int chapterId)+ {+ return await _context.MangaFile+ .Where(c => chapterId == c.ChapterId)+ .AsNoTracking()+ .ToListAsync();+ }++ /// <summary>+ /// Returns a Chapter for an Id. Includes linked <see cref="MangaFile"/>s.+ /// </summary>+ /// <param name="chapterId"></param>+ /// <returns></returns>+ public async Task<Chapter> GetChapterAsync(int chapterId)+ {+ return await _context.Chapter+ .Include(c => c.Files)+ .SingleOrDefaultAsync(c => c.Id == chapterId);+ }++ /// <summary>+ /// Returns Chapters for a volume id.+ /// </summary>+ /// <param name="volumeId"></param>+ /// <returns></returns>+ public async Task<IList<Chapter>> GetChaptersAsync(int volumeId)+ {+ return await _context.Chapter+ .Where(c => c.VolumeId == volumeId)+ .ToListAsync();+ }++ /// <summary>+ /// Returns the cover image for a chapter id.+ /// </summary>+ /// <param name="chapterId"></param>+ /// <returns></returns>+ public async Task<string> GetChapterCoverImageAsync(int chapterId)+ {++ return await _context.Chapter+ .Where(c => c.Id == chapterId)+ .Select(c => c.CoverImage)+ .AsNoTracking()+ .SingleOrDefaultAsync();+ }++ public async Task<IList<string>> GetAllCoverImagesAsync()+ {+ return await _context.Chapter+ .Select(c => c.CoverImage)+ .Where(t => !string.IsNullOrEmpty(t))+ .AsNoTracking()+ .ToListAsync();+ }++ /// <summary>+ /// Returns cover images for locked chapters+ /// </summary>+ /// <returns></returns>+ public async Task<IEnumerable<string>> GetCoverImagesForLockedChaptersAsync()+ {+ return await _context.Chapter+ .Where(c => c.CoverImageLocked)+ .Select(c => c.CoverImage)+ .Where(t => !string.IsNullOrEmpty(t))+ .AsNoTracking()+ .ToListAsync();+ }++ /// <summary>+ /// Returns non-tracked files for a set of <paramref name="chapterIds"/>+ /// </summary>+ /// <param name="chapterIds">List of chapter Ids</param>+ /// <returns></returns>+ public async Task<IList<MangaFile>> GetFilesForChaptersAsync(IReadOnlyList<int> chapterIds){- private readonly DataContext _context;- private readonly IMapper _mapper;-- public ChapterRepository(DataContext context, IMapper mapper)- {- _context = context;- _mapper = mapper;- }-- public void Update(Chapter chapter)- {- _context.Entry(chapter).State = EntityState.Modified;- }-- public async Task<IEnumerable<Chapter>> GetChaptersByIdsAsync(IList<int> chapterIds)- {- return await _context.Chapter- .Where(c => chapterIds.Contains(c.Id))- .Include(c => c.Volume)- .ToListAsync();- }-- /// <summary>- /// Populates a partial IChapterInfoDto- /// </summary>- /// <returns></returns>- public async Task<IChapterInfoDto> GetChapterInfoDtoAsync(int chapterId)- {- return await _context.Chapter- .Where(c => c.Id == chapterId)- .Join(_context.Volume, c => c.VolumeId, v => v.Id, (chapter, volume) => new- {- ChapterNumber = chapter.Range,- VolumeNumber = volume.Number,- VolumeId = volume.Id,- chapter.IsSpecial,- volume.SeriesId,- chapter.Pages- })- .Join(_context.Series, data => data.SeriesId, series => series.Id, (data, series) => new- {- data.ChapterNumber,- data.VolumeNumber,- data.VolumeId,- data.IsSpecial,- data.SeriesId,- data.Pages,- SeriesFormat = series.Format,- SeriesName = series.Name,- series.LibraryId- })- .Select(data => new BookInfoDto()- {- ChapterNumber = data.ChapterNumber,- VolumeNumber = data.VolumeNumber + string.Empty,- VolumeId = data.VolumeId,- IsSpecial = data.IsSpecial,- SeriesId =data.SeriesId,- SeriesFormat = data.SeriesFormat,- SeriesName = data.SeriesName,- LibraryId = data.LibraryId,- Pages = data.Pages- })- .AsNoTracking()- .SingleAsync();- }-- public Task<int> GetChapterTotalPagesAsync(int chapterId)- {- return _context.Chapter- .Where(c => c.Id == chapterId)- .Select(c => c.Pages)- .SingleOrDefaultAsync();- }- public async Task<ChapterDto> GetChapterDtoAsync(int chapterId)- {- var chapter = await _context.Chapter- .Include(c => c.Files)- .ProjectTo<ChapterDto>(_mapper.ConfigurationProvider)- .AsNoTracking()- .SingleOrDefaultAsync(c => c.Id == chapterId);-- return chapter;- }-- /// <summary>- /// Returns non-tracked files for a given chapterId- /// </summary>- /// <param name="chapterId"></param>- /// <returns></returns>- public async Task<IList<MangaFile>> GetFilesForChapterAsync(int chapterId)- {- return await _context.MangaFile- .Where(c => chapterId == c.ChapterId)- .AsNoTracking()- .ToListAsync();- }-- /// <summary>- /// Returns a Chapter for an Id. Includes linked <see cref="MangaFile"/>s.- /// </summary>- /// <param name="chapterId"></param>- /// <returns></returns>- public async Task<Chapter> GetChapterAsync(int chapterId)- {- return await _context.Chapter- .Include(c => c.Files)- .SingleOrDefaultAsync(c => c.Id == chapterId);- }-- /// <summary>- /// Returns Chapters for a volume id.- /// </summary>- /// <param name="volumeId"></param>- /// <returns></returns>- public async Task<IList<Chapter>> GetChaptersAsync(int volumeId)- {- return await _context.Chapter- .Where(c => c.VolumeId == volumeId)- .ToListAsync();- }-- /// <summary>- /// Returns the cover image for a chapter id.- /// </summary>- /// <param name="chapterId"></param>- /// <returns></returns>- public async Task<string> GetChapterCoverImageAsync(int chapterId)- {-- return await _context.Chapter- .Where(c => c.Id == chapterId)- .Select(c => c.CoverImage)- .AsNoTracking()- .SingleOrDefaultAsync();- }-- public async Task<IList<string>> GetAllCoverImagesAsync()- {- return await _context.Chapter- .Select(c => c.CoverImage)- .Where(t => !string.IsNullOrEmpty(t))- .AsNoTracking()- .ToListAsync();- }-- /// <summary>- /// Returns cover images for locked chapters- /// </summary>- /// <returns></returns>- public async Task<IEnumerable<string>> GetCoverImagesForLockedChaptersAsync()- {- return await _context.Chapter- .Where(c => c.CoverImageLocked)- .Select(c => c.CoverImage)- .Where(t => !string.IsNullOrEmpty(t))- .AsNoTracking()- .ToListAsync();- }-- /// <summary>- /// Returns non-tracked files for a set of <paramref name="chapterIds"/>- /// </summary>- /// <param name="chapterIds">List of chapter Ids</param>- /// <returns></returns>- public async Task<IList<MangaFile>> GetFilesForChaptersAsync(IReadOnlyList<int> chapterIds)- {- return await _context.MangaFile- .Where(c => chapterIds.Contains(c.ChapterId))- .AsNoTracking()- .ToListAsync();- }+ return await _context.MangaFile+ .Where(c => chapterIds.Contains(c.ChapterId))+ .AsNoTracking()+ .ToListAsync();}}diff --git a/API/Data/Repositories/CollectionTagRepository.cs b/API/Data/Repositories/CollectionTagRepository.csindex f47ce721f..a519c774f 100644--- a/API/Data/Repositories/CollectionTagRepository.cs+++ b/API/Data/Repositories/CollectionTagRepository.cs@@ -2,126 +2,138 @@using System.IO;using System.Linq;using System.Threading.Tasks;-using API.DTOs;using API.DTOs.CollectionTags;using API.Entities;-using API.Interfaces.Repositories;using AutoMapper;using AutoMapper.QueryableExtensions;using Microsoft.EntityFrameworkCore;-namespace API.Data.Repositories+namespace API.Data.Repositories;++public interface ICollectionTagRepository+{+ void Add(CollectionTag tag);+ void Remove(CollectionTag tag);+ Task<IEnumerable<CollectionTagDto>> GetAllTagDtosAsync();+ Task<IEnumerable<CollectionTagDto>> SearchTagDtosAsync(string searchQuery);+ Task<string> GetCoverImageAsync(int collectionTagId);+ Task<IEnumerable<CollectionTagDto>> GetAllPromotedTagDtosAsync();+ Task<CollectionTag> GetTagAsync(int tagId);+ Task<CollectionTag> GetFullTagAsync(int tagId);+ void Update(CollectionTag tag);+ Task<int> RemoveTagsWithoutSeries();+ Task<IEnumerable<CollectionTag>> GetAllTagsAsync();+ Task<IList<string>> GetAllCoverImagesAsync();+}+public class CollectionTagRepository : ICollectionTagRepository{- public class CollectionTagRepository : ICollectionTagRepository+ private readonly DataContext _context;+ private readonly IMapper _mapper;++ public CollectionTagRepository(DataContext context, IMapper mapper)+ {+ _context = context;+ _mapper = mapper;+ }++ public void Add(CollectionTag tag)+ {+ _context.CollectionTag.Add(tag);+ }++ public void Remove(CollectionTag tag)+ {+ _context.CollectionTag.Remove(tag);+ }++ public void Update(CollectionTag tag)+ {+ _context.Entry(tag).State = EntityState.Modified;+ }++ /// <summary>+ /// Removes any collection tags without any series+ /// </summary>+ public async Task<int> RemoveTagsWithoutSeries()+ {+ var tagsToDelete = await _context.CollectionTag+ .Include(c => c.SeriesMetadatas)+ .Where(c => c.SeriesMetadatas.Count == 0)+ .ToListAsync();+ _context.RemoveRange(tagsToDelete);++ return await _context.SaveChangesAsync();+ }++ public async Task<IEnumerable<CollectionTag>> GetAllTagsAsync()+ {+ return await _context.CollectionTag+ .OrderBy(c => c.NormalizedTitle)+ .ToListAsync();+ }++ public async Task<IList<string>> GetAllCoverImagesAsync()+ {+ return await _context.CollectionTag+ .Select(t => t.CoverImage)+ .Where(t => !string.IsNullOrEmpty(t))+ .AsNoTracking()+ .ToListAsync();+ }++ public async Task<IEnumerable<CollectionTagDto>> GetAllTagDtosAsync()+ {+ return await _context.CollectionTag+ .Select(c => c)+ .OrderBy(c => c.NormalizedTitle)+ .AsNoTracking()+ .ProjectTo<CollectionTagDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }++ public async Task<IEnumerable<CollectionTagDto>> GetAllPromotedTagDtosAsync()+ {+ return await _context.CollectionTag+ .Where(c => c.Promoted)+ .OrderBy(c => c.NormalizedTitle)+ .AsNoTracking()+ .ProjectTo<CollectionTagDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }++ public async Task<CollectionTag> GetTagAsync(int tagId)+ {+ return await _context.CollectionTag+ .Where(c => c.Id == tagId)+ .SingleOrDefaultAsync();+ }++ public async Task<CollectionTag> GetFullTagAsync(int tagId)+ {+ return await _context.CollectionTag+ .Where(c => c.Id == tagId)+ .Include(c => c.SeriesMetadatas)+ .SingleOrDefaultAsync();+ }++ public async Task<IEnumerable<CollectionTagDto>> SearchTagDtosAsync(string searchQuery)+ {+ return await _context.CollectionTag+ .Where(s => EF.Functions.Like(s.Title, $"%{searchQuery}%")+ || EF.Functions.Like(s.NormalizedTitle, $"%{searchQuery}%"))+ .OrderBy(s => s.Title)+ .AsNoTracking()+ .OrderBy(c => c.NormalizedTitle)+ .ProjectTo<CollectionTagDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }++ public async Task<string> GetCoverImageAsync(int collectionTagId){- private readonly DataContext _context;- private readonly IMapper _mapper;-- public CollectionTagRepository(DataContext context, IMapper mapper)- {- _context = context;- _mapper = mapper;- }-- public void Add(CollectionTag tag)- {- _context.CollectionTag.Add(tag);- }-- public void Remove(CollectionTag tag)- {- _context.CollectionTag.Remove(tag);- }-- public void Update(CollectionTag tag)- {- _context.Entry(tag).State = EntityState.Modified;- }-- /// <summary>- /// Removes any collection tags without any series- /// </summary>- public async Task<int> RemoveTagsWithoutSeries()- {- var tagsToDelete = await _context.CollectionTag- .Include(c => c.SeriesMetadatas)- .Where(c => c.SeriesMetadatas.Count == 0)- .ToListAsync();- _context.RemoveRange(tagsToDelete);-- return await _context.SaveChangesAsync();- }-- public async Task<IEnumerable<CollectionTag>> GetAllTagsAsync()- {- return await _context.CollectionTag- .OrderBy(c => c.NormalizedTitle)- .ToListAsync();- }-- public async Task<IList<string>> GetAllCoverImagesAsync()- {- return await _context.CollectionTag- .Select(t => t.CoverImage)- .Where(t => !string.IsNullOrEmpty(t))- .AsNoTracking()- .ToListAsync();- }-- public async Task<IEnumerable<CollectionTagDto>> GetAllTagDtosAsync()- {- return await _context.CollectionTag- .Select(c => c)- .OrderBy(c => c.NormalizedTitle)- .AsNoTracking()- .ProjectTo<CollectionTagDto>(_mapper.ConfigurationProvider)- .ToListAsync();- }-- public async Task<IEnumerable<CollectionTagDto>> GetAllPromotedTagDtosAsync()- {- return await _context.CollectionTag- .Where(c => c.Promoted)- .OrderBy(c => c.NormalizedTitle)- .AsNoTracking()- .ProjectTo<CollectionTagDto>(_mapper.ConfigurationProvider)- .ToListAsync();- }-- public async Task<CollectionTag> GetTagAsync(int tagId)- {- return await _context.CollectionTag- .Where(c => c.Id == tagId)- .SingleOrDefaultAsync();- }-- public async Task<CollectionTag> GetFullTagAsync(int tagId)- {- return await _context.CollectionTag- .Where(c => c.Id == tagId)- .Include(c => c.SeriesMetadatas)- .SingleOrDefaultAsync();- }-- public async Task<IEnumerable<CollectionTagDto>> SearchTagDtosAsync(string searchQuery)- {- return await _context.CollectionTag- .Where(s => EF.Functions.Like(s.Title, $"%{searchQuery}%")- || EF.Functions.Like(s.NormalizedTitle, $"%{searchQuery}%"))- .OrderBy(s => s.Title)- .AsNoTracking()- .OrderBy(c => c.NormalizedTitle)- .ProjectTo<CollectionTagDto>(_mapper.ConfigurationProvider)- .ToListAsync();- }-- public async Task<string> GetCoverImageAsync(int collectionTagId)- {- return await _context.CollectionTag- .Where(c => c.Id == collectionTagId)- .Select(c => c.CoverImage)- .AsNoTracking()- .SingleOrDefaultAsync();- }+ return await _context.CollectionTag+ .Where(c => c.Id == collectionTagId)+ .Select(c => c.CoverImage)+ .AsNoTracking()+ .SingleOrDefaultAsync();}}diff --git a/API/Data/Repositories/FileRepository.cs b/API/Data/Repositories/FileRepository.csdeleted file mode 100644index 4665dac7e..000000000--- a/API/Data/Repositories/FileRepository.cs+++ /dev/null@@ -1,35 +0,0 @@-using System.Collections.Generic;-using System.IO;-using System.Linq;-using System.Threading.Tasks;-using API.Interfaces.Repositories;-using Microsoft.EntityFrameworkCore;--namespace API.Data.Repositories-{- public class FileRepository : IFileRepository- {- private readonly DataContext _dbContext;-- public FileRepository(DataContext context)- {- _dbContext = context;- }-- public async Task<IEnumerable<string>> GetFileExtensions()- {- var fileExtensions = await _dbContext.MangaFile- .AsNoTracking()- .Select(x => x.FilePath.ToLower())- .Distinct()- .ToArrayAsync();-- var uniqueFileTypes = fileExtensions- .Select(Path.GetExtension)- .Where(x => x is not null)- .Distinct();-- return uniqueFileTypes;- }- }-}diff --git a/API/Data/Repositories/GenreRepository.cs b/API/Data/Repositories/GenreRepository.csnew file mode 100644index 000000000..05f2052f4--- /dev/null+++ b/API/Data/Repositories/GenreRepository.cs@@ -0,0 +1,86 @@+using System.Collections.Generic;+using System.Linq;+using System.Threading.Tasks;+using API.DTOs.Metadata;+using API.Entities;+using AutoMapper;+using AutoMapper.QueryableExtensions;+using Microsoft.EntityFrameworkCore;++namespace API.Data.Repositories;++public interface IGenreRepository+{+ void Attach(Genre genre);+ void Remove(Genre genre);+ Task<Genre> FindByNameAsync(string genreName);+ Task<IList<Genre>> GetAllGenresAsync();+ Task<IList<GenreTagDto>> GetAllGenreDtosAsync();+ Task RemoveAllGenreNoLongerAssociated(bool removeExternal = false);+ Task<IList<GenreTagDto>> GetAllGenreDtosForLibrariesAsync(IList<int> libraryIds);+}++public class GenreRepository : IGenreRepository+{+ private readonly DataContext _context;+ private readonly IMapper _mapper;++ public GenreRepository(DataContext context, IMapper mapper)+ {+ _context = context;+ _mapper = mapper;+ }++ public void Attach(Genre genre)+ {+ _context.Genre.Attach(genre);+ }++ public void Remove(Genre genre)+ {+ _context.Genre.Remove(genre);+ }++ public async Task<Genre> FindByNameAsync(string genreName)+ {+ var normalizedName = Parser.Parser.Normalize(genreName);+ return await _context.Genre+ .FirstOrDefaultAsync(g => g.NormalizedTitle.Equals(normalizedName));+ }++ public async Task RemoveAllGenreNoLongerAssociated(bool removeExternal = false)+ {+ var genresWithNoConnections = await _context.Genre+ .Include(p => p.SeriesMetadatas)+ .Include(p => p.Chapters)+ .Where(p => p.SeriesMetadatas.Count == 0 && p.Chapters.Count == 0 && p.ExternalTag == removeExternal)+ .ToListAsync();++ _context.Genre.RemoveRange(genresWithNoConnections);++ await _context.SaveChangesAsync();+ }++ public async Task<IList<GenreTagDto>> GetAllGenreDtosForLibrariesAsync(IList<int> libraryIds)+ {+ return await _context.Series+ .Where(s => libraryIds.Contains(s.LibraryId))+ .SelectMany(s => s.Metadata.Genres)+ .Distinct()+ .ProjectTo<GenreTagDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }++ public async Task<IList<Genre>> GetAllGenresAsync()+ {+ return await _context.Genre.ToListAsync();+ }++ public async Task<IList<GenreTagDto>> GetAllGenreDtosAsync()+ {+ return await _context.Genre+ .AsNoTracking()+ .ProjectTo<GenreTagDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }+}diff --git a/API/Data/Repositories/LibraryRepository.cs b/API/Data/Repositories/LibraryRepository.csindex caae93dd6..26fc517a2 100644--- a/API/Data/Repositories/LibraryRepository.cs+++ b/API/Data/Repositories/LibraryRepository.cs@@ -5,194 +5,208 @@ using System.Threading.Tasks;using API.DTOs;using API.Entities;using API.Entities.Enums;-using API.Interfaces.Repositories;using AutoMapper;using AutoMapper.QueryableExtensions;using Microsoft.EntityFrameworkCore;-namespace API.Data.Repositories+namespace API.Data.Repositories;++[Flags]+public enum LibraryIncludes{+ None = 1,+ Series = 2,+ AppUser = 4,+ Folders = 8,+ // Ratings = 16+}++public interface ILibraryRepository+{+ void Add(Library library);+ void Update(Library library);+ void Delete(Library library);+ Task<IEnumerable<LibraryDto>> GetLibraryDtosAsync();+ Task<bool> LibraryExists(string libraryName);+ Task<Library> GetLibraryForIdAsync(int libraryId, LibraryIncludes includes);+ Task<Library> GetFullLibraryForIdAsync(int libraryId);+ Task<Library> GetFullLibraryForIdAsync(int libraryId, int seriesId);+ Task<IEnumerable<LibraryDto>> GetLibraryDtosForUsernameAsync(string userName);+ Task<IEnumerable<Library>> GetLibrariesAsync();+ Task<bool> DeleteLibrary(int libraryId);+ Task<IEnumerable<Library>> GetLibrariesForUserIdAsync(int userId);+ Task<LibraryType> GetLibraryTypeAsync(int libraryId);+}- [Flags]- public enum LibraryIncludes+public class LibraryRepository : ILibraryRepository+{+ private readonly DataContext _context;+ private readonly IMapper _mapper;++ public LibraryRepository(DataContext context, IMapper mapper){- None = 1,- Series = 2,- AppUser = 4,- Folders = 8,- // Ratings = 16+ _context = context;+ _mapper = mapper;}- public class LibraryRepository : ILibraryRepository+ public void Add(Library library){- private readonly DataContext _context;- private readonly IMapper _mapper;-- public LibraryRepository(DataContext context, IMapper mapper)- {- _context = context;- _mapper = mapper;- }+ _context.Library.Add(library);+ }- public void Add(Library library)- {- _context.Library.Add(library);- }+ public void Update(Library library)+ {+ _context.Entry(library).State = EntityState.Modified;+ }- public void Update(Library library)- {- _context.Entry(library).State = EntityState.Modified;- }+ public void Delete(Library library)+ {+ _context.Library.Remove(library);+ }- public void Delete(Library library)- {- _context.Library.Remove(library);- }+ public async Task<IEnumerable<LibraryDto>> GetLibraryDtosForUsernameAsync(string userName)+ {+ return await _context.Library+ .Include(l => l.AppUsers)+ .Where(library => library.AppUsers.Any(x => x.UserName == userName))+ .OrderBy(l => l.Name)+ .ProjectTo<LibraryDto>(_mapper.ConfigurationProvider)+ .AsNoTracking()+ .AsSingleQuery()+ .ToListAsync();+ }- public async Task<IEnumerable<LibraryDto>> GetLibraryDtosForUsernameAsync(string userName)- {- return await _context.Library- .Include(l => l.AppUsers)- .Where(library => library.AppUsers.Any(x => x.UserName == userName))- .OrderBy(l => l.Name)- .ProjectTo<LibraryDto>(_mapper.ConfigurationProvider)- .AsNoTracking()- .AsSingleQuery()- .ToListAsync();- }+ public async Task<IEnumerable<Library>> GetLibrariesAsync()+ {+ return await _context.Library+ .Include(l => l.AppUsers)+ .ToListAsync();+ }- public async Task<IEnumerable<Library>> GetLibrariesAsync()- {- return await _context.Library- .Include(l => l.AppUsers)- .ToListAsync();- }+ public async Task<bool> DeleteLibrary(int libraryId)+ {+ var library = await GetLibraryForIdAsync(libraryId, LibraryIncludes.Folders | LibraryIncludes.Series);+ _context.Library.Remove(library);+ return await _context.SaveChangesAsync() > 0;+ }- public async Task<bool> DeleteLibrary(int libraryId)- {- var library = await GetLibraryForIdAsync(libraryId, LibraryIncludes.Folders | LibraryIncludes.Series);- _context.Library.Remove(library);- return await _context.SaveChangesAsync() > 0;- }+ public async Task<IEnumerable<Library>> GetLibrariesForUserIdAsync(int userId)+ {+ return await _context.Library+ .Include(l => l.AppUsers)+ .Where(l => l.AppUsers.Select(ap => ap.Id).Contains(userId))+ .AsNoTracking()+ .ToListAsync();+ }- public async Task<IEnumerable<Library>> GetLibrariesForUserIdAsync(int userId)- {- return await _context.Library- .Include(l => l.AppUsers)- .Where(l => l.AppUsers.Select(ap => ap.Id).Contains(userId))- .AsNoTracking()- .ToListAsync();- }+ public async Task<LibraryType> GetLibraryTypeAsync(int libraryId)+ {+ return await _context.Library+ .Where(l => l.Id == libraryId)+ .AsNoTracking()+ .Select(l => l.Type)+ .SingleAsync();+ }- public async Task<LibraryType> GetLibraryTypeAsync(int libraryId)- {- return await _context.Library- .Where(l => l.Id == libraryId)- .AsNoTracking()- .Select(l => l.Type)- .SingleAsync();- }+ public async Task<IEnumerable<LibraryDto>> GetLibraryDtosAsync()+ {+ return await _context.Library+ .Include(f => f.Folders)+ .OrderBy(l => l.Name)+ .ProjectTo<LibraryDto>(_mapper.ConfigurationProvider)+ .AsNoTracking()+ .ToListAsync();+ }- public async Task<IEnumerable<LibraryDto>> GetLibraryDtosAsync()- {- return await _context.Library- .Include(f => f.Folders)- .OrderBy(l => l.Name)- .ProjectTo<LibraryDto>(_mapper.ConfigurationProvider)- .AsNoTracking()- .ToListAsync();- }+ public async Task<Library> GetLibraryForIdAsync(int libraryId, LibraryIncludes includes)+ {- public async Task<Library> GetLibraryForIdAsync(int libraryId, LibraryIncludes includes)- {+ var query = _context.Library+ .Where(x => x.Id == libraryId);- var query = _context.Library- .Where(x => x.Id == libraryId);+ query = AddIncludesToQuery(query, includes);+ return await query.SingleAsync();+ }- query = AddIncludesToQuery(query, includes);- return await query.SingleAsync();+ private static IQueryable<Library> AddIncludesToQuery(IQueryable<Library> query, LibraryIncludes includeFlags)+ {+ if (includeFlags.HasFlag(LibraryIncludes.Folders))+ {+ query = query.Include(l => l.Folders);}- private static IQueryable<Library> AddIncludesToQuery(IQueryable<Library> query, LibraryIncludes includeFlags)+ if (includeFlags.HasFlag(LibraryIncludes.Series)){- if (includeFlags.HasFlag(LibraryIncludes.Folders))- {- query = query.Include(l => l.Folders);- }-- if (includeFlags.HasFlag(LibraryIncludes.Series))- {- query = query.Include(l => l.Series);- }-- if (includeFlags.HasFlag(LibraryIncludes.AppUser))- {- query = query.Include(l => l.AppUsers);- }-- return query;+ query = query.Include(l => l.Series);}-- /// <summary>- /// This returns a Library with all it's Series -> Volumes -> Chapters. This is expensive. Should only be called when needed.- /// </summary>- /// <param name="libraryId"></param>- /// <returns></returns>- public async Task<Library> GetFullLibraryForIdAsync(int libraryId)+ if (includeFlags.HasFlag(LibraryIncludes.AppUser)){- return await _context.Library- .Where(x => x.Id == libraryId)- .Include(f => f.Folders)- .Include(l => l.Series)- .ThenInclude(s => s.Metadata)- .Include(l => l.Series)- .ThenInclude(s => s.Volumes)- .ThenInclude(v => v.Chapters)- .ThenInclude(c => c.Files)- .AsSplitQuery()- .SingleAsync();+ query = query.Include(l => l.AppUsers);}- /// <summary>- /// This is a heavy call, pulls all entities for a Library, except this version only grabs for one series id- /// </summary>- /// <param name="libraryId"></param>- /// <param name="seriesId"></param>- /// <returns></returns>- public async Task<Library> GetFullLibraryForIdAsync(int libraryId, int seriesId)- {+ return query;+ }- return await _context.Library- .Where(x => x.Id == libraryId)- .Include(f => f.Folders)- .Include(l => l.Series.Where(s => s.Id == seriesId))- .ThenInclude(s => s.Metadata)- .Include(l => l.Series.Where(s => s.Id == seriesId))- .ThenInclude(s => s.Volumes)- .ThenInclude(v => v.Chapters)- .ThenInclude(c => c.Files)- .AsSplitQuery()- .SingleAsync();- }- public async Task<bool> LibraryExists(string libraryName)- {- return await _context.Library- .AsNoTracking()- .AnyAsync(x => x.Name == libraryName);- }+ /// <summary>+ /// This returns a Library with all it's Series -> Volumes -> Chapters. This is expensive. Should only be called when needed.+ /// </summary>+ /// <param name="libraryId"></param>+ /// <returns></returns>+ public async Task<Library> GetFullLibraryForIdAsync(int libraryId)+ {+ return await _context.Library+ .Where(x => x.Id == libraryId)+ .Include(f => f.Folders)+ .Include(l => l.Series)+ .ThenInclude(s => s.Metadata)+ .Include(l => l.Series)+ .ThenInclude(s => s.Volumes)+ .ThenInclude(v => v.Chapters)+ .ThenInclude(c => c.Files)+ .AsSplitQuery()+ .SingleAsync();+ }- public async Task<IEnumerable<LibraryDto>> GetLibrariesForUserAsync(AppUser user)- {- return await _context.Library- .Where(library => library.AppUsers.Contains(user))- .Include(l => l.Folders)- .AsNoTracking()- .ProjectTo<LibraryDto>(_mapper.ConfigurationProvider)- .ToListAsync();- }+ /// <summary>+ /// This is a heavy call, pulls all entities for a Library, except this version only grabs for one series id+ /// </summary>+ /// <param name="libraryId"></param>+ /// <param name="seriesId"></param>+ /// <returns></returns>+ public async Task<Library> GetFullLibraryForIdAsync(int libraryId, int seriesId)+ {++ return await _context.Library+ .Where(x => x.Id == libraryId)+ .Include(f => f.Folders)+ .Include(l => l.Series.Where(s => s.Id == seriesId))+ .ThenInclude(s => s.Metadata)+ .Include(l => l.Series.Where(s => s.Id == seriesId))+ .ThenInclude(s => s.Volumes)+ .ThenInclude(v => v.Chapters)+ .ThenInclude(c => c.Files)+ .AsSplitQuery()+ .SingleAsync();+ }+ public async Task<bool> LibraryExists(string libraryName)+ {+ return await _context.Library+ .AsNoTracking()+ .AnyAsync(x => x.Name == libraryName);+ }+ public async Task<IEnumerable<LibraryDto>> GetLibrariesForUserAsync(AppUser user)+ {+ return await _context.Library+ .Where(library => library.AppUsers.Contains(user))+ .Include(l => l.Folders)+ .AsNoTracking()+ .ProjectTo<LibraryDto>(_mapper.ConfigurationProvider)+ .ToListAsync();}++}diff --git a/API/Data/Repositories/PersonRepository.cs b/API/Data/Repositories/PersonRepository.csnew file mode 100644index 000000000..71ec69639--- /dev/null+++ b/API/Data/Repositories/PersonRepository.cs@@ -0,0 +1,79 @@+using System.Collections.Generic;+using System.Linq;+using System.Threading.Tasks;+using API.DTOs;+using API.Entities;+using AutoMapper;+using AutoMapper.QueryableExtensions;+using Microsoft.EntityFrameworkCore;++namespace API.Data.Repositories;++public interface IPersonRepository+{+ void Attach(Person person);+ void Remove(Person person);+ Task<IList<Person>> GetAllPeople();+ Task RemoveAllPeopleNoLongerAssociated(bool removeExternal = false);+ Task<IList<PersonDto>> GetAllPeopleDtosForLibrariesAsync(List<int> libraryIds);+}++public class PersonRepository : IPersonRepository+{+ private readonly DataContext _context;+ private readonly IMapper _mapper;++ public PersonRepository(DataContext context, IMapper mapper)+ {+ _context = context;+ _mapper = mapper;+ }++ public void Attach(Person person)+ {+ _context.Person.Attach(person);+ }++ public void Remove(Person person)+ {+ _context.Person.Remove(person);+ }++ public async Task<Person> FindByNameAsync(string name)+ {+ var normalizedName = Parser.Parser.Normalize(name);+ return await _context.Person+ .Where(p => normalizedName.Equals(p.NormalizedName))+ .SingleOrDefaultAsync();+ }++ public async Task RemoveAllPeopleNoLongerAssociated(bool removeExternal = false)+ {+ var peopleWithNoConnections = await _context.Person+ .Include(p => p.SeriesMetadatas)+ .Include(p => p.ChapterMetadatas)+ .Where(p => p.SeriesMetadatas.Count == 0 && p.ChapterMetadatas.Count == 0)+ .ToListAsync();++ _context.Person.RemoveRange(peopleWithNoConnections);++ await _context.SaveChangesAsync();+ }++ public async Task<IList<PersonDto>> GetAllPeopleDtosForLibrariesAsync(List<int> libraryIds)+ {+ return await _context.Series+ .Where(s => libraryIds.Contains(s.LibraryId))+ .SelectMany(s => s.Metadata.People)+ .Distinct()+ .ProjectTo<PersonDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }+++ public async Task<IList<Person>> GetAllPeople()+ {+ return await _context.Person+ .ToListAsync();+ }+}diff --git a/API/Data/Repositories/ReadingListRepository.cs b/API/Data/Repositories/ReadingListRepository.csindex fc9199ccb..329ec47a8 100644--- a/API/Data/Repositories/ReadingListRepository.cs+++ b/API/Data/Repositories/ReadingListRepository.cs@@ -4,175 +4,187 @@ using System.Threading.Tasks;using API.DTOs.ReadingLists;using API.Entities;using API.Helpers;-using API.Interfaces.Repositories;using AutoMapper;using AutoMapper.QueryableExtensions;using Microsoft.EntityFrameworkCore;-namespace API.Data.Repositories+namespace API.Data.Repositories;++public interface IReadingListRepository{- public class ReadingListRepository : IReadingListRepository- {- private readonly DataContext _context;- private readonly IMapper _mapper;+ Task<PagedList<ReadingListDto>> GetReadingListDtosForUserAsync(int userId, bool includePromoted, UserParams userParams);+ Task<ReadingList> GetReadingListByIdAsync(int readingListId);+ Task<IEnumerable<ReadingListItemDto>> GetReadingListItemDtosByIdAsync(int readingListId, int userId);+ Task<ReadingListDto> GetReadingListDtoByIdAsync(int readingListId, int userId);+ Task<IEnumerable<ReadingListItemDto>> AddReadingProgressModifiers(int userId, IList<ReadingListItemDto> items);+ Task<ReadingListDto> GetReadingListDtoByTitleAsync(string title);+ Task<IEnumerable<ReadingListItem>> GetReadingListItemsByIdAsync(int readingListId);+ void Remove(ReadingListItem item);+ void BulkRemove(IEnumerable<ReadingListItem> items);+ void Update(ReadingList list);+}- public ReadingListRepository(DataContext context, IMapper mapper)- {- _context = context;- _mapper = mapper;- }+public class ReadingListRepository : IReadingListRepository+{+ private readonly DataContext _context;+ private readonly IMapper _mapper;- public void Update(ReadingList list)- {- _context.Entry(list).State = EntityState.Modified;- }+ public ReadingListRepository(DataContext context, IMapper mapper)+ {+ _context = context;+ _mapper = mapper;+ }- public void Remove(ReadingListItem item)- {- _context.ReadingListItem.Remove(item);- }+ public void Update(ReadingList list)+ {+ _context.Entry(list).State = EntityState.Modified;+ }- public void BulkRemove(IEnumerable<ReadingListItem> items)- {- _context.ReadingListItem.RemoveRange(items);- }+ public void Remove(ReadingListItem item)+ {+ _context.ReadingListItem.Remove(item);+ }+ public void BulkRemove(IEnumerable<ReadingListItem> items)+ {+ _context.ReadingListItem.RemoveRange(items);+ }- public async Task<PagedList<ReadingListDto>> GetReadingListDtosForUserAsync(int userId, bool includePromoted, UserParams userParams)- {- var query = _context.ReadingList- .Where(l => l.AppUserId == userId || (includePromoted && l.Promoted ))- .OrderBy(l => l.LastModified)- .ProjectTo<ReadingListDto>(_mapper.ConfigurationProvider)- .AsNoTracking();- return await PagedList<ReadingListDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);- }+ public async Task<PagedList<ReadingListDto>> GetReadingListDtosForUserAsync(int userId, bool includePromoted, UserParams userParams)+ {+ var query = _context.ReadingList+ .Where(l => l.AppUserId == userId || (includePromoted && l.Promoted ))+ .OrderBy(l => l.LastModified)+ .ProjectTo<ReadingListDto>(_mapper.ConfigurationProvider)+ .AsNoTracking();- public async Task<ReadingList> GetReadingListByIdAsync(int readingListId)- {- return await _context.ReadingList- .Where(r => r.Id == readingListId)- .Include(r => r.Items.OrderBy(item => item.Order))- .SingleOrDefaultAsync();- }+ return await PagedList<ReadingListDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);+ }- public async Task<IEnumerable<ReadingListItemDto>> GetReadingListItemDtosByIdAsync(int readingListId, int userId)- {- var userLibraries = _context.Library- .Include(l => l.AppUsers)- .Where(library => library.AppUsers.Any(user => user.Id == userId))- .AsNoTracking()- .Select(library => library.Id)- .ToList();-- var items = await _context.ReadingListItem- .Where(s => s.ReadingListId == readingListId)- .Join(_context.Chapter, s => s.ChapterId, chapter => chapter.Id, (data, chapter) => new- {- TotalPages = chapter.Pages,- ChapterNumber = chapter.Range,- readingListItem = data- })- .Join(_context.Volume, s => s.readingListItem.VolumeId, volume => volume.Id, (data, volume) => new+ public async Task<ReadingList> GetReadingListByIdAsync(int readingListId)+ {+ return await _context.ReadingList+ .Where(r => r.Id == readingListId)+ .Include(r => r.Items.OrderBy(item => item.Order))+ .SingleOrDefaultAsync();+ }++ public async Task<IEnumerable<ReadingListItemDto>> GetReadingListItemDtosByIdAsync(int readingListId, int userId)+ {+ var userLibraries = _context.Library+ .Include(l => l.AppUsers)+ .Where(library => library.AppUsers.Any(user => user.Id == userId))+ .AsNoTracking()+ .Select(library => library.Id)+ .ToList();++ var items = await _context.ReadingListItem+ .Where(s => s.ReadingListId == readingListId)+ .Join(_context.Chapter, s => s.ChapterId, chapter => chapter.Id, (data, chapter) => new+ {+ TotalPages = chapter.Pages,+ ChapterNumber = chapter.Range,+ readingListItem = data+ })+ .Join(_context.Volume, s => s.readingListItem.VolumeId, volume => volume.Id, (data, volume) => new+ {+ data.readingListItem,+ data.TotalPages,+ data.ChapterNumber,+ VolumeId = volume.Id,+ VolumeNumber = volume.Name,+ })+ .Join(_context.Series, s => s.readingListItem.SeriesId, series => series.Id,+ (data, s) => new{+ SeriesName = s.Name,+ SeriesFormat = s.Format,+ s.LibraryId,data.readingListItem,data.TotalPages,data.ChapterNumber,- VolumeId = volume.Id,- VolumeNumber = volume.Name,- })- .Join(_context.Series, s => s.readingListItem.SeriesId, series => series.Id,- (data, s) => new- {- SeriesName = s.Name,- SeriesFormat = s.Format,- s.LibraryId,- data.readingListItem,- data.TotalPages,- data.ChapterNumber,- data.VolumeNumber,- data.VolumeId- })- .Select(data => new ReadingListItemDto()- {- Id = data.readingListItem.Id,- ChapterId = data.readingListItem.ChapterId,- Order = data.readingListItem.Order,- SeriesId = data.readingListItem.SeriesId,- SeriesName = data.SeriesName,- SeriesFormat = data.SeriesFormat,- PagesTotal = data.TotalPages,- ChapterNumber = data.ChapterNumber,- VolumeNumber = data.VolumeNumber,- LibraryId = data.LibraryId,- VolumeId = data.VolumeId,- ReadingListId = data.readingListItem.ReadingListId+ data.VolumeNumber,+ data.VolumeId})- .Where(o => userLibraries.Contains(o.LibraryId))- .OrderBy(rli => rli.Order)- .AsNoTracking()- .ToListAsync();-- // Attach progress information- var fetchedChapterIds = items.Select(i => i.ChapterId);- var progresses = await _context.AppUserProgresses- .Where(p => fetchedChapterIds.Contains(p.ChapterId))- .AsNoTracking()- .ToListAsync();-- foreach (var progress in progresses)+ .Select(data => new ReadingListItemDto(){- var progressItem = items.SingleOrDefault(i => i.ChapterId == progress.ChapterId && i.ReadingListId == readingListId);- if (progressItem == null) continue;-- progressItem.PagesRead = progress.PagesRead;- }-- return items;- }-- public async Task<ReadingListDto> GetReadingListDtoByIdAsync(int readingListId, int userId)+ Id = data.readingListItem.Id,+ ChapterId = data.readingListItem.ChapterId,+ Order = data.readingListItem.Order,+ SeriesId = data.readingListItem.SeriesId,+ SeriesName = data.SeriesName,+ SeriesFormat = data.SeriesFormat,+ PagesTotal = data.TotalPages,+ ChapterNumber = data.ChapterNumber,+ VolumeNumber = data.VolumeNumber,+ LibraryId = data.LibraryId,+ VolumeId = data.VolumeId,+ ReadingListId = data.readingListItem.ReadingListId+ })+ .Where(o => userLibraries.Contains(o.LibraryId))+ .OrderBy(rli => rli.Order)+ .AsNoTracking()+ .ToListAsync();++ // Attach progress information+ var fetchedChapterIds = items.Select(i => i.ChapterId);+ var progresses = await _context.AppUserProgresses+ .Where(p => fetchedChapterIds.Contains(p.ChapterId))+ .AsNoTracking()+ .ToListAsync();++ foreach (var progress in progresses){- return await _context.ReadingList- .Where(r => r.Id == readingListId && (r.AppUserId == userId || r.Promoted))- .ProjectTo<ReadingListDto>(_mapper.ConfigurationProvider)- .SingleOrDefaultAsync();+ var progressItem = items.SingleOrDefault(i => i.ChapterId == progress.ChapterId && i.ReadingListId == readingListId);+ if (progressItem == null) continue;++ progressItem.PagesRead = progress.PagesRead;}- public async Task<IEnumerable<ReadingListItemDto>> AddReadingProgressModifiers(int userId, IList<ReadingListItemDto> items)- {- var chapterIds = items.Select(i => i.ChapterId).Distinct().ToList();- var userProgress = await _context.AppUserProgresses- .Where(p => p.AppUserId == userId && chapterIds.Contains(p.ChapterId))- .AsNoTracking()- .ToListAsync();+ return items;+ }- foreach (var item in items)- {- var progress = userProgress.Where(p => p.ChapterId == item.ChapterId);- item.PagesRead = progress.Sum(p => p.PagesRead);- }+ public async Task<ReadingListDto> GetReadingListDtoByIdAsync(int readingListId, int userId)+ {+ return await _context.ReadingList+ .Where(r => r.Id == readingListId && (r.AppUserId == userId || r.Promoted))+ .ProjectTo<ReadingListDto>(_mapper.ConfigurationProvider)+ .SingleOrDefaultAsync();+ }- return items;- }+ public async Task<IEnumerable<ReadingListItemDto>> AddReadingProgressModifiers(int userId, IList<ReadingListItemDto> items)+ {+ var chapterIds = items.Select(i => i.ChapterId).Distinct().ToList();+ var userProgress = await _context.AppUserProgresses+ .Where(p => p.AppUserId == userId && chapterIds.Contains(p.ChapterId))+ .AsNoTracking()+ .ToListAsync();- public async Task<ReadingListDto> GetReadingListDtoByTitleAsync(string title)+ foreach (var item in items){- return await _context.ReadingList- .Where(r => r.Title.Equals(title))- .ProjectTo<ReadingListDto>(_mapper.ConfigurationProvider)- .SingleOrDefaultAsync();+ var progress = userProgress.Where(p => p.ChapterId == item.ChapterId);+ item.PagesRead = progress.Sum(p => p.PagesRead);}- public async Task<IEnumerable<ReadingListItem>> GetReadingListItemsByIdAsync(int readingListId)- {- return await _context.ReadingListItem- .Where(r => r.ReadingListId == readingListId)- .OrderBy(r => r.Order)- .ToListAsync();- }+ return items;+ }+ public async Task<ReadingListDto> GetReadingListDtoByTitleAsync(string title)+ {+ return await _context.ReadingList+ .Where(r => r.Title.Equals(title))+ .ProjectTo<ReadingListDto>(_mapper.ConfigurationProvider)+ .SingleOrDefaultAsync();+ }+ public async Task<IEnumerable<ReadingListItem>> GetReadingListItemsByIdAsync(int readingListId)+ {+ return await _context.ReadingListItem+ .Where(r => r.ReadingListId == readingListId)+ .OrderBy(r => r.Order)+ .ToListAsync();}++}diff --git a/API/Data/Repositories/SeriesMetadataRepository.cs b/API/Data/Repositories/SeriesMetadataRepository.csindex 32ab0f4e2..0a3efee26 100644--- a/API/Data/Repositories/SeriesMetadataRepository.cs+++ b/API/Data/Repositories/SeriesMetadataRepository.cs@@ -1,20 +1,23 @@-using API.Entities;-using API.Interfaces.Repositories;+using API.Entities.Metadata;-namespace API.Data.Repositories+namespace API.Data.Repositories;++public interface ISeriesMetadataRepository{- public class SeriesMetadataRepository : ISeriesMetadataRepository- {- private readonly DataContext _context;+ void Update(SeriesMetadata seriesMetadata);+}++public class SeriesMetadataRepository : ISeriesMetadataRepository+{+ private readonly DataContext _context;- public SeriesMetadataRepository(DataContext context)- {- _context = context;- }+ public SeriesMetadataRepository(DataContext context)+ {+ _context = context;+ }- public void Update(SeriesMetadata seriesMetadata)- {- _context.SeriesMetadata.Update(seriesMetadata);- }+ public void Update(SeriesMetadata seriesMetadata)+ {+ _context.SeriesMetadata.Update(seriesMetadata);}}diff --git a/API/Data/Repositories/SeriesRepository.cs b/API/Data/Repositories/SeriesRepository.csindex baa55330f..e8ffa9e16 100644--- a/API/Data/Repositories/SeriesRepository.cs+++ b/API/Data/Repositories/SeriesRepository.cs@@ -1,527 +1,805 @@using System;using System.Collections.Generic;+using System.Globalization;using System.Linq;using System.Threading.Tasks;using API.Data.Scanner;using API.DTOs;using API.DTOs.CollectionTags;using API.DTOs.Filtering;+using API.DTOs.Metadata;using API.Entities;using API.Entities.Enums;+using API.Entities.Metadata;using API.Extensions;using API.Helpers;-using API.Interfaces.Repositories;using API.Services.Tasks;using AutoMapper;using AutoMapper.QueryableExtensions;+using Kavita.Common.Extensions;using Microsoft.EntityFrameworkCore;-namespace API.Data.Repositories+namespace API.Data.Repositories;++public interface ISeriesRepository+{+ void Attach(Series series);+ void Update(Series series);+ void Remove(Series series);+ void Remove(IEnumerable<Series> series);+ Task<bool> DoesSeriesNameExistInLibrary(string name, MangaFormat format);+ /// <summary>+ /// Adds user information like progress, ratings, etc+ /// </summary>+ /// <param name="libraryId"></param>+ /// <param name="userId"></param>+ /// <param name="userParams"></param>+ /// <returns></returns>+ Task<PagedList<SeriesDto>> GetSeriesDtoForLibraryIdAsync(int libraryId, int userId, UserParams userParams, FilterDto filter);+ /// <summary>+ /// Does not add user information like progress, ratings, etc.+ /// </summary>+ /// <param name="libraryIds"></param>+ /// <param name="searchQuery">Series name to search for</param>+ /// <returns></returns>+ Task<IEnumerable<SearchResultDto>> SearchSeries(int[] libraryIds, string searchQuery);+ Task<IEnumerable<Series>> GetSeriesForLibraryIdAsync(int libraryId);+ Task<SeriesDto> GetSeriesDtoByIdAsync(int seriesId, int userId);+ Task<bool> DeleteSeriesAsync(int seriesId);+ Task<Series> GetSeriesByIdAsync(int seriesId);+ Task<IList<Series>> GetSeriesByIdsAsync(IList<int> seriesIds);+ Task<int[]> GetChapterIdsForSeriesAsync(IList<int> seriesIds);+ Task<IDictionary<int, IList<int>>> GetChapterIdWithSeriesIdForSeriesAsync(int[] seriesIds);+ /// <summary>+ /// Used to add Progress/Rating information to series list.+ /// </summary>+ /// <param name="userId"></param>+ /// <param name="series"></param>+ /// <returns></returns>+ Task AddSeriesModifiers(int userId, List<SeriesDto> series);+ Task<string> GetSeriesCoverImageAsync(int seriesId);+ Task<IEnumerable<SeriesDto>> GetOnDeck(int userId, int libraryId, UserParams userParams, FilterDto filter);+ Task<PagedList<SeriesDto>> GetRecentlyAdded(int libraryId, int userId, UserParams userParams, FilterDto filter); // NOTE: Probably put this in LibraryRepo+ Task<SeriesMetadataDto> GetSeriesMetadata(int seriesId);+ Task<PagedList<SeriesDto>> GetSeriesDtoForCollectionAsync(int collectionId, int userId, UserParams userParams);+ Task<IList<MangaFile>> GetFilesForSeries(int seriesId);+ Task<IEnumerable<SeriesDto>> GetSeriesDtoForIdsAsync(IEnumerable<int> seriesIds, int userId);+ Task<IList<string>> GetAllCoverImagesAsync();+ Task<IEnumerable<string>> GetLockedCoverImagesAsync();+ Task<PagedList<Series>> GetFullSeriesForLibraryIdAsync(int libraryId, UserParams userParams);+ Task<Series> GetFullSeriesForSeriesIdAsync(int seriesId);+ Task<Chunk> GetChunkInfo(int libraryId = 0);+ Task<IList<SeriesMetadata>> GetSeriesMetadataForIdsAsync(IEnumerable<int> seriesIds);+ Task<IList<AgeRatingDto>> GetAllAgeRatingsDtosForLibrariesAsync(List<int> libraryIds);+ Task<IList<LanguageDto>> GetAllLanguagesForLibrariesAsync(List<int> libraryIds);+ Task<IList<PublicationStatusDto>> GetAllPublicationStatusesDtosForLibrariesAsync(List<int> libraryIds);+}++public class SeriesRepository : ISeriesRepository{- public class SeriesRepository : ISeriesRepository+ private readonly DataContext _context;+ private readonly IMapper _mapper;+ public SeriesRepository(DataContext context, IMapper mapper){- private readonly DataContext _context;- private readonly IMapper _mapper;- public SeriesRepository(DataContext context, IMapper mapper)- {- _context = context;- _mapper = mapper;- }+ _context = context;+ _mapper = mapper;+ }- public void Attach(Series series)- {- _context.Series.Attach(series);- }+ public void Attach(Series series)+ {+ _context.Series.Attach(series);+ }- public void Update(Series series)- {- _context.Entry(series).State = EntityState.Modified;- }+ public void Update(Series series)+ {+ _context.Entry(series).State = EntityState.Modified;+ }- public void Remove(Series series)- {- _context.Series.Remove(series);- }+ public void Remove(Series series)+ {+ _context.Series.Remove(series);+ }- public void Remove(IEnumerable<Series> series)- {- _context.Series.RemoveRange(series);- }+ public void Remove(IEnumerable<Series> series)+ {+ _context.Series.RemoveRange(series);+ }- /// <summary>- /// Returns if a series name and format exists already in a library- /// </summary>- /// <param name="name">Name of series</param>- /// <param name="format">Format of series</param>- /// <returns></returns>- public async Task<bool> DoesSeriesNameExistInLibrary(string name, MangaFormat format)- {- var libraries = _context.Series- .AsNoTracking()- .Where(x => x.Name.Equals(name) && x.Format == format)- .Select(s => s.LibraryId);+ /// <summary>+ /// Returns if a series name and format exists already in a library+ /// </summary>+ /// <param name="name">Name of series</param>+ /// <param name="format">Format of series</param>+ /// <returns></returns>+ public async Task<bool> DoesSeriesNameExistInLibrary(string name, MangaFormat format)+ {+ var libraries = _context.Series+ .AsNoTracking()+ .Where(x => x.Name.Equals(name) && x.Format == format)+ .Select(s => s.LibraryId);++ return await _context.Series+ .AsNoTracking()+ .Where(s => libraries.Contains(s.LibraryId) && s.Name.Equals(name) && s.Format == format)+ .CountAsync() > 1;+ }- return await _context.Series- .AsNoTracking()- .Where(s => libraries.Contains(s.LibraryId) && s.Name.Equals(name) && s.Format == format)- .CountAsync() > 1;- }+ public async Task<IEnumerable<Series>> GetSeriesForLibraryIdAsync(int libraryId)+ {+ return await _context.Series+ .Where(s => s.LibraryId == libraryId)+ .OrderBy(s => s.SortName)+ .ToListAsync();+ }- public async Task<IEnumerable<Series>> GetSeriesForLibraryIdAsync(int libraryId)- {- return await _context.Series- .Where(s => s.LibraryId == libraryId)- .OrderBy(s => s.SortName)- .ToListAsync();- }+ /// <summary>+ /// Used for <see cref="ScannerService"/> to+ /// </summary>+ /// <param name="libraryId"></param>+ /// <returns></returns>+ public async Task<PagedList<Series>> GetFullSeriesForLibraryIdAsync(int libraryId, UserParams userParams)+ {+ var query = _context.Series+ .Where(s => s.LibraryId == libraryId)- /// <summary>- /// Used for <see cref="ScannerService"/> to- /// </summary>- /// <param name="libraryId"></param>- /// <returns></returns>- public async Task<PagedList<Series>> GetFullSeriesForLibraryIdAsync(int libraryId, UserParams userParams)- {- var query = _context.Series- .Where(s => s.LibraryId == libraryId)- .Include(s => s.Metadata)- .Include(s => s.Volumes)- .ThenInclude(v => v.Chapters)- .ThenInclude(c => c.Files)- .AsSplitQuery()- .OrderBy(s => s.SortName);+ .Include(s => s.Metadata)+ .ThenInclude(m => m.People)- return await PagedList<Series>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);- }+ .Include(s => s.Metadata)+ .ThenInclude(m => m.Genres)- /// <summary>- /// This is a heavy call. Returns all entities down to Files and Library and Series Metadata.- /// </summary>- /// <param name="seriesId"></param>- /// <returns></returns>- public async Task<Series> GetFullSeriesForSeriesIdAsync(int seriesId)- {- return await _context.Series- .Where(s => s.Id == seriesId)- .Include(s => s.Metadata)- .Include(s => s.Library)- .Include(s => s.Volumes)- .ThenInclude(v => v.Chapters)- .ThenInclude(c => c.Files)- .AsSplitQuery()- .SingleOrDefaultAsync();- }+ .Include(s => s.Metadata)+ .ThenInclude(m => m.Tags)++ .Include(s => s.Volumes)+ .ThenInclude(v => v.Chapters)+ .ThenInclude(cm => cm.People)++ .Include(s => s.Volumes)+ .ThenInclude(v => v.Chapters)+ .ThenInclude(c => c.Genres)++ .Include(s => s.Volumes)+ .ThenInclude(v => v.Chapters)+ .ThenInclude(c => c.Tags)++ .Include(s => s.Volumes)+ .ThenInclude(v => v.Chapters)+ .ThenInclude(c => c.Files)+ .AsSplitQuery()+ .OrderBy(s => s.SortName);++ return await PagedList<Series>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);+ }++ /// <summary>+ /// This is a heavy call. Returns all entities down to Files and Library and Series Metadata.+ /// </summary>+ /// <param name="seriesId"></param>+ /// <returns></returns>+ public async Task<Series> GetFullSeriesForSeriesIdAsync(int seriesId)+ {+ return await _context.Series+ .Where(s => s.Id == seriesId)+ .Include(s => s.Metadata)+ .ThenInclude(m => m.People)+ .Include(s => s.Metadata)+ .ThenInclude(m => m.Genres)+ .Include(s => s.Library)+ .Include(s => s.Volumes)+ .ThenInclude(v => v.Chapters)+ .ThenInclude(cm => cm.People)++ .Include(s => s.Volumes)+ .ThenInclude(v => v.Chapters)+ .ThenInclude(c => c.Tags)++ .Include(s => s.Volumes)+ .ThenInclude(v => v.Chapters)+ .ThenInclude(c => c.Genres)+++ .Include(s => s.Metadata)+ .ThenInclude(m => m.Tags)++ .Include(s => s.Volumes)+ .ThenInclude(v => v.Chapters)+ .ThenInclude(c => c.Files)+ .AsSplitQuery()+ .SingleOrDefaultAsync();+ }- public async Task<PagedList<SeriesDto>> GetSeriesDtoForLibraryIdAsync(int libraryId, int userId, UserParams userParams, FilterDto filter)+ public async Task<PagedList<SeriesDto>> GetSeriesDtoForLibraryIdAsync(int libraryId, int userId, UserParams userParams, FilterDto filter)+ {+ var query = await CreateFilteredSearchQueryable(userId, libraryId, filter);++ if (filter.SortOptions == null){- var formats = filter.GetSqlFilter();- var query = _context.Series- .Where(s => s.LibraryId == libraryId && formats.Contains(s.Format))- .OrderBy(s => s.SortName)- .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)- .AsNoTracking();-- return await PagedList<SeriesDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);+ query = query.OrderBy(s => s.SortName);}- public async Task<IEnumerable<SearchResultDto>> SearchSeries(int[] libraryIds, string searchQuery)+ var retSeries = query+ .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)+ .AsSplitQuery()+ .AsNoTracking();++ return await PagedList<SeriesDto>.CreateAsync(retSeries, userParams.PageNumber, userParams.PageSize);+ }++ private async Task<List<int>> GetUserLibraries(int libraryId, int userId)+ {+ if (libraryId == 0){- return await _context.Series- .Where(s => libraryIds.Contains(s.LibraryId))- .Where(s => EF.Functions.Like(s.Name, $"%{searchQuery}%")- || EF.Functions.Like(s.OriginalName, $"%{searchQuery}%")- || EF.Functions.Like(s.LocalizedName, $"%{searchQuery}%"))- .Include(s => s.Library)- .OrderBy(s => s.SortName)+ return await _context.Library+ .Include(l => l.AppUsers)+ .Where(library => library.AppUsers.Any(user => user.Id == userId)).AsNoTracking()- .ProjectTo<SearchResultDto>(_mapper.ConfigurationProvider)+ .Select(library => library.Id).ToListAsync();}+ return new List<int>()+ {+ libraryId+ };+ }+ public async Task<IEnumerable<SearchResultDto>> SearchSeries(int[] libraryIds, string searchQuery)+ {+ return await _context.Series+ .Where(s => libraryIds.Contains(s.LibraryId))+ .Where(s => EF.Functions.Like(s.Name, $"%{searchQuery}%")+ || EF.Functions.Like(s.OriginalName, $"%{searchQuery}%")+ || EF.Functions.Like(s.LocalizedName, $"%{searchQuery}%"))+ .Include(s => s.Library)+ .OrderBy(s => s.SortName)+ .AsNoTracking()+ .ProjectTo<SearchResultDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }- public async Task<SeriesDto> GetSeriesDtoByIdAsync(int seriesId, int userId)- {- var series = await _context.Series.Where(x => x.Id == seriesId)- .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)- .SingleAsync();- var seriesList = new List<SeriesDto>() {series};- await AddSeriesModifiers(userId, seriesList);- return seriesList[0];- }+ public async Task<SeriesDto> GetSeriesDtoByIdAsync(int seriesId, int userId)+ {+ var series = await _context.Series.Where(x => x.Id == seriesId)+ .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)+ .SingleAsync();+ var seriesList = new List<SeriesDto>() {series};+ await AddSeriesModifiers(userId, seriesList);+ return seriesList[0];+ }- public async Task<bool> DeleteSeriesAsync(int seriesId)- {- var series = await _context.Series.Where(s => s.Id == seriesId).SingleOrDefaultAsync();- _context.Series.Remove(series);- return await _context.SaveChangesAsync() > 0;- }+ public async Task<bool> DeleteSeriesAsync(int seriesId)+ {+ var series = await _context.Series.Where(s => s.Id == seriesId).SingleOrDefaultAsync();+ if (series != null) _context.Series.Remove(series);- /// <summary>- /// Returns Volumes, Metadata, and Collection Tags- /// </summary>- /// <param name="seriesId"></param>- /// <returns></returns>- public async Task<Series> GetSeriesByIdAsync(int seriesId)- {- return await _context.Series- .Include(s => s.Volumes)- .Include(s => s.Metadata)- .ThenInclude(m => m.CollectionTags)- .Where(s => s.Id == seriesId)- .SingleOrDefaultAsync();- }+ return await _context.SaveChangesAsync() > 0;+ }- /// <summary>- /// Returns Volumes, Metadata, and Collection Tags- /// </summary>- /// <param name="seriesIds"></param>- /// <returns></returns>- public async Task<IList<Series>> GetSeriesByIdsAsync(IList<int> seriesIds)- {- return await _context.Series- .Include(s => s.Volumes)- .Include(s => s.Metadata)- .ThenInclude(m => m.CollectionTags)- .Where(s => seriesIds.Contains(s.Id))- .ToListAsync();- }- public async Task<int[]> GetChapterIdsForSeriesAsync(int[] seriesIds)- {- var volumes = await _context.Volume- .Where(v => seriesIds.Contains(v.SeriesId))- .Include(v => v.Chapters)- .ToListAsync();+ /// <summary>+ /// Returns Volumes, Metadata, and Collection Tags+ /// </summary>+ /// <param name="seriesId"></param>+ /// <returns></returns>+ public async Task<Series> GetSeriesByIdAsync(int seriesId)+ {+ return await _context.Series+ .Include(s => s.Volumes)+ .Include(s => s.Metadata)+ .ThenInclude(m => m.CollectionTags)+ .Include(s => s.Metadata)+ .ThenInclude(m => m.Genres)+ .Include(s => s.Metadata)+ .ThenInclude(m => m.People)+ .Where(s => s.Id == seriesId)+ .AsSplitQuery()+ .SingleOrDefaultAsync();+ }++ /// <summary>+ /// Returns Volumes, Metadata, and Collection Tags+ /// </summary>+ /// <param name="seriesIds"></param>+ /// <returns></returns>+ public async Task<IList<Series>> GetSeriesByIdsAsync(IList<int> seriesIds)+ {+ return await _context.Series+ .Include(s => s.Volumes)+ .Include(s => s.Metadata)+ .ThenInclude(m => m.CollectionTags)+ .Where(s => seriesIds.Contains(s.Id))+ .AsSplitQuery()+ .ToListAsync();+ }- IList<int> chapterIds = new List<int>();- foreach (var v in volumes)+ public async Task<int[]> GetChapterIdsForSeriesAsync(IList<int> seriesIds)+ {+ var volumes = await _context.Volume+ .Where(v => seriesIds.Contains(v.SeriesId))+ .Include(v => v.Chapters)+ .ToListAsync();++ IList<int> chapterIds = new List<int>();+ foreach (var v in volumes)+ {+ foreach (var c in v.Chapters){- foreach (var c in v.Chapters)- {- chapterIds.Add(c.Id);- }+ chapterIds.Add(c.Id);}-- return chapterIds.ToArray();}- /// <summary>- /// This returns a dictonary mapping seriesId -> list of chapters back for each series id passed- /// </summary>- /// <param name="seriesIds"></param>- /// <returns></returns>- public async Task<IDictionary<int, IList<int>>> GetChapterIdWithSeriesIdForSeriesAsync(int[] seriesIds)- {- var volumes = await _context.Volume- .Where(v => seriesIds.Contains(v.SeriesId))- .Include(v => v.Chapters)- .ToListAsync();+ return chapterIds.ToArray();+ }++ /// <summary>+ /// This returns a dictonary mapping seriesId -> list of chapters back for each series id passed+ /// </summary>+ /// <param name="seriesIds"></param>+ /// <returns></returns>+ public async Task<IDictionary<int, IList<int>>> GetChapterIdWithSeriesIdForSeriesAsync(int[] seriesIds)+ {+ var volumes = await _context.Volume+ .Where(v => seriesIds.Contains(v.SeriesId))+ .Include(v => v.Chapters)+ .ToListAsync();- var seriesChapters = new Dictionary<int, IList<int>>();- foreach (var v in volumes)+ var seriesChapters = new Dictionary<int, IList<int>>();+ foreach (var v in volumes)+ {+ foreach (var c in v.Chapters){- foreach (var c in v.Chapters)+ if (!seriesChapters.ContainsKey(v.SeriesId)){- if (!seriesChapters.ContainsKey(v.SeriesId))- {- var list = new List<int>();- seriesChapters.Add(v.SeriesId, list);- }- seriesChapters[v.SeriesId].Add(c.Id);+ var list = new List<int>();+ seriesChapters.Add(v.SeriesId, list);}+ seriesChapters[v.SeriesId].Add(c.Id);}-- return seriesChapters;}- public async Task AddSeriesModifiers(int userId, List<SeriesDto> series)- {- var userProgress = await _context.AppUserProgresses- .Where(p => p.AppUserId == userId && series.Select(s => s.Id).Contains(p.SeriesId))- .ToListAsync();+ return seriesChapters;+ }- var userRatings = await _context.AppUserRating- .Where(r => r.AppUserId == userId && series.Select(s => s.Id).Contains(r.SeriesId))- .ToListAsync();+ public async Task AddSeriesModifiers(int userId, List<SeriesDto> series)+ {+ var userProgress = await _context.AppUserProgresses+ .Where(p => p.AppUserId == userId && series.Select(s => s.Id).Contains(p.SeriesId))+ .ToListAsync();- foreach (var s in series)- {- s.PagesRead = userProgress.Where(p => p.SeriesId == s.Id).Sum(p => p.PagesRead);- var rating = userRatings.SingleOrDefault(r => r.SeriesId == s.Id);- if (rating == null) continue;- s.UserRating = rating.Rating;- s.UserReview = rating.Review;- }- }+ var userRatings = await _context.AppUserRating+ .Where(r => r.AppUserId == userId && series.Select(s => s.Id).Contains(r.SeriesId))+ .ToListAsync();- public async Task<string> GetSeriesCoverImageAsync(int seriesId)+ foreach (var s in series){- return await _context.Series- .Where(s => s.Id == seriesId)- .Select(s => s.CoverImage)- .AsNoTracking()- .SingleOrDefaultAsync();+ s.PagesRead = userProgress.Where(p => p.SeriesId == s.Id).Sum(p => p.PagesRead);+ var rating = userRatings.SingleOrDefault(r => r.SeriesId == s.Id);+ if (rating == null) continue;+ s.UserRating = rating.Rating;+ s.UserReview = rating.Review;}+ }+ public async Task<string> GetSeriesCoverImageAsync(int seriesId)+ {+ return await _context.Series+ .Where(s => s.Id == seriesId)+ .Select(s => s.CoverImage)+ .AsNoTracking()+ .SingleOrDefaultAsync();+ }- /// <summary>- /// Returns a list of Series that were added, ordered by Created desc- /// </summary>- /// <param name="userId"></param>- /// <param name="libraryId">Library to restrict to, if 0, will apply to all libraries</param>- /// <param name="userParams">Contains pagination information</param>- /// <param name="filter">Optional filter on query</param>- /// <returns></returns>- public async Task<PagedList<SeriesDto>> GetRecentlyAdded(int libraryId, int userId, UserParams userParams, FilterDto filter)- {- var formats = filter.GetSqlFilter();- if (libraryId == 0)- {- var userLibraries = _context.Library- .Include(l => l.AppUsers)- .Where(library => library.AppUsers.Any(user => user.Id == userId))- .AsNoTracking()- .Select(library => library.Id)- .ToList();-- var allQuery = _context.Series- .Where(s => userLibraries.Contains(s.LibraryId) && formats.Contains(s.Format))- .OrderByDescending(s => s.Created)- .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)- .AsNoTracking();-- return await PagedList<SeriesDto>.CreateAsync(allQuery, userParams.PageNumber, userParams.PageSize);- }+ /// <summary>+ /// Returns a list of Series that were added, ordered by Created desc+ /// </summary>+ /// <param name="userId"></param>+ /// <param name="libraryId">Library to restrict to, if 0, will apply to all libraries</param>+ /// <param name="userParams">Contains pagination information</param>+ /// <param name="filter">Optional filter on query</param>+ /// <returns></returns>+ public async Task<PagedList<SeriesDto>> GetRecentlyAdded(int libraryId, int userId, UserParams userParams, FilterDto filter)+ {+ var query = await CreateFilteredSearchQueryable(userId, libraryId, filter);- var query = _context.Series- .Where(s => s.LibraryId == libraryId && formats.Contains(s.Format))- .OrderByDescending(s => s.Created)- .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)- .AsSplitQuery()- .AsNoTracking();+ var retSeries = query+ .OrderByDescending(s => s.Created)+ .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)+ .AsSplitQuery()+ .AsNoTracking();- return await PagedList<SeriesDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);+ return await PagedList<SeriesDto>.CreateAsync(retSeries, userParams.PageNumber, userParams.PageSize);+ }++ private IList<MangaFormat> ExtractFilters(int libraryId, int userId, FilterDto filter, ref List<int> userLibraries,+ out List<int> allPeopleIds, out bool hasPeopleFilter, out bool hasGenresFilter, out bool hasCollectionTagFilter,+ out bool hasRatingFilter, out bool hasProgressFilter, out IList<int> seriesIds, out bool hasAgeRating, out bool hasTagsFilter,+ out bool hasLanguageFilter, out bool hasPublicationFilter)+ {+ var formats = filter.GetSqlFilter();++ if (filter.Libraries.Count > 0)+ {+ userLibraries = userLibraries.Where(l => filter.Libraries.Contains(l)).ToList();+ }+ else if (libraryId > 0)+ {+ userLibraries = userLibraries.Where(l => l == libraryId).ToList();}- /// <summary>- /// Returns Series that the user has some partial progress on. Sorts based on activity. Sort first by User progress, but if a series- /// has been updated recently, bump it to the front.- /// </summary>- /// <param name="userId"></param>- /// <param name="libraryId">Library to restrict to, if 0, will apply to all libraries</param>- /// <param name="userParams">Pagination information</param>- /// <param name="filter">Optional (default null) filter on query</param>- /// <returns></returns>- public async Task<IEnumerable<SeriesDto>> GetOnDeck(int userId, int libraryId, UserParams userParams, FilterDto filter)+ allPeopleIds = new List<int>();+ allPeopleIds.AddRange(filter.Writers);+ allPeopleIds.AddRange(filter.Character);+ allPeopleIds.AddRange(filter.Colorist);+ allPeopleIds.AddRange(filter.Editor);+ allPeopleIds.AddRange(filter.Inker);+ allPeopleIds.AddRange(filter.Letterer);+ allPeopleIds.AddRange(filter.Penciller);+ allPeopleIds.AddRange(filter.Publisher);+ allPeopleIds.AddRange(filter.CoverArtist);+ allPeopleIds.AddRange(filter.Translators);+ //allPeopleIds.AddRange(filter.Artist);++ hasPeopleFilter = allPeopleIds.Count > 0;+ hasGenresFilter = filter.Genres.Count > 0;+ hasCollectionTagFilter = filter.CollectionTags.Count > 0;+ hasRatingFilter = filter.Rating > 0;+ hasProgressFilter = !filter.ReadStatus.Read || !filter.ReadStatus.InProgress || !filter.ReadStatus.NotRead;+ hasAgeRating = filter.AgeRating.Count > 0;+ hasTagsFilter = filter.Tags.Count > 0;+ hasLanguageFilter = filter.Languages.Count > 0;+ hasPublicationFilter = filter.PublicationStatus.Count > 0;+++ bool ProgressComparison(int pagesRead, int totalPages){- var formats = filter.GetSqlFilter();- IList<int> userLibraries;- if (libraryId == 0)+ var result = false;+ if (filter.ReadStatus.NotRead){- userLibraries = _context.Library- .Include(l => l.AppUsers)- .Where(library => library.AppUsers.Any(user => user.Id == userId))- .AsNoTracking()- .Select(library => library.Id)- .ToList();+ result = (pagesRead == 0);}- else++ if (filter.ReadStatus.Read){- userLibraries = new List<int>() {libraryId};+ result = result || (pagesRead == totalPages);}- var series = _context.Series- .Where(s => formats.Contains(s.Format) && userLibraries.Contains(s.LibraryId))- .Join(_context.AppUserProgresses, s => s.Id, progress => progress.SeriesId, (s, progress) => new- {- Series = s,- PagesRead = _context.AppUserProgresses.Where(s1 => s1.SeriesId == s.Id && s1.AppUserId == userId).Sum(s1 => s1.PagesRead),- progress.AppUserId,- LastModified = _context.AppUserProgresses.Where(p => p.Id == progress.Id && p.AppUserId == userId).Max(p => p.LastModified)- })- .AsNoTracking();-- var retSeries = series.Where(s => s.AppUserId == userId- && s.PagesRead > 0- && s.PagesRead < s.Series.Pages)- .OrderByDescending(s => s.LastModified)- .ThenByDescending(s => s.Series.LastModified)- .Select(s => s.Series)- .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)- .AsSplitQuery()- .AsNoTracking();-- // Pagination does not work for this query as when we pull the data back, we get multiple rows of the same series. See controller for pagination code- return await retSeries.ToListAsync();- }-- public async Task<SeriesMetadataDto> GetSeriesMetadata(int seriesId)- {- var metadataDto = await _context.SeriesMetadata- .Where(metadata => metadata.SeriesId == seriesId)- .AsNoTracking()- .ProjectTo<SeriesMetadataDto>(_mapper.ConfigurationProvider)- .SingleOrDefaultAsync();-- if (metadataDto != null)+ if (filter.ReadStatus.InProgress){- metadataDto.Tags = await _context.CollectionTag- .Include(t => t.SeriesMetadatas)- .Where(t => t.SeriesMetadatas.Select(s => s.SeriesId).Contains(seriesId))- .ProjectTo<CollectionTagDto>(_mapper.ConfigurationProvider)- .AsNoTracking()- .ToListAsync();+ result = result || (pagesRead > 0 && pagesRead < totalPages);}- return metadataDto;+ return result;}- public async Task<PagedList<SeriesDto>> GetSeriesDtoForCollectionAsync(int collectionId, int userId, UserParams userParams)+ seriesIds = new List<int>();+ if (hasProgressFilter){- var userLibraries = _context.Library- .Include(l => l.AppUsers)- .Where(library => library.AppUsers.Any(user => user.Id == userId))- .AsNoTracking()- .Select(library => library.Id)+ seriesIds = _context.Series+ .Include(s => s.Progress)+ .Select(s => new+ {+ Series = s,+ PagesRead = s.Progress.Where(p => p.AppUserId == userId).Sum(p => p.PagesRead),+ })+ .AsEnumerable()+ .Where(s => ProgressComparison(s.PagesRead, s.Series.Pages))+ .Select(s => s.Series.Id).ToList();-- var query = _context.CollectionTag- .Where(s => s.Id == collectionId)- .Include(c => c.SeriesMetadatas)- .ThenInclude(m => m.Series)- .SelectMany(c => c.SeriesMetadatas.Select(sm => sm.Series).Where(s => userLibraries.Contains(s.LibraryId)))- .OrderBy(s => s.LibraryId)- .ThenBy(s => s.SortName)- .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)- .AsNoTracking();-- return await PagedList<SeriesDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);}- public async Task<IList<MangaFile>> GetFilesForSeries(int seriesId)+ return formats;+ }++ /// <summary>+ /// Returns Series that the user has some partial progress on. Sorts based on activity. Sort first by User progress, but if a series+ /// has been updated recently, bump it to the front.+ /// </summary>+ /// <param name="userId"></param>+ /// <param name="libraryId">Library to restrict to, if 0, will apply to all libraries</param>+ /// <param name="userParams">Pagination information</param>+ /// <param name="filter">Optional (default null) filter on query</param>+ /// <returns></returns>+ public async Task<IEnumerable<SeriesDto>> GetOnDeck(int userId, int libraryId, UserParams userParams, FilterDto filter)+ {+ //var allSeriesWithProgress = await _context.AppUserProgresses.Select(p => p.SeriesId).ToListAsync();+ //var allChapters = await GetChapterIdsForSeriesAsync(allSeriesWithProgress);++ var query = (await CreateFilteredSearchQueryable(userId, libraryId, filter))+ .Join(_context.AppUserProgresses, s => s.Id, progress => progress.SeriesId, (s, progress) =>+ new+ {+ Series = s,+ PagesRead = _context.AppUserProgresses.Where(s1 => s1.SeriesId == s.Id && s1.AppUserId == userId)+ .Sum(s1 => s1.PagesRead),+ progress.AppUserId,+ LastReadingProgress = _context.AppUserProgresses.Where(p => p.Id == progress.Id && p.AppUserId == userId)+ .Max(p => p.LastModified),+ // This is only taking into account chapters that have progress on them, not all chapters in said series+ LastChapterCreated = _context.Chapter.Where(c => progress.ChapterId == c.Id).Max(c => c.Created)+ //LastChapterCreated = _context.Chapter.Where(c => allChapters.Contains(c.Id)).Max(c => c.Created)+ });+ // I think I need another Join statement. The problem is the chapters are still limited to progress++++ var retSeries = query.Where(s => s.AppUserId == userId+ && s.PagesRead > 0+ && s.PagesRead < s.Series.Pages)+ .OrderByDescending(s => s.LastReadingProgress)+ .ThenByDescending(s => s.LastChapterCreated)+ .Select(s => s.Series)+ .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)+ .AsSplitQuery()+ .AsNoTracking();++ // Pagination does not work for this query as when we pull the data back, we get multiple rows of the same series. See controller for pagination code+ return await retSeries.ToListAsync();+ }++ private async Task<IQueryable<Series>> CreateFilteredSearchQueryable(int userId, int libraryId, FilterDto filter)+ {+ var userLibraries = await GetUserLibraries(libraryId, userId);+ var formats = ExtractFilters(libraryId, userId, filter, ref userLibraries,+ out var allPeopleIds, out var hasPeopleFilter, out var hasGenresFilter,+ out var hasCollectionTagFilter, out var hasRatingFilter, out var hasProgressFilter,+ out var seriesIds, out var hasAgeRating, out var hasTagsFilter, out var hasLanguageFilter, out var hasPublicationFilter);++ var query = _context.Series+ .Where(s => userLibraries.Contains(s.LibraryId)+ && formats.Contains(s.Format)+ && (!hasGenresFilter || s.Metadata.Genres.Any(g => filter.Genres.Contains(g.Id)))+ && (!hasPeopleFilter || s.Metadata.People.Any(p => allPeopleIds.Contains(p.Id)))+ && (!hasCollectionTagFilter ||+ s.Metadata.CollectionTags.Any(t => filter.CollectionTags.Contains(t.Id)))+ && (!hasRatingFilter || s.Ratings.Any(r => r.Rating >= filter.Rating))+ && (!hasProgressFilter || seriesIds.Contains(s.Id))+ && (!hasAgeRating || filter.AgeRating.Contains(s.Metadata.AgeRating))+ && (!hasTagsFilter || s.Metadata.Tags.Any(t => filter.Tags.Contains(t.Id)))+ && (!hasLanguageFilter || filter.Languages.Contains(s.Metadata.Language))+ && (!hasPublicationFilter || filter.PublicationStatus.Contains(s.Metadata.PublicationStatus))+ )+ .AsNoTracking();++ if (filter.SortOptions != null){- return await _context.Volume- .Where(v => v.SeriesId == seriesId)- .Include(v => v.Chapters)- .ThenInclude(c => c.Files)- .SelectMany(v => v.Chapters.SelectMany(c => c.Files))- .AsNoTracking()- .ToListAsync();+ if (filter.SortOptions.IsAscending)+ {+ if (filter.SortOptions.SortField == SortField.SortName)+ {+ query = query.OrderBy(s => s.SortName);+ } else if (filter.SortOptions.SortField == SortField.CreatedDate)+ {+ query = query.OrderBy(s => s.Created);+ } else if (filter.SortOptions.SortField == SortField.LastModifiedDate)+ {+ query = query.OrderBy(s => s.LastModified);+ }+ }+ else+ {+ if (filter.SortOptions.SortField == SortField.SortName)+ {+ query = query.OrderByDescending(s => s.SortName);+ } else if (filter.SortOptions.SortField == SortField.CreatedDate)+ {+ query = query.OrderByDescending(s => s.Created);+ } else if (filter.SortOptions.SortField == SortField.LastModifiedDate)+ {+ query = query.OrderByDescending(s => s.LastModified);+ }+ }}- public async Task<IEnumerable<SeriesDto>> GetSeriesDtoForIdsAsync(IEnumerable<int> seriesIds, int userId)- {- var allowedLibraries = _context.Library- .Include(l => l.AppUsers)- .Where(library => library.AppUsers.Any(x => x.Id == userId))- .Select(l => l.Id);+ return query;+ }- return await _context.Series- .Where(s => seriesIds.Contains(s.Id) && allowedLibraries.Contains(s.LibraryId))- .OrderBy(s => s.SortName)- .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)+ public async Task<SeriesMetadataDto> GetSeriesMetadata(int seriesId)+ {+ var metadataDto = await _context.SeriesMetadata+ .Where(metadata => metadata.SeriesId == seriesId)+ .Include(m => m.Genres)+ .Include(m => m.Tags)+ .Include(m => m.People)+ .AsNoTracking()+ .ProjectTo<SeriesMetadataDto>(_mapper.ConfigurationProvider)+ .AsSplitQuery()+ .SingleOrDefaultAsync();++ if (metadataDto != null)+ {+ metadataDto.CollectionTags = await _context.CollectionTag+ .Include(t => t.SeriesMetadatas)+ .Where(t => t.SeriesMetadatas.Select(s => s.SeriesId).Contains(seriesId))+ .ProjectTo<CollectionTagDto>(_mapper.ConfigurationProvider).AsNoTracking().AsSplitQuery().ToListAsync();}- public async Task<IList<string>> GetAllCoverImagesAsync()- {- return await _context.Series- .Select(s => s.CoverImage)- .Where(t => !string.IsNullOrEmpty(t))- .AsNoTracking()- .ToListAsync();- }+ return metadataDto;+ }++ public async Task<PagedList<SeriesDto>> GetSeriesDtoForCollectionAsync(int collectionId, int userId, UserParams userParams)+ {+ var userLibraries = _context.Library+ .Include(l => l.AppUsers)+ .Where(library => library.AppUsers.Any(user => user.Id == userId))+ .AsNoTracking()+ .Select(library => library.Id)+ .ToList();++ var query = _context.CollectionTag+ .Where(s => s.Id == collectionId)+ .Include(c => c.SeriesMetadatas)+ .ThenInclude(m => m.Series)+ .SelectMany(c => c.SeriesMetadatas.Select(sm => sm.Series).Where(s => userLibraries.Contains(s.LibraryId)))+ .OrderBy(s => s.LibraryId)+ .ThenBy(s => s.SortName)+ .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)+ .AsSplitQuery()+ .AsNoTracking();++ return await PagedList<SeriesDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);+ }- public async Task<IEnumerable<string>> GetLockedCoverImagesAsync()+ public async Task<IList<MangaFile>> GetFilesForSeries(int seriesId)+ {+ return await _context.Volume+ .Where(v => v.SeriesId == seriesId)+ .Include(v => v.Chapters)+ .ThenInclude(c => c.Files)+ .SelectMany(v => v.Chapters.SelectMany(c => c.Files))+ .AsNoTracking()+ .ToListAsync();+ }++ public async Task<IEnumerable<SeriesDto>> GetSeriesDtoForIdsAsync(IEnumerable<int> seriesIds, int userId)+ {+ var allowedLibraries = _context.Library+ .Include(l => l.AppUsers)+ .Where(library => library.AppUsers.Any(x => x.Id == userId))+ .Select(l => l.Id);++ return await _context.Series+ .Where(s => seriesIds.Contains(s.Id) && allowedLibraries.Contains(s.LibraryId))+ .OrderBy(s => s.SortName)+ .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)+ .AsNoTracking()+ .AsSplitQuery()+ .ToListAsync();+ }++ public async Task<IList<string>> GetAllCoverImagesAsync()+ {+ return await _context.Series+ .Select(s => s.CoverImage)+ .Where(t => !string.IsNullOrEmpty(t))+ .AsNoTracking()+ .ToListAsync();+ }++ public async Task<IEnumerable<string>> GetLockedCoverImagesAsync()+ {+ return await _context.Series+ .Where(s => s.CoverImageLocked && !string.IsNullOrEmpty(s.CoverImage))+ .Select(s => s.CoverImage)+ .AsNoTracking()+ .ToListAsync();+ }++ /// <summary>+ /// Returns the number of series for a given library (or all libraries if libraryId is 0)+ /// </summary>+ /// <param name="libraryId">Defaults to 0, library to restrict count to</param>+ /// <returns></returns>+ private async Task<int> GetSeriesCount(int libraryId = 0)+ {+ if (libraryId > 0){return await _context.Series- .Where(s => s.CoverImageLocked && !string.IsNullOrEmpty(s.CoverImage))- .Select(s => s.CoverImage)- .AsNoTracking()- .ToListAsync();+ .Where(s => s.LibraryId == libraryId)+ .CountAsync();}+ return await _context.Series.CountAsync();+ }- /// <summary>- /// Returns the number of series for a given library (or all libraries if libraryId is 0)- /// </summary>- /// <param name="libraryId">Defaults to 0, library to restrict count to</param>- /// <returns></returns>- private async Task<int> GetSeriesCount(int libraryId = 0)- {- if (libraryId > 0)- {- return await _context.Series- .Where(s => s.LibraryId == libraryId)- .CountAsync();- }- return await _context.Series.CountAsync();- }+ /// <summary>+ /// Returns the number of series that should be processed in parallel to optimize speed and memory. Minimum of 50+ /// </summary>+ /// <param name="libraryId">Defaults to 0 meaning no library</param>+ /// <returns></returns>+ private async Task<Tuple<int, int>> GetChunkSize(int libraryId = 0)+ {+ var totalSeries = await GetSeriesCount(libraryId);+ return new Tuple<int, int>(totalSeries, 50);+ }++ public async Task<Chunk> GetChunkInfo(int libraryId = 0)+ {+ var (totalSeries, chunkSize) = await GetChunkSize(libraryId);- /// <summary>- /// Returns the number of series that should be processed in parallel to optimize speed and memory. Minimum of 50- /// </summary>- /// <param name="libraryId">Defaults to 0 meaning no library</param>- /// <returns></returns>- private async Task<Tuple<int, int>> GetChunkSize(int libraryId = 0)+ if (totalSeries == 0) return new Chunk(){- // TODO: Think about making this bigger depending on number of files a user has in said library- // and number of cores and amount of memory. We can then make an optimal choice- var totalSeries = await GetSeriesCount(libraryId);- // var procCount = Math.Max(Environment.ProcessorCount - 1, 1);- //- // if (totalSeries < procCount * 2 || totalSeries < 50)- // {- // return new Tuple<int, int>(totalSeries, totalSeries);- // }- //- // return new Tuple<int, int>(totalSeries, Math.Max(totalSeries / procCount, 50));- return new Tuple<int, int>(totalSeries, 50);- }+ TotalChunks = 0,+ TotalSize = 0,+ ChunkSize = 0+ };++ var totalChunks = Math.Max((int) Math.Ceiling((totalSeries * 1.0) / chunkSize), 1);- public async Task<Chunk> GetChunkInfo(int libraryId = 0)+ return new Chunk(){- var (totalSeries, chunkSize) = await GetChunkSize(libraryId);+ TotalSize = totalSeries,+ ChunkSize = chunkSize,+ TotalChunks = totalChunks+ };+ }- if (totalSeries == 0) return new Chunk()- {- TotalChunks = 0,- TotalSize = 0,- ChunkSize = 0- };+ public async Task<IList<SeriesMetadata>> GetSeriesMetadataForIdsAsync(IEnumerable<int> seriesIds)+ {+ return await _context.SeriesMetadata+ .Where(sm => seriesIds.Contains(sm.SeriesId))+ .Include(sm => sm.CollectionTags)+ .ToListAsync();+ }- var totalChunks = Math.Max((int) Math.Ceiling((totalSeries * 1.0) / chunkSize), 1);+ public async Task<IList<AgeRatingDto>> GetAllAgeRatingsDtosForLibrariesAsync(List<int> libraryIds)+ {+ return await _context.Series+ .Where(s => libraryIds.Contains(s.LibraryId))+ .Select(s => s.Metadata.AgeRating)+ .Distinct()+ .Select(s => new AgeRatingDto()+ {+ Value = s,+ Title = s.ToDescription()+ })+ .ToListAsync();+ }- return new Chunk()+ public async Task<IList<LanguageDto>> GetAllLanguagesForLibrariesAsync(List<int> libraryIds)+ {+ var ret = await _context.Series+ .Where(s => libraryIds.Contains(s.LibraryId))+ .Select(s => s.Metadata.Language)+ .Distinct()+ .ToListAsync();++ return ret+ .Where(s => !string.IsNullOrEmpty(s))+ .Select(s => new LanguageDto(){- TotalSize = totalSeries,- ChunkSize = chunkSize,- TotalChunks = totalChunks- };- }+ Title = CultureInfo.GetCultureInfo(s).DisplayName,+ IsoCode = s+ }).ToList();+ }- public async Task<IList<SeriesMetadata>> GetSeriesMetadataForIdsAsync(IEnumerable<int> seriesIds)- {- return await _context.SeriesMetadata- .Where(sm => seriesIds.Contains(sm.SeriesId))- .Include(sm => sm.CollectionTags)- .ToListAsync();- }+ public async Task<IList<PublicationStatusDto>> GetAllPublicationStatusesDtosForLibrariesAsync(List<int> libraryIds)+ {+ return await _context.Series+ .Where(s => libraryIds.Contains(s.LibraryId))+ .Select(s => s.Metadata.PublicationStatus)+ .Distinct()+ .Select(s => new PublicationStatusDto()+ {+ Value = s,+ Title = s.ToDescription()+ })+ .ToListAsync();}}diff --git a/API/Data/Repositories/SettingsRepository.cs b/API/Data/Repositories/SettingsRepository.csindex 4489cf3bd..be66cbe62 100644--- a/API/Data/Repositories/SettingsRepository.cs+++ b/API/Data/Repositories/SettingsRepository.cs@@ -4,45 +4,50 @@ using System.Threading.Tasks;using API.DTOs.Settings;using API.Entities;using API.Entities.Enums;-using API.Interfaces.Repositories;using AutoMapper;using Microsoft.EntityFrameworkCore;-namespace API.Data.Repositories+namespace API.Data.Repositories;++public interface ISettingsRepository{- public class SettingsRepository : ISettingsRepository- {- private readonly DataContext _context;- private readonly IMapper _mapper;+ void Update(ServerSetting settings);+ Task<ServerSettingDto> GetSettingsDtoAsync();+ Task<ServerSetting> GetSettingAsync(ServerSettingKey key);+ Task<IEnumerable<ServerSetting>> GetSettingsAsync();+}+public class SettingsRepository : ISettingsRepository+{+ private readonly DataContext _context;+ private readonly IMapper _mapper;- public SettingsRepository(DataContext context, IMapper mapper)- {- _context = context;- _mapper = mapper;- }+ public SettingsRepository(DataContext context, IMapper mapper)+ {+ _context = context;+ _mapper = mapper;+ }- public void Update(ServerSetting settings)- {- _context.Entry(settings).State = EntityState.Modified;- }+ public void Update(ServerSetting settings)+ {+ _context.Entry(settings).State = EntityState.Modified;+ }- public async Task<ServerSettingDto> GetSettingsDtoAsync()- {- var settings = await _context.ServerSetting- .Select(x => x)- .AsNoTracking()- .ToListAsync();- return _mapper.Map<ServerSettingDto>(settings);- }+ public async Task<ServerSettingDto> GetSettingsDtoAsync()+ {+ var settings = await _context.ServerSetting+ .Select(x => x)+ .AsNoTracking()+ .ToListAsync();+ return _mapper.Map<ServerSettingDto>(settings);+ }- public Task<ServerSetting> GetSettingAsync(ServerSettingKey key)- {- return _context.ServerSetting.SingleOrDefaultAsync(x => x.Key == key);- }+ public Task<ServerSetting> GetSettingAsync(ServerSettingKey key)+ {+ return _context.ServerSetting.SingleOrDefaultAsync(x => x.Key == key);+ }- public async Task<IEnumerable<ServerSetting>> GetSettingsAsync()- {- return await _context.ServerSetting.ToListAsync();- }+ public async Task<IEnumerable<ServerSetting>> GetSettingsAsync()+ {+ return await _context.ServerSetting.ToListAsync();}}diff --git a/API/Data/Repositories/TagRepository.cs b/API/Data/Repositories/TagRepository.csnew file mode 100644index 000000000..772957aa9--- /dev/null+++ b/API/Data/Repositories/TagRepository.cs@@ -0,0 +1,86 @@+using System.Collections.Generic;+using System.Linq;+using System.Threading.Tasks;+using API.DTOs.Metadata;+using API.Entities;+using AutoMapper;+using AutoMapper.QueryableExtensions;+using Microsoft.EntityFrameworkCore;++namespace API.Data.Repositories;++public interface ITagRepository+{+ void Attach(Tag tag);+ void Remove(Tag tag);+ Task<Tag> FindByNameAsync(string tagName);+ Task<IList<Tag>> GetAllTagsAsync();+ Task<IList<TagDto>> GetAllTagDtosAsync();+ Task RemoveAllTagNoLongerAssociated(bool removeExternal = false);+ Task<IList<TagDto>> GetAllTagDtosForLibrariesAsync(IList<int> libraryIds);+}++public class TagRepository : ITagRepository+{+ private readonly DataContext _context;+ private readonly IMapper _mapper;++ public TagRepository(DataContext context, IMapper mapper)+ {+ _context = context;+ _mapper = mapper;+ }++ public void Attach(Tag tag)+ {+ _context.Tag.Attach(tag);+ }++ public void Remove(Tag tag)+ {+ _context.Tag.Remove(tag);+ }++ public async Task<Tag> FindByNameAsync(string tagName)+ {+ var normalizedName = Parser.Parser.Normalize(tagName);+ return await _context.Tag+ .FirstOrDefaultAsync(g => g.NormalizedTitle.Equals(normalizedName));+ }++ public async Task RemoveAllTagNoLongerAssociated(bool removeExternal = false)+ {+ var TagsWithNoConnections = await _context.Tag+ .Include(p => p.SeriesMetadatas)+ .Include(p => p.Chapters)+ .Where(p => p.SeriesMetadatas.Count == 0 && p.Chapters.Count == 0 && p.ExternalTag == removeExternal)+ .ToListAsync();++ _context.Tag.RemoveRange(TagsWithNoConnections);++ await _context.SaveChangesAsync();+ }++ public async Task<IList<TagDto>> GetAllTagDtosForLibrariesAsync(IList<int> libraryIds)+ {+ return await _context.Series+ .Where(s => libraryIds.Contains(s.LibraryId))+ .SelectMany(s => s.Metadata.Tags)+ .Distinct()+ .ProjectTo<TagDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }++ public async Task<IList<Tag>> GetAllTagsAsync()+ {+ return await _context.Tag.ToListAsync();+ }++ public async Task<IList<TagDto>> GetAllTagDtosAsync()+ {+ return await _context.Tag+ .AsNoTracking()+ .ProjectTo<TagDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }+}diff --git a/API/Data/Repositories/UserRepository.cs b/API/Data/Repositories/UserRepository.csindex ece1356fd..138ef15b8 100644--- a/API/Data/Repositories/UserRepository.cs+++ b/API/Data/Repositories/UserRepository.cs@@ -6,254 +6,303 @@ using API.Constants;using API.DTOs;using API.DTOs.Reader;using API.Entities;-using API.Interfaces.Repositories;using AutoMapper;using AutoMapper.QueryableExtensions;using Microsoft.AspNetCore.Identity;using Microsoft.EntityFrameworkCore;-namespace API.Data.Repositories+namespace API.Data.Repositories;++[Flags]+public enum AppUserIncludes+{+ None = 1,+ Progress = 2,+ Bookmarks = 4,+ ReadingLists = 8,+ Ratings = 16+}++public interface IUserRepository+{+ void Update(AppUser user);+ void Update(AppUserPreferences preferences);+ void Update(AppUserBookmark bookmark);+ public void Delete(AppUser user);+ Task<IEnumerable<MemberDto>> GetMembersAsync();+ Task<IEnumerable<AppUser>> GetAdminUsersAsync();+ Task<IEnumerable<AppUser>> GetNonAdminUsersAsync();+ Task<bool> IsUserAdminAsync(AppUser user);+ Task<AppUserRating> GetUserRatingAsync(int seriesId, int userId);+ Task<AppUserPreferences> GetPreferencesAsync(string username);+ Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForSeries(int userId, int seriesId);+ Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForVolume(int userId, int volumeId);+ Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForChapter(int userId, int chapterId);+ Task<IEnumerable<BookmarkDto>> GetAllBookmarkDtos(int userId);+ Task<IEnumerable<AppUserBookmark>> GetAllBookmarksAsync();+ Task<AppUserBookmark> GetBookmarkForPage(int page, int chapterId, int userId);+ Task<AppUserBookmark> GetBookmarkAsync(int bookmarkId);+ Task<int> GetUserIdByApiKeyAsync(string apiKey);+ Task<AppUser> GetUserByUsernameAsync(string username, AppUserIncludes includeFlags = AppUserIncludes.None);+ Task<AppUser> GetUserByIdAsync(int userId, AppUserIncludes includeFlags = AppUserIncludes.None);+ Task<int> GetUserIdByUsernameAsync(string username);+ Task<AppUser> GetUserWithReadingListsByUsernameAsync(string username);+ Task<IList<AppUserBookmark>> GetAllBookmarksByIds(IList<int> bookmarkIds);+}++public class UserRepository : IUserRepository{- [Flags]- public enum AppUserIncludes+ private readonly DataContext _context;+ private readonly UserManager<AppUser> _userManager;+ private readonly IMapper _mapper;++ public UserRepository(DataContext context, UserManager<AppUser> userManager, IMapper mapper){- None = 1,- Progress = 2,- Bookmarks = 4,- ReadingLists = 8,- Ratings = 16+ _context = context;+ _userManager = userManager;+ _mapper = mapper;}- public class UserRepository : IUserRepository+ public void Update(AppUser user){- private readonly DataContext _context;- private readonly UserManager<AppUser> _userManager;- private readonly IMapper _mapper;+ _context.Entry(user).State = EntityState.Modified;+ }- public UserRepository(DataContext context, UserManager<AppUser> userManager, IMapper mapper)- {- _context = context;- _userManager = userManager;- _mapper = mapper;- }+ public void Update(AppUserPreferences preferences)+ {+ _context.Entry(preferences).State = EntityState.Modified;+ }- public void Update(AppUser user)- {- _context.Entry(user).State = EntityState.Modified;- }+ public void Update(AppUserBookmark bookmark)+ {+ _context.Entry(bookmark).State = EntityState.Modified;+ }- public void Update(AppUserPreferences preferences)- {- _context.Entry(preferences).State = EntityState.Modified;- }+ public void Delete(AppUser user)+ {+ _context.AppUser.Remove(user);+ }- public void Update(AppUserBookmark bookmark)- {- _context.Entry(bookmark).State = EntityState.Modified;- }+ /// <summary>+ /// A one stop shop to get a tracked AppUser instance with any number of JOINs generated by passing bitwise flags.+ /// </summary>+ /// <param name="username"></param>+ /// <param name="includeFlags">Includes() you want. Pass multiple with flag1 | flag2 </param>+ /// <returns></returns>+ public async Task<AppUser> GetUserByUsernameAsync(string username, AppUserIncludes includeFlags = AppUserIncludes.None)+ {+ var query = _context.Users+ .Where(x => x.UserName == username);- public void Delete(AppUser user)- {- _context.AppUser.Remove(user);- }+ query = AddIncludesToQuery(query, includeFlags);- /// <summary>- /// A one stop shop to get a tracked AppUser instance with any number of JOINs generated by passing bitwise flags.- /// </summary>- /// <param name="username"></param>- /// <param name="includeFlags">Includes() you want. Pass multiple with flag1 | flag2 </param>- /// <returns></returns>- public async Task<AppUser> GetUserByUsernameAsync(string username, AppUserIncludes includeFlags = AppUserIncludes.None)- {- var query = _context.Users- .Where(x => x.UserName == username);+ return await query.SingleOrDefaultAsync();+ }- query = AddIncludesToQuery(query, includeFlags);+ /// <summary>+ /// A one stop shop to get a tracked AppUser instance with any number of JOINs generated by passing bitwise flags.+ /// </summary>+ /// <param name="userId"></param>+ /// <param name="includeFlags">Includes() you want. Pass multiple with flag1 | flag2 </param>+ /// <returns></returns>+ public async Task<AppUser> GetUserByIdAsync(int userId, AppUserIncludes includeFlags = AppUserIncludes.None)+ {+ var query = _context.Users+ .Where(x => x.Id == userId);- return await query.SingleOrDefaultAsync();- }+ query = AddIncludesToQuery(query, includeFlags);- /// <summary>- /// A one stop shop to get a tracked AppUser instance with any number of JOINs generated by passing bitwise flags.- /// </summary>- /// <param name="userId"></param>- /// <param name="includeFlags">Includes() you want. Pass multiple with flag1 | flag2 </param>- /// <returns></returns>- public async Task<AppUser> GetUserByIdAsync(int userId, AppUserIncludes includeFlags = AppUserIncludes.None)- {- var query = _context.Users- .Where(x => x.Id == userId);+ return await query.SingleOrDefaultAsync();+ }- query = AddIncludesToQuery(query, includeFlags);+ public async Task<IEnumerable<AppUserBookmark>> GetAllBookmarksAsync()+ {+ return await _context.AppUserBookmark.ToListAsync();+ }- return await query.SingleOrDefaultAsync();- }+ public async Task<AppUserBookmark> GetBookmarkForPage(int page, int chapterId, int userId)+ {+ return await _context.AppUserBookmark+ .Where(b => b.Page == page && b.ChapterId == chapterId && b.AppUserId == userId)+ .SingleOrDefaultAsync();+ }- public async Task<AppUserBookmark> GetBookmarkForPage(int page, int chapterId, int userId)- {- return await _context.AppUserBookmark- .Where(b => b.Page == page && b.ChapterId == chapterId && b.AppUserId == userId)- .SingleOrDefaultAsync();- }+ public async Task<AppUserBookmark> GetBookmarkAsync(int bookmarkId)+ {+ return await _context.AppUserBookmark+ .Where(b => b.Id == bookmarkId)+ .SingleOrDefaultAsync();+ }- private static IQueryable<AppUser> AddIncludesToQuery(IQueryable<AppUser> query, AppUserIncludes includeFlags)+ private static IQueryable<AppUser> AddIncludesToQuery(IQueryable<AppUser> query, AppUserIncludes includeFlags)+ {+ if (includeFlags.HasFlag(AppUserIncludes.Bookmarks)){- if (includeFlags.HasFlag(AppUserIncludes.Bookmarks))- {- query = query.Include(u => u.Bookmarks);- }-- if (includeFlags.HasFlag(AppUserIncludes.Progress))- {- query = query.Include(u => u.Progresses);- }-- if (includeFlags.HasFlag(AppUserIncludes.ReadingLists))- {- query = query.Include(u => u.ReadingLists);- }-- if (includeFlags.HasFlag(AppUserIncludes.Ratings))- {- query = query.Include(u => u.Ratings);- }-- return query;+ query = query.Include(u => u.Bookmarks);}-- /// <summary>- /// This fetches the Id for a user. Use whenever you just need an ID.- /// </summary>- /// <param name="username"></param>- /// <returns></returns>- public async Task<int> GetUserIdByUsernameAsync(string username)+ if (includeFlags.HasFlag(AppUserIncludes.Progress)){- return await _context.Users- .Where(x => x.UserName == username)- .Select(u => u.Id)- .SingleOrDefaultAsync();+ query = query.Include(u => u.Progresses);}- /// <summary>- /// Gets an AppUser by username. Returns back Reading List and their Items.- /// </summary>- /// <param name="username"></param>- /// <returns></returns>- public async Task<AppUser> GetUserWithReadingListsByUsernameAsync(string username)+ if (includeFlags.HasFlag(AppUserIncludes.ReadingLists)){- return await _context.Users- .Include(u => u.ReadingLists)- .ThenInclude(l => l.Items)- .SingleOrDefaultAsync(x => x.UserName == username);+ query = query.Include(u => u.ReadingLists);}- public async Task<IEnumerable<AppUser>> GetAdminUsersAsync()+ if (includeFlags.HasFlag(AppUserIncludes.Ratings)){- return await _userManager.GetUsersInRoleAsync(PolicyConstants.AdminRole);+ query = query.Include(u => u.Ratings);}- public async Task<IEnumerable<AppUser>> GetNonAdminUsersAsync()- {- return await _userManager.GetUsersInRoleAsync(PolicyConstants.PlebRole);- }+ return query;+ }- public async Task<bool> IsUserAdmin(AppUser user)- {- return await _userManager.IsInRoleAsync(user, PolicyConstants.AdminRole);- }- public async Task<AppUserRating> GetUserRating(int seriesId, int userId)- {- return await _context.AppUserRating.Where(r => r.SeriesId == seriesId && r.AppUserId == userId)- .SingleOrDefaultAsync();- }+ /// <summary>+ /// This fetches the Id for a user. Use whenever you just need an ID.+ /// </summary>+ /// <param name="username"></param>+ /// <returns></returns>+ public async Task<int> GetUserIdByUsernameAsync(string username)+ {+ return await _context.Users+ .Where(x => x.UserName == username)+ .Select(u => u.Id)+ .SingleOrDefaultAsync();+ }- public async Task<AppUserPreferences> GetPreferencesAsync(string username)- {- return await _context.AppUserPreferences- .Include(p => p.AppUser)- .SingleOrDefaultAsync(p => p.AppUser.UserName == username);- }+ /// <summary>+ /// Gets an AppUser by username. Returns back Reading List and their Items.+ /// </summary>+ /// <param name="username"></param>+ /// <returns></returns>+ public async Task<AppUser> GetUserWithReadingListsByUsernameAsync(string username)+ {+ return await _context.Users+ .Include(u => u.ReadingLists)+ .ThenInclude(l => l.Items)+ .SingleOrDefaultAsync(x => x.UserName == username);+ }- public async Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForSeries(int userId, int seriesId)- {- return await _context.AppUserBookmark- .Where(x => x.AppUserId == userId && x.SeriesId == seriesId)- .OrderBy(x => x.Page)- .AsNoTracking()- .ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider)- .ToListAsync();- }+ /// <summary>+ /// Returns all Bookmarks for a given set of Ids+ /// </summary>+ /// <param name="bookmarkIds"></param>+ /// <returns></returns>+ public async Task<IList<AppUserBookmark>> GetAllBookmarksByIds(IList<int> bookmarkIds)+ {+ return await _context.AppUserBookmark+ .Where(b => bookmarkIds.Contains(b.Id))+ .ToListAsync();+ }- public async Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForVolume(int userId, int volumeId)- {- return await _context.AppUserBookmark- .Where(x => x.AppUserId == userId && x.VolumeId == volumeId)- .OrderBy(x => x.Page)- .AsNoTracking()- .ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider)- .ToListAsync();- }+ public async Task<IEnumerable<AppUser>> GetAdminUsersAsync()+ {+ return await _userManager.GetUsersInRoleAsync(PolicyConstants.AdminRole);+ }- public async Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForChapter(int userId, int chapterId)- {- return await _context.AppUserBookmark- .Where(x => x.AppUserId == userId && x.ChapterId == chapterId)- .OrderBy(x => x.Page)- .AsNoTracking()- .ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider)- .ToListAsync();- }+ public async Task<IEnumerable<AppUser>> GetNonAdminUsersAsync()+ {+ return await _userManager.GetUsersInRoleAsync(PolicyConstants.PlebRole);+ }- public async Task<IEnumerable<BookmarkDto>> GetAllBookmarkDtos(int userId)- {- return await _context.AppUserBookmark- .Where(x => x.AppUserId == userId)- .OrderBy(x => x.Page)- .AsNoTracking()- .ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider)- .ToListAsync();- }+ public async Task<bool> IsUserAdminAsync(AppUser user)+ {+ return await _userManager.IsInRoleAsync(user, PolicyConstants.AdminRole);+ }- /// <summary>- /// Fetches the UserId by API Key. This does not include any extra information- /// </summary>- /// <param name="apiKey"></param>- /// <returns></returns>- public async Task<int> GetUserIdByApiKeyAsync(string apiKey)- {- return await _context.AppUser- .Where(u => u.ApiKey.Equals(apiKey))- .Select(u => u.Id)- .SingleOrDefaultAsync();- }+ public async Task<AppUserRating> GetUserRatingAsync(int seriesId, int userId)+ {+ return await _context.AppUserRating.Where(r => r.SeriesId == seriesId && r.AppUserId == userId)+ .SingleOrDefaultAsync();+ }+ public async Task<AppUserPreferences> GetPreferencesAsync(string username)+ {+ return await _context.AppUserPreferences+ .Include(p => p.AppUser)+ .SingleOrDefaultAsync(p => p.AppUser.UserName == username);+ }- public async Task<IEnumerable<MemberDto>> GetMembersAsync()- {- return await _context.Users- .Include(x => x.Libraries)- .Include(r => r.UserRoles)- .ThenInclude(r => r.Role)- .OrderBy(u => u.UserName)- .Select(u => new MemberDto+ public async Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForSeries(int userId, int seriesId)+ {+ return await _context.AppUserBookmark+ .Where(x => x.AppUserId == userId && x.SeriesId == seriesId)+ .OrderBy(x => x.Page)+ .AsNoTracking()+ .ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }++ public async Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForVolume(int userId, int volumeId)+ {+ return await _context.AppUserBookmark+ .Where(x => x.AppUserId == userId && x.VolumeId == volumeId)+ .OrderBy(x => x.Page)+ .AsNoTracking()+ .ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }++ public async Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForChapter(int userId, int chapterId)+ {+ return await _context.AppUserBookmark+ .Where(x => x.AppUserId == userId && x.ChapterId == chapterId)+ .OrderBy(x => x.Page)+ .AsNoTracking()+ .ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }++ public async Task<IEnumerable<BookmarkDto>> GetAllBookmarkDtos(int userId)+ {+ return await _context.AppUserBookmark+ .Where(x => x.AppUserId == userId)+ .OrderBy(x => x.Page)+ .AsNoTracking()+ .ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider)+ .ToListAsync();+ }++ /// <summary>+ /// Fetches the UserId by API Key. This does not include any extra information+ /// </summary>+ /// <param name="apiKey"></param>+ /// <returns></returns>+ public async Task<int> GetUserIdByApiKeyAsync(string apiKey)+ {+ return await _context.AppUser+ .Where(u => u.ApiKey.Equals(apiKey))+ .Select(u => u.Id)+ .SingleOrDefaultAsync();+ }+++ public async Task<IEnumerable<MemberDto>> GetMembersAsync()+ {+ return await _context.Users+ .Include(x => x.Libraries)+ .Include(r => r.UserRoles)+ .ThenInclude(r => r.Role)+ .OrderBy(u => u.UserName)+ .Select(u => new MemberDto+ {+ Id = u.Id,+ Username = u.UserName,+ Created = u.Created,+ LastActive = u.LastActive,+ Roles = u.UserRoles.Select(r => r.Role.Name).ToList(),+ Libraries = u.Libraries.Select(l => new LibraryDto{- Id = u.Id,- Username = u.UserName,- Created = u.Created,- LastActive = u.LastActive,- Roles = u.UserRoles.Select(r => r.Role.Name).ToList(),- Libraries = u.Libraries.Select(l => new LibraryDto- {- Name = l.Name,- Type = l.Type,- LastScanned = l.LastScanned,- Folders = l.Folders.Select(x => x.Path).ToList()- }).ToList()- })- .AsNoTracking()- .ToListAsync();- }+ Name = l.Name,+ Type = l.Type,+ LastScanned = l.LastScanned,+ Folders = l.Folders.Select(x => x.Path).ToList()+ }).ToList()+ })+ .AsNoTracking()+ .ToListAsync();}}diff --git a/API/Data/Repositories/VolumeRepository.cs b/API/Data/Repositories/VolumeRepository.csindex 339da798d..e63b469e6 100644--- a/API/Data/Repositories/VolumeRepository.cs+++ b/API/Data/Repositories/VolumeRepository.cs@@ -4,205 +4,223 @@ using System.Threading.Tasks;using API.Comparators;using API.DTOs;using API.Entities;-using API.Interfaces.Repositories;+using API.Extensions;using AutoMapper;using AutoMapper.QueryableExtensions;using Microsoft.EntityFrameworkCore;-namespace API.Data.Repositories+namespace API.Data.Repositories;++public interface IVolumeRepository+{+ void Add(Volume volume);+ void Update(Volume volume);+ void Remove(Volume volume);+ Task<IList<MangaFile>> GetFilesForVolume(int volumeId);+ Task<string> GetVolumeCoverImageAsync(int volumeId);+ Task<IList<int>> GetChapterIdsByVolumeIds(IReadOnlyList<int> volumeIds);+ Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId, int userId);+ Task<Volume> GetVolumeAsync(int volumeId);+ Task<VolumeDto> GetVolumeDtoAsync(int volumeId, int userId);+ Task<IEnumerable<Volume>> GetVolumesForSeriesAsync(IList<int> seriesIds, bool includeChapters = false);+ Task<IEnumerable<Volume>> GetVolumes(int seriesId);+ Task<Volume> GetVolumeByIdAsync(int volumeId);+}+public class VolumeRepository : IVolumeRepository{- public class VolumeRepository : IVolumeRepository+ private readonly DataContext _context;+ private readonly IMapper _mapper;++ public VolumeRepository(DataContext context, IMapper mapper){- private readonly DataContext _context;- private readonly IMapper _mapper;+ _context = context;+ _mapper = mapper;+ }- public VolumeRepository(DataContext context, IMapper mapper)- {- _context = context;- _mapper = mapper;- }+ public void Add(Volume volume)+ {+ _context.Volume.Add(volume);+ }- public void Add(Volume volume)- {- _context.Volume.Add(volume);- }+ public void Update(Volume volume)+ {+ _context.Entry(volume).State = EntityState.Modified;+ }- public void Update(Volume volume)- {- _context.Entry(volume).State = EntityState.Modified;- }+ public void Remove(Volume volume)+ {+ _context.Volume.Remove(volume);+ }- public void Remove(Volume volume)- {- _context.Volume.Remove(volume);- }+ /// <summary>+ /// Returns a list of non-tracked files for a given volume.+ /// </summary>+ /// <param name="volumeId"></param>+ /// <returns></returns>+ public async Task<IList<MangaFile>> GetFilesForVolume(int volumeId)+ {+ return await _context.Chapter+ .Where(c => volumeId == c.VolumeId)+ .Include(c => c.Files)+ .SelectMany(c => c.Files)+ .AsNoTracking()+ .ToListAsync();+ }- /// <summary>- /// Returns a list of non-tracked files for a given volume.- /// </summary>- /// <param name="volumeId"></param>- /// <returns></returns>- public async Task<IList<MangaFile>> GetFilesForVolume(int volumeId)- {- return await _context.Chapter- .Where(c => volumeId == c.VolumeId)- .Include(c => c.Files)- .SelectMany(c => c.Files)- .AsNoTracking()- .ToListAsync();- }+ /// <summary>+ /// Returns the cover image file for the given volume+ /// </summary>+ /// <param name="volumeId"></param>+ /// <returns></returns>+ public async Task<string> GetVolumeCoverImageAsync(int volumeId)+ {+ return await _context.Volume+ .Where(v => v.Id == volumeId)+ .Select(v => v.CoverImage)+ .AsNoTracking()+ .SingleOrDefaultAsync();+ }- /// <summary>- /// Returns the cover image file for the given volume- /// </summary>- /// <param name="volumeId"></param>- /// <returns></returns>- public async Task<string> GetVolumeCoverImageAsync(int volumeId)- {- return await _context.Volume- .Where(v => v.Id == volumeId)- .Select(v => v.CoverImage)- .AsNoTracking()- .SingleOrDefaultAsync();- }+ /// <summary>+ /// Returns all chapter Ids belonging to a list of Volume Ids+ /// </summary>+ /// <param name="volumeIds"></param>+ /// <returns></returns>+ public async Task<IList<int>> GetChapterIdsByVolumeIds(IReadOnlyList<int> volumeIds)+ {+ return await _context.Chapter+ .Where(c => volumeIds.Contains(c.VolumeId))+ .Select(c => c.Id)+ .ToListAsync();+ }- /// <summary>- /// Returns all chapter Ids belonging to a list of Volume Ids- /// </summary>- /// <param name="volumeIds"></param>- /// <returns></returns>- public async Task<IList<int>> GetChapterIdsByVolumeIds(IReadOnlyList<int> volumeIds)- {- return await _context.Chapter- .Where(c => volumeIds.Contains(c.VolumeId))- .Select(c => c.Id)- .ToListAsync();- }+ /// <summary>+ /// Returns all volumes that contain a seriesId in passed array.+ /// </summary>+ /// <param name="seriesIds"></param>+ /// <param name="includeChapters">Include chapter entities</param>+ /// <returns></returns>+ public async Task<IEnumerable<Volume>> GetVolumesForSeriesAsync(IList<int> seriesIds, bool includeChapters = false)+ {+ var query = _context.Volume+ .Where(v => seriesIds.Contains(v.SeriesId));- /// <summary>- /// Returns all volumes that contain a seriesId in passed array.- /// </summary>- /// <param name="seriesIds"></param>- /// <returns></returns>- public async Task<IEnumerable<Volume>> GetVolumesForSeriesAsync(IList<int> seriesIds, bool includeChapters = false)+ if (includeChapters){- var query = _context.Volume- .Where(v => seriesIds.Contains(v.SeriesId));-- if (includeChapters)- {- query = query.Include(v => v.Chapters);- }- return await query.ToListAsync();+ query = query.Include(v => v.Chapters);}+ return await query.ToListAsync();+ }- /// <summary>- /// Returns an individual Volume including Chapters and Files and Reading Progress for a given volumeId- /// </summary>- /// <param name="volumeId"></param>- /// <param name="userId"></param>- /// <returns></returns>- public async Task<VolumeDto> GetVolumeDtoAsync(int volumeId, int userId)- {- var volume = await _context.Volume- .Where(vol => vol.Id == volumeId)- .Include(vol => vol.Chapters)- .ThenInclude(c => c.Files)- .ProjectTo<VolumeDto>(_mapper.ConfigurationProvider)- .SingleAsync(vol => vol.Id == volumeId);+ /// <summary>+ /// Returns an individual Volume including Chapters and Files and Reading Progress for a given volumeId+ /// </summary>+ /// <param name="volumeId"></param>+ /// <param name="userId"></param>+ /// <returns></returns>+ public async Task<VolumeDto> GetVolumeDtoAsync(int volumeId, int userId)+ {+ var volume = await _context.Volume+ .Where(vol => vol.Id == volumeId)+ .Include(vol => vol.Chapters)+ .ThenInclude(c => c.Files)+ .ProjectTo<VolumeDto>(_mapper.ConfigurationProvider)+ .SingleAsync(vol => vol.Id == volumeId);- var volumeList = new List<VolumeDto>() {volume};- await AddVolumeModifiers(userId, volumeList);+ var volumeList = new List<VolumeDto>() {volume};+ await AddVolumeModifiers(userId, volumeList);- return volumeList[0];- }+ return volumeList[0];+ }- /// <summary>- /// Returns the full Volumes including Chapters and Files for a given series- /// </summary>- /// <param name="seriesId"></param>- /// <returns></returns>- public async Task<IEnumerable<Volume>> GetVolumes(int seriesId)- {- return await _context.Volume- .Where(vol => vol.SeriesId == seriesId)- .Include(vol => vol.Chapters)- .ThenInclude(c => c.Files)- .OrderBy(vol => vol.Number)- .ToListAsync();- }+ /// <summary>+ /// Returns the full Volumes including Chapters and Files for a given series+ /// </summary>+ /// <param name="seriesId"></param>+ /// <returns></returns>+ public async Task<IEnumerable<Volume>> GetVolumes(int seriesId)+ {+ return await _context.Volume+ .Where(vol => vol.SeriesId == seriesId)+ .Include(vol => vol.Chapters)+ .ThenInclude(c => c.Files)+ .OrderBy(vol => vol.Number)+ .ToListAsync();+ }- /// <summary>- /// Returns a single volume with Chapter and Files- /// </summary>- /// <param name="volumeId"></param>- /// <returns></returns>- public async Task<Volume> GetVolumeAsync(int volumeId)- {- return await _context.Volume- .Include(vol => vol.Chapters)- .ThenInclude(c => c.Files)- .SingleOrDefaultAsync(vol => vol.Id == volumeId);- }+ /// <summary>+ /// Returns a single volume with Chapter and Files+ /// </summary>+ /// <param name="volumeId"></param>+ /// <returns></returns>+ public async Task<Volume> GetVolumeAsync(int volumeId)+ {+ return await _context.Volume+ .Include(vol => vol.Chapters)+ .ThenInclude(c => c.Files)+ .SingleOrDefaultAsync(vol => vol.Id == volumeId);+ }- /// <summary>- /// Returns all volumes for a given series with progress information attached. Includes all Chapters as well.- /// </summary>- /// <param name="seriesId"></param>- /// <param name="userId"></param>- /// <returns></returns>- public async Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId, int userId)- {- var volumes = await _context.Volume- .Where(vol => vol.SeriesId == seriesId)- .Include(vol => vol.Chapters)- .OrderBy(volume => volume.Number)- .ProjectTo<VolumeDto>(_mapper.ConfigurationProvider)- .AsNoTracking()- .ToListAsync();-- await AddVolumeModifiers(userId, volumes);- SortSpecialChapters(volumes);-- return volumes;- }+ /// <summary>+ /// Returns all volumes for a given series with progress information attached. Includes all Chapters as well.+ /// </summary>+ /// <param name="seriesId"></param>+ /// <param name="userId"></param>+ /// <returns></returns>+ public async Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId, int userId)+ {+ var volumes = await _context.Volume+ .Where(vol => vol.SeriesId == seriesId)+ .Include(vol => vol.Chapters)+ .ThenInclude(c => c.People)+ .Include(vol => vol.Chapters)+ .ThenInclude(c => c.Tags)+ .OrderBy(volume => volume.Number)+ .ProjectTo<VolumeDto>(_mapper.ConfigurationProvider)+ .AsNoTracking()+ .AsSplitQuery()+ .ToListAsync();++ await AddVolumeModifiers(userId, volumes);+ SortSpecialChapters(volumes);++ return volumes;+ }- public async Task<Volume> GetVolumeByIdAsync(int volumeId)- {- return await _context.Volume.SingleOrDefaultAsync(x => x.Id == volumeId);- }+ public async Task<Volume> GetVolumeByIdAsync(int volumeId)+ {+ return await _context.Volume.SingleOrDefaultAsync(x => x.Id == volumeId);+ }- private static void SortSpecialChapters(IEnumerable<VolumeDto> volumes)+ private static void SortSpecialChapters(IEnumerable<VolumeDto> volumes)+ {+ foreach (var v in volumes.Where(vDto => vDto.Number == 0)){- var sorter = new NaturalSortComparer();- foreach (var v in volumes.Where(vDto => vDto.Number == 0))- {- v.Chapters = v.Chapters.OrderBy(x => x.Range, sorter).ToList();- }+ v.Chapters = v.Chapters.OrderByNatural(x => x.Range).ToList();}+ }- private async Task AddVolumeModifiers(int userId, IReadOnlyCollection<VolumeDto> volumes)- {- var volIds = volumes.Select(s => s.Id);- var userProgress = await _context.AppUserProgresses- .Where(p => p.AppUserId == userId && volIds.Contains(p.VolumeId))- .AsNoTracking()- .ToListAsync();+ private async Task AddVolumeModifiers(int userId, IReadOnlyCollection<VolumeDto> volumes)+ {+ var volIds = volumes.Select(s => s.Id);+ var userProgress = await _context.AppUserProgresses+ .Where(p => p.AppUserId == userId && volIds.Contains(p.VolumeId))+ .AsNoTracking()+ .ToListAsync();- foreach (var v in volumes)+ foreach (var v in volumes)+ {+ foreach (var c in v.Chapters){- foreach (var c in v.Chapters)- {- c.PagesRead = userProgress.Where(p => p.ChapterId == c.Id).Sum(p => p.PagesRead);- }-- v.PagesRead = userProgress.Where(p => p.VolumeId == v.Id).Sum(p => p.PagesRead);+ c.PagesRead = userProgress.Where(p => p.ChapterId == c.Id).Sum(p => p.PagesRead);}++ v.PagesRead = userProgress.Where(p => p.VolumeId == v.Id).Sum(p => p.PagesRead);}+ }- }}diff --git a/API/Data/Seed.cs b/API/Data/Seed.csindex 9cfbaeaa4..b7590e168 100644--- a/API/Data/Seed.cs+++ b/API/Data/Seed.cs@@ -8,6 +8,7 @@ using API.Entities;using API.Entities.Enums;using API.Services;using Kavita.Common;+using Kavita.Common.EnvironmentInfo;using Microsoft.AspNetCore.Identity;using Microsoft.EntityFrameworkCore;@@ -15,6 +16,11 @@ namespace API.Data{public static class Seed{+ /// <summary>+ /// Generated on Startup. Seed.SeedSettings must run before+ /// </summary>+ public static IList<ServerSetting> DefaultSettings;+public static async Task SeedRoles(RoleManager<AppRole> roleManager){var roles = typeof(PolicyConstants)@@ -35,16 +41,16 @@ namespace API.Data}}- public static async Task SeedSettings(DataContext context)+ public static async Task SeedSettings(DataContext context, IDirectoryService directoryService){await context.Database.EnsureCreatedAsync();- IList<ServerSetting> defaultSettings = new List<ServerSetting>()+ DefaultSettings = new List<ServerSetting>(){- new () {Key = ServerSettingKey.CacheDirectory, Value = DirectoryService.CacheDirectory},+ new () {Key = ServerSettingKey.CacheDirectory, Value = directoryService.CacheDirectory},new () {Key = ServerSettingKey.TaskScan, Value = "daily"},new () {Key = ServerSettingKey.LoggingLevel, Value = "Information"}, // Not used from DB, but DB is sync with appSettings.json- new () {Key = ServerSettingKey.TaskBackup, Value = "weekly"},+ new () {Key = ServerSettingKey.TaskBackup, Value = "daily"},new () {Key = ServerSettingKey.BackupDirectory, Value = Path.GetFullPath(DirectoryService.BackupDirectory)},new () {Key = ServerSettingKey.Port, Value = "5000"}, // Not used from DB, but DB is sync with appSettings.jsonnew () {Key = ServerSettingKey.AllowStatCollection, Value = "true"},@@ -52,9 +58,11 @@ namespace API.Datanew () {Key = ServerSettingKey.EnableAuthentication, Value = "true"},new () {Key = ServerSettingKey.BaseUrl, Value = "/"},new () {Key = ServerSettingKey.InstallId, Value = HashUtil.AnonymousToken()},+ new () {Key = ServerSettingKey.InstallVersion, Value = BuildInfo.Version.ToString()},+ new () {Key = ServerSettingKey.BookmarkDirectory, Value = directoryService.BookmarkDirectory},};- foreach (var defaultSetting in defaultSettings)+ foreach (var defaultSetting in DefaultSettings){var existing = context.ServerSetting.FirstOrDefault(s => s.Key == defaultSetting.Key);if (existing == null)@@ -71,7 +79,7 @@ namespace API.Datacontext.ServerSetting.First(s => s.Key == ServerSettingKey.LoggingLevel).Value =Configuration.LogLevel + string.Empty;context.ServerSetting.First(s => s.Key == ServerSettingKey.CacheDirectory).Value =- DirectoryService.CacheDirectory + string.Empty;+ directoryService.CacheDirectory + string.Empty;context.ServerSetting.First(s => s.Key == ServerSettingKey.BackupDirectory).Value =DirectoryService.BackupDirectory + string.Empty;diff --git a/API/Data/UnitOfWork.cs b/API/Data/UnitOfWork.csindex a1f797188..82046ca2a 100644--- a/API/Data/UnitOfWork.cs+++ b/API/Data/UnitOfWork.cs@@ -1,84 +1,104 @@using System.Threading.Tasks;using API.Data.Repositories;using API.Entities;-using API.Interfaces;-using API.Interfaces.Repositories;using AutoMapper;using Microsoft.AspNetCore.Identity;-namespace API.Data+namespace API.Data;++public interface IUnitOfWork{- public class UnitOfWork : IUnitOfWork- {- private readonly DataContext _context;- private readonly IMapper _mapper;- private readonly UserManager<AppUser> _userManager;+ ISeriesRepository SeriesRepository { get; }+ IUserRepository UserRepository { get; }+ ILibraryRepository LibraryRepository { get; }+ IVolumeRepository VolumeRepository { get; }+ ISettingsRepository SettingsRepository { get; }+ IAppUserProgressRepository AppUserProgressRepository { get; }+ ICollectionTagRepository CollectionTagRepository { get; }+ IChapterRepository ChapterRepository { get; }+ IReadingListRepository ReadingListRepository { get; }+ ISeriesMetadataRepository SeriesMetadataRepository { get; }+ IPersonRepository PersonRepository { get; }+ IGenreRepository GenreRepository { get; }+ ITagRepository TagRepository { get; }+ bool Commit();+ Task<bool> CommitAsync();+ bool HasChanges();+ bool Rollback();+ Task<bool> RollbackAsync();+}+public class UnitOfWork : IUnitOfWork+{+ private readonly DataContext _context;+ private readonly IMapper _mapper;+ private readonly UserManager<AppUser> _userManager;- public UnitOfWork(DataContext context, IMapper mapper, UserManager<AppUser> userManager)- {- _context = context;- _mapper = mapper;- _userManager = userManager;- }+ public UnitOfWork(DataContext context, IMapper mapper, UserManager<AppUser> userManager)+ {+ _context = context;+ _mapper = mapper;+ _userManager = userManager;+ }- public ISeriesRepository SeriesRepository => new SeriesRepository(_context, _mapper);- public IUserRepository UserRepository => new UserRepository(_context, _userManager, _mapper);- public ILibraryRepository LibraryRepository => new LibraryRepository(_context, _mapper);+ public ISeriesRepository SeriesRepository => new SeriesRepository(_context, _mapper);+ public IUserRepository UserRepository => new UserRepository(_context, _userManager, _mapper);+ public ILibraryRepository LibraryRepository => new LibraryRepository(_context, _mapper);- public IVolumeRepository VolumeRepository => new VolumeRepository(_context, _mapper);+ public IVolumeRepository VolumeRepository => new VolumeRepository(_context, _mapper);- public ISettingsRepository SettingsRepository => new SettingsRepository(_context, _mapper);+ public ISettingsRepository SettingsRepository => new SettingsRepository(_context, _mapper);- public IAppUserProgressRepository AppUserProgressRepository => new AppUserProgressRepository(_context);- public ICollectionTagRepository CollectionTagRepository => new CollectionTagRepository(_context, _mapper);- public IFileRepository FileRepository => new FileRepository(_context);- public IChapterRepository ChapterRepository => new ChapterRepository(_context, _mapper);- public IReadingListRepository ReadingListRepository => new ReadingListRepository(_context, _mapper);- public ISeriesMetadataRepository SeriesMetadataRepository => new SeriesMetadataRepository(_context);+ public IAppUserProgressRepository AppUserProgressRepository => new AppUserProgressRepository(_context);+ public ICollectionTagRepository CollectionTagRepository => new CollectionTagRepository(_context, _mapper);+ public IChapterRepository ChapterRepository => new ChapterRepository(_context, _mapper);+ public IReadingListRepository ReadingListRepository => new ReadingListRepository(_context, _mapper);+ public ISeriesMetadataRepository SeriesMetadataRepository => new SeriesMetadataRepository(_context);+ public IPersonRepository PersonRepository => new PersonRepository(_context, _mapper);+ public IGenreRepository GenreRepository => new GenreRepository(_context, _mapper);+ public ITagRepository TagRepository => new TagRepository(_context, _mapper);- /// <summary>- /// Commits changes to the DB. Completes the open transaction.- /// </summary>- /// <returns></returns>- public bool Commit()- {- return _context.SaveChanges() > 0;- }- /// <summary>- /// Commits changes to the DB. Completes the open transaction.- /// </summary>- /// <returns></returns>- public async Task<bool> CommitAsync()- {- return await _context.SaveChangesAsync() > 0;- }+ /// <summary>+ /// Commits changes to the DB. Completes the open transaction.+ /// </summary>+ /// <returns></returns>+ public bool Commit()+ {+ return _context.SaveChanges() > 0;+ }+ /// <summary>+ /// Commits changes to the DB. Completes the open transaction.+ /// </summary>+ /// <returns></returns>+ public async Task<bool> CommitAsync()+ {+ return await _context.SaveChangesAsync() > 0;+ }- /// <summary>- /// Is the DB Context aware of Changes in loaded entities- /// </summary>- /// <returns></returns>- public bool HasChanges()- {- return _context.ChangeTracker.HasChanges();- }+ /// <summary>+ /// Is the DB Context aware of Changes in loaded entities+ /// </summary>+ /// <returns></returns>+ public bool HasChanges()+ {+ return _context.ChangeTracker.HasChanges();+ }- /// <summary>- /// Rollback transaction- /// </summary>- /// <returns></returns>- public async Task<bool> RollbackAsync()- {- await _context.DisposeAsync();- return true;- }- /// <summary>- /// Rollback transaction- /// </summary>- /// <returns></returns>- public bool Rollback()- {- _context.Dispose();- return true;- }+ /// <summary>+ /// Rollback transaction+ /// </summary>+ /// <returns></returns>+ public async Task<bool> RollbackAsync()+ {+ await _context.DisposeAsync();+ return true;+ }+ /// <summary>+ /// Rollback transaction+ /// </summary>+ /// <returns></returns>+ public bool Rollback()+ {+ _context.Dispose();+ return true;}}diff --git a/API/Dockerfile b/API/Dockerfileindex 4289aaa3d..ce607a02f 100644--- a/API/Dockerfile+++ b/API/Dockerfile@@ -1,5 +1,5 @@#This Dockerfile pulls the latest git commit and builds Kavita from source-FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS builder+FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS builderENV DEBIAN_FRONTEND=noninteractiveARG TARGETPLATFORM@@ -37,4 +37,4 @@ EXPOSE 5000WORKDIR /kavitaENTRYPOINT ["/bin/bash"]-CMD ["/entrypoint.sh"]\ No newline at end of file+CMD ["/entrypoint.sh"]diff --git a/API/Entities/AppUserBookmark.cs b/API/Entities/AppUserBookmark.csindex cfb9aa29a..81a26a08b 100644--- a/API/Entities/AppUserBookmark.cs+++ b/API/Entities/AppUserBookmark.cs@@ -13,6 +13,11 @@ namespace API.Entitiespublic int SeriesId { get; set; }public int ChapterId { get; set; }+ /// <summary>+ /// Filename in the Bookmark Directory+ /// </summary>+ public string FileName { get; set; } = string.Empty;+// Relationships[JsonIgnore]diff --git a/API/Entities/Chapter.cs b/API/Entities/Chapter.csindex ef12de8ce..e6e7926e3 100644--- a/API/Entities/Chapter.cs+++ b/API/Entities/Chapter.cs@@ -41,6 +41,50 @@ namespace API.Entities/// Used for books/specials to display custom title. For non-specials/books, will be set to <see cref="Range"/>/// </summary>public string Title { get; set; }+ /// <summary>+ /// Age Rating for the issue/chapter+ /// </summary>+ public AgeRating AgeRating { get; set; }++ /// <summary>+ /// Chapter title+ /// </summary>+ /// <remarks>This should not be confused with Title which is used for special filenames.</remarks>+ public string TitleName { get; set; } = string.Empty;+ /// <summary>+ /// Date which chapter was released+ /// </summary>+ public DateTime ReleaseDate { get; set; }+ /// <summary>+ /// Summary for the Chapter/Issue+ /// </summary>+ public string Summary { get; set; }+ /// <summary>+ /// Language for the Chapter/Issue+ /// </summary>+ public string Language { get; set; }+ /// <summary>+ /// Total number of issues in the series+ /// </summary>+ public int TotalCount { get; set; } = 0;+ /// <summary>+ /// Number in the Total Count+ /// </summary>+ public int Count { get; set; } = 0;+++ /// <summary>+ /// All people attached at a Chapter level. Usually Comics will have different people per issue.+ /// </summary>+ public ICollection<Person> People { get; set; } = new List<Person>();+ /// <summary>+ /// Genres for the Chapter+ /// </summary>+ public ICollection<Genre> Genres { get; set; } = new List<Genre>();+ public ICollection<Tag> Tags { get; set; } = new List<Tag>();+++// Relationshipspublic Volume Volume { get; set; }diff --git a/API/Entities/CollectionTag.cs b/API/Entities/CollectionTag.csindex ee966cafc..b38960f89 100644--- a/API/Entities/CollectionTag.cs+++ b/API/Entities/CollectionTag.cs@@ -1,4 +1,5 @@using System.Collections.Generic;+using API.Entities.Metadata;using Microsoft.EntityFrameworkCore;namespace API.Entitiesdiff --git a/API/Entities/Enums/AgeRating.cs b/API/Entities/Enums/AgeRating.csnew file mode 100644index 000000000..ddb288ee1--- /dev/null+++ b/API/Entities/Enums/AgeRating.cs@@ -0,0 +1,43 @@+using System.ComponentModel;++namespace API.Entities.Enums;++/// <summary>+/// Represents Age Rating for content.+/// </summary>+/// <remarks>Based on ComicInfo.xml v2.1 https://github.com/anansi-project/comicinfo/blob/main/drafts/v2.1/ComicInfo.xsd</remarks>+public enum AgeRating+{+ [Description("Unknown")]+ Unknown = 0,+ [Description("Rating Pending")]+ RatingPending = 1,+ [Description("Early Childhood")]+ EarlyChildhood = 2,+ [Description("Everyone")]+ Everyone = 3,+ [Description("G")]+ G = 4,+ [Description("Everyone 10+")]+ Everyone10Plus = 5,+ [Description("PG")]+ PG = 6,+ [Description("Kids to Adults")]+ KidsToAdults = 7,+ [Description("Teen")]+ Teen = 8,+ [Description("MA 15+")]+ Mature15Plus = 9,+ [Description("Mature 17+")]+ Mature17Plus = 10,+ [Description("M")]+ Mature = 11,+ [Description("R18+")]+ R18Plus = 12,+ [Description("Adults Only 18+")]+ AdultsOnly = 13,+ [Description("X18+")]+ X18Plus = 14+++}diff --git a/API/Entities/Enums/LibraryType.cs b/API/Entities/Enums/LibraryType.csindex 23bb8df25..dd2c83b92 100644--- a/API/Entities/Enums/LibraryType.cs+++ b/API/Entities/Enums/LibraryType.cs@@ -4,10 +4,19 @@ namespace API.Entities.Enums{public enum LibraryType{+ /// <summary>+ /// Uses Manga regex for filename parsing+ /// </summary>[Description("Manga")]Manga = 0,+ /// <summary>+ /// Uses Comic regex for filename parsing+ /// </summary>[Description("Comic")]Comic = 1,+ /// <summary>+ /// Uses Manga regex for filename parsing also uses epub metadata+ /// </summary>[Description("Book")]Book = 2,}diff --git a/API/Entities/Enums/PersonRole.cs b/API/Entities/Enums/PersonRole.csindex 47e60721b..714e1d534 100644--- a/API/Entities/Enums/PersonRole.cs+++ b/API/Entities/Enums/PersonRole.cs@@ -5,15 +5,31 @@/// <summary>/// Another role, not covered by other types/// </summary>- Other = 0,+ Other = 1,/// <summary>- /// Author+ /// Artist/// </summary>- Author = 1,+ //Artist = 2,/// <summary>- /// Artist+ /// Author or Writer+ /// </summary>+ Writer = 3,+ Penciller = 4,+ Inker = 5,+ Colorist = 6,+ Letterer = 7,+ CoverArtist = 8,+ Editor = 9,+ Publisher = 10,+ /// <summary>+ /// Represents a character/person within the story+ /// </summary>+ Character = 11,+ /// <summary>+ /// The Translator/// </summary>- Artist = 2,-+ Translator = 12++}-}\ No newline at end of file+}diff --git a/API/Entities/Enums/PublicationStatus.cs b/API/Entities/Enums/PublicationStatus.csnew file mode 100644index 000000000..4d8124391--- /dev/null+++ b/API/Entities/Enums/PublicationStatus.cs@@ -0,0 +1,23 @@+using System.ComponentModel;++namespace API.Entities.Enums;++public enum PublicationStatus+{+ /// <summary>+ /// Default Status. Publication is currently in progress+ /// </summary>+ [Description("On Going")]+ OnGoing = 0,+ /// <summary>+ /// Series is on temp or indefinite Hiatus+ /// </summary>+ [Description("Hiatus")]+ Hiatus = 1,+ /// <summary>+ /// Publication has finished releasing+ /// </summary>+ [Description("Completed")]+ Completed = 2++}diff --git a/API/Entities/Enums/ServerSettingKey.cs b/API/Entities/Enums/ServerSettingKey.csindex 3f097c675..80484d693 100644--- a/API/Entities/Enums/ServerSettingKey.cs+++ b/API/Entities/Enums/ServerSettingKey.cs@@ -58,7 +58,18 @@ namespace API.Entities.Enums/// Represents this installation of Kavita. Is tied to Stat reporting but has no information about user or files./// </summary>[Description("InstallId")]- InstallId = 10+ InstallId = 10,+ /// <summary>+ /// Represents the version the software is running.+ /// </summary>+ /// <remarks>This will be updated on Startup to the latest release. Provides ability to detect if certain migrations need to be run.</remarks>+ [Description("InstallVersion")]+ InstallVersion = 11,+ /// <summary>+ /// Location of where bookmarks are stored+ /// </summary>+ [Description("BookmarkDirectory")]+ BookmarkDirectory = 12,}}diff --git a/API/Entities/Genre.cs b/API/Entities/Genre.csindex 9490c03e7..447f14943 100644--- a/API/Entities/Genre.cs+++ b/API/Entities/Genre.cs@@ -1,22 +1,18 @@-using System.ComponentModel.DataAnnotations;-using API.Entities.Interfaces;+using System.Collections.Generic;+using API.Entities.Metadata;+using Microsoft.EntityFrameworkCore;namespace API.Entities{- public class Genre : IHasConcurrencyToken+ [Index(nameof(NormalizedTitle), nameof(ExternalTag), IsUnique = true)]+ public class Genre{public int Id { get; set; }- public string Name { get; set; }- // MetadataUpdate add ProviderId+ public string Title { get; set; }+ public string NormalizedTitle { get; set; }+ public bool ExternalTag { get; set; }- /// <inheritdoc />- [ConcurrencyCheck]- public uint RowVersion { get; private set; }-- /// <inheritdoc />- public void OnSavingChanges()- {- RowVersion++;- }+ public ICollection<SeriesMetadata> SeriesMetadatas { get; set; }+ public ICollection<Chapter> Chapters { get; set; }}}diff --git a/API/Entities/MangaFile.cs b/API/Entities/MangaFile.csindex 2865178c7..8cd99f3e1 100644--- a/API/Entities/MangaFile.cs+++ b/API/Entities/MangaFile.cs@@ -23,24 +23,17 @@ namespace API.Entities/// <summary>/// Last time underlying file was modified/// </summary>+ /// <remarks>This gets updated anytime the file is scanned</remarks>public DateTime LastModified { get; set; }+// Relationship Mappingpublic Chapter Chapter { get; set; }public int ChapterId { get; set; }- // Methods- /// <summary>- /// If the File on disk's last modified time is after what is stored in MangaFile- /// </summary>- /// <returns></returns>- public bool HasFileBeenModified()- {- return File.GetLastWriteTime(FilePath) > LastModified;- }/// <summary>- /// Updates the Last Modified time of the underlying file+ /// Updates the Last Modified time of the underlying file to the LastWriteTime/// </summary>public void UpdateLastModified(){diff --git a/API/Entities/Metadata/ChapterMetadata.cs b/API/Entities/Metadata/ChapterMetadata.csnew file mode 100644index 000000000..ef4836c23--- /dev/null+++ b/API/Entities/Metadata/ChapterMetadata.cs@@ -0,0 +1,34 @@+using System.Collections.Generic;++namespace API.Entities.Metadata+{+ /// <summary>+ /// Has a 1-to-1 relationship with a Chapter. Represents metadata about a chapter.+ /// </summary>+ public class ChapterMetadata+ {+ public int Id { get; set; }++ /// <summary>+ /// Chapter title+ /// </summary>+ /// <remarks>This should not be confused with Chapter.Title which is used for special filenames.</remarks>+ public string Title { get; set; } = string.Empty;+ public string Year { get; set; } // Only time I can think this will be more than 1 year is for a volume which will be a spread+ public string StoryArc { get; set; } // This might be a list++ /// <summary>+ /// All people attached at a Chapter level. Usually Comics will have different people per issue.+ /// </summary>+ public ICollection<Person> People { get; set; } = new List<Person>();++++++ // Relationships+ public Chapter Chapter { get; set; }+ public int ChapterId { get; set; }++ }+}diff --git a/API/Entities/Metadata/SeriesMetadata.cs b/API/Entities/Metadata/SeriesMetadata.csnew file mode 100644index 000000000..54ea8ccc0--- /dev/null+++ b/API/Entities/Metadata/SeriesMetadata.cs@@ -0,0 +1,58 @@+using System;+using System.Collections.Generic;+using System.ComponentModel.DataAnnotations;+using API.Entities.Enums;+using API.Entities.Interfaces;+using Microsoft.EntityFrameworkCore;++namespace API.Entities.Metadata+{+ [Index(nameof(Id), nameof(SeriesId), IsUnique = true)]+ public class SeriesMetadata : IHasConcurrencyToken+ {+ public int Id { get; set; }++ public string Summary { get; set; }++ public ICollection<CollectionTag> CollectionTags { get; set; }++ public ICollection<Genre> Genres { get; set; } = new List<Genre>();+ public ICollection<Tag> Tags { get; set; } = new List<Tag>();+ /// <summary>+ /// All people attached at a Series level.+ /// </summary>+ public ICollection<Person> People { get; set; } = new List<Person>();++ /// <summary>+ /// Highest Age Rating from all Chapters+ /// </summary>+ public AgeRating AgeRating { get; set; }+ /// <summary>+ /// Earliest Year from all chapters+ /// </summary>+ public int ReleaseYear { get; set; }+ /// <summary>+ /// Language of the content (BCP-47 code)+ /// </summary>+ public string Language { get; set; } = string.Empty;+ /// <summary>+ /// Total number of issues in the series+ /// </summary>+ public int Count { get; set; } = 0;+ public PublicationStatus PublicationStatus { get; set; }++ // Relationship+ public Series Series { get; set; }+ public int SeriesId { get; set; }++ /// <inheritdoc />+ [ConcurrencyCheck]+ public uint RowVersion { get; private set; }++ /// <inheritdoc />+ public void OnSavingChanges()+ {+ RowVersion++;+ }+ }+}diff --git a/API/Entities/Person.cs b/API/Entities/Person.csindex c9f182215..785a037bd 100644--- a/API/Entities/Person.cs+++ b/API/Entities/Person.cs@@ -1,23 +1,24 @@-using System.ComponentModel.DataAnnotations;+using System.Collections.Generic;using API.Entities.Enums;-using API.Entities.Interfaces;+using API.Entities.Metadata;namespace API.Entities{- public class Person : IHasConcurrencyToken+ public enum ProviderSource+ {+ Local = 1,+ External = 2+ }+ public class Person{public int Id { get; set; }public string Name { get; set; }+ public string NormalizedName { get; set; }public PersonRole Role { get; set; }+ //public ProviderSource Source { get; set; }- /// <inheritdoc />- [ConcurrencyCheck]- public uint RowVersion { get; private set; }-- /// <inheritdoc />- public void OnSavingChanges()- {- RowVersion++;- }+ // Relationships+ public ICollection<SeriesMetadata> SeriesMetadatas { get; set; }+ public ICollection<Chapter> ChapterMetadatas { get; set; }}}diff --git a/API/Entities/Series.cs b/API/Entities/Series.csindex de02ad427..a532028bb 100644--- a/API/Entities/Series.cs+++ b/API/Entities/Series.cs@@ -2,6 +2,7 @@using System.Collections.Generic;using API.Entities.Enums;using API.Entities.Interfaces;+using API.Entities.Metadata;using Microsoft.EntityFrameworkCore;namespace API.Entities@@ -30,10 +31,6 @@ namespace API.Entities/// Original Name on disk. Not exposed to UI./// </summary>public string OriginalName { get; set; }- /// <summary>- /// Summary information related to the Series- /// </summary>- public string Summary { get; set; } // NOTE: Migrate into SeriesMetdata (with Metadata update)public DateTime Created { get; set; }public DateTime LastModified { get; set; }/// <summary>@@ -56,6 +53,8 @@ namespace API.Entitiespublic MangaFormat Format { get; set; } = MangaFormat.Unknown;public SeriesMetadata Metadata { get; set; }+ public ICollection<AppUserRating> Ratings { get; set; } = new List<AppUserRating>();+ public ICollection<AppUserProgress> Progress { get; set; } = new List<AppUserProgress>();// Relationshipspublic List<Volume> Volumes { get; set; }diff --git a/API/Entities/SeriesMetadata.cs b/API/Entities/SeriesMetadata.csdeleted file mode 100644index f86c5430e..000000000--- a/API/Entities/SeriesMetadata.cs+++ /dev/null@@ -1,29 +0,0 @@-using System.Collections.Generic;-using System.ComponentModel.DataAnnotations;-using API.Entities.Interfaces;-using Microsoft.EntityFrameworkCore;--namespace API.Entities-{- [Index(nameof(Id), nameof(SeriesId), IsUnique = true)]- public class SeriesMetadata : IHasConcurrencyToken- {- public int Id { get; set; }-- public ICollection<CollectionTag> CollectionTags { get; set; }-- // Relationship- public Series Series { get; set; }- public int SeriesId { get; set; }-- /// <inheritdoc />- [ConcurrencyCheck]- public uint RowVersion { get; private set; }-- /// <inheritdoc />- public void OnSavingChanges()- {- RowVersion++;- }- }-}diff --git a/API/Entities/Tag.cs b/API/Entities/Tag.csnew file mode 100644index 000000000..5d1631760--- /dev/null+++ b/API/Entities/Tag.cs@@ -0,0 +1,17 @@+using System.Collections.Generic;+using API.Entities.Metadata;+using Microsoft.EntityFrameworkCore;++namespace API.Entities;++[Index(nameof(NormalizedTitle), nameof(ExternalTag), IsUnique = true)]+public class Tag+{+ public int Id { get; set; }+ public string Title { get; set; }+ public string NormalizedTitle { get; set; }+ public bool ExternalTag { get; set; }++ public ICollection<SeriesMetadata> SeriesMetadatas { get; set; }+ public ICollection<Chapter> Chapters { get; set; }+}diff --git a/API/Extensions/ApplicationServiceExtensions.cs b/API/Extensions/ApplicationServiceExtensions.csindex cd5a621fc..fd0c5f5ca 100644--- a/API/Extensions/ApplicationServiceExtensions.cs+++ b/API/Extensions/ApplicationServiceExtensions.cs@@ -1,7 +1,6 @@-using API.Data;+using System.IO.Abstractions;+using API.Data;using API.Helpers;-using API.Interfaces;-using API.Interfaces.Services;using API.Services;using API.Services.Tasks;using API.SignalR.Presence;@@ -36,8 +35,14 @@ namespace API.Extensionsservices.AddScoped<IVersionUpdaterService, VersionUpdaterService>();services.AddScoped<IDownloadService, DownloadService>();services.AddScoped<IReaderService, ReaderService>();+ services.AddScoped<IReadingItemService, ReadingItemService>();services.AddScoped<IAccountService, AccountService>();++ services.AddScoped<IFileSystem, FileSystem>();+ services.AddScoped<IFileService, FileService>();+ services.AddScoped<ICacheHelper, CacheHelper>();+services.AddScoped<IPresenceTracker, PresenceTracker>();services.AddSqLite(config, env);@@ -51,6 +56,7 @@ namespace API.Extensionsservices.AddDbContext<DataContext>(options =>{options.UseSqlite(config.GetConnectionString("DefaultConnection"));+ options.EnableDetailedErrors();options.EnableSensitiveDataLogging(env.IsDevelopment() || Configuration.LogLevel.Equals("Debug"));});}diff --git a/API/Extensions/DateTimeExtensions.cs b/API/Extensions/DateTimeExtensions.csnew file mode 100644index 000000000..da205608c--- /dev/null+++ b/API/Extensions/DateTimeExtensions.cs@@ -0,0 +1,18 @@+using System;++namespace API.Extensions;++public static class DateTimeExtensions+{+ /// <summary>+ /// <para>Truncates a DateTime to a specified resolution.</para>+ /// <para>A convenient source for resolution is TimeSpan.TicksPerXXXX constants.</para>+ /// </summary>+ /// <param name="date">The DateTime object to truncate</param>+ /// <param name="resolution">e.g. to round to nearest second, TimeSpan.TicksPerSecond</param>+ /// <returns>Truncated DateTime</returns>+ public static DateTime Truncate(this DateTime date, long resolution)+ {+ return new DateTime(date.Ticks - (date.Ticks % resolution), date.Kind);+ }+}diff --git a/API/Extensions/DirectoryInfoExtensions.cs b/API/Extensions/DirectoryInfoExtensions.csdeleted file mode 100644index b92901046..000000000--- a/API/Extensions/DirectoryInfoExtensions.cs+++ /dev/null@@ -1,86 +0,0 @@-using System.IO;-using System.Linq;-using API.Comparators;--namespace API.Extensions-{- public static class DirectoryInfoExtensions- {- private static readonly NaturalSortComparer Comparer = new NaturalSortComparer();- public static void Empty(this DirectoryInfo directory)- {- // NOTE: We have this in DirectoryService.Empty(), do we need this here?- foreach(FileInfo file in directory.EnumerateFiles()) file.Delete();- foreach(DirectoryInfo subDirectory in directory.EnumerateDirectories()) subDirectory.Delete(true);- }-- public static void RemoveNonImages(this DirectoryInfo directory)- {- foreach (var file in directory.EnumerateFiles())- {- if (!Parser.Parser.IsImage(file.FullName))- {- file.Delete();- }- }- }-- /// <summary>- /// Flattens all files in subfolders to the passed directory recursively.- ///- ///- /// foo<para />- /// ├── 1.txt<para />- /// ├── 2.txt<para />- /// ├── 3.txt<para />- /// ├── 4.txt<para />- /// └── bar<para />- /// ├── 1.txt<para />- /// ├── 2.txt<para />- /// └── 5.txt<para />- ///- /// becomes:<para />- /// foo<para />- /// ├── 1.txt<para />- /// ├── 2.txt<para />- /// ├── 3.txt<para />- /// ├── 4.txt<para />- /// ├── bar_1.txt<para />- /// ├── bar_2.txt<para />- /// └── bar_5.txt<para />- /// </summary>- /// <param name="directory"></param>- public static void Flatten(this DirectoryInfo directory)- {- var index = 0;- FlattenDirectory(directory, directory, ref index);- }-- private static void FlattenDirectory(DirectoryInfo root, DirectoryInfo directory, ref int directoryIndex)- {- if (!root.FullName.Equals(directory.FullName))- {- var fileIndex = 1;-- foreach (var file in directory.EnumerateFiles().OrderBy(file => file.FullName, Comparer))- {- if (file.Directory == null) continue;- var paddedIndex = Parser.Parser.PadZeros(directoryIndex + "");- // We need to rename the files so that after flattening, they are in the order we found them- var newName = $"{paddedIndex}_{Parser.Parser.PadZeros(fileIndex + "")}{file.Extension}";- var newPath = Path.Join(root.FullName, newName);- if (!File.Exists(newPath)) file.MoveTo(newPath);- fileIndex++;- }-- directoryIndex++;- }-- var sort = new NaturalSortComparer();- foreach (var subDirectory in directory.EnumerateDirectories().OrderBy(d => d.FullName, sort))- {- FlattenDirectory(root, subDirectory, ref directoryIndex);- }- }- }-}diff --git a/API/Extensions/EnumerableExtensions.cs b/API/Extensions/EnumerableExtensions.csindex b8293436e..c1dd412e2 100644--- a/API/Extensions/EnumerableExtensions.cs+++ b/API/Extensions/EnumerableExtensions.cs@@ -1,21 +1,30 @@using System;using System.Collections.Generic;+using System.Linq;+using System.Text.RegularExpressions;namespace API.Extensions{public static class EnumerableExtensions{- public static IEnumerable<TSource> DistinctBy<TSource, TKey>- (this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)+ private static readonly Regex Regex = new Regex(@"\d+", RegexOptions.Compiled, TimeSpan.FromMilliseconds(500));++ /// <summary>+ /// A natural sort implementation+ /// </summary>+ /// <param name="items">IEnumerable to process</param>+ /// <param name="selector">Function that produces a string. Does not support null values</param>+ /// <param name="stringComparer">Defaults to CurrentCulture</param>+ /// <typeparam name="T"></typeparam>+ /// <returns>Sorted Enumerable</returns>+ public static IEnumerable<T> OrderByNatural<T>(this IEnumerable<T> items, Func<T, string> selector, StringComparer stringComparer = null){- var seenKeys = new HashSet<TKey>();- foreach (var element in source)- {- if (seenKeys.Add(keySelector(element)))- {- yield return element;- }- }+ var maxDigits = items+ .SelectMany(i => Regex.Matches(selector(i))+ .Select(digitChunk => (int?)digitChunk.Value.Length))+ .Max() ?? 0;++ return items.OrderBy(i => Regex.Replace(selector(i), match => match.Value.PadLeft(maxDigits, '0')), stringComparer ?? StringComparer.CurrentCulture);}}-}\ No newline at end of file+}diff --git a/API/Extensions/FilterDtoExtensions.cs b/API/Extensions/FilterDtoExtensions.csindex 7e5a818ec..b0d9f80f6 100644--- a/API/Extensions/FilterDtoExtensions.cs+++ b/API/Extensions/FilterDtoExtensions.cs@@ -11,15 +11,12 @@ namespace API.Extensionspublic static IList<MangaFormat> GetSqlFilter(this FilterDto filter){- var format = filter.MangaFormat;- if (format != null)+ if (filter.Formats == null || filter.Formats.Count == 0){- return new List<MangaFormat>()- {- (MangaFormat) format- };+ return AllFormats;}- return AllFormats;++ return filter.Formats;}}}diff --git a/API/Extensions/HttpExtensions.cs b/API/Extensions/HttpExtensions.csindex 975cbde5f..68655f43d 100644--- a/API/Extensions/HttpExtensions.cs+++ b/API/Extensions/HttpExtensions.cs@@ -1,5 +1,7 @@using System.IO;using System.Linq;+using System.Runtime.Intrinsics.Arm;+using System.Security.Cryptography;using System.Text;using System.Text.Json;using API.Helpers;@@ -30,7 +32,8 @@ namespace API.Extensionspublic static void AddCacheHeader(this HttpResponse response, byte[] content){if (content == null || content.Length <= 0) return;- using var sha1 = new System.Security.Cryptography.SHA256CryptoServiceProvider();+ using var sha1 = SHA256.Create();+response.Headers.Add("ETag", string.Concat(sha1.ComputeHash(content).Select(x => x.ToString("X2"))));}@@ -43,7 +46,7 @@ namespace API.Extensions{if (filename == null || filename.Length <= 0) return;var hashContent = filename + File.GetLastWriteTimeUtc(filename);- using var sha1 = new System.Security.Cryptography.SHA256CryptoServiceProvider();+ using var sha1 = SHA256.Create();response.Headers.Add("ETag", string.Concat(sha1.ComputeHash(Encoding.UTF8.GetBytes(hashContent)).Select(x => x.ToString("X2"))));}diff --git a/API/Extensions/IdentityServiceExtensions.cs b/API/Extensions/IdentityServiceExtensions.csindex 9b32c9320..1d0638e67 100644--- a/API/Extensions/IdentityServiceExtensions.cs+++ b/API/Extensions/IdentityServiceExtensions.cs@@ -17,8 +17,13 @@ namespace API.Extensions{services.AddIdentityCore<AppUser>(opt =>{- // Change password / signin requirements hereopt.Password.RequireNonAlphanumeric = false;+ opt.Password.RequireDigit = false;+ opt.Password.RequireDigit = false;+ opt.Password.RequireLowercase = false;+ opt.Password.RequireUppercase = false;+ opt.Password.RequireNonAlphanumeric = false;+ opt.Password.RequiredLength = 6;}).AddRoles<AppRole>().AddRoleManager<RoleManager<AppRole>>()diff --git a/API/Extensions/ParserInfoListExtensions.cs b/API/Extensions/ParserInfoListExtensions.csindex 0ea098b20..31a65c819 100644--- a/API/Extensions/ParserInfoListExtensions.cs+++ b/API/Extensions/ParserInfoListExtensions.cs@@ -31,15 +31,15 @@ namespace API.Extensions: infos.Any(v => v.Chapters == chapter.Range);}- /// <summary>- /// Returns the MangaFormat that is common to all the files. Unknown if files are mixed (should never happen) or no infos- /// </summary>- /// <param name="infos"></param>- /// <returns></returns>- public static MangaFormat GetFormat(this IList<ParserInfo> infos)- {- if (infos.Count == 0) return MangaFormat.Unknown;- return infos.DistinctBy(x => x.Format).First().Format;- }+ // /// <summary>+ // /// Returns the MangaFormat that is common to all the files. Unknown if files are mixed (should never happen) or no infos+ // /// </summary>+ // /// <param name="infos"></param>+ // /// <returns></returns>+ // public static MangaFormat GetFormat(this IList<ParserInfo> infos)+ // {+ // if (infos.Count == 0) return MangaFormat.Unknown;+ // return infos.DistinctBy(x => x.Format).First().Format;+ // }}}diff --git a/API/Extensions/PathExtensions.cs b/API/Extensions/PathExtensions.csnew file mode 100644index 000000000..f45787d1a--- /dev/null+++ b/API/Extensions/PathExtensions.cs@@ -0,0 +1,14 @@+using System.IO;++namespace API.Extensions;++public static class PathExtensions+{+ public static string GetFullPathWithoutExtension(this string filepath)+ {+ if (string.IsNullOrEmpty(filepath)) return filepath;+ var extension = Path.GetExtension(filepath);+ if (string.IsNullOrEmpty(extension)) return filepath;+ return Path.GetFullPath(filepath.Replace(extension, string.Empty));+ }+}diff --git a/API/Extensions/SeriesExtensions.cs b/API/Extensions/SeriesExtensions.csindex 30a7b1b5b..cd3254e34 100644--- a/API/Extensions/SeriesExtensions.cs+++ b/API/Extensions/SeriesExtensions.cs@@ -9,7 +9,7 @@ namespace API.Extensionspublic static class SeriesExtensions{/// <summary>- /// Checks against all the name variables of the Series if it matches anything in the list.+ /// Checks against all the name variables of the Series if it matches anything in the list. This does not check against format./// </summary>/// <param name="series"></param>/// <param name="list"></param>diff --git a/API/Extensions/StringExtensions.cs b/API/Extensions/StringExtensions.csnew file mode 100644index 000000000..b172c0e46--- /dev/null+++ b/API/Extensions/StringExtensions.cs@@ -0,0 +1,13 @@+using System.Text.RegularExpressions;++namespace API.Extensions;++public static class StringExtensions+{+ private static readonly Regex SentenceCaseRegex = new Regex(@"(^[a-z])|\.\s+(.)", RegexOptions.ExplicitCapture | RegexOptions.Compiled);++ public static string SentenceCase(this string value)+ {+ return SentenceCaseRegex.Replace(value.ToLower(), s => s.Value.ToUpper());+ }+}diff --git a/API/Extensions/VolumeListExtensions.cs b/API/Extensions/VolumeListExtensions.csindex 4752cce5b..97126e28f 100644--- a/API/Extensions/VolumeListExtensions.cs+++ b/API/Extensions/VolumeListExtensions.cs@@ -1,5 +1,6 @@using System.Collections.Generic;using System.Linq;+using API.Comparators;using API.Entities;using API.Entities.Enums;@@ -7,11 +8,12 @@ namespace API.Extensions{public static class VolumeListExtensions{- public static Volume FirstWithChapters(this IList<Volume> volumes, bool inBookSeries)+ public static Volume FirstWithChapters(this IEnumerable<Volume> volumes, bool inBookSeries){return inBookSeries? volumes.FirstOrDefault(v => v.Chapters.Any())- : volumes.FirstOrDefault(v => v.Chapters.Any() && (v.Number == 1));+ : volumes.OrderBy(v => v.Number, new ChapterSortComparer())+ .FirstOrDefault(v => v.Chapters.Any());}/// <summary>diff --git a/API/Helpers/AutoMapperProfiles.cs b/API/Helpers/AutoMapperProfiles.csindex 74bd8d57c..0b3f89161 100644--- a/API/Helpers/AutoMapperProfiles.cs+++ b/API/Helpers/AutoMapperProfiles.cs@@ -2,10 +2,13 @@using System.Linq;using API.DTOs;using API.DTOs.CollectionTags;+using API.DTOs.Metadata;using API.DTOs.Reader;using API.DTOs.ReadingLists;using API.DTOs.Settings;using API.Entities;+using API.Entities.Enums;+using API.Entities.Metadata;using API.Helpers.Converters;using AutoMapper;@@ -21,15 +24,101 @@ namespace API.HelpersCreateMap<MangaFile, MangaFileDto>();- CreateMap<Chapter, ChapterDto>();+ CreateMap<Chapter, ChapterDto>()+ .ForMember(dest => dest.Writers,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Writer)))+ .ForMember(dest => dest.CoverArtist,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.CoverArtist)))+ .ForMember(dest => dest.Colorist,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Colorist)))+ .ForMember(dest => dest.Inker,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Inker)))+ .ForMember(dest => dest.Letterer,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Letterer)))+ .ForMember(dest => dest.Penciller,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Penciller)))+ .ForMember(dest => dest.Publisher,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Publisher)))+ .ForMember(dest => dest.Editor,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Editor)))+ .ForMember(dest => dest.Translators,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Translator)));CreateMap<Series, SeriesDto>();-CreateMap<CollectionTag, CollectionTagDto>();+ CreateMap<Person, PersonDto>();+ CreateMap<Genre, GenreTagDto>();+ CreateMap<Tag, TagDto>();++ CreateMap<SeriesMetadata, SeriesMetadataDto>()+ .ForMember(dest => dest.Writers,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Writer)))+ .ForMember(dest => dest.CoverArtists,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.CoverArtist)))+ .ForMember(dest => dest.Characters,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Character)))+ .ForMember(dest => dest.Publishers,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Publisher)))+ .ForMember(dest => dest.Colorists,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Colorist)))+ .ForMember(dest => dest.Inkers,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Inker)))+ .ForMember(dest => dest.Letterers,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Letterer)))+ .ForMember(dest => dest.Pencillers,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Penciller)))+ .ForMember(dest => dest.Translators,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Translator)))+ .ForMember(dest => dest.Editors,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Editor)));++ CreateMap<ChapterMetadata, ChapterMetadataDto>()+ .ForMember(dest => dest.Writers,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Writer)))+ .ForMember(dest => dest.CoverArtist,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.CoverArtist)))+ .ForMember(dest => dest.Colorist,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Colorist)))+ .ForMember(dest => dest.Inker,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Inker)))+ .ForMember(dest => dest.Letterer,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Letterer)))+ .ForMember(dest => dest.Penciller,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Penciller)))+ .ForMember(dest => dest.Publisher,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Publisher)))+ .ForMember(dest => dest.Editor,+ opt =>+ opt.MapFrom(src => src.People.Where(p => p.Role == PersonRole.Editor)));+- CreateMap<SeriesMetadata, SeriesMetadataDto>();- CreateMap<Person, PersonDto>();CreateMap<AppUserPreferences, UserPreferencesDto>();@@ -55,8 +144,10 @@ namespace API.HelpersCreateMap<RegisterDto, AppUser>();+CreateMap<IEnumerable<ServerSetting>, ServerSettingDto>().ConvertUsing<ServerSettingConverter>();+}}}diff --git a/API/Helpers/CacheHelper.cs b/API/Helpers/CacheHelper.csnew file mode 100644index 000000000..80a63490d--- /dev/null+++ b/API/Helpers/CacheHelper.cs@@ -0,0 +1,73 @@+using System;+using API.Entities;+using API.Entities.Interfaces;+using API.Services;++namespace API.Helpers;++public interface ICacheHelper+{+ bool ShouldUpdateCoverImage(string coverPath, MangaFile firstFile, DateTime chapterCreated,+ bool forceUpdate = false,+ bool isCoverLocked = false);++ bool CoverImageExists(string path);++ bool HasFileNotChangedSinceCreationOrLastScan(IEntityDate chapter, bool forceUpdate, MangaFile firstFile);++}++public class CacheHelper : ICacheHelper+{+ private readonly IFileService _fileService;++ public CacheHelper(IFileService fileService)+ {+ _fileService = fileService;+ }++ /// <summary>+ /// Determines whether an entity should regenerate cover image.+ /// </summary>+ /// <remarks>If a cover image is locked but the underlying file has been deleted, this will allow regenerating. </remarks>+ /// <param name="coverPath">This should just be the filename, no path information</param>+ /// <param name="firstFile"></param>+ /// <param name="forceUpdate">If the user has told us to force the refresh</param>+ /// <param name="isCoverLocked">If cover has been locked by user. This will force false</param>+ /// <returns></returns>+ public bool ShouldUpdateCoverImage(string coverPath, MangaFile firstFile, DateTime chapterCreated, bool forceUpdate = false,+ bool isCoverLocked = false)+ {++ var fileExists = !string.IsNullOrEmpty(coverPath) && _fileService.Exists(coverPath);+ if (isCoverLocked && fileExists) return false;+ if (forceUpdate) return true;+ if (firstFile == null) return true;+ return (_fileService.HasFileBeenModifiedSince(firstFile.FilePath, firstFile.LastModified)) || !fileExists;+ }++ /// <summary>+ /// Has the file been modified since last scan or is user forcing an update+ /// </summary>+ /// <param name="chapter"></param>+ /// <param name="forceUpdate"></param>+ /// <param name="firstFile"></param>+ /// <returns></returns>+ public bool HasFileNotChangedSinceCreationOrLastScan(IEntityDate chapter, bool forceUpdate, MangaFile firstFile)+ {+ return firstFile != null &&+ (!forceUpdate &&+ !(_fileService.HasFileBeenModifiedSince(firstFile.FilePath, chapter.Created)+ || _fileService.HasFileBeenModifiedSince(firstFile.FilePath, firstFile.LastModified)));+ }++ /// <summary>+ /// Determines if a given coverImage path exists+ /// </summary>+ /// <param name="path"></param>+ /// <returns></returns>+ public bool CoverImageExists(string path)+ {+ return !string.IsNullOrEmpty(path) && _fileService.Exists(path);+ }+}diff --git a/API/Helpers/Converters/CronConverter.cs b/API/Helpers/Converters/CronConverter.csindex cacf018b1..32df46753 100644--- a/API/Helpers/Converters/CronConverter.cs+++ b/API/Helpers/Converters/CronConverter.cs@@ -26,16 +26,16 @@ namespace API.Helpers.Convertersreturn destination;}- public static string ConvertFromCronNotation(string cronNotation)- {- var destination = string.Empty;- destination = cronNotation.ToLower() switch- {- "0 0 31 2 *" => "disabled",- _ => destination- };-- return destination;- }+ // public static string ConvertFromCronNotation(string cronNotation)+ // {+ // var destination = string.Empty;+ // destination = cronNotation.ToLower() switch+ // {+ // "0 0 31 2 *" => "disabled",+ // _ => destination+ // };+ //+ // return destination;+ // }}-}\ No newline at end of file+}diff --git a/API/Helpers/Converters/ServerSettingConverter.cs b/API/Helpers/Converters/ServerSettingConverter.csindex 86ed6235e..50a839010 100644--- a/API/Helpers/Converters/ServerSettingConverter.cs+++ b/API/Helpers/Converters/ServerSettingConverter.cs@@ -42,6 +42,9 @@ namespace API.Helpers.Converterscase ServerSettingKey.BaseUrl:destination.BaseUrl = row.Value;break;+ case ServerSettingKey.BookmarkDirectory:+ destination.BookmarksDirectory = row.Value;+ break;}}diff --git a/API/Helpers/GenreHelper.cs b/API/Helpers/GenreHelper.csnew file mode 100644index 000000000..aa465f58e--- /dev/null+++ b/API/Helpers/GenreHelper.cs@@ -0,0 +1,64 @@+using System;+using System.Collections.Generic;+using System.Linq;+using API.Data;+using API.Entities;++namespace API.Helpers;++public static class GenreHelper+{+ /// <summary>+ ///+ /// </summary>+ /// <param name="allGenres"></param>+ /// <param name="names"></param>+ /// <param name="isExternal"></param>+ /// <param name="action"></param>+ public static void UpdateGenre(ICollection<Genre> allGenres, IEnumerable<string> names, bool isExternal, Action<Genre> action)+ {+ foreach (var name in names)+ {+ if (string.IsNullOrEmpty(name.Trim())) continue;++ var normalizedName = Parser.Parser.Normalize(name);+ var genre = allGenres.FirstOrDefault(p =>+ p.NormalizedTitle.Equals(normalizedName) && p.ExternalTag == isExternal);+ if (genre == null)+ {+ genre = DbFactory.Genre(name, false);+ allGenres.Add(genre);+ }++ action(genre);+ }+ }++ public static void KeepOnlySameGenreBetweenLists(ICollection<Genre> existingGenres, ICollection<Genre> removeAllExcept, Action<Genre> action = null)+ {+ var existing = existingGenres.ToList();+ foreach (var genre in existing)+ {+ var existingPerson = removeAllExcept.FirstOrDefault(g => g.ExternalTag == genre.ExternalTag && genre.NormalizedTitle.Equals(g.NormalizedTitle));+ if (existingPerson != null) continue;+ existingGenres.Remove(genre);+ action?.Invoke(genre);+ }++ }++ /// <summary>+ /// Adds the genre to the list if it's not already in there. This will ignore the ExternalTag.+ /// </summary>+ /// <param name="metadataGenres"></param>+ /// <param name="genre"></param>+ public static void AddGenreIfNotExists(ICollection<Genre> metadataGenres, Genre genre)+ {+ var existingGenre = metadataGenres.FirstOrDefault(p =>+ p.NormalizedTitle == Parser.Parser.Normalize(genre.Title));+ if (existingGenre == null)+ {+ metadataGenres.Add(genre);+ }+ }+}diff --git a/API/Helpers/ParserInfoHelpers.cs b/API/Helpers/ParserInfoHelpers.csnew file mode 100644index 000000000..48421cd70--- /dev/null+++ b/API/Helpers/ParserInfoHelpers.cs@@ -0,0 +1,50 @@+using System.Collections.Generic;+using API.Entities;+using API.Entities.Enums;+using API.Extensions;+using API.Parser;+using API.Services.Tasks.Scanner;++namespace API.Helpers;++public static class ParserInfoHelpers+{+ /// <summary>+ /// Checks each parser info to see if there is a name match and if so, checks if the format matches the Series object.+ /// This accounts for if the Series has an Unknown type and if so, considers it matching.+ /// </summary>+ /// <param name="series"></param>+ /// <param name="parsedSeries"></param>+ /// <returns></returns>+ public static bool SeriesHasMatchingParserInfoFormat(Series series,+ Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)+ {+ var format = MangaFormat.Unknown;+ foreach (var pSeries in parsedSeries.Keys)+ {+ var name = pSeries.Name;+ var normalizedName = Parser.Parser.Normalize(name);++ //if (series.NameInParserInfo(pSeries.))+ if (normalizedName == series.NormalizedName ||+ normalizedName == Parser.Parser.Normalize(series.Name) ||+ name == series.Name || name == series.LocalizedName ||+ name == series.OriginalName ||+ normalizedName == Parser.Parser.Normalize(series.OriginalName))+ {+ format = pSeries.Format;+ if (format == series.Format)+ {+ return true;+ }+ }+ }++ if (series.Format == MangaFormat.Unknown && format != MangaFormat.Unknown)+ {+ return true;+ }++ return format == series.Format;+ }+}diff --git a/API/Helpers/PersonHelper.cs b/API/Helpers/PersonHelper.csnew file mode 100644index 000000000..36d544d4d--- /dev/null+++ b/API/Helpers/PersonHelper.cs@@ -0,0 +1,96 @@+using System;+using System.Collections.Generic;+using System.Linq;+using API.Data;+using API.Entities;+using API.Entities.Enums;++namespace API.Helpers;++public static class PersonHelper+{+ /// <summary>+ /// Given a list of all existing people, this will check the new names and roles and if it doesn't exist in allPeople, will create and+ /// add an entry. For each person in name, the callback will be executed.+ /// </summary>+ /// <remarks>This is used to add new people to a list without worrying about duplicating rows in the DB</remarks>+ /// <param name="allPeople"></param>+ /// <param name="names"></param>+ /// <param name="role"></param>+ /// <param name="action"></param>+ public static void UpdatePeople(ICollection<Person> allPeople, IEnumerable<string> names, PersonRole role, Action<Person> action)+ {+ var allPeopleTypeRole = allPeople.Where(p => p.Role == role).ToList();++ foreach (var name in names)+ {+ var normalizedName = Parser.Parser.Normalize(name);+ var person = allPeopleTypeRole.FirstOrDefault(p =>+ p.NormalizedName.Equals(normalizedName));+ if (person == null)+ {+ person = DbFactory.Person(name, role);+ allPeople.Add(person);+ }++ action(person);+ }+ }++ /// <summary>+ /// Remove people on a list for a given role+ /// </summary>+ /// <remarks>Used to remove before we update/add new people</remarks>+ /// <param name="existingPeople">Existing people on Entity</param>+ /// <param name="people">People from metadata</param>+ /// <param name="role">Role to filter on</param>+ /// <param name="action">Callback which will be executed for each person removed</param>+ public static void RemovePeople(ICollection<Person> existingPeople, IEnumerable<string> people, PersonRole role, Action<Person> action = null)+ {+ var normalizedPeople = people.Select(Parser.Parser.Normalize).ToList();+ foreach (var person in normalizedPeople)+ {+ var existingPerson = existingPeople.FirstOrDefault(p => p.Role == role && person.Equals(p.NormalizedName));+ if (existingPerson == null) continue;++ existingPeople.Remove(existingPerson);+ action?.Invoke(existingPerson);+ }++ }++ /// <summary>+ /// Removes all people that are not present in the removeAllExcept list.+ /// </summary>+ /// <param name="existingPeople"></param>+ /// <param name="removeAllExcept"></param>+ /// <param name="action">Callback for all entities that was removed</param>+ public static void KeepOnlySamePeopleBetweenLists(ICollection<Person> existingPeople, ICollection<Person> removeAllExcept, Action<Person> action = null)+ {+ var existing = existingPeople.ToList();+ foreach (var person in existing)+ {+ var existingPerson = removeAllExcept.FirstOrDefault(p => p.Role == person.Role && person.NormalizedName.Equals(p.NormalizedName));+ if (existingPerson == null)+ {+ existingPeople.Remove(person);+ action?.Invoke(person);+ }+ }+ }++ /// <summary>+ /// Adds the person to the list if it's not already in there+ /// </summary>+ /// <param name="metadataPeople"></param>+ /// <param name="person"></param>+ public static void AddPersonIfNotExists(ICollection<Person> metadataPeople, Person person)+ {+ var existingPerson = metadataPeople.SingleOrDefault(p =>+ p.NormalizedName == Parser.Parser.Normalize(person.Name) && p.Role == person.Role);+ if (existingPerson == null)+ {+ metadataPeople.Add(person);+ }+ }+}diff --git a/API/Helpers/SQLHelper.cs b/API/Helpers/SQLHelper.csindex fcd44e7da..d06d246ef 100644--- a/API/Helpers/SQLHelper.cs+++ b/API/Helpers/SQLHelper.cs@@ -2,6 +2,7 @@using System.Collections.Generic;using System.Data;using System.Data.Common;+using API.DTOs;using Microsoft.EntityFrameworkCore;namespace API.Helpersdiff --git a/API/Helpers/SeriesHelper.cs b/API/Helpers/SeriesHelper.csnew file mode 100644index 000000000..b03ebad18--- /dev/null+++ b/API/Helpers/SeriesHelper.cs@@ -0,0 +1,46 @@+using System.Collections.Generic;+using System.Linq;+using API.Entities;+using API.Entities.Enums;+using API.Services.Tasks.Scanner;++namespace API.Helpers;++public static class SeriesHelper+{+ /// <summary>+ /// Given a parsedSeries checks if any of the names match against said Series and the format matches+ /// </summary>+ /// <param name="series"></param>+ /// <param name="parsedInfoKey"></param>+ /// <returns></returns>+ public static bool FindSeries(Series series, ParsedSeries parsedInfoKey)+ {+ return (series.NormalizedName.Equals(parsedInfoKey.NormalizedName)+ || Parser.Parser.Normalize(series.OriginalName).Equals(parsedInfoKey.NormalizedName)+ || Parser.Parser.Normalize(series.LocalizedName).Equals(parsedInfoKey.NormalizedName))+ && (series.Format == parsedInfoKey.Format || series.Format == MangaFormat.Unknown);+ }++ /// <summary>+ /// Removes all instances of missingSeries' Series from existingSeries Collection. Existing series is updated by+ /// reference and the removed element count is returned.+ /// </summary>+ /// <param name="existingSeries">Existing Series in DB</param>+ /// <param name="missingSeries">Series not found on disk or can't be parsed</param>+ /// <param name="removeCount"></param>+ /// <returns>the updated existingSeries</returns>+ public static IEnumerable<Series> RemoveMissingSeries(IList<Series> existingSeries, IEnumerable<Series> missingSeries, out int removeCount)+ {+ var existingCount = existingSeries.Count;+ var missingList = missingSeries.ToList();++ existingSeries = existingSeries.Where(+ s => !missingList.Exists(+ m => m.NormalizedName.Equals(s.NormalizedName) && m.Format == s.Format)).ToList();++ removeCount = existingCount - existingSeries.Count;++ return existingSeries;+ }+}diff --git a/API/Helpers/TagHelper.cs b/API/Helpers/TagHelper.csnew file mode 100644index 000000000..4c230a053--- /dev/null+++ b/API/Helpers/TagHelper.cs@@ -0,0 +1,90 @@+using System;+using System.Collections.Generic;+using System.Linq;+using API.Data;+using API.Entities;++namespace API.Helpers;++public static class TagHelper+{+ /// <summary>+ ///+ /// </summary>+ /// <param name="allTags"></param>+ /// <param name="names"></param>+ /// <param name="isExternal"></param>+ /// <param name="action">Callback for every item. Will give said item back and a bool if item was added</param>+ public static void UpdateTag(ICollection<Tag> allTags, IEnumerable<string> names, bool isExternal, Action<Tag, bool> action)+ {+ foreach (var name in names)+ {+ if (string.IsNullOrEmpty(name.Trim())) continue;++ var added = false;+ var normalizedName = Parser.Parser.Normalize(name);++ var genre = allTags.FirstOrDefault(p =>+ p.NormalizedTitle.Equals(normalizedName) && p.ExternalTag == isExternal);+ if (genre == null)+ {+ added = true;+ genre = DbFactory.Tag(name, false);+ allTags.Add(genre);+ }++ action(genre, added);+ }+ }++ public static void KeepOnlySameTagBetweenLists(ICollection<Tag> existingTags, ICollection<Tag> removeAllExcept, Action<Tag> action = null)+ {+ var existing = existingTags.ToList();+ foreach (var genre in existing)+ {+ var existingPerson = removeAllExcept.FirstOrDefault(g => g.ExternalTag == genre.ExternalTag && genre.NormalizedTitle.Equals(g.NormalizedTitle));+ if (existingPerson != null) continue;+ existingTags.Remove(genre);+ action?.Invoke(genre);+ }++ }++ /// <summary>+ /// Adds the tag to the list if it's not already in there. This will ignore the ExternalTag.+ /// </summary>+ /// <param name="metadataTags"></param>+ /// <param name="tag"></param>+ public static void AddTagIfNotExists(ICollection<Tag> metadataTags, Tag tag)+ {+ var existingGenre = metadataTags.FirstOrDefault(p =>+ p.NormalizedTitle == Parser.Parser.Normalize(tag.Title));+ if (existingGenre == null)+ {+ metadataTags.Add(tag);+ }+ }++ /// <summary>+ /// Remove tags on a list+ /// </summary>+ /// <remarks>Used to remove before we update/add new tags</remarks>+ /// <param name="existingTags">Existing tags on Entity</param>+ /// <param name="tags">Tags from metadata</param>+ /// <param name="isExternal">Remove external tags?</param>+ /// <param name="action">Callback which will be executed for each tag removed</param>+ public static void RemoveTags(ICollection<Tag> existingTags, IEnumerable<string> tags, bool isExternal, Action<Tag> action = null)+ {+ var normalizedTags = tags.Select(Parser.Parser.Normalize).ToList();+ foreach (var person in normalizedTags)+ {+ var existingTag = existingTags.FirstOrDefault(p => p.ExternalTag == isExternal && person.Equals(p.NormalizedTitle));+ if (existingTag == null) continue;++ existingTags.Remove(existingTag);+ action?.Invoke(existingTag);+ }++ }+}+diff --git a/API/Interfaces/ITaskScheduler.cs b/API/Interfaces/ITaskScheduler.csdeleted file mode 100644index 215cccf80..000000000--- a/API/Interfaces/ITaskScheduler.cs+++ /dev/null@@ -1,22 +0,0 @@-using System.Threading.Tasks;--namespace API.Interfaces-{- public interface ITaskScheduler- {- /// <summary>- /// For use on Server startup- /// </summary>- void ScheduleTasks();- Task ScheduleStatsTasks();- void ScheduleUpdaterTasks();- void ScanLibrary(int libraryId, bool forceUpdate = false);- void CleanupChapters(int[] chapterIds);- void RefreshMetadata(int libraryId, bool forceUpdate = true);- void CleanupTemp();- void RefreshSeriesMetadata(int libraryId, int seriesId, bool forceUpdate = false);- void ScanSeries(int libraryId, int seriesId, bool forceUpdate = false);- void CancelStatsTasks();- Task RunStatCollection();- }-}diff --git a/API/Interfaces/IUnitOfWork.cs b/API/Interfaces/IUnitOfWork.csdeleted file mode 100644index 733008192..000000000--- a/API/Interfaces/IUnitOfWork.cs+++ /dev/null@@ -1,25 +0,0 @@-using System.Threading.Tasks;-using API.Interfaces.Repositories;--namespace API.Interfaces-{- public interface IUnitOfWork- {- ISeriesRepository SeriesRepository { get; }- IUserRepository UserRepository { get; }- ILibraryRepository LibraryRepository { get; }- IVolumeRepository VolumeRepository { get; }- ISettingsRepository SettingsRepository { get; }- IAppUserProgressRepository AppUserProgressRepository { get; }- ICollectionTagRepository CollectionTagRepository { get; }- IFileRepository FileRepository { get; }- IChapterRepository ChapterRepository { get; }- IReadingListRepository ReadingListRepository { get; }- ISeriesMetadataRepository SeriesMetadataRepository { get; }- bool Commit();- Task<bool> CommitAsync();- bool HasChanges();- bool Rollback();- Task<bool> RollbackAsync();- }-}diff --git a/API/Interfaces/Repositories/IAppUserProgressRepository.cs b/API/Interfaces/Repositories/IAppUserProgressRepository.csdeleted file mode 100644index d37198fb2..000000000--- a/API/Interfaces/Repositories/IAppUserProgressRepository.cs+++ /dev/null@@ -1,14 +0,0 @@-using System.Threading.Tasks;-using API.Entities;-using API.Entities.Enums;--namespace API.Interfaces.Repositories-{- public interface IAppUserProgressRepository- {- void Update(AppUserProgress userProgress);- Task<int> CleanupAbandonedChapters();- Task<bool> UserHasProgress(LibraryType libraryType, int userId);- Task<AppUserProgress> GetUserProgressAsync(int chapterId, int userId);- }-}diff --git a/API/Interfaces/Repositories/IChapterRepository.cs b/API/Interfaces/Repositories/IChapterRepository.csdeleted file mode 100644index 9ce145f4c..000000000--- a/API/Interfaces/Repositories/IChapterRepository.cs+++ /dev/null@@ -1,24 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.DTOs;-using API.DTOs.Reader;-using API.Entities;--namespace API.Interfaces.Repositories-{- public interface IChapterRepository- {- void Update(Chapter chapter);- Task<IEnumerable<Chapter>> GetChaptersByIdsAsync(IList<int> chapterIds);- Task<IChapterInfoDto> GetChapterInfoDtoAsync(int chapterId);- Task<int> GetChapterTotalPagesAsync(int chapterId);- Task<Chapter> GetChapterAsync(int chapterId);- Task<ChapterDto> GetChapterDtoAsync(int chapterId);- Task<IList<MangaFile>> GetFilesForChapterAsync(int chapterId);- Task<IList<Chapter>> GetChaptersAsync(int volumeId);- Task<IList<MangaFile>> GetFilesForChaptersAsync(IReadOnlyList<int> chapterIds);- Task<string> GetChapterCoverImageAsync(int chapterId);- Task<IList<string>> GetAllCoverImagesAsync();- Task<IEnumerable<string>> GetCoverImagesForLockedChaptersAsync();- }-}diff --git a/API/Interfaces/Repositories/ICollectionTagRepository.cs b/API/Interfaces/Repositories/ICollectionTagRepository.csdeleted file mode 100644index 18c9f490b..000000000--- a/API/Interfaces/Repositories/ICollectionTagRepository.cs+++ /dev/null@@ -1,24 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.DTOs;-using API.DTOs.CollectionTags;-using API.Entities;--namespace API.Interfaces.Repositories-{- public interface ICollectionTagRepository- {- void Add(CollectionTag tag);- void Remove(CollectionTag tag);- Task<IEnumerable<CollectionTagDto>> GetAllTagDtosAsync();- Task<IEnumerable<CollectionTagDto>> SearchTagDtosAsync(string searchQuery);- Task<string> GetCoverImageAsync(int collectionTagId);- Task<IEnumerable<CollectionTagDto>> GetAllPromotedTagDtosAsync();- Task<CollectionTag> GetTagAsync(int tagId);- Task<CollectionTag> GetFullTagAsync(int tagId);- void Update(CollectionTag tag);- Task<int> RemoveTagsWithoutSeries();- Task<IEnumerable<CollectionTag>> GetAllTagsAsync();- Task<IList<string>> GetAllCoverImagesAsync();- }-}diff --git a/API/Interfaces/Repositories/IFileRepository.cs b/API/Interfaces/Repositories/IFileRepository.csdeleted file mode 100644index a852032d7..000000000--- a/API/Interfaces/Repositories/IFileRepository.cs+++ /dev/null@@ -1,10 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;--namespace API.Interfaces.Repositories-{- public interface IFileRepository- {- Task<IEnumerable<string>> GetFileExtensions();- }-}diff --git a/API/Interfaces/Repositories/ILibraryRepository.cs b/API/Interfaces/Repositories/ILibraryRepository.csdeleted file mode 100644index 1ba6ac910..000000000--- a/API/Interfaces/Repositories/ILibraryRepository.cs+++ /dev/null@@ -1,26 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.Data.Repositories;-using API.DTOs;-using API.Entities;-using API.Entities.Enums;--namespace API.Interfaces.Repositories-{- public interface ILibraryRepository- {- void Add(Library library);- void Update(Library library);- void Delete(Library library);- Task<IEnumerable<LibraryDto>> GetLibraryDtosAsync();- Task<bool> LibraryExists(string libraryName);- Task<Library> GetLibraryForIdAsync(int libraryId, LibraryIncludes includes);- Task<Library> GetFullLibraryForIdAsync(int libraryId);- Task<Library> GetFullLibraryForIdAsync(int libraryId, int seriesId);- Task<IEnumerable<LibraryDto>> GetLibraryDtosForUsernameAsync(string userName);- Task<IEnumerable<Library>> GetLibrariesAsync();- Task<bool> DeleteLibrary(int libraryId);- Task<IEnumerable<Library>> GetLibrariesForUserIdAsync(int userId);- Task<LibraryType> GetLibraryTypeAsync(int libraryId);- }-}diff --git a/API/Interfaces/Repositories/IReadingListRepository.cs b/API/Interfaces/Repositories/IReadingListRepository.csdeleted file mode 100644index 8b5ab085d..000000000--- a/API/Interfaces/Repositories/IReadingListRepository.cs+++ /dev/null@@ -1,22 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.DTOs.ReadingLists;-using API.Entities;-using API.Helpers;--namespace API.Interfaces.Repositories-{- public interface IReadingListRepository- {- Task<PagedList<ReadingListDto>> GetReadingListDtosForUserAsync(int userId, bool includePromoted, UserParams userParams);- Task<ReadingList> GetReadingListByIdAsync(int readingListId);- Task<IEnumerable<ReadingListItemDto>> GetReadingListItemDtosByIdAsync(int readingListId, int userId);- Task<ReadingListDto> GetReadingListDtoByIdAsync(int readingListId, int userId);- Task<IEnumerable<ReadingListItemDto>> AddReadingProgressModifiers(int userId, IList<ReadingListItemDto> items);- Task<ReadingListDto> GetReadingListDtoByTitleAsync(string title);- Task<IEnumerable<ReadingListItem>> GetReadingListItemsByIdAsync(int readingListId);- void Remove(ReadingListItem item);- void BulkRemove(IEnumerable<ReadingListItem> items);- void Update(ReadingList list);- }-}diff --git a/API/Interfaces/Repositories/ISeriesMetadataRepository.cs b/API/Interfaces/Repositories/ISeriesMetadataRepository.csdeleted file mode 100644index 00dd234ee..000000000--- a/API/Interfaces/Repositories/ISeriesMetadataRepository.cs+++ /dev/null@@ -1,9 +0,0 @@-using API.Entities;--namespace API.Interfaces.Repositories-{- public interface ISeriesMetadataRepository- {- void Update(SeriesMetadata seriesMetadata);- }-}diff --git a/API/Interfaces/Repositories/ISeriesRepository.cs b/API/Interfaces/Repositories/ISeriesRepository.csdeleted file mode 100644index 4c8b2e74e..000000000--- a/API/Interfaces/Repositories/ISeriesRepository.cs+++ /dev/null@@ -1,62 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.Data.Scanner;-using API.DTOs;-using API.DTOs.Filtering;-using API.Entities;-using API.Entities.Enums;-using API.Helpers;--namespace API.Interfaces.Repositories-{- public interface ISeriesRepository- {- void Attach(Series series);- void Update(Series series);- void Remove(Series series);- void Remove(IEnumerable<Series> series);- Task<bool> DoesSeriesNameExistInLibrary(string name, MangaFormat format);- /// <summary>- /// Adds user information like progress, ratings, etc- /// </summary>- /// <param name="libraryId"></param>- /// <param name="userId"></param>- /// <param name="userParams"></param>- /// <returns></returns>- Task<PagedList<SeriesDto>> GetSeriesDtoForLibraryIdAsync(int libraryId, int userId, UserParams userParams, FilterDto filter);- /// <summary>- /// Does not add user information like progress, ratings, etc.- /// </summary>- /// <param name="libraryIds"></param>- /// <param name="searchQuery">Series name to search for</param>- /// <returns></returns>- Task<IEnumerable<SearchResultDto>> SearchSeries(int[] libraryIds, string searchQuery);- Task<IEnumerable<Series>> GetSeriesForLibraryIdAsync(int libraryId);- Task<SeriesDto> GetSeriesDtoByIdAsync(int seriesId, int userId);- Task<bool> DeleteSeriesAsync(int seriesId);- Task<Series> GetSeriesByIdAsync(int seriesId);- Task<IList<Series>> GetSeriesByIdsAsync(IList<int> seriesIds);- Task<int[]> GetChapterIdsForSeriesAsync(int[] seriesIds);- Task<IDictionary<int, IList<int>>> GetChapterIdWithSeriesIdForSeriesAsync(int[] seriesIds);- /// <summary>- /// Used to add Progress/Rating information to series list.- /// </summary>- /// <param name="userId"></param>- /// <param name="series"></param>- /// <returns></returns>- Task AddSeriesModifiers(int userId, List<SeriesDto> series);- Task<string> GetSeriesCoverImageAsync(int seriesId);- Task<IEnumerable<SeriesDto>> GetOnDeck(int userId, int libraryId, UserParams userParams, FilterDto filter);- Task<PagedList<SeriesDto>> GetRecentlyAdded(int libraryId, int userId, UserParams userParams, FilterDto filter); // NOTE: Probably put this in LibraryRepo- Task<SeriesMetadataDto> GetSeriesMetadata(int seriesId);- Task<PagedList<SeriesDto>> GetSeriesDtoForCollectionAsync(int collectionId, int userId, UserParams userParams);- Task<IList<MangaFile>> GetFilesForSeries(int seriesId);- Task<IEnumerable<SeriesDto>> GetSeriesDtoForIdsAsync(IEnumerable<int> seriesIds, int userId);- Task<IList<string>> GetAllCoverImagesAsync();- Task<IEnumerable<string>> GetLockedCoverImagesAsync();- Task<PagedList<Series>> GetFullSeriesForLibraryIdAsync(int libraryId, UserParams userParams);- Task<Series> GetFullSeriesForSeriesIdAsync(int seriesId);- Task<Chunk> GetChunkInfo(int libraryId = 0);- Task<IList<SeriesMetadata>> GetSeriesMetadataForIdsAsync(IEnumerable<int> seriesIds);- }-}diff --git a/API/Interfaces/Repositories/ISettingsRepository.cs b/API/Interfaces/Repositories/ISettingsRepository.csdeleted file mode 100644index 95178ea79..000000000--- a/API/Interfaces/Repositories/ISettingsRepository.cs+++ /dev/null@@ -1,17 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.DTOs.Settings;-using API.Entities;-using API.Entities.Enums;--namespace API.Interfaces.Repositories-{- public interface ISettingsRepository- {- void Update(ServerSetting settings);- Task<ServerSettingDto> GetSettingsDtoAsync();- Task<ServerSetting> GetSettingAsync(ServerSettingKey key);- Task<IEnumerable<ServerSetting>> GetSettingsAsync();-- }-}diff --git a/API/Interfaces/Repositories/IUserRepository.cs b/API/Interfaces/Repositories/IUserRepository.csdeleted file mode 100644index 65d943623..000000000--- a/API/Interfaces/Repositories/IUserRepository.cs+++ /dev/null@@ -1,33 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.Data.Repositories;-using API.DTOs;-using API.DTOs.Reader;-using API.Entities;--namespace API.Interfaces.Repositories-{- public interface IUserRepository- {- void Update(AppUser user);- void Update(AppUserPreferences preferences);- void Update(AppUserBookmark bookmark);- public void Delete(AppUser user);- Task<IEnumerable<MemberDto>> GetMembersAsync();- Task<IEnumerable<AppUser>> GetAdminUsersAsync();- Task<IEnumerable<AppUser>> GetNonAdminUsersAsync();- Task<bool> IsUserAdmin(AppUser user);- Task<AppUserRating> GetUserRating(int seriesId, int userId);- Task<AppUserPreferences> GetPreferencesAsync(string username);- Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForSeries(int userId, int seriesId);- Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForVolume(int userId, int volumeId);- Task<IEnumerable<BookmarkDto>> GetBookmarkDtosForChapter(int userId, int chapterId);- Task<IEnumerable<BookmarkDto>> GetAllBookmarkDtos(int userId);- Task<AppUserBookmark> GetBookmarkForPage(int page, int chapterId, int userId);- Task<int> GetUserIdByApiKeyAsync(string apiKey);- Task<AppUser> GetUserByUsernameAsync(string username, AppUserIncludes includeFlags = AppUserIncludes.None);- Task<AppUser> GetUserByIdAsync(int userId, AppUserIncludes includeFlags = AppUserIncludes.None);- Task<int> GetUserIdByUsernameAsync(string username);- Task<AppUser> GetUserWithReadingListsByUsernameAsync(string username);- }-}diff --git a/API/Interfaces/Repositories/IVolumeRepository.cs b/API/Interfaces/Repositories/IVolumeRepository.csdeleted file mode 100644index 63045a38d..000000000--- a/API/Interfaces/Repositories/IVolumeRepository.cs+++ /dev/null@@ -1,25 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.DTOs;-using API.Entities;--namespace API.Interfaces.Repositories-{- public interface IVolumeRepository- {- void Add(Volume volume);- void Update(Volume volume);- void Remove(Volume volume);- Task<IList<MangaFile>> GetFilesForVolume(int volumeId);- Task<string> GetVolumeCoverImageAsync(int volumeId);- Task<IList<int>> GetChapterIdsByVolumeIds(IReadOnlyList<int> volumeIds);-- // From Series Repo- Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId, int userId);- Task<Volume> GetVolumeAsync(int volumeId);- Task<VolumeDto> GetVolumeDtoAsync(int volumeId, int userId);- Task<IEnumerable<Volume>> GetVolumesForSeriesAsync(IList<int> seriesIds, bool includeChapters = false);- Task<IEnumerable<Volume>> GetVolumes(int seriesId);- Task<Volume> GetVolumeByIdAsync(int volumeId);- }-}diff --git a/API/Interfaces/Services/IAccountService.cs b/API/Interfaces/Services/IAccountService.csdeleted file mode 100644index e07ce2f79..000000000--- a/API/Interfaces/Services/IAccountService.cs+++ /dev/null@@ -1,12 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.Entities;-using API.Errors;--namespace API.Interfaces.Services-{- public interface IAccountService- {- Task<IEnumerable<ApiException>> ChangeUserPassword(AppUser user, string newPassword);- }-}diff --git a/API/Interfaces/Services/IArchiveService.cs b/API/Interfaces/Services/IArchiveService.csdeleted file mode 100644index f2567341a..000000000--- a/API/Interfaces/Services/IArchiveService.cs+++ /dev/null@@ -1,21 +0,0 @@-using System;-using System.Collections.Generic;-using System.IO.Compression;-using System.Threading.Tasks;-using API.Archive;-using API.Data.Metadata;--namespace API.Interfaces.Services-{- public interface IArchiveService- {- void ExtractArchive(string archivePath, string extractPath);- int GetNumberOfPagesFromArchive(string archivePath);- string GetCoverImage(string archivePath, string fileName);- bool IsValidArchive(string archivePath);- ComicInfo GetComicInfo(string archivePath);- ArchiveLibrary CanOpen(string archivePath);- bool ArchiveNeedsFlattening(ZipArchive archive);- Task<Tuple<byte[], string>> CreateZipForDownload(IEnumerable<string> files, string tempFolder);- }-}diff --git a/API/Interfaces/Services/IBackupService.cs b/API/Interfaces/Services/IBackupService.csdeleted file mode 100644index 315b852f0..000000000--- a/API/Interfaces/Services/IBackupService.cs+++ /dev/null@@ -1,20 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using Microsoft.Extensions.Configuration;--namespace API.Interfaces.Services-{- public interface IBackupService- {- Task BackupDatabase();- /// <summary>- /// Returns a list of full paths of the logs files detailed in <see cref="IConfiguration"/>.- /// </summary>- /// <param name="maxRollingFiles"></param>- /// <param name="logFileName"></param>- /// <returns></returns>- IEnumerable<string> LogFiles(int maxRollingFiles, string logFileName);-- void CleanupBackups();- }-}\ No newline at end of filediff --git a/API/Interfaces/Services/IBookService.cs b/API/Interfaces/Services/IBookService.csdeleted file mode 100644index e78669755..000000000--- a/API/Interfaces/Services/IBookService.cs+++ /dev/null@@ -1,33 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.Data.Metadata;-using API.Parser;-using VersOne.Epub;--namespace API.Interfaces.Services-{- public interface IBookService- {- int GetNumberOfPages(string filePath);- string GetCoverImage(string fileFilePath, string fileName);- Task<Dictionary<string, int>> CreateKeyToPageMappingAsync(EpubBookRef book);-- /// <summary>- /// Scopes styles to .reading-section and replaces img src to the passed apiBase- /// </summary>- /// <param name="stylesheetHtml"></param>- /// <param name="apiBase"></param>- /// <param name="filename">If the stylesheetHtml contains Import statements, when scoping the filename, scope needs to be wrt filepath.</param>- /// <param name="book">Book Reference, needed for if you expect Import statements</param>- /// <returns></returns>- Task<string> ScopeStyles(string stylesheetHtml, string apiBase, string filename, EpubBookRef book);- ComicInfo GetComicInfo(string filePath);- ParserInfo ParseInfo(string filePath);- /// <summary>- /// Extracts a PDF file's pages as images to an target directory- /// </summary>- /// <param name="fileFilePath"></param>- /// <param name="targetDirectory">Where the files will be extracted to. If doesn't exist, will be created.</param>- void ExtractPdfImages(string fileFilePath, string targetDirectory);- }-}diff --git a/API/Interfaces/Services/ICacheService.cs b/API/Interfaces/Services/ICacheService.csdeleted file mode 100644index 395898dc2..000000000--- a/API/Interfaces/Services/ICacheService.cs+++ /dev/null@@ -1,41 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.Entities;--namespace API.Interfaces.Services-{- public interface ICacheService- {- /// <summary>- /// Ensures the cache is created for the given chapter and if not, will create it. Should be called before any other- /// cache operations (except cleanup).- /// </summary>- /// <param name="chapterId"></param>- /// <returns>Chapter for the passed chapterId. Side-effect from ensuring cache.</returns>- Task<Chapter> Ensure(int chapterId);-- /// <summary>- /// Clears cache directory of all folders and files.- /// </summary>- void Cleanup();-- /// <summary>- /// Clears cache directory of all volumes. This can be invoked from deleting a library or a series.- /// </summary>- /// <param name="chapterIds">Volumes that belong to that library. Assume the library might have been deleted before this invocation.</param>- void CleanupChapters(IEnumerable<int> chapterIds);--- /// <summary>- /// Returns the absolute path of a cached page.- /// </summary>- /// <param name="chapter">Chapter entity with Files populated.</param>- /// <param name="page">Page number to look for</param>- /// <returns></returns>- Task<(string path, MangaFile file)> GetCachedPagePath(Chapter chapter, int page);-- void EnsureCacheDirectory();- string GetCachedEpubFile(int chapterId, Chapter chapter);- public void ExtractChapterFiles(string extractPath, IReadOnlyList<MangaFile> files);- }-}diff --git a/API/Interfaces/Services/ICleanupService.cs b/API/Interfaces/Services/ICleanupService.csdeleted file mode 100644index afabb9900..000000000--- a/API/Interfaces/Services/ICleanupService.cs+++ /dev/null@@ -1,10 +0,0 @@-using System.Threading.Tasks;--namespace API.Interfaces.Services-{- public interface ICleanupService- {- Task Cleanup();- void CleanupCacheDirectory();- }-}diff --git a/API/Interfaces/Services/IDirectoryService.cs b/API/Interfaces/Services/IDirectoryService.csdeleted file mode 100644index a8ae8c05f..000000000--- a/API/Interfaces/Services/IDirectoryService.cs+++ /dev/null@@ -1,20 +0,0 @@-using System.Collections.Generic;-using System.IO;-using System.Threading.Tasks;--namespace API.Interfaces.Services-{- public interface IDirectoryService- {- /// <summary>- /// Lists out top-level folders for a given directory. Filters out System and Hidden folders.- /// </summary>- /// <param name="rootPath">Absolute path of directory to scan.</param>- /// <returns>List of folder names</returns>- IEnumerable<string> ListDirectory(string rootPath);- Task<byte[]> ReadFileAsync(string path);- bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, string prepend = "");- bool Exists(string directory);- void CopyFileToDirectory(string fullFilePath, string targetDirectory);- }-}diff --git a/API/Interfaces/Services/IImageService.cs b/API/Interfaces/Services/IImageService.csdeleted file mode 100644index 0aba07f39..000000000--- a/API/Interfaces/Services/IImageService.cs+++ /dev/null@@ -1,23 +0,0 @@-using API.Entities;-using API.Services;--namespace API.Interfaces.Services-{- public interface IImageService- {- string GetCoverImage(string path, string fileName);- string GetCoverFile(MangaFile file);- /// <summary>- /// Creates a Thumbnail version of an image- /// </summary>- /// <param name="path">Path to the image file</param>- /// <returns>File name with extension of the file. This will always write to <see cref="DirectoryService.CoverImageDirectory"/></returns>- public string CreateThumbnail(string path, string fileName);- /// <summary>- /// Creates a Thumbnail version of a base64 image- /// </summary>- /// <param name="encodedImage">base64 encoded image</param>- /// <returns>File name with extension of the file. This will always write to <see cref="DirectoryService.CoverImageDirectory"/></returns>- public string CreateThumbnailFromBase64(string encodedImage, string fileName);- }-}diff --git a/API/Interfaces/Services/IMetadataService.cs b/API/Interfaces/Services/IMetadataService.csdeleted file mode 100644index 6d4d725cf..000000000--- a/API/Interfaces/Services/IMetadataService.cs+++ /dev/null@@ -1,25 +0,0 @@-using System.Threading.Tasks;-using API.Entities;--namespace API.Interfaces.Services-{- public interface IMetadataService- {- /// <summary>- /// Recalculates metadata for all entities in a library.- /// </summary>- /// <param name="libraryId"></param>- /// <param name="forceUpdate"></param>- Task RefreshMetadata(int libraryId, bool forceUpdate = false);-- public bool UpdateMetadata(Chapter chapter, bool forceUpdate);- public bool UpdateMetadata(Volume volume, bool forceUpdate);- public bool UpdateMetadata(Series series, bool forceUpdate);- /// <summary>- /// Performs a forced refresh of metatdata just for a series and it's nested entities- /// </summary>- /// <param name="libraryId"></param>- /// <param name="seriesId"></param>- Task RefreshMetadataForSeries(int libraryId, int seriesId, bool forceUpdate = false);- }-}diff --git a/API/Interfaces/Services/IReaderService.cs b/API/Interfaces/Services/IReaderService.csdeleted file mode 100644index a72b90699..000000000--- a/API/Interfaces/Services/IReaderService.cs+++ /dev/null@@ -1,17 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.DTOs;-using API.Entities;--namespace API.Interfaces.Services-{- public interface IReaderService- {- void MarkChaptersAsRead(AppUser user, int seriesId, IEnumerable<Chapter> chapters);- void MarkChaptersAsUnread(AppUser user, int seriesId, IEnumerable<Chapter> chapters);- Task<bool> SaveReadingProgress(ProgressDto progressDto, int userId);- Task<int> CapPageToChapter(int chapterId, int page);- Task<int> GetNextChapterIdAsync(int seriesId, int volumeId, int currentChapterId, int userId);- Task<int> GetPrevChapterIdAsync(int seriesId, int volumeId, int currentChapterId, int userId);- }-}diff --git a/API/Interfaces/Services/IScannerService.cs b/API/Interfaces/Services/IScannerService.csdeleted file mode 100644index bab0ca588..000000000--- a/API/Interfaces/Services/IScannerService.cs+++ /dev/null@@ -1,18 +0,0 @@--using System.Threading;-using System.Threading.Tasks;--namespace API.Interfaces.Services-{- public interface IScannerService- {- /// <summary>- /// Given a library id, scans folders for said library. Parses files and generates DB updates. Will overwrite- /// cover images if forceUpdate is true.- /// </summary>- /// <param name="libraryId">Library to scan against</param>- Task ScanLibrary(int libraryId);- Task ScanLibraries();- Task ScanSeries(int libraryId, int seriesId, CancellationToken token);- }-}diff --git a/API/Interfaces/Services/IStartupTask.cs b/API/Interfaces/Services/IStartupTask.csdeleted file mode 100644index e2a99ecad..000000000--- a/API/Interfaces/Services/IStartupTask.cs+++ /dev/null@@ -1,10 +0,0 @@-using System.Threading;-using System.Threading.Tasks;--namespace API.Interfaces.Services-{- public interface IStartupTask- {- Task ExecuteAsync(CancellationToken cancellationToken = default);- }-}\ No newline at end of filediff --git a/API/Interfaces/Services/IStatsService.cs b/API/Interfaces/Services/IStatsService.csdeleted file mode 100644index 685c3057d..000000000--- a/API/Interfaces/Services/IStatsService.cs+++ /dev/null@@ -1,11 +0,0 @@-using System.Threading.Tasks;-using API.DTOs.Stats;--namespace API.Interfaces.Services-{- public interface IStatsService- {- Task Send();- Task<ServerInfoDto> GetServerInfo();- }-}diff --git a/API/Interfaces/Services/ITokenService.cs b/API/Interfaces/Services/ITokenService.csdeleted file mode 100644index 14765f2f0..000000000--- a/API/Interfaces/Services/ITokenService.cs+++ /dev/null@@ -1,10 +0,0 @@-using System.Threading.Tasks;-using API.Entities;--namespace API.Interfaces.Services-{- public interface ITokenService- {- Task<string> CreateToken(AppUser user);- }-}\ No newline at end of filediff --git a/API/Interfaces/Services/IVersionUpdaterService.cs b/API/Interfaces/Services/IVersionUpdaterService.csdeleted file mode 100644index ddde09960..000000000--- a/API/Interfaces/Services/IVersionUpdaterService.cs+++ /dev/null@@ -1,13 +0,0 @@-using System.Collections.Generic;-using System.Threading.Tasks;-using API.DTOs.Update;--namespace API.Interfaces.Services-{- public interface IVersionUpdaterService- {- Task<UpdateNotificationDto> CheckForUpdate();- Task PushUpdate(UpdateNotificationDto update);- Task<IEnumerable<UpdateNotificationDto>> GetAllReleases();- }-}diff --git a/API/Interfaces/Services/ReaderService.cs b/API/Interfaces/Services/ReaderService.csdeleted file mode 100644index 7eb2e1118..000000000--- a/API/Interfaces/Services/ReaderService.cs+++ /dev/null@@ -1,310 +0,0 @@--using System;-using System.Collections.Generic;-using System.Linq;-using System.Threading.Tasks;-using API.Comparators;-using API.Data.Repositories;-using API.DTOs;-using API.Entities;-using Microsoft.Extensions.Logging;--namespace API.Interfaces.Services-{- public class ReaderService : IReaderService- {- private readonly IUnitOfWork _unitOfWork;- private readonly ILogger<ReaderService> _logger;- private readonly ChapterSortComparer _chapterSortComparer = new ChapterSortComparer();- private readonly ChapterSortComparerZeroFirst _chapterSortComparerForInChapterSorting = new ChapterSortComparerZeroFirst();-- public ReaderService(IUnitOfWork unitOfWork, ILogger<ReaderService> logger)- {- _unitOfWork = unitOfWork;- _logger = logger;- }-- /// <summary>- /// Marks all Chapters as Read by creating or updating UserProgress rows. Does not commit.- /// </summary>- /// <param name="user"></param>- /// <param name="seriesId"></param>- /// <param name="chapters"></param>- public void MarkChaptersAsRead(AppUser user, int seriesId, IEnumerable<Chapter> chapters)- {- foreach (var chapter in chapters)- {- var userProgress = GetUserProgressForChapter(user, chapter);-- if (userProgress == null)- {- user.Progresses.Add(new AppUserProgress- {- PagesRead = chapter.Pages,- VolumeId = chapter.VolumeId,- SeriesId = seriesId,- ChapterId = chapter.Id- });- }- else- {- userProgress.PagesRead = chapter.Pages;- userProgress.SeriesId = seriesId;- userProgress.VolumeId = chapter.VolumeId;- }- }- }-- /// <summary>- /// Marks all Chapters as Unread by creating or updating UserProgress rows. Does not commit.- /// </summary>- /// <param name="user"></param>- /// <param name="seriesId"></param>- /// <param name="chapters"></param>- public void MarkChaptersAsUnread(AppUser user, int seriesId, IEnumerable<Chapter> chapters)- {- foreach (var chapter in chapters)- {- var userProgress = GetUserProgressForChapter(user, chapter);-- if (userProgress == null)- {- user.Progresses.Add(new AppUserProgress- {- PagesRead = 0,- VolumeId = chapter.VolumeId,- SeriesId = seriesId,- ChapterId = chapter.Id- });- }- else- {- userProgress.PagesRead = 0;- userProgress.SeriesId = seriesId;- userProgress.VolumeId = chapter.VolumeId;- }- }- }-- /// <summary>- /// Gets the User Progress for a given Chapter. This will handle any duplicates that might have occured in past versions and will delete them. Does not commit.- /// </summary>- /// <param name="user"></param>- /// <param name="chapter"></param>- /// <returns></returns>- public static AppUserProgress GetUserProgressForChapter(AppUser user, Chapter chapter)- {- AppUserProgress userProgress = null;- try- {- userProgress =- user.Progresses.SingleOrDefault(x => x.ChapterId == chapter.Id && x.AppUserId == user.Id);- }- catch (Exception)- {- // There is a very rare chance that user progress will duplicate current row. If that happens delete one with less pages- var progresses = user.Progresses.Where(x => x.ChapterId == chapter.Id && x.AppUserId == user.Id).ToList();- if (progresses.Count > 1)- {- user.Progresses = new List<AppUserProgress>()- {- user.Progresses.First()- };- userProgress = user.Progresses.First();- }- }-- return userProgress;- }-- /// <summary>- /// Saves progress to DB- /// </summary>- /// <param name="progressDto"></param>- /// <param name="userId"></param>- /// <returns></returns>- public async Task<bool> SaveReadingProgress(ProgressDto progressDto, int userId)- {- // Don't let user save past total pages.- progressDto.PageNum = await CapPageToChapter(progressDto.ChapterId, progressDto.PageNum);-- try- {- var userProgress =- await _unitOfWork.AppUserProgressRepository.GetUserProgressAsync(progressDto.ChapterId, userId);-- if (userProgress == null)- {- // Create a user object- var userWithProgress =- await _unitOfWork.UserRepository.GetUserByIdAsync(userId, AppUserIncludes.Progress);- userWithProgress.Progresses ??= new List<AppUserProgress>();- userWithProgress.Progresses.Add(new AppUserProgress- {- PagesRead = progressDto.PageNum,- VolumeId = progressDto.VolumeId,- SeriesId = progressDto.SeriesId,- ChapterId = progressDto.ChapterId,- BookScrollId = progressDto.BookScrollId,- LastModified = DateTime.Now- });- _unitOfWork.UserRepository.Update(userWithProgress);- }- else- {- userProgress.PagesRead = progressDto.PageNum;- userProgress.SeriesId = progressDto.SeriesId;- userProgress.VolumeId = progressDto.VolumeId;- userProgress.BookScrollId = progressDto.BookScrollId;- userProgress.LastModified = DateTime.Now;- _unitOfWork.AppUserProgressRepository.Update(userProgress);- }-- if (await _unitOfWork.CommitAsync())- {- return true;- }- }- catch (Exception exception)- {- _logger.LogError(exception, "Could not save progress");- await _unitOfWork.RollbackAsync();- }-- return false;- }-- /// <summary>- /// Ensures that the page is within 0 and total pages for a chapter. Makes one DB call.- /// </summary>- /// <param name="chapterId"></param>- /// <param name="page"></param>- /// <returns></returns>- public async Task<int> CapPageToChapter(int chapterId, int page)- {- var totalPages = await _unitOfWork.ChapterRepository.GetChapterTotalPagesAsync(chapterId);- if (page > totalPages)- {- page = totalPages;- }-- if (page < 0)- {- page = 0;- }-- return page;- }-- /// <summary>- /// Tries to find the next logical Chapter- /// </summary>- /// <example>- /// V1 → V2 → V3 chapter 0 → V3 chapter 10 → SP 01 → SP 02- /// </example>- /// <param name="seriesId"></param>- /// <param name="volumeId"></param>- /// <param name="currentChapterId"></param>- /// <param name="userId"></param>- /// <returns>-1 if nothing can be found</returns>- public async Task<int> GetNextChapterIdAsync(int seriesId, int volumeId, int currentChapterId, int userId)- {- var volumes = (await _unitOfWork.VolumeRepository.GetVolumesDtoAsync(seriesId, userId)).ToList();- var currentVolume = volumes.Single(v => v.Id == volumeId);- var currentChapter = currentVolume.Chapters.Single(c => c.Id == currentChapterId);-- if (currentVolume.Number == 0)- {- // Handle specials by sorting on their Filename aka Range- var chapterId = GetNextChapterId(currentVolume.Chapters.OrderBy(x => x.Range, new NaturalSortComparer()), currentChapter.Number);- if (chapterId > 0) return chapterId;- }-- foreach (var volume in volumes)- {- if (volume.Number == currentVolume.Number && volume.Chapters.Count > 1)- {- // Handle Chapters within current Volume- // In this case, i need 0 first because 0 represents a full volume file.- var chapterId = GetNextChapterId(currentVolume.Chapters.OrderBy(x => double.Parse(x.Number), _chapterSortComparerForInChapterSorting), currentChapter.Number);- if (chapterId > 0) return chapterId;- }-- if (volume.Number != currentVolume.Number + 1) continue;-- // Handle Chapters within next Volume- // ! When selecting the chapter for the next volume, we need to make sure a c0 comes before a c1+- var chapters = volume.Chapters.OrderBy(x => double.Parse(x.Number), _chapterSortComparer).ToList();- if (currentChapter.Number.Equals("0") && chapters.Last().Number.Equals("0"))- {- return chapters.Last().Id;- }-- var firstChapter = chapters.FirstOrDefault();- if (firstChapter == null) return -1;- return firstChapter.Id;-- }-- return -1;- }- /// <summary>- /// Tries to find the prev logical Chapter- /// </summary>- /// <example>- /// V1 ← V2 ← V3 chapter 0 ← V3 chapter 10 ← SP 01 ← SP 02- /// </example>- /// <param name="seriesId"></param>- /// <param name="volumeId"></param>- /// <param name="currentChapterId"></param>- /// <param name="userId"></param>- /// <returns>-1 if nothing can be found</returns>- public async Task<int> GetPrevChapterIdAsync(int seriesId, int volumeId, int currentChapterId, int userId)- {- var volumes = (await _unitOfWork.VolumeRepository.GetVolumesDtoAsync(seriesId, userId)).Reverse().ToList();- var currentVolume = volumes.Single(v => v.Id == volumeId);- var currentChapter = currentVolume.Chapters.Single(c => c.Id == currentChapterId);-- if (currentVolume.Number == 0)- {- var chapterId = GetNextChapterId(currentVolume.Chapters.OrderBy(x => x.Range, new NaturalSortComparer()).Reverse(), currentChapter.Number);- if (chapterId > 0) return chapterId;- }-- foreach (var volume in volumes)- {- if (volume.Number == currentVolume.Number)- {- var chapterId = GetNextChapterId(currentVolume.Chapters.OrderBy(x => double.Parse(x.Number), _chapterSortComparerForInChapterSorting).Reverse(), currentChapter.Number);- if (chapterId > 0) return chapterId;- }- if (volume.Number == currentVolume.Number - 1)- {- var lastChapter = volume.Chapters- .OrderBy(x => double.Parse(x.Number), _chapterSortComparerForInChapterSorting).LastOrDefault();- if (lastChapter == null) return -1;- return lastChapter.Id;- }- }- return -1;- }-- private static int GetNextChapterId(IEnumerable<ChapterDto> chapters, string currentChapterNumber)- {- var next = false;- var chaptersList = chapters.ToList();- foreach (var chapter in chaptersList)- {- if (next)- {- return chapter.Id;- }- if (currentChapterNumber.Equals(chapter.Number)) next = true;- }-- return -1;- }--- }-}diff --git a/API/Middleware/ExceptionMiddleware.cs b/API/Middleware/ExceptionMiddleware.csindex 8badfeb96..0712eaea1 100644--- a/API/Middleware/ExceptionMiddleware.cs+++ b/API/Middleware/ExceptionMiddleware.cs@@ -14,7 +14,7 @@ namespace API.Middlewareprivate readonly RequestDelegate _next;private readonly ILogger<ExceptionMiddleware> _logger;private readonly IHostEnvironment _env;-+public ExceptionMiddleware(RequestDelegate next, ILogger<ExceptionMiddleware> logger, IHostEnvironment env){@@ -34,14 +34,14 @@ namespace API.Middleware_logger.LogError(ex, "There was an exception");context.Response.ContentType = "application/json";context.Response.StatusCode = (int) HttpStatusCode.InternalServerError;-- var response = _env.IsDevelopment()++ var response = _env.IsDevelopment()? new ApiException(context.Response.StatusCode, ex.Message, ex.StackTrace)- : new ApiException(context.Response.StatusCode, "Internal Server Error");-+ : new ApiException(context.Response.StatusCode, "Internal Server Error", ex.StackTrace);+var options = new JsonSerializerOptions{- PropertyNamingPolicy =+ PropertyNamingPolicy =JsonNamingPolicy.CamelCase};@@ -52,4 +52,4 @@ namespace API.Middleware}}}-}\ No newline at end of file+}diff --git a/API/Parser/DefaultParser.cs b/API/Parser/DefaultParser.csnew file mode 100644index 000000000..23b5c1d58--- /dev/null+++ b/API/Parser/DefaultParser.cs@@ -0,0 +1,160 @@+using System.IO;+using System.Linq;+using API.Entities.Enums;+using API.Services;++namespace API.Parser;++/// <summary>+/// This is an implementation of the Parser that is the basis for everything+/// </summary>+public class DefaultParser+{+ private readonly IDirectoryService _directoryService;++ public DefaultParser(IDirectoryService directoryService)+ {+ _directoryService = directoryService;+ }++ /// <summary>+ /// Parses information out of a file path. Will fallback to using directory name if Series couldn't be parsed+ /// from filename.+ /// </summary>+ /// <param name="filePath"></param>+ /// <param name="rootPath">Root folder</param>+ /// <param name="type">Defaults to Manga. Allows different Regex to be used for parsing.</param>+ /// <returns><see cref="ParserInfo"/> or null if Series was empty</returns>+ public ParserInfo Parse(string filePath, string rootPath, LibraryType type = LibraryType.Manga)+ {+ var fileName = _directoryService.FileSystem.Path.GetFileNameWithoutExtension(filePath);+ ParserInfo ret;++ if (Parser.IsEpub(filePath))+ {+ ret = new ParserInfo()+ {+ Chapters = Parser.ParseChapter(fileName) ?? Parser.ParseComicChapter(fileName),+ Series = Parser.ParseSeries(fileName) ?? Parser.ParseComicSeries(fileName),+ Volumes = Parser.ParseVolume(fileName) ?? Parser.ParseComicVolume(fileName),+ Filename = Path.GetFileName(filePath),+ Format = Parser.ParseFormat(filePath),+ FullFilePath = filePath+ };+ }+ else+ {+ ret = new ParserInfo()+ {+ Chapters = type == LibraryType.Manga ? Parser.ParseChapter(fileName) : Parser.ParseComicChapter(fileName),+ Series = type == LibraryType.Manga ? Parser.ParseSeries(fileName) : Parser.ParseComicSeries(fileName),+ Volumes = type == LibraryType.Manga ? Parser.ParseVolume(fileName) : Parser.ParseComicVolume(fileName),+ Filename = Path.GetFileName(filePath),+ Format = Parser.ParseFormat(filePath),+ Title = Path.GetFileNameWithoutExtension(fileName),+ FullFilePath = filePath+ };+ }++ if (Parser.IsImage(filePath) && Parser.IsCoverImage(filePath)) return null;++ if (Parser.IsImage(filePath))+ {+ // Reset Chapters, Volumes, and Series as images are not good to parse information out of. Better to use folders.+ ret.Volumes = Parser.DefaultVolume;+ ret.Chapters = Parser.DefaultChapter;+ ret.Series = string.Empty;+ }++ if (ret.Series == string.Empty || Parser.IsImage(filePath))+ {+ // Try to parse information out of each folder all the way to rootPath+ ParseFromFallbackFolders(filePath, rootPath, type, ref ret);+ }++ var edition = Parser.ParseEdition(fileName);+ if (!string.IsNullOrEmpty(edition))+ {+ ret.Series = Parser.CleanTitle(ret.Series.Replace(edition, ""), type is LibraryType.Comic);+ ret.Edition = edition;+ }++ var isSpecial = type == LibraryType.Comic ? Parser.ParseComicSpecial(fileName) : Parser.ParseMangaSpecial(fileName);+ // We must ensure that we can only parse a special out. As some files will have v20 c171-180+Omake and that+ // could cause a problem as Omake is a special term, but there is valid volume/chapter information.+ if (ret.Chapters == Parser.DefaultChapter && ret.Volumes == Parser.DefaultVolume && !string.IsNullOrEmpty(isSpecial))+ {+ ret.IsSpecial = true;+ ParseFromFallbackFolders(filePath, rootPath, type, ref ret);+ }++ // If we are a special with marker, we need to ensure we use the correct series name. we can do this by falling back to Folder name+ if (Parser.HasSpecialMarker(fileName))+ {+ ret.IsSpecial = true;+ ret.Chapters = Parser.DefaultChapter;+ ret.Volumes = Parser.DefaultVolume;++ ParseFromFallbackFolders(filePath, rootPath, type, ref ret);+ }++ if (string.IsNullOrEmpty(ret.Series))+ {+ ret.Series = Parser.CleanTitle(fileName, type is LibraryType.Comic);+ }++ // Pdfs may have .pdf in the series name, remove that+ if (Parser.IsPdf(filePath) && ret.Series.ToLower().EndsWith(".pdf"))+ {+ ret.Series = ret.Series.Substring(0, ret.Series.Length - ".pdf".Length);+ }++ return ret.Series == string.Empty ? null : ret;+ }++ /// <summary>+ /// Fills out <see cref="ParserInfo"/> by trying to parse volume, chapters, and series from folders+ /// </summary>+ /// <param name="filePath"></param>+ /// <param name="rootPath"></param>+ /// <param name="type"></param>+ /// <param name="ret">Expects a non-null ParserInfo which this method will populate</param>+ public void ParseFromFallbackFolders(string filePath, string rootPath, LibraryType type, ref ParserInfo ret)+ {+ var fallbackFolders = _directoryService.GetFoldersTillRoot(rootPath, filePath).ToList();+ for (var i = 0; i < fallbackFolders.Count; i++)+ {+ var folder = fallbackFolders[i];+ if (!string.IsNullOrEmpty(Parser.ParseMangaSpecial(folder))) continue;++ var parsedVolume = type is LibraryType.Manga ? Parser.ParseVolume(folder) : Parser.ParseComicVolume(folder);+ var parsedChapter = type is LibraryType.Manga ? Parser.ParseChapter(folder) : Parser.ParseComicChapter(folder);++ if (!parsedVolume.Equals(Parser.DefaultVolume) || !parsedChapter.Equals(Parser.DefaultChapter))+ {+ if ((ret.Volumes.Equals(Parser.DefaultVolume) || string.IsNullOrEmpty(ret.Volumes)) && !parsedVolume.Equals(Parser.DefaultVolume))+ {+ ret.Volumes = parsedVolume;+ }+ if ((ret.Chapters.Equals(Parser.DefaultChapter) || string.IsNullOrEmpty(ret.Chapters)) && !parsedChapter.Equals(Parser.DefaultChapter))+ {+ ret.Chapters = parsedChapter;+ }+ }++ var series = Parser.ParseSeries(folder);++ if ((string.IsNullOrEmpty(series) && i == fallbackFolders.Count - 1))+ {+ ret.Series = Parser.CleanTitle(folder, type is LibraryType.Comic);+ break;+ }++ if (!string.IsNullOrEmpty(series))+ {+ ret.Series = series;+ break;+ }+ }+ }+}diff --git a/API/Parser/Parser.cs b/API/Parser/Parser.csindex 02dc6894c..c17290c5b 100644--- a/API/Parser/Parser.cs+++ b/API/Parser/Parser.cs@@ -28,7 +28,8 @@ namespace API.Parser/// Matches against font-family css syntax. Does not match if url import has data: starting, as that is binary data/// </summary>/// <remarks>See here for some examples https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face</remarks>- public static readonly Regex FontSrcUrlRegex = new Regex(@"(?<Start>(src:\s?)?url\((?!data:).(?!data:))" + "(?<Filename>(?!data:)[^\"']*)" + @"(?<End>.{1}\))",+ public static readonly Regex FontSrcUrlRegex = new Regex(@"(?<Start>(?:src:\s?)?(?:url|local)\((?!data:)" + "(?:[\"']?)" + @"(?!data:))"+ + "(?<Filename>(?!data:)[^\"']+?)" + "(?<End>[\"']?" + @"\);?)",MatchOptions, RegexTimeout);/// <summary>/// https://developer.mozilla.org/en-US/docs/Web/CSS/@import@@ -48,11 +49,13 @@ namespace API.ParserMatchOptions, RegexTimeout);private static readonly Regex ArchiveFileRegex = new Regex(ArchiveFileExtensions,MatchOptions, RegexTimeout);+ private static readonly Regex ComicInfoArchiveRegex = new Regex(@"\.cbz|\.cbr|\.cb7|\.cbt",+ MatchOptions, RegexTimeout);private static readonly Regex XmlRegex = new Regex(XmlRegexExtensions,MatchOptions, RegexTimeout);private static readonly Regex BookFileRegex = new Regex(BookFileExtensions,MatchOptions, RegexTimeout);- private static readonly Regex CoverImageRegex = new Regex(@"(?<![[a-z]\d])(?:!?)(cover|folder)(?![\w\d])",+ private static readonly Regex CoverImageRegex = new Regex(@"(?<![[a-z]\d])(?:!?)((?<!back)cover|folder)(?![\w\d])",MatchOptions, RegexTimeout);private static readonly Regex NormalizeRegex = new Regex(@"[^a-zA-Z0-9\+]",@@ -164,7 +167,7 @@ namespace API.ParserMatchOptions, RegexTimeout),// Hinowa ga CRUSH! 018 (2019) (Digital) (LuCaZ).cbznew Regex(- @"(?<Series>.*) (?<Chapter>\d+) (?:\(\d{4}\)) ",+ @"(?<Series>.*)\s+(?<Chapter>\d+)\s+(?:\(\d{4}\))\s",MatchOptions, RegexTimeout),// Goblin Slayer - Brand New Day 006.5 (2019) (Digital) (danke-Empire)new Regex(@@ -207,7 +210,6 @@ namespace API.Parsernew Regex(@"^(?!Vol\.?)(?<Series>.*)( |_|-)(?<!-)(episode|chapter|(ch\.?) ?)\d+-?\d*",MatchOptions, RegexTimeout),-// Baketeriya ch01-05.zipnew Regex(@"^(?!Vol)(?<Series>.*)ch\d+-?\d?",@@ -236,9 +238,13 @@ namespace API.Parserprivate static readonly Regex[] ComicSeriesRegex = new[]{+ // Tintin - T22 Vol 714 pour Sydney+ new Regex(+ @"(?<Series>.+?)\s?(\b|_|-)\s?((vol|tome|t)\.?)(?<Volume>\d+(-\d+)?)",+ MatchOptions, RegexTimeout),// Invincible Vol 01 Family matters (2005) (Digital)new Regex(- @"(?<Series>.*)(\b|_)(vol\.?)( |_)(?<Volume>\d+(-\d+)?)",+ @"(?<Series>.+?)(\b|_)((vol|tome|t)\.?)(\s|_)(?<Volume>\d+(-\d+)?)",MatchOptions, RegexTimeout),// Batman Beyond 2.0 001 (2013)new Regex(@@ -256,9 +262,9 @@ namespace API.Parsernew Regex(@"(?<Series>.*(\d{4})?)( |_)(?:\((?<Volume>\d+) of \d+)",MatchOptions, RegexTimeout),- // Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus)+ // Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus), Aldebaran-Antares-t6new Regex(- @"^(?<Series>.+?)(?: |_)v\d+",+ @"^(?<Series>.+?)(?: |_|-)(v|t)\d+",MatchOptions, RegexTimeout),// Amazing Man Comics chapter 25new Regex(@@ -306,11 +312,11 @@ namespace API.Parser{// Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus)new Regex(- @"^(?<Series>.*)(?: |_)v(?<Volume>\d+)",+ @"^(?<Series>.*)(?: |_)(t|v)(?<Volume>\d+)",MatchOptions, RegexTimeout),// Batgirl Vol.2000 #57 (December, 2004)new Regex(- @"^(?<Series>.+?)(?:\s|_)vol\.?\s?(?<Volume>\d+)",+ @"^(?<Series>.+?)(?:\s|_)(v|vol|tome|t)\.?(\s|_)?(?<Volume>\d+)",MatchOptions, RegexTimeout),};@@ -407,7 +413,7 @@ namespace API.ParserMatchOptions, RegexTimeout),// Hinowa ga CRUSH! 018 (2019) (Digital) (LuCaZ).cbz, Hinowa ga CRUSH! 018.5 (2019) (Digital) (LuCaZ).cbznew Regex(- @"^(?!Vol)(?<Series>.+?)(?<!Vol)\.?\s(?<Chapter>\d+(?:.\d+|-\d+)?)(?:\s\(\d{4}\))?(\b|_|-)",+ @"^(?!Vol)(?<Series>.+?)(?<!Vol)(?<!Vol.)\s(\d\s)?(?<Chapter>\d+(?:\.\d+|-\d+)?)(?:\s\(\d{4}\))?(\b|_|-)",MatchOptions, RegexTimeout),// Tower Of God S01 014 (CBT) (digital).cbznew Regex(@@ -470,7 +476,7 @@ namespace API.Parser{// All Keywords, does not account for checking if contains volume/chapter identification. Parser.Parse() will handle.new Regex(- @"(?<Special>Specials?|OneShot|One\-Shot|Omake|Extra( Chapter)?|Art Collection|Side( |_)Stories|Bonus)",+ @"(?<Special>Specials?|OneShot|One\-Shot|Omake|Extra(?:(\sChapter)?[^\S])|Art Collection|Side( |_)Stories|Bonus)",MatchOptions, RegexTimeout),};@@ -478,7 +484,15 @@ namespace API.Parser{// All Keywords, does not account for checking if contains volume/chapter identification. Parser.Parse() will handle.new Regex(- @"(?<Special>Specials?|OneShot|One\-Shot|Extra( Chapter)?|Book \d.+?|Compendium \d.+?|Omnibus \d.+?|[_\s\-]TPB[_\s\-]|FCBD \d.+?|Absolute \d.+?|Preview \d.+?|Art Collection|Side( |_)Stories|Bonus)",+ @"(?<Special>Specials?|OneShot|One\-Shot|Extra(?:(\sChapter)?[^\S])|Book \d.+?|Compendium \d.+?|Omnibus \d.+?|[_\s\-]TPB[_\s\-]|FCBD \d.+?|Absolute \d.+?|Preview \d.+?|Art Collection|Side(\s|_)Stories|Bonus|Hors Série|(\W|_|-)HS(\W|_|-)|(\W|_|-)THS(\W|_|-))",+ MatchOptions, RegexTimeout),+ };++ private static readonly Regex[] EuropeanComicRegex =+ {+ // All Keywords, does not account for checking if contains volume/chapter identification. Parser.Parse() will handle.+ new Regex(+ @"(?<Special>Bd(\s|_|-)Fr)",MatchOptions, RegexTimeout),};@@ -488,147 +502,10 @@ namespace API.ParserMatchOptions, RegexTimeout);-- /// <summary>- /// Parses information out of a file path. Will fallback to using directory name if Series couldn't be parsed- /// from filename.- /// </summary>- /// <param name="filePath"></param>- /// <param name="rootPath">Root folder</param>- /// <param name="type">Defaults to Manga. Allows different Regex to be used for parsing.</param>- /// <returns><see cref="ParserInfo"/> or null if Series was empty</returns>- public static ParserInfo Parse(string filePath, string rootPath, LibraryType type = LibraryType.Manga)- {- var fileName = Path.GetFileNameWithoutExtension(filePath);- ParserInfo ret;-- if (IsEpub(filePath))- {- ret = new ParserInfo()- {- Chapters = ParseChapter(fileName) ?? ParseComicChapter(fileName),- Series = ParseSeries(fileName) ?? ParseComicSeries(fileName),- Volumes = ParseVolume(fileName) ?? ParseComicVolume(fileName),- Filename = Path.GetFileName(filePath),- Format = ParseFormat(filePath),- FullFilePath = filePath- };- }- else- {- ret = new ParserInfo()- {- Chapters = type == LibraryType.Manga ? ParseChapter(fileName) : ParseComicChapter(fileName),- Series = type == LibraryType.Manga ? ParseSeries(fileName) : ParseComicSeries(fileName),- Volumes = type == LibraryType.Manga ? ParseVolume(fileName) : ParseComicVolume(fileName),- Filename = Path.GetFileName(filePath),- Format = ParseFormat(filePath),- Title = Path.GetFileNameWithoutExtension(fileName),- FullFilePath = filePath- };- }-- if (IsImage(filePath) && IsCoverImage(filePath)) return null;-- if (IsImage(filePath))- {- // Reset Chapters, Volumes, and Series as images are not good to parse information out of. Better to use folders.- ret.Volumes = DefaultVolume;- ret.Chapters = DefaultChapter;- ret.Series = string.Empty;- }-- if (ret.Series == string.Empty || IsImage(filePath))- {- // Try to parse information out of each folder all the way to rootPath- ParseFromFallbackFolders(filePath, rootPath, type, ref ret);- }-- var edition = ParseEdition(fileName);- if (!string.IsNullOrEmpty(edition))- {- ret.Series = CleanTitle(ret.Series.Replace(edition, ""), type is LibraryType.Comic);- ret.Edition = edition;- }-- var isSpecial = type == LibraryType.Comic ? ParseComicSpecial(fileName) : ParseMangaSpecial(fileName);- // We must ensure that we can only parse a special out. As some files will have v20 c171-180+Omake and that- // could cause a problem as Omake is a special term, but there is valid volume/chapter information.- if (ret.Chapters == DefaultChapter && ret.Volumes == DefaultVolume && !string.IsNullOrEmpty(isSpecial))- {- ret.IsSpecial = true;- ParseFromFallbackFolders(filePath, rootPath, type, ref ret);- }-- // If we are a special with marker, we need to ensure we use the correct series name. we can do this by falling back to Folder name- if (HasSpecialMarker(fileName))- {- ret.IsSpecial = true;- ret.Chapters = DefaultChapter;- ret.Volumes = DefaultVolume;-- ParseFromFallbackFolders(filePath, rootPath, type, ref ret);- }-- if (string.IsNullOrEmpty(ret.Series))- {- ret.Series = CleanTitle(fileName, type is LibraryType.Comic);- }-- // Pdfs may have .pdf in the series name, remove that- if (IsPdf(filePath) && ret.Series.ToLower().EndsWith(".pdf"))- {- ret.Series = ret.Series.Substring(0, ret.Series.Length - ".pdf".Length);- }-- return ret.Series == string.Empty ? null : ret;- }-- /// <summary>- ///- /// </summary>- /// <param name="filePath"></param>- /// <param name="rootPath"></param>- /// <param name="type"></param>- /// <param name="ret">Expects a non-null ParserInfo which this method will populate</param>- public static void ParseFromFallbackFolders(string filePath, string rootPath, LibraryType type, ref ParserInfo ret)- {- var fallbackFolders = DirectoryService.GetFoldersTillRoot(rootPath, filePath).ToList();- for (var i = 0; i < fallbackFolders.Count; i++)- {- var folder = fallbackFolders[i];- if (!string.IsNullOrEmpty(ParseMangaSpecial(folder))) continue;-- var parsedVolume = type is LibraryType.Manga ? ParseVolume(folder) : ParseComicVolume(folder);- var parsedChapter = type is LibraryType.Manga ? ParseChapter(folder) : ParseComicChapter(folder);-- if (!parsedVolume.Equals(DefaultVolume) || !parsedChapter.Equals(DefaultChapter))- {- if ((ret.Volumes.Equals(DefaultVolume) || string.IsNullOrEmpty(ret.Volumes)) && !parsedVolume.Equals(DefaultVolume))- {- ret.Volumes = parsedVolume;- }- if ((ret.Chapters.Equals(DefaultChapter) || string.IsNullOrEmpty(ret.Chapters)) && !parsedChapter.Equals(DefaultChapter))- {- ret.Chapters = parsedChapter;- }- }-- var series = ParseSeries(folder);-- if ((string.IsNullOrEmpty(series) && i == fallbackFolders.Count - 1))- {- ret.Series = CleanTitle(folder, type is LibraryType.Comic);- break;- }-- if (!string.IsNullOrEmpty(series))- {- ret.Series = series;- break;- }- }- }+ private static readonly Regex EmptySpaceRegex = new Regex(+ @"(?!=.+)(\s{2,})(?!=.+)",+ MatchOptions, RegexTimeout+ );public static MangaFormat ParseFormat(string filePath){@@ -862,7 +739,6 @@ namespace API.Parser}}- // TODO: Since we have loops like this, think about using a methodforeach (var regex in MangaEditionRegex){var matches = regex.Matches(title);@@ -895,6 +771,23 @@ namespace API.Parserreturn title;}+ private static string RemoveEuropeanTags(string title)+ {+ foreach (var regex in EuropeanComicRegex)+ {+ var matches = regex.Matches(title);+ foreach (Match match in matches)+ {+ if (match.Success)+ {+ title = title.Replace(match.Value, string.Empty).Trim();+ }+ }+ }++ return title;+ }+private static string RemoveComicSpecialTags(string title){foreach (var regex in ComicSpecialRegex)@@ -931,6 +824,16 @@ namespace API.Parsertitle = isComic ? RemoveComicSpecialTags(title) : RemoveMangaSpecialTags(title);+ if (isComic)+ {+ title = RemoveComicSpecialTags(title);+ title = RemoveEuropeanTags(title);+ }+ else+ {+ title = RemoveMangaSpecialTags(title);+ }+title = title.Replace("_", " ").Trim();if (title.EndsWith("-") || title.EndsWith(","))@@ -938,6 +841,13 @@ namespace API.Parsertitle = title.Substring(0, title.Length - 1);}+ if (title.StartsWith("-") || title.StartsWith(","))+ {+ title = title.Substring(1);+ }++ title = EmptySpaceRegex.Replace(title, " ");+return title.Trim();}@@ -997,15 +907,18 @@ namespace API.Parser{return ArchiveFileRegex.IsMatch(Path.GetExtension(filePath));}+ public static bool IsComicInfoExtension(string filePath)+ {+ return ComicInfoArchiveRegex.IsMatch(Path.GetExtension(filePath));+ }public static bool IsBook(string filePath){return BookFileRegex.IsMatch(Path.GetExtension(filePath));}- public static bool IsImage(string filePath, bool suppressExtraChecks = false)+ public static bool IsImage(string filePath){- if (filePath.StartsWith(".") || (!suppressExtraChecks && filePath.StartsWith("!"))) return false;- return ImageRegex.IsMatch(Path.GetExtension(filePath));+ return !filePath.StartsWith(".") && ImageRegex.IsMatch(Path.GetExtension(filePath));}public static bool IsXml(string filePath)@@ -1040,16 +953,17 @@ namespace API.Parser/// <summary>/// Tests whether the file is a cover image such that: contains "cover", is named "folder", and is an image/// </summary>- /// <param name="name"></param>+ /// <remarks>If the path has "backcover" in it, it will be ignored</remarks>+ /// <param name="filename">Filename with extension</param>/// <returns></returns>- public static bool IsCoverImage(string name)+ public static bool IsCoverImage(string filename){- return IsImage(name, true) && (CoverImageRegex.IsMatch(name));+ return IsImage(filename) && CoverImageRegex.IsMatch(filename);}public static bool HasBlacklistedFolderInPath(string path){- return path.Contains("__MACOSX");+ return path.Contains("__MACOSX") || path.StartsWith("@Recently-Snapshot") || path.StartsWith("._");}@@ -1062,5 +976,28 @@ namespace API.Parser{return Path.GetExtension(filePath).ToLower() == ".pdf";}++ /// <summary>+ /// Cleans an author's name+ /// </summary>+ /// <remarks>If the author is Last, First, this will not reverse</remarks>+ /// <param name="author"></param>+ /// <returns></returns>+ public static string CleanAuthor(string author)+ {+ if (string.IsNullOrEmpty(author)) return string.Empty;+ return author.Trim();+ }++ /// <summary>+ /// Normalizes the slashes in a path to be <see cref="Path.AltDirectorySeparatorChar"/>+ /// </summary>+ /// <example>/manga/1\1 -> /manga/1/1</example>+ /// <param name="path"></param>+ /// <returns></returns>+ public static string NormalizePath(string path)+ {+ return path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);+ }}}diff --git a/API/Parser/ParserInfo.cs b/API/Parser/ParserInfo.csindex a2c4a9c51..cb55bd18e 100644--- a/API/Parser/ParserInfo.cs+++ b/API/Parser/ParserInfo.cs@@ -1,4 +1,5 @@-using API.Entities.Enums;+using API.Data.Metadata;+using API.Entities.Enums;namespace API.Parser{@@ -15,7 +16,11 @@ namespace API.Parser/// <summary>/// Represents the parsed series from the file or folder/// </summary>- public string Series { get; set; } = "";+ public string Series { get; set; } = string.Empty;+ /// <summary>+ /// This can be filled in from ComicInfo.xml/Epub during scanning. Will update the SortName field on <see cref="Entities.Series"/>+ /// </summary>+ public string SeriesSort { get; set; } = string.Empty;/// <summary>/// Represents the parsed volumes from a file. By default, will be 0 which means that nothing could be parsed./// If Volumes is 0 and Chapters is 0, the file is a special. If Chapters is non-zero, then no volume could be parsed.@@ -43,6 +48,7 @@ namespace API.Parser/// <summary>/// This can potentially story things like "Omnibus, Color, Full Contact Edition, Extra, Final, etc"/// </summary>+ /// <remarks>Not Used in Database</remarks>public string Edition { get; set; } = "";/// <summary>@@ -55,16 +61,22 @@ namespace API.Parser/// <remarks>Manga does not use this field</remarks>/// </summary>public string Title { get; set; } = string.Empty;-+/// <summary>/// If the ParserInfo has the IsSpecial tag or both volumes and chapters are default aka 0/// </summary>/// <returns></returns>public bool IsSpecialInfo()- {+ {return (IsSpecial || (Volumes == "0" && Chapters == "0"));}+ /// <summary>+ /// This will contain any EXTRA comicInfo information parsed from the epub or archive. If there is an archive with comicInfo.xml AND it contains+ /// series, volume information, that will override what we parsed.+ /// </summary>+ public ComicInfo ComicInfo { get; set; }+/// <summary>/// Merges non empty/null properties from info2 into this entity./// </summary>@@ -80,4 +92,4 @@ namespace API.ParserIsSpecial = IsSpecial || info2.IsSpecial;}}-}\ No newline at end of file+}diff --git a/API/Program.cs b/API/Program.csindex f35bf8bd3..4ed8ce56a 100644--- a/API/Program.cs+++ b/API/Program.cs@@ -1,12 +1,14 @@using System;-using System.Collections.Generic;using System.IO;+using System.IO.Abstractions;using System.Linq;using System.Security.Cryptography;using System.Threading.Tasks;using API.Data;using API.Entities;+using API.Entities.Enums;using API.Services;+using API.Services.Tasks;using Kavita.Common;using Kavita.Common.EnvironmentInfo;using Microsoft.AspNetCore.Hosting;@@ -33,7 +35,9 @@ namespace APIConsole.OutputEncoding = System.Text.Encoding.UTF8;var isDocker = new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker;- MigrateConfigFiles.Migrate(isDocker);++ var directoryService = new DirectoryService(null, new FileSystem());+ MigrateConfigFiles.Migrate(isDocker, directoryService);// Before anything, check if JWT has been generated properly or if user still has defaultif (!Configuration.CheckIfJwtTokenSet() &&@@ -41,7 +45,7 @@ namespace API{Console.WriteLine("Generating JWT TokenKey for encrypting user sessions...");var rBytes = new byte[128];- using (var crypto = new RNGCryptoServiceProvider()) crypto.GetBytes(rBytes);+ RandomNumberGenerator.Create().GetBytes(rBytes);Configuration.JwtToken = Convert.ToBase64String(rBytes).Replace("/", string.Empty);}@@ -52,47 +56,33 @@ namespace APItry{+ var logger = services.GetRequiredService<ILogger<Program>>();var context = services.GetRequiredService<DataContext>();- var roleManager = services.GetRequiredService<RoleManager<AppRole>>();-- if (isDocker && new FileInfo("data/appsettings.json").Exists)+ var pendingMigrations = await context.Database.GetPendingMigrationsAsync();+ if (pendingMigrations.Any()){- var logger = services.GetRequiredService<ILogger<Startup>>();- logger.LogCritical("WARNING! Mount point is incorrect, nothing here will persist. Please change your container mount from /kavita/data to /kavita/config");- return;+ logger.LogInformation("Performing backup as migrations are needed. Backup will be kavita.db in temp folder");+ directoryService.CopyFileToDirectory(directoryService.FileSystem.Path.Join(directoryService.ConfigDirectory, "kavita.db"), directoryService.TempDirectory);}+ await context.Database.MigrateAsync();+ var roleManager = services.GetRequiredService<RoleManager<AppRole>>();- var requiresCoverImageMigration = !Directory.Exists(DirectoryService.CoverImageDirectory);- try- {- // If this is a new install, tables wont exist yet- if (requiresCoverImageMigration)- {- MigrateCoverImages.ExtractToImages(context);- }- }- catch (Exception)- {- requiresCoverImageMigration = false;- }+ await Seed.SeedRoles(roleManager);+ await Seed.SeedSettings(context, directoryService);+ await Seed.SeedUserApiKeys(context);- // Apply all migrations on startup- await context.Database.MigrateAsync();- if (requiresCoverImageMigration)+ if (isDocker && new FileInfo("data/appsettings.json").Exists){- await MigrateCoverImages.UpdateDatabaseWithImages(context);+ logger.LogCritical("WARNING! Mount point is incorrect, nothing here will persist. Please change your container mount from /kavita/data to /kavita/config");+ return;}-- await Seed.SeedRoles(roleManager);- await Seed.SeedSettings(context);- await Seed.SeedUserApiKeys(context);}catch (Exception ex){var logger = services.GetRequiredService<ILogger<Program>>();- logger.LogError(ex, "An error occurred during migration");+ logger.LogCritical(ex, "An error occurred during migration");}await host.RunAsync();diff --git a/API/Services/AccountService.cs b/API/Services/AccountService.csindex 0cc720bb6..0591770ec 100644--- a/API/Services/AccountService.cs+++ b/API/Services/AccountService.cs@@ -3,12 +3,16 @@ using System.Linq;using System.Threading.Tasks;using API.Entities;using API.Errors;-using API.Interfaces.Services;using Microsoft.AspNetCore.Identity;using Microsoft.Extensions.Logging;namespace API.Services{+ public interface IAccountService+ {+ Task<IEnumerable<ApiException>> ChangeUserPassword(AppUser user, string newPassword);+ }+public class AccountService : IAccountService{private readonly UserManager<AppUser> _userManager;diff --git a/API/Services/ArchiveService.cs b/API/Services/ArchiveService.csindex 2eb59a9fc..11042ed34 100644--- a/API/Services/ArchiveService.cs+++ b/API/Services/ArchiveService.cs@@ -10,7 +10,6 @@ using API.Archive;using API.Comparators;using API.Data.Metadata;using API.Extensions;-using API.Interfaces.Services;using API.Services.Tasks;using Kavita.Common;using Microsoft.Extensions.Logging;@@ -19,6 +18,19 @@ using SharpCompress.Common;namespace API.Services{+ public interface IArchiveService+ {+ void ExtractArchive(string archivePath, string extractPath);+ int GetNumberOfPagesFromArchive(string archivePath);+ string GetCoverImage(string archivePath, string fileName, string outputDirectory);+ bool IsValidArchive(string archivePath);+ ComicInfo GetComicInfo(string archivePath);+ ArchiveLibrary CanOpen(string archivePath);+ bool ArchiveNeedsFlattening(ZipArchive archive);+ Task<Tuple<byte[], string>> CreateZipForDownload(IEnumerable<string> files, string tempFolder);+ string FindCoverImageFilename(string archivePath, IList<string> entryNames);+ }+/// <summary>/// Responsible for manipulating Archive files. Used by <see cref="CacheService"/> and <see cref="ScannerService"/>/// </summary>@@ -27,12 +39,14 @@ namespace API.Services{private readonly ILogger<ArchiveService> _logger;private readonly IDirectoryService _directoryService;+ private readonly IImageService _imageService;private const string ComicInfoFilename = "comicinfo";- public ArchiveService(ILogger<ArchiveService> logger, IDirectoryService directoryService)+ public ArchiveService(ILogger<ArchiveService> logger, IDirectoryService directoryService, IImageService imageService){_logger = logger;_directoryService = directoryService;+ _imageService = imageService;}/// <summary>@@ -42,7 +56,10 @@ namespace API.Services/// <returns></returns>public virtual ArchiveLibrary CanOpen(string archivePath){- if (!(File.Exists(archivePath) && Parser.Parser.IsArchive(archivePath) || Parser.Parser.IsEpub(archivePath))) return ArchiveLibrary.NotSupported;+ if (string.IsNullOrEmpty(archivePath) || !(File.Exists(archivePath) && Parser.Parser.IsArchive(archivePath) || Parser.Parser.IsEpub(archivePath))) return ArchiveLibrary.NotSupported;++ var ext = _directoryService.FileSystem.Path.GetExtension(archivePath).ToUpper();+ if (ext.Equals(".CBR") || ext.Equals(".RAR")) return ArchiveLibrary.SharpCompress;try{@@ -108,46 +125,47 @@ namespace API.Services/// </summary>/// <param name="entryFullNames"></param>/// <returns>Entry name of match, null if no match</returns>- public string FindFolderEntry(IEnumerable<string> entryFullNames)+ public static string FindFolderEntry(IEnumerable<string> entryFullNames){var result = entryFullNames- .FirstOrDefault(x => !Path.EndsInDirectorySeparator(x) && !Parser.Parser.HasBlacklistedFolderInPath(x)- && Parser.Parser.IsCoverImage(x)- && !x.StartsWith(Parser.Parser.MacOsMetadataFileStartsWith));+ .OrderByNatural(Path.GetFileNameWithoutExtension)+ .Where(path => !(Path.EndsInDirectorySeparator(path) || Parser.Parser.HasBlacklistedFolderInPath(path) || path.StartsWith(Parser.Parser.MacOsMetadataFileStartsWith)))+ .FirstOrDefault(Parser.Parser.IsCoverImage);return string.IsNullOrEmpty(result) ? null : result;}/// <summary>- /// Returns first entry that is an image and is not in a blacklisted folder path. Uses <see cref="NaturalSortComparer"/> for ordering files+ /// Returns first entry that is an image and is not in a blacklisted folder path. Uses <see cref="OrderByNatural"/> for ordering files/// </summary>/// <param name="entryFullNames"></param>/// <returns>Entry name of match, null if no match</returns>- public static string FirstFileEntry(IEnumerable<string> entryFullNames, string archiveName)+ public static string? FirstFileEntry(IEnumerable<string> entryFullNames, string archiveName){// First check if there are any files that are not in a nested folder before just comparing by filename. This is needed// because NaturalSortComparer does not work with paths and doesn't seem 001.jpg as before chapter 1/001.jpg.- var fullNames = entryFullNames.Where(x =>!Parser.Parser.HasBlacklistedFolderInPath(x)- && Parser.Parser.IsImage(x)- && !x.StartsWith(Parser.Parser.MacOsMetadataFileStartsWith)).ToList();+ var fullNames = entryFullNames+ .OrderByNatural(c => c.GetFullPathWithoutExtension())+ .Where(path => !(Path.EndsInDirectorySeparator(path) || Parser.Parser.HasBlacklistedFolderInPath(path) || path.StartsWith(Parser.Parser.MacOsMetadataFileStartsWith)) && Parser.Parser.IsImage(path))+ .ToList();if (fullNames.Count == 0) return null;var nonNestedFile = fullNames.Where(entry => (Path.GetDirectoryName(entry) ?? string.Empty).Equals(archiveName))- .OrderBy(Path.GetFullPath, new NaturalSortComparer())+ .OrderByNatural(c => c.GetFullPathWithoutExtension()).FirstOrDefault();if (!string.IsNullOrEmpty(nonNestedFile)) return nonNestedFile;// Check the first folder and sort within that to see if we can find a file, else fallback to first file with basic sort.// Get first folder, then sort within that- var firstDirectoryFile = fullNames.OrderBy(Path.GetDirectoryName, new NaturalSortComparer()).FirstOrDefault();+ var firstDirectoryFile = fullNames.OrderByNatural(Path.GetDirectoryName).FirstOrDefault();if (!string.IsNullOrEmpty(firstDirectoryFile)){var firstDirectory = Path.GetDirectoryName(firstDirectoryFile);if (!string.IsNullOrEmpty(firstDirectory)){var firstDirectoryResult = fullNames.Where(f => firstDirectory.Equals(Path.GetDirectoryName(f)))- .OrderBy(Path.GetFileName, new NaturalSortComparer())+ .OrderByNatural(Path.GetFileNameWithoutExtension).FirstOrDefault();if (!string.IsNullOrEmpty(firstDirectoryResult)) return firstDirectoryResult;@@ -155,7 +173,7 @@ namespace API.Services}var result = fullNames- .OrderBy(Path.GetFileName, new NaturalSortComparer())+ .OrderByNatural(Path.GetFileNameWithoutExtension).FirstOrDefault();return string.IsNullOrEmpty(result) ? null : result;@@ -173,7 +191,7 @@ namespace API.Services/// <param name="archivePath"></param>/// <param name="fileName">File name to use based on context of entity.</param>/// <returns></returns>- public string GetCoverImage(string archivePath, string fileName)+ public string GetCoverImage(string archivePath, string fileName, string outputDirectory){if (archivePath == null || !IsValidArchive(archivePath)) return string.Empty;try@@ -184,25 +202,24 @@ namespace API.Servicescase ArchiveLibrary.Default:{using var archive = ZipFile.OpenRead(archivePath);- var entryNames = archive.Entries.Select(e => e.FullName).ToArray();+ var entryNames = archive.Entries.Select(e => e.FullName).ToList();- var entryName = FindFolderEntry(entryNames) ?? FirstFileEntry(entryNames, Path.GetFileName(archivePath));+ var entryName = FindCoverImageFilename(archivePath, entryNames);var entry = archive.Entries.Single(e => e.FullName == entryName);- using var stream = entry.Open();- return CreateThumbnail(archivePath + " - " + entry.FullName, stream, fileName);+ using var stream = entry.Open();+ return _imageService.WriteCoverThumbnail(stream, fileName, outputDirectory);}case ArchiveLibrary.SharpCompress:{using var archive = ArchiveFactory.Open(archivePath);var entryNames = archive.Entries.Where(archiveEntry => !archiveEntry.IsDirectory).Select(e => e.Key).ToList();- var entryName = FindFolderEntry(entryNames) ?? FirstFileEntry(entryNames, Path.GetFileName(archivePath));+ var entryName = FindCoverImageFilename(archivePath, entryNames);var entry = archive.Entries.Single(e => e.Key == entryName);using var stream = entry.OpenEntryStream();-- return CreateThumbnail(archivePath + " - " + entry.Key, stream, fileName);+ return _imageService.WriteCoverThumbnail(stream, fileName, outputDirectory);}case ArchiveLibrary.NotSupported:_logger.LogWarning("[GetCoverImage] This archive cannot be read: {ArchivePath}. Defaulting to no cover image", archivePath);@@ -220,6 +237,18 @@ namespace API.Servicesreturn string.Empty;}+ /// <summary>+ /// Given a list of image paths (assume within an archive), find the filename that corresponds to the cover+ /// </summary>+ /// <param name="archivePath"></param>+ /// <param name="entryNames"></param>+ /// <returns></returns>+ public string FindCoverImageFilename(string archivePath, IList<string> entryNames)+ {+ var entryName = FindFolderEntry(entryNames) ?? FirstFileEntry(entryNames, Path.GetFileName(archivePath));+ return entryName;+ }+/// <summary>/// Given an archive stream, will assess whether directory needs to be flattened so that the extracted archive files are directly/// under extract path and not nested in subfolders. See <see cref="DirectoryInfoExtensions"/> Flatten method.@@ -235,18 +264,25 @@ namespace API.Services}// TODO: Refactor CreateZipForDownload to return the temp file so we can stream it from temp+ /// <summary>+ ///+ /// </summary>+ /// <param name="files"></param>+ /// <param name="tempFolder">Temp folder name to use for preparing the files. Will be created and deleted</param>+ /// <returns></returns>+ /// <exception cref="KavitaException"></exception>public async Task<Tuple<byte[], string>> CreateZipForDownload(IEnumerable<string> files, string tempFolder){var dateString = DateTime.Now.ToShortDateString().Replace("/", "_");- var tempLocation = Path.Join(DirectoryService.TempDirectory, $"{tempFolder}_{dateString}");- DirectoryService.ExistOrCreate(tempLocation);+ var tempLocation = Path.Join(_directoryService.TempDirectory, $"{tempFolder}_{dateString}");+ _directoryService.ExistOrCreate(tempLocation);if (!_directoryService.CopyFilesToDirectory(files, tempLocation)){throw new KavitaException("Unable to copy files to temp directory archive download.");}- var zipPath = Path.Join(DirectoryService.TempDirectory, $"kavita_{tempFolder}_{dateString}.zip");+ var zipPath = Path.Join(_directoryService.TempDirectory, $"kavita_{tempFolder}_{dateString}.zip");try{ZipFile.CreateFromDirectory(tempLocation, zipPath);@@ -260,25 +296,12 @@ namespace API.Servicesvar fileBytes = await _directoryService.ReadFileAsync(zipPath);- DirectoryService.ClearAndDeleteDirectory(tempLocation);+ _directoryService.ClearAndDeleteDirectory(tempLocation); // NOTE: For sending back just zip, just schedule this to be called after the file is returned or let next temp storage cleanup take care of it(new FileInfo(zipPath)).Delete();return Tuple.Create(fileBytes, zipPath);}- private string CreateThumbnail(string entryName, Stream stream, string fileName)- {- try- {- return ImageService.WriteCoverThumbnail(stream, fileName);- }- catch (Exception ex)- {- _logger.LogWarning(ex, "[GetCoverImage] There was an error and prevented thumbnail generation on {EntryName}. Defaulting to no cover image", entryName);- }-- return string.Empty;- }/// <summary>/// Test if the archive path exists and an archive@@ -322,7 +345,12 @@ namespace API.Servicesreturn null;}- public ComicInfo GetComicInfo(string archivePath)+ /// <summary>+ /// This can be null if nothing is found or any errors occur during access+ /// </summary>+ /// <param name="archivePath"></param>+ /// <returns></returns>+ public ComicInfo? GetComicInfo(string archivePath){if (!IsValidArchive(archivePath)) return null;@@ -336,7 +364,7 @@ namespace API.Servicescase ArchiveLibrary.Default:{using var archive = ZipFile.OpenRead(archivePath);- var entry = archive.Entries.SingleOrDefault(x =>+ var entry = archive.Entries.FirstOrDefault(x =>!Parser.Parser.HasBlacklistedFolderInPath(x.FullName)&& Path.GetFileNameWithoutExtension(x.Name)?.ToLower() == ComicInfoFilename&& !Path.GetFileNameWithoutExtension(x.Name)@@ -346,7 +374,9 @@ namespace API.Services{using var stream = entry.Open();var serializer = new XmlSerializer(typeof(ComicInfo));- return (ComicInfo) serializer.Deserialize(stream);+ var info = (ComicInfo) serializer.Deserialize(stream);+ ComicInfo.CleanComicInfo(info);+ return info;}break;@@ -354,7 +384,7 @@ namespace API.Servicescase ArchiveLibrary.SharpCompress:{using var archive = ArchiveFactory.Open(archivePath);- return FindComicInfoXml(archive.Entries.Where(entry => !entry.IsDirectory+ var info = FindComicInfoXml(archive.Entries.Where(entry => !entry.IsDirectory&& !Parser.Parser.HasBlacklistedFolderInPath(Path.GetDirectoryName(@@ -365,6 +395,9 @@ namespace API.Services.Parser.MacOsMetadataFileStartsWith)&& Parser.Parser.IsXml(entry.Key)));+ ComicInfo.CleanComicInfo(info);++ return info;}case ArchiveLibrary.NotSupported:_logger.LogWarning("[GetComicInfo] This archive cannot be read: {ArchivePath}", archivePath);@@ -385,9 +418,9 @@ namespace API.Services}- private static void ExtractArchiveEntities(IEnumerable<IArchiveEntry> entries, string extractPath)+ private void ExtractArchiveEntities(IEnumerable<IArchiveEntry> entries, string extractPath){- DirectoryService.ExistOrCreate(extractPath);+ _directoryService.ExistOrCreate(extractPath);foreach (var entry in entries){entry.WriteToDirectory(extractPath, new ExtractionOptions()@@ -400,7 +433,7 @@ namespace API.Servicesprivate void ExtractArchiveEntries(ZipArchive archive, string extractPath){- // NOTE: In cases where we try to extract, but there are InvalidPathChars, we need to inform the user+ // TODO: In cases where we try to extract, but there are InvalidPathChars, we need to inform the user (throw exception, let middleware inform user)var needsFlattening = ArchiveNeedsFlattening(archive);if (!archive.HasFiles() && !needsFlattening) return;@@ -408,7 +441,7 @@ namespace API.Servicesif (!needsFlattening) return;_logger.LogDebug("Extracted archive is nested in root folder, flattening...");- new DirectoryInfo(extractPath).Flatten();+ _directoryService.Flatten(extractPath);}/// <summary>@@ -447,10 +480,10 @@ namespace API.Servicesbreak;}case ArchiveLibrary.NotSupported:- _logger.LogWarning("[ExtractArchive] This archive cannot be read: {ArchivePath}. Defaulting to 0 pages", archivePath);+ _logger.LogWarning("[ExtractArchive] This archive cannot be read: {ArchivePath}", archivePath);return;default:- _logger.LogWarning("[ExtractArchive] There was an exception when reading archive stream: {ArchivePath}. Defaulting to 0 pages", archivePath);+ _logger.LogWarning("[ExtractArchive] There was an exception when reading archive stream: {ArchivePath}", archivePath);return;}diff --git a/API/Services/BookService.cs b/API/Services/BookService.csindex 137f21dca..871b7dd32 100644--- a/API/Services/BookService.cs+++ b/API/Services/BookService.cs@@ -1,17 +1,13 @@using System;using System.Collections.Generic;-using System.Drawing;-using System.Drawing.Imaging;using System.IO;using System.Linq;-using System.Runtime.InteropServices;using System.Text;using System.Text.RegularExpressions;using System.Threading.Tasks;using System.Web;using API.Data.Metadata;using API.Entities.Enums;-using API.Interfaces.Services;using API.Parser;using Docnet.Core;using Docnet.Core.Converters;@@ -21,21 +17,54 @@ using ExCSS;using HtmlAgilityPack;using Microsoft.Extensions.Logging;using Microsoft.IO;+using SixLabors.ImageSharp;+using SixLabors.ImageSharp.PixelFormats;using VersOne.Epub;+using Image = SixLabors.ImageSharp.Image;namespace API.Services{+ public interface IBookService+ {+ int GetNumberOfPages(string filePath);+ string GetCoverImage(string fileFilePath, string fileName, string outputDirectory);+ Task<Dictionary<string, int>> CreateKeyToPageMappingAsync(EpubBookRef book);++ /// <summary>+ /// Scopes styles to .reading-section and replaces img src to the passed apiBase+ /// </summary>+ /// <param name="stylesheetHtml"></param>+ /// <param name="apiBase"></param>+ /// <param name="filename">If the stylesheetHtml contains Import statements, when scoping the filename, scope needs to be wrt filepath.</param>+ /// <param name="book">Book Reference, needed for if you expect Import statements</param>+ /// <returns></returns>+ Task<string> ScopeStyles(string stylesheetHtml, string apiBase, string filename, EpubBookRef book);+ ComicInfo GetComicInfo(string filePath);+ ParserInfo ParseInfo(string filePath);+ /// <summary>+ /// Extracts a PDF file's pages as images to an target directory+ /// </summary>+ /// <param name="fileFilePath"></param>+ /// <param name="targetDirectory">Where the files will be extracted to. If doesn't exist, will be created.</param>+ void ExtractPdfImages(string fileFilePath, string targetDirectory);++ Task<string> ScopePage(HtmlDocument doc, EpubBookRef book, string apiBase, HtmlNode body, Dictionary<string, int> mappings, int page);+ }+public class BookService : IBookService{private readonly ILogger<BookService> _logger;+ private readonly IDirectoryService _directoryService;+ private readonly IImageService _imageService;private readonly StylesheetParser _cssParser = new ();private static readonly RecyclableMemoryStreamManager StreamManager = new ();private const string CssScopeClass = ".book-content";- public BookService(ILogger<BookService> logger)+ public BookService(ILogger<BookService> logger, IDirectoryService directoryService, IImageService imageService){_logger = logger;-+ _directoryService = directoryService;+ _imageService = imageService;}private static bool HasClickableHrefPart(HtmlNode anchor)@@ -141,13 +170,10 @@ namespace API.Services}stylesheetHtml = stylesheetHtml.Insert(0, importBuilder.ToString());- var importMatches = Parser.Parser.CssImportUrlRegex.Matches(stylesheetHtml);- foreach (Match match in importMatches)- {- if (!match.Success) continue;- var importFile = match.Groups["Filename"].Value;- stylesheetHtml = stylesheetHtml.Replace(importFile, apiBase + prepend + importFile);- }++ EscapeCSSImportReferences(ref stylesheetHtml, apiBase, prepend);++ EscapeFontFamilyReferences(ref stylesheetHtml, apiBase, prepend);// Check if there are any background images and rewrite those urlsEscapeCssImageReferences(ref stylesheetHtml, apiBase, book);@@ -174,6 +200,26 @@ namespace API.Servicesreturn RemoveWhiteSpaceFromStylesheets(stylesheet.ToCss());}+ private static void EscapeCSSImportReferences(ref string stylesheetHtml, string apiBase, string prepend)+ {+ foreach (Match match in Parser.Parser.CssImportUrlRegex.Matches(stylesheetHtml))+ {+ if (!match.Success) continue;+ var importFile = match.Groups["Filename"].Value;+ stylesheetHtml = stylesheetHtml.Replace(importFile, apiBase + prepend + importFile);+ }+ }++ private static void EscapeFontFamilyReferences(ref string stylesheetHtml, string apiBase, string prepend)+ {+ foreach (Match match in Parser.Parser.FontSrcUrlRegex.Matches(stylesheetHtml))+ {+ if (!match.Success) continue;+ var importFile = match.Groups["Filename"].Value;+ stylesheetHtml = stylesheetHtml.Replace(importFile, apiBase + prepend + importFile);+ }+ }+private static void EscapeCssImageReferences(ref string stylesheetHtml, string apiBase, EpubBookRef book){var matches = Parser.Parser.CssImageUrlRegex.Matches(stylesheetHtml);@@ -189,6 +235,139 @@ namespace API.Services}}+ private static void ScopeImages(HtmlDocument doc, EpubBookRef book, string apiBase)+ {+ var images = doc.DocumentNode.SelectNodes("//img");+ if (images != null)+ {+ foreach (var image in images)+ {+ if (image.Name != "img") continue;++ // Need to do for xlink:href+ if (image.Attributes["src"] != null)+ {+ var imageFile = image.Attributes["src"].Value;+ if (!book.Content.Images.ContainsKey(imageFile))+ {+ // TODO: Refactor the Key code to a method to allow the hacks to be tested+ var correctedKey = book.Content.Images.Keys.SingleOrDefault(s => s.EndsWith(imageFile));+ if (correctedKey != null)+ {+ imageFile = correctedKey;+ } else if (imageFile.StartsWith(".."))+ {+ // There are cases where the key is defined static like OEBPS/Images/1-4.jpg but reference is ../Images/1-4.jpg+ correctedKey = book.Content.Images.Keys.SingleOrDefault(s => s.EndsWith(imageFile.Replace("..", string.Empty)));+ if (correctedKey != null)+ {+ imageFile = correctedKey;+ }+ }++++ }++ image.Attributes.Remove("src");+ image.Attributes.Add("src", $"{apiBase}" + imageFile);+ }+ }+ }++ images = doc.DocumentNode.SelectNodes("//image");+ if (images != null)+ {+ foreach (var image in images)+ {+ if (image.Name != "image") continue;++ if (image.Attributes["xlink:href"] != null)+ {+ var imageFile = image.Attributes["xlink:href"].Value;+ if (!book.Content.Images.ContainsKey(imageFile))+ {+ var correctedKey = book.Content.Images.Keys.SingleOrDefault(s => s.EndsWith(imageFile));+ if (correctedKey != null)+ {+ imageFile = correctedKey;+ }+ }++ image.Attributes.Remove("xlink:href");+ image.Attributes.Add("xlink:href", $"{apiBase}" + imageFile);+ }+ }+ }+ }++ private static string PrepareFinalHtml(HtmlDocument doc, HtmlNode body)+ {+ // Check if any classes on the html node (some r2l books do this) and move them to body tag for scoping+ var htmlNode = doc.DocumentNode.SelectSingleNode("//html");+ if (htmlNode == null || !htmlNode.Attributes.Contains("class")) return body.InnerHtml;++ var bodyClasses = body.Attributes.Contains("class") ? body.Attributes["class"].Value : string.Empty;+ var classes = htmlNode.Attributes["class"].Value + " " + bodyClasses;+ body.Attributes.Add("class", $"{classes}");+ // I actually need the body tag itself for the classes, so i will create a div and put the body stuff there.+ return $"<div class=\"{body.Attributes["class"].Value}\">{body.InnerHtml}</div>";+ }++ private static void RewriteAnchors(int page, HtmlDocument doc, Dictionary<string, int> mappings)+ {+ var anchors = doc.DocumentNode.SelectNodes("//a");+ if (anchors != null)+ {+ foreach (var anchor in anchors)+ {+ BookService.UpdateLinks(anchor, mappings, page);+ }+ }+ }++ private async Task InlineStyles(HtmlDocument doc, EpubBookRef book, string apiBase, HtmlNode body)+ {+ var inlineStyles = doc.DocumentNode.SelectNodes("//style");+ if (inlineStyles != null)+ {+ foreach (var inlineStyle in inlineStyles)+ {+ var styleContent = await ScopeStyles(inlineStyle.InnerHtml, apiBase, "", book);+ body.PrependChild(HtmlNode.CreateNode($"<style>{styleContent}</style>"));+ }+ }++ var styleNodes = doc.DocumentNode.SelectNodes("/html/head/link");+ if (styleNodes != null)+ {+ foreach (var styleLinks in styleNodes)+ {+ var key = BookService.CleanContentKeys(styleLinks.Attributes["href"].Value);+ // Some epubs are malformed the key in content.opf might be: content/resources/filelist_0_0.xml but the actual html links to resources/filelist_0_0.xml+ // In this case, we will do a search for the key that ends with+ if (!book.Content.Css.ContainsKey(key))+ {+ var correctedKey = book.Content.Css.Keys.SingleOrDefault(s => s.EndsWith(key));+ if (correctedKey == null)+ {+ _logger.LogError("Epub is Malformed, key: {Key} is not matching OPF file", key);+ continue;+ }++ key = correctedKey;+ }++ var styleContent = await ScopeStyles(await book.Content.Css[key].ReadContentAsync(), apiBase,+ book.Content.Css[key].FileName, book);+ if (styleContent != null)+ {+ body.PrependChild(HtmlNode.CreateNode($"<style>{styleContent}</style>"));+ }+ }+ }+ }+public ComicInfo GetComicInfo(string filePath){if (!IsValidFile(filePath) || Parser.Parser.IsPdf(filePath)) return null;@@ -202,10 +381,13 @@ namespace API.Servicesvar info = new ComicInfo(){Summary = epubBook.Schema.Package.Metadata.Description,- Writer = string.Join(",", epubBook.Schema.Package.Metadata.Creators),+ Writer = string.Join(",", epubBook.Schema.Package.Metadata.Creators.Select(c => Parser.Parser.CleanAuthor(c.Creator))),Publisher = string.Join(",", epubBook.Schema.Package.Metadata.Publishers),Month = !string.IsNullOrEmpty(publicationDate) ? DateTime.Parse(publicationDate).Month : 0,Year = !string.IsNullOrEmpty(publicationDate) ? DateTime.Parse(publicationDate).Year : 0,+ Title = epubBook.Title,+ Genre = string.Join(",", epubBook.Schema.Package.Metadata.Subjects.Select(s => s.ToLower().Trim())),+};// Parse tags not exposed via Libraryforeach (var metadataItem in epubBook.Schema.Package.Metadata.MetaItems)@@ -215,6 +397,9 @@ namespace API.Servicescase "calibre:rating":info.UserRating = float.Parse(metadataItem.Content);break;+ case "calibre:title_sort":+ info.TitleSort = metadataItem.Content;+ break;}}@@ -305,8 +490,6 @@ namespace API.Services{using var epubBook = EpubReader.OpenBook(filePath);- // If the epub has the following tags, we can group the books as Volumes- // <meta content="5.0" name="calibre:series_index"/>// <meta content="The Dark Tower" name="calibre:series"/>// <meta content="Wolves of the Calla" name="calibre:title_sort"/>// If all three are present, we can take that over dc:title and format as:@@ -323,6 +506,7 @@ namespace API.Servicesvar series = string.Empty;var specialName = string.Empty;var groupPosition = string.Empty;+ var titleSort = string.Empty;foreach (var metadataItem in epubBook.Schema.Package.Metadata.MetaItems)@@ -338,6 +522,7 @@ namespace API.Servicesbreak;case "calibre:title_sort":specialName = metadataItem.Content;+ titleSort = metadataItem.Content;break;}@@ -363,18 +548,26 @@ namespace API.Services{specialName = epubBook.Title;}- return new ParserInfo()+ var info = new ParserInfo(){Chapters = Parser.Parser.DefaultChapter,Edition = string.Empty,Format = MangaFormat.Epub,Filename = Path.GetFileName(filePath),- Title = specialName.Trim(),+ Title = specialName?.Trim(),FullFilePath = filePath,IsSpecial = false,Series = series.Trim(),Volumes = seriesIndex};++ // Don't set titleSort if the book belongs to a group+ if (!string.IsNullOrEmpty(titleSort) && string.IsNullOrEmpty(seriesIndex))+ {+ info.SeriesSort = titleSort;+ }++ return info;}}catch (Exception)@@ -392,7 +585,7 @@ namespace API.ServicesFullFilePath = filePath,IsSpecial = false,Series = epubBook.Title.Trim(),- Volumes = Parser.Parser.DefaultVolume+ Volumes = Parser.Parser.DefaultVolume,};}catch (Exception ex)@@ -403,31 +596,46 @@ namespace API.Servicesreturn null;}- private static void AddBytesToBitmap(Bitmap bmp, byte[] rawBytes)- {- var rect = new Rectangle(0, 0, bmp.Width, bmp.Height);-- var bmpData = bmp.LockBits(rect, ImageLockMode.WriteOnly, bmp.PixelFormat);- var pNative = bmpData.Scan0;-- Marshal.Copy(rawBytes, 0, pNative, rawBytes.Length);- bmp.UnlockBits(bmpData);- }-+ /// <summary>+ /// Extracts a pdf into images to a target directory. Uses multi-threaded implementation since docnet is slow normally.+ /// </summary>+ /// <param name="fileFilePath"></param>+ /// <param name="targetDirectory"></param>public void ExtractPdfImages(string fileFilePath, string targetDirectory){- DirectoryService.ExistOrCreate(targetDirectory);+ _directoryService.ExistOrCreate(targetDirectory);using var docReader = DocLib.Instance.GetDocReader(fileFilePath, new PageDimensions(1080, 1920));var pages = docReader.GetPageCount();- using var stream = StreamManager.GetStream("BookService.GetPdfPage");- for (var pageNumber = 0; pageNumber < pages; pageNumber++)+ Parallel.For(0, pages, pageNumber =>{+ using var stream = StreamManager.GetStream("BookService.GetPdfPage");GetPdfPage(docReader, pageNumber, stream);using var fileStream = File.Create(Path.Combine(targetDirectory, "Page-" + pageNumber + ".png"));stream.Seek(0, SeekOrigin.Begin);stream.CopyTo(fileStream);- }+ });+ }++ /// <summary>+ /// Responsible to scope all the css, links, tags, etc to prepare a self contained html file for the page+ /// </summary>+ /// <param name="doc">Html Doc that will be appended to</param>+ /// <param name="book">Underlying epub</param>+ /// <param name="apiBase">API Url for file loading to pass through</param>+ /// <param name="body">Body element from the epub</param>+ /// <param name="mappings">Epub mappings</param>+ /// <param name="page">Page number we are loading</param>+ /// <returns></returns>+ public async Task<string> ScopePage(HtmlDocument doc, EpubBookRef book, string apiBase, HtmlNode body, Dictionary<string, int> mappings, int page)+ {+ await InlineStyles(doc, book, apiBase, body);++ RewriteAnchors(page, doc, mappings);++ ScopeImages(doc, book, apiBase);++ return PrepareFinalHtml(doc, body);}/// <summary>@@ -436,13 +644,13 @@ namespace API.Services/// <param name="fileFilePath"></param>/// <param name="fileName">Name of the new file.</param>/// <returns></returns>- public string GetCoverImage(string fileFilePath, string fileName)+ public string GetCoverImage(string fileFilePath, string fileName, string outputDirectory){if (!IsValidFile(fileFilePath)) return string.Empty;if (Parser.Parser.IsPdf(fileFilePath)){- return GetPdfCoverImage(fileFilePath, fileName);+ return GetPdfCoverImage(fileFilePath, fileName, outputDirectory);}using var epubBook = EpubReader.OpenBook(fileFilePath);@@ -458,7 +666,7 @@ namespace API.Servicesif (coverImageContent == null) return string.Empty;using var stream = coverImageContent.GetContentStream();- return ImageService.WriteCoverThumbnail(stream, fileName);+ return _imageService.WriteCoverThumbnail(stream, fileName, outputDirectory);}catch (Exception ex){@@ -469,7 +677,7 @@ namespace API.Services}- private string GetPdfCoverImage(string fileFilePath, string fileName)+ private string GetPdfCoverImage(string fileFilePath, string fileName, string outputDirectory){try{@@ -479,7 +687,7 @@ namespace API.Servicesusing var stream = StreamManager.GetStream("BookService.GetPdfPage");GetPdfPage(docReader, 0, stream);- return ImageService.WriteCoverThumbnail(stream, fileName);+ return _imageService.WriteCoverThumbnail(stream, fileName, outputDirectory);}catch (Exception ex)@@ -498,15 +706,10 @@ namespace API.Servicesvar rawBytes = pageReader.GetImage(new NaiveTransparencyRemover());var width = pageReader.GetPageWidth();var height = pageReader.GetPageHeight();- using var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);- AddBytesToBitmap(bmp, rawBytes);- // Removes 1px margin on left/right side after bitmap is copied out- for (var y = 0; y < bmp.Height; y++)- {- bmp.SetPixel(bmp.Width - 1, y, bmp.GetPixel(bmp.Width - 2, y));- }+ var image = Image.LoadPixelData<Bgra32>(rawBytes, width, height);+stream.Seek(0, SeekOrigin.Begin);- bmp.Save(stream, ImageFormat.Jpeg);+ image.SaveAsPng(stream);stream.Seek(0, SeekOrigin.Begin);}diff --git a/API/Services/CacheService.cs b/API/Services/CacheService.csindex a64bde675..0b6c4aa0d 100644--- a/API/Services/CacheService.cs+++ b/API/Services/CacheService.cs@@ -1,46 +1,54 @@using System;using System.Collections.Generic;+using System.Collections.Immutable;using System.IO;using System.Linq;using System.Threading.Tasks;using API.Comparators;+using API.Data;using API.Entities;using API.Entities.Enums;using API.Extensions;-using API.Interfaces;-using API.Interfaces.Services;using Microsoft.Extensions.Logging;namespace API.Services{+ public interface ICacheService+ {+ /// <summary>+ /// Ensures the cache is created for the given chapter and if not, will create it. Should be called before any other+ /// cache operations (except cleanup).+ /// </summary>+ /// <param name="chapterId"></param>+ /// <returns>Chapter for the passed chapterId. Side-effect from ensuring cache.</returns>+ Task<Chapter> Ensure(int chapterId);+ /// <summary>+ /// Clears cache directory of all volumes. This can be invoked from deleting a library or a series.+ /// </summary>+ /// <param name="chapterIds">Volumes that belong to that library. Assume the library might have been deleted before this invocation.</param>+ void CleanupChapters(IEnumerable<int> chapterIds);+ string GetCachedPagePath(Chapter chapter, int page);+ string GetCachedEpubFile(int chapterId, Chapter chapter);+ public void ExtractChapterFiles(string extractPath, IReadOnlyList<MangaFile> files);+ }public class CacheService : ICacheService{private readonly ILogger<CacheService> _logger;private readonly IUnitOfWork _unitOfWork;- private readonly IArchiveService _archiveService;private readonly IDirectoryService _directoryService;- private readonly IBookService _bookService;+ private readonly IReadingItemService _readingItemService;private readonly NumericComparer _numericComparer;- public CacheService(ILogger<CacheService> logger, IUnitOfWork unitOfWork, IArchiveService archiveService,- IDirectoryService directoryService, IBookService bookService)+ public CacheService(ILogger<CacheService> logger, IUnitOfWork unitOfWork,+ IDirectoryService directoryService, IReadingItemService readingItemService){_logger = logger;_unitOfWork = unitOfWork;- _archiveService = archiveService;_directoryService = directoryService;- _bookService = bookService;+ _readingItemService = readingItemService;_numericComparer = new NumericComparer();}- public void EnsureCacheDirectory()- {- if (!DirectoryService.ExistOrCreate(DirectoryService.CacheDirectory))- {- _logger.LogError("Cache directory {CacheDirectory} is not accessible or does not exist. Creating...", DirectoryService.CacheDirectory);- }- }-/// <summary>/// Returns the full path to the cached epub file. If the file does not exist, will fallback to the original./// </summary>@@ -50,8 +58,8 @@ namespace API.Servicespublic string GetCachedEpubFile(int chapterId, Chapter chapter){var extractPath = GetCachePath(chapterId);- var path = Path.Join(extractPath, Path.GetFileName(chapter.Files.First().FilePath));- if (!(new FileInfo(path).Exists))+ var path = Path.Join(extractPath, _directoryService.FileSystem.Path.GetFileName(chapter.Files.First().FilePath));+ if (!(_directoryService.FileSystem.FileInfo.FromFileName(path).Exists)){path = chapter.Files.First().FilePath;}@@ -62,14 +70,14 @@ namespace API.Services/// Caches the files for the given chapter to CacheDirectory/// </summary>/// <param name="chapterId"></param>- /// <returns>This will always return the Chapter for the chpaterId</returns>+ /// <returns>This will always return the Chapter for the chapterId</returns>public async Task<Chapter> Ensure(int chapterId){- EnsureCacheDirectory();+ _directoryService.ExistOrCreate(_directoryService.CacheDirectory);var chapter = await _unitOfWork.ChapterRepository.GetChapterAsync(chapterId);var extractPath = GetCachePath(chapterId);- if (!Directory.Exists(extractPath))+ if (!_directoryService.Exists(extractPath)){var files = chapter.Files.ToList();ExtractChapterFiles(extractPath, files);@@ -90,22 +98,12 @@ namespace API.Servicesvar removeNonImages = true;var fileCount = files.Count;var extraPath = "";- var extractDi = new DirectoryInfo(extractPath);+ var extractDi = _directoryService.FileSystem.DirectoryInfo.FromDirectoryName(extractPath);if (files.Count > 0 && files[0].Format == MangaFormat.Image){- DirectoryService.ExistOrCreate(extractPath);- if (files.Count == 1)- {- _directoryService.CopyFileToDirectory(files[0].FilePath, extractPath);- }- else- {- DirectoryService.CopyDirectoryToDirectory(Path.GetDirectoryName(files[0].FilePath), extractPath,- Parser.Parser.ImageFileExtensions);- }-- extractDi.Flatten();+ _readingItemService.Extract(files[0].FilePath, extractPath, MangaFormat.Image, files.Count);+ _directoryService.Flatten(extractDi.FullName);}foreach (var file in files)@@ -117,63 +115,37 @@ namespace API.Servicesif (file.Format == MangaFormat.Archive){- _archiveService.ExtractArchive(file.FilePath, Path.Join(extractPath, extraPath));+ _readingItemService.Extract(file.FilePath, Path.Join(extractPath, extraPath), file.Format);}else if (file.Format == MangaFormat.Pdf){- _bookService.ExtractPdfImages(file.FilePath, Path.Join(extractPath, extraPath));+ _readingItemService.Extract(file.FilePath, Path.Join(extractPath, extraPath), file.Format);}else if (file.Format == MangaFormat.Epub){removeNonImages = false;- DirectoryService.ExistOrCreate(extractPath);+ _directoryService.ExistOrCreate(extractPath);_directoryService.CopyFileToDirectory(files[0].FilePath, extractPath);}}- extractDi.Flatten();+ _directoryService.Flatten(extractDi.FullName);if (removeNonImages){- extractDi.RemoveNonImages();+ _directoryService.RemoveNonImages(extractDi.FullName);}}-- public void Cleanup()- {- _logger.LogInformation("Performing cleanup of Cache directory");- EnsureCacheDirectory();-- try- {- DirectoryService.ClearDirectory(DirectoryService.CacheDirectory);- }- catch (Exception ex)- {- _logger.LogError(ex, "There was an issue deleting one or more folders/files during cleanup");- }-- _logger.LogInformation("Cache directory purged");- }-/// <summary>/// Removes the cached files and folders for a set of chapterIds/// </summary>/// <param name="chapterIds"></param>public void CleanupChapters(IEnumerable<int> chapterIds){- _logger.LogInformation("Running Cache cleanup on Chapters");-foreach (var chapter in chapterIds){- var di = new DirectoryInfo(GetCachePath(chapter));- if (di.Exists)- {- di.Delete(true);- }-+ _directoryService.ClearDirectory(GetCachePath(chapter));}- _logger.LogInformation("Cache directory purged");}@@ -184,46 +156,32 @@ namespace API.Services/// <returns></returns>private string GetCachePath(int chapterId){- return Path.GetFullPath(Path.Join(DirectoryService.CacheDirectory, $"{chapterId}/"));+ return _directoryService.FileSystem.Path.GetFullPath(_directoryService.FileSystem.Path.Join(_directoryService.CacheDirectory, $"{chapterId}/"));}- public async Task<(string path, MangaFile file)> GetCachedPagePath(Chapter chapter, int page)+ /// <summary>+ /// Returns the absolute path of a cached page.+ /// </summary>+ /// <param name="chapter">Chapter entity with Files populated.</param>+ /// <param name="page">Page number to look for</param>+ /// <returns>Page filepath or empty if no files found.</returns>+ public string GetCachedPagePath(Chapter chapter, int page){// Calculate what chapter the page belongs to- var pagesSoFar = 0;- var chapterFiles = chapter.Files ?? await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapter.Id);- foreach (var mangaFile in chapterFiles)+ var path = GetCachePath(chapter.Id);+ var files = _directoryService.GetFilesWithExtension(path, Parser.Parser.ImageFileExtensions);+ files = files+ .AsEnumerable()+ .OrderByNatural(Path.GetFileNameWithoutExtension)+ .ToArray();++ if (files.Length == 0){- if (page <= (mangaFile.Pages + pagesSoFar))- {- var path = GetCachePath(chapter.Id);- var files = DirectoryService.GetFilesWithExtension(path, Parser.Parser.ImageFileExtensions);- Array.Sort(files, _numericComparer);-- if (files.Length == 0)- {- return (files.ElementAt(0), mangaFile);- }-- // Since array is 0 based, we need to keep that in account (only affects last image)- if (page == files.Length)- {- return (files.ElementAt(page - 1 - pagesSoFar), mangaFile);- }-- if (mangaFile.Format == MangaFormat.Image && mangaFile.Pages == 1)- {- // Each file is one page, meaning we should just get element at page- return (files.ElementAt(page), mangaFile);- }-- return (files.ElementAt(page - pagesSoFar), mangaFile);- }-- pagesSoFar += mangaFile.Pages;+ return string.Empty;}- return (string.Empty, null);+ // Since array is 0 based, we need to keep that in account (only affects last image)+ return page == files.Length ? files.ElementAt(page - 1) : files.ElementAt(page);}}}diff --git a/API/Services/DirectoryService.cs b/API/Services/DirectoryService.csindex 04240245a..bf3c01d25 100644--- a/API/Services/DirectoryService.cs+++ b/API/Services/DirectoryService.cs@@ -1,31 +1,88 @@-using System;+using System;+using System.Collections;using System.Collections.Generic;using System.Collections.Immutable;using System.IO;+using System.IO.Abstractions;using System.Linq;using System.Text.RegularExpressions;using System.Threading.Tasks;-using API.Interfaces.Services;+using API.Comparators;+using API.Extensions;using Microsoft.Extensions.Logging;namespace API.Services{+ public interface IDirectoryService+ {+ IFileSystem FileSystem { get; }+ string CacheDirectory { get; }+ string CoverImageDirectory { get; }+ string LogDirectory { get; }+ string TempDirectory { get; }+ string ConfigDirectory { get; }+ /// <summary>+ /// Original BookmarkDirectory. Only used for resetting directory. Use <see cref="ServerSettings.BackupDirectory"/> for actual path.+ /// </summary>+ string BookmarkDirectory { get; }+ /// <summary>+ /// Lists out top-level folders for a given directory. Filters out System and Hidden folders.+ /// </summary>+ /// <param name="rootPath">Absolute path of directory to scan.</param>+ /// <returns>List of folder names</returns>+ IEnumerable<string> ListDirectory(string rootPath);+ Task<byte[]> ReadFileAsync(string path);+ bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, string prepend = "");+ bool Exists(string directory);+ void CopyFileToDirectory(string fullFilePath, string targetDirectory);+ int TraverseTreeParallelForEach(string root, Action<string> action, string searchPattern, ILogger logger);+ bool IsDriveMounted(string path);+ bool IsDirectoryEmpty(string path);+ long GetTotalSize(IEnumerable<string> paths);+ void ClearDirectory(string directoryPath);+ void ClearAndDeleteDirectory(string directoryPath);+ string[] GetFilesWithExtension(string path, string searchPatternExpression = "");+ bool CopyDirectoryToDirectory(string sourceDirName, string destDirName, string searchPattern = "");++ Dictionary<string, string> FindHighestDirectoriesFromFiles(IEnumerable<string> libraryFolders,+ IList<string> filePaths);++ IEnumerable<string> GetFoldersTillRoot(string rootPath, string fullPath);++ IEnumerable<string> GetFiles(string path, string fileNameRegex = "", SearchOption searchOption = SearchOption.TopDirectoryOnly);++ bool ExistOrCreate(string directoryPath);+ void DeleteFiles(IEnumerable<string> files);+ void RemoveNonImages(string directoryName);+ void Flatten(string directoryName);+ Task<bool> CheckWriteAccess(string directoryName);+ }public class DirectoryService : IDirectoryService{- private readonly ILogger<DirectoryService> _logger;+ public IFileSystem FileSystem { get; }+ public string CacheDirectory { get; }+ public string CoverImageDirectory { get; }+ public string LogDirectory { get; }+ public string TempDirectory { get; }+ public string ConfigDirectory { get; }+ public string BookmarkDirectory { get; }+ private readonly ILogger<DirectoryService> _logger;+private static readonly Regex ExcludeDirectories = new Regex(- @"@eaDir|\.DS_Store",+ @"@eaDir|\.DS_Store|\.qpkg",RegexOptions.Compiled | RegexOptions.IgnoreCase);- public static readonly string TempDirectory = Path.Join(Directory.GetCurrentDirectory(), "config", "temp");- public static readonly string LogDirectory = Path.Join(Directory.GetCurrentDirectory(), "config", "logs");- public static readonly string CacheDirectory = Path.Join(Directory.GetCurrentDirectory(), "config", "cache");- public static readonly string CoverImageDirectory = Path.Join(Directory.GetCurrentDirectory(), "config", "covers");public static readonly string BackupDirectory = Path.Join(Directory.GetCurrentDirectory(), "config", "backups");- public static readonly string ConfigDirectory = Path.Join(Directory.GetCurrentDirectory(), "config");- public DirectoryService(ILogger<DirectoryService> logger)+ public DirectoryService(ILogger<DirectoryService> logger, IFileSystem fileSystem){- _logger = logger;+ _logger = logger;+ FileSystem = fileSystem;+ CoverImageDirectory = FileSystem.Path.Join(FileSystem.Directory.GetCurrentDirectory(), "config", "covers");+ CacheDirectory = FileSystem.Path.Join(FileSystem.Directory.GetCurrentDirectory(), "config", "cache");+ LogDirectory = FileSystem.Path.Join(FileSystem.Directory.GetCurrentDirectory(), "config", "logs");+ TempDirectory = FileSystem.Path.Join(FileSystem.Directory.GetCurrentDirectory(), "config", "temp");+ ConfigDirectory = FileSystem.Path.Join(FileSystem.Directory.GetCurrentDirectory(), "config");+ BookmarkDirectory = FileSystem.Path.Join(FileSystem.Directory.GetCurrentDirectory(), "config", "bookmarks");}/// <summary>@@ -36,16 +93,16 @@ namespace API.Services/// <param name="searchPatternExpression">Regex version of search pattern (ie \.mp3|\.mp4). Defaults to * meaning all files.</param>/// <param name="searchOption">SearchOption to use, defaults to TopDirectoryOnly</param>/// <returns>List of file paths</returns>- private static IEnumerable<string> GetFilesWithCertainExtensions(string path,+ private IEnumerable<string> GetFilesWithCertainExtensions(string path,string searchPatternExpression = "",SearchOption searchOption = SearchOption.TopDirectoryOnly){- if (!Directory.Exists(path)) return ImmutableList<string>.Empty;+ if (!FileSystem.Directory.Exists(path)) return ImmutableList<string>.Empty;var reSearchPattern = new Regex(searchPatternExpression, RegexOptions.IgnoreCase);- return Directory.EnumerateFiles(path, "*", searchOption)+ return FileSystem.Directory.EnumerateFiles(path, "*", searchOption).Where(file =>- reSearchPattern.IsMatch(Path.GetExtension(file)) && !Path.GetFileName(file).StartsWith(Parser.Parser.MacOsMetadataFileStartsWith));+ reSearchPattern.IsMatch(FileSystem.Path.GetExtension(file)) && !FileSystem.Path.GetFileName(file).StartsWith(Parser.Parser.MacOsMetadataFileStartsWith));}@@ -57,17 +114,17 @@ namespace API.Services/// <param name="rootPath"></param>/// <param name="fullPath"></param>/// <returns></returns>- public static IEnumerable<string> GetFoldersTillRoot(string rootPath, string fullPath)+ public IEnumerable<string> GetFoldersTillRoot(string rootPath, string fullPath){- var separator = Path.AltDirectorySeparatorChar;- if (fullPath.Contains(Path.DirectorySeparatorChar))+ var separator = FileSystem.Path.AltDirectorySeparatorChar;+ if (fullPath.Contains(FileSystem.Path.DirectorySeparatorChar)){- fullPath = fullPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);+ fullPath = fullPath.Replace(FileSystem.Path.DirectorySeparatorChar, FileSystem.Path.AltDirectorySeparatorChar);}if (rootPath.Contains(Path.DirectorySeparatorChar)){- rootPath = rootPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);+ rootPath = rootPath.Replace(FileSystem.Path.DirectorySeparatorChar, FileSystem.Path.AltDirectorySeparatorChar);}@@ -76,14 +133,14 @@ namespace API.Servicesvar root = rootPath.EndsWith(separator) ? rootPath.Substring(0, rootPath.Length - 1) : rootPath;var paths = new List<string>();// If a file is at the end of the path, remove it before we start processing folders- if (Path.GetExtension(path) != string.Empty)+ if (FileSystem.Path.GetExtension(path) != string.Empty){path = path.Substring(0, path.LastIndexOf(separator));}- while (Path.GetDirectoryName(path) != Path.GetDirectoryName(root))+ while (FileSystem.Path.GetDirectoryName(path) != Path.GetDirectoryName(root)){- var folder = new DirectoryInfo(path).Name;+ var folder = FileSystem.DirectoryInfo.FromDirectoryName(path).Name;paths.Add(folder);path = path.Substring(0, path.LastIndexOf(separator));}@@ -91,35 +148,60 @@ namespace API.Servicesreturn paths;}+ /// <summary>+ /// Does Directory Exist+ /// </summary>+ /// <param name="directory"></param>+ /// <returns></returns>public bool Exists(string directory){- var di = new DirectoryInfo(directory);- return di.Exists;+ var di = FileSystem.DirectoryInfo.FromDirectoryName(directory);+ return di.Exists;}- public static IEnumerable<string> GetFiles(string path, string searchPatternExpression = "",- SearchOption searchOption = SearchOption.TopDirectoryOnly)+ /// <summary>+ /// Get files given a path.+ /// </summary>+ /// <remarks>This will automatically filter out restricted files, like MacOsMetadata files</remarks>+ /// <param name="path"></param>+ /// <param name="fileNameRegex">An optional regex string to search against. Will use file path to match against.</param>+ /// <param name="searchOption">Defaults to top level directory only, can be given all to provide recursive searching</param>+ /// <returns></returns>+ public IEnumerable<string> GetFiles(string path, string fileNameRegex = "", SearchOption searchOption = SearchOption.TopDirectoryOnly){- if (searchPatternExpression != string.Empty)+ if (!FileSystem.Directory.Exists(path)) return ImmutableList<string>.Empty;++ if (fileNameRegex != string.Empty){- if (!Directory.Exists(path)) return ImmutableList<string>.Empty;- var reSearchPattern = new Regex(searchPatternExpression, RegexOptions.IgnoreCase);- return Directory.EnumerateFiles(path, "*", searchOption)+ var reSearchPattern = new Regex(fileNameRegex, RegexOptions.IgnoreCase);+ return FileSystem.Directory.EnumerateFiles(path, "*", searchOption).Where(file =>- reSearchPattern.IsMatch(file) && !file.StartsWith(Parser.Parser.MacOsMetadataFileStartsWith));+ {+ var fileName = FileSystem.Path.GetFileName(file);+ return reSearchPattern.IsMatch(fileName) &&+ !fileName.StartsWith(Parser.Parser.MacOsMetadataFileStartsWith);+ });}- return !Directory.Exists(path) ? Array.Empty<string>() : Directory.GetFiles(path);+ return FileSystem.Directory.EnumerateFiles(path, "*", searchOption).Where(file =>+ !FileSystem.Path.GetFileName(file).StartsWith(Parser.Parser.MacOsMetadataFileStartsWith));}+ /// <summary>+ /// Copies a file into a directory. Does not maintain parent folder of file.+ /// Will create target directory if doesn't exist. Automatically overwrites what is there.+ /// </summary>+ /// <param name="fullFilePath"></param>+ /// <param name="targetDirectory"></param>public void CopyFileToDirectory(string fullFilePath, string targetDirectory){try{- var fileInfo = new FileInfo(fullFilePath);+ var fileInfo = FileSystem.FileInfo.FromFileName(fullFilePath);if (fileInfo.Exists){- fileInfo.CopyTo(Path.Join(targetDirectory, fileInfo.Name), true);+ ExistOrCreate(targetDirectory);+ fileInfo.CopyTo(FileSystem.Path.Join(targetDirectory, fileInfo.Name), true);}}catch (Exception ex)@@ -129,19 +211,19 @@ namespace API.Services}/// <summary>- /// Copies a Directory with all files and subdirectories to a target location+ /// Copies all files and subdirectories within a directory to a target location/// </summary>- /// <param name="sourceDirName"></param>- /// <param name="destDirName"></param>- /// <param name="searchPattern">Defaults to *, meaning all files</param>- /// <returns></returns>- /// <exception cref="DirectoryNotFoundException"></exception>- public static bool CopyDirectoryToDirectory(string sourceDirName, string destDirName, string searchPattern = "")+ /// <param name="sourceDirName">Directory to copy from. Does not copy the parent folder</param>+ /// <param name="destDirName">Destination to copy to. Will be created if doesn't exist</param>+ /// <param name="searchPattern">Defaults to all files</param>+ /// <returns>If was successful</returns>+ /// <exception cref="DirectoryNotFoundException">Thrown when source directory does not exist</exception>+ public bool CopyDirectoryToDirectory(string sourceDirName, string destDirName, string searchPattern = ""){if (string.IsNullOrEmpty(sourceDirName)) return false;// Get the subdirectories for the specified directory.- var dir = new DirectoryInfo(sourceDirName);+ var dir = FileSystem.DirectoryInfo.FromDirectoryName(sourceDirName);if (!dir.Exists){@@ -156,17 +238,17 @@ namespace API.ServicesExistOrCreate(destDirName);// Get the files in the directory and copy them to the new location.- var files = GetFilesWithExtension(dir.FullName, searchPattern).Select(n => new FileInfo(n));+ var files = GetFilesWithExtension(dir.FullName, searchPattern).Select(n => FileSystem.FileInfo.FromFileName(n));foreach (var file in files){- var tempPath = Path.Combine(destDirName, file.Name);+ var tempPath = FileSystem.Path.Combine(destDirName, file.Name);file.CopyTo(tempPath, false);}// If copying subdirectories, copy them and their contents to new location.foreach (var subDir in dirs){- var tempPath = Path.Combine(destDirName, subDir.Name);+ var tempPath = FileSystem.Path.Combine(destDirName, subDir.Name);CopyDirectoryToDirectory(subDir.FullName, tempPath);}@@ -178,19 +260,30 @@ namespace API.Services/// </summary>/// <param name="path"></param>/// <returns></returns>- public static bool IsDriveMounted(string path)+ public bool IsDriveMounted(string path){- return new DirectoryInfo(Path.GetPathRoot(path) ?? string.Empty).Exists;+ return FileSystem.DirectoryInfo.FromDirectoryName(FileSystem.Path.GetPathRoot(path) ?? string.Empty).Exists;}- public static string[] GetFilesWithExtension(string path, string searchPatternExpression = "")++ /// <summary>+ /// Checks if the root path of a path is empty or not.+ /// </summary>+ /// <param name="path"></param>+ /// <returns></returns>+ public bool IsDirectoryEmpty(string path)+ {+ return FileSystem.Directory.Exists(path) && !FileSystem.Directory.EnumerateFileSystemEntries(path).Any();+ }++ public string[] GetFilesWithExtension(string path, string searchPatternExpression = ""){- if (searchPatternExpression != string.Empty)- {- return GetFilesWithCertainExtensions(path, searchPatternExpression).ToArray();- }+ if (searchPatternExpression != string.Empty)+ {+ return GetFilesWithCertainExtensions(path, searchPatternExpression).ToArray();+ }- return !Directory.Exists(path) ? Array.Empty<string>() : Directory.GetFiles(path);+ return !FileSystem.Directory.Exists(path) ? Array.Empty<string>() : FileSystem.Directory.GetFiles(path);}/// <summary>@@ -198,9 +291,9 @@ namespace API.Services/// </summary>/// <param name="paths"></param>/// <returns>Total bytes</returns>- public static long GetTotalSize(IEnumerable<string> paths)+ public long GetTotalSize(IEnumerable<string> paths){- return paths.Sum(path => new FileInfo(path).Length);+ return paths.Sum(path => FileSystem.FileInfo.FromFileName(path).Length);}/// <summary>@@ -208,13 +301,13 @@ namespace API.Services/// </summary>/// <param name="directoryPath"></param>/// <returns></returns>- public static bool ExistOrCreate(string directoryPath)+ public bool ExistOrCreate(string directoryPath){- var di = new DirectoryInfo(directoryPath);+ var di = FileSystem.DirectoryInfo.FromDirectoryName(directoryPath);if (di.Exists) return true;try{- Directory.CreateDirectory(directoryPath);+ FileSystem.Directory.CreateDirectory(directoryPath);}catch (Exception){@@ -227,11 +320,11 @@ namespace API.Services/// Deletes all files within the directory, then the directory itself./// </summary>/// <param name="directoryPath"></param>- public static void ClearAndDeleteDirectory(string directoryPath)+ public void ClearAndDeleteDirectory(string directoryPath){- if (!Directory.Exists(directoryPath)) return;+ if (!FileSystem.Directory.Exists(directoryPath)) return;- DirectoryInfo di = new DirectoryInfo(directoryPath);+ var di = FileSystem.DirectoryInfo.FromDirectoryName(directoryPath);ClearDirectory(directoryPath);@@ -239,13 +332,13 @@ namespace API.Services}/// <summary>- /// Deletes all files within the directory.+ /// Deletes all files and folders within the directory path/// </summary>/// <param name="directoryPath"></param>/// <returns></returns>- public static void ClearDirectory(string directoryPath)+ public void ClearDirectory(string directoryPath){- var di = new DirectoryInfo(directoryPath);+ var di = FileSystem.DirectoryInfo.FromDirectoryName(directoryPath);if (!di.Exists) return;foreach (var file in di.EnumerateFiles())@@ -265,7 +358,7 @@ namespace API.Services/// <param name="directoryPath"></param>/// <param name="prepend">An optional string to prepend to the target file's name</param>/// <returns></returns>- public static bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, string prepend = "", ILogger logger = null)+ public bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, string prepend = ""){ExistOrCreate(directoryPath);string currentFile = null;@@ -274,36 +367,36 @@ namespace API.Servicesforeach (var file in filePaths){currentFile = file;- var fileInfo = new FileInfo(file);+ var fileInfo = FileSystem.FileInfo.FromFileName(file);if (fileInfo.Exists){- fileInfo.CopyTo(Path.Join(directoryPath, prepend + fileInfo.Name));+ fileInfo.CopyTo(FileSystem.Path.Join(directoryPath, prepend + fileInfo.Name));}else{- logger?.LogWarning("Tried to copy {File} but it doesn't exist", file);+ _logger.LogWarning("Tried to copy {File} but it doesn't exist", file);}}}catch (Exception ex){- logger?.LogError(ex, "Unable to copy {File} to {DirectoryPath}", currentFile, directoryPath);+ _logger.LogError(ex, "Unable to copy {File} to {DirectoryPath}", currentFile, directoryPath);return false;}return true;}- public bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, string prepend = "")- {- return CopyFilesToDirectory(filePaths, directoryPath, prepend, _logger);- }-+ /// <summary>+ /// Lists all directories in a root path. Will exclude Hidden or System directories.+ /// </summary>+ /// <param name="rootPath"></param>+ /// <returns></returns>public IEnumerable<string> ListDirectory(string rootPath){- if (!Directory.Exists(rootPath)) return ImmutableList<string>.Empty;+ if (!FileSystem.Directory.Exists(rootPath)) return ImmutableList<string>.Empty;- var di = new DirectoryInfo(rootPath);+ var di = FileSystem.DirectoryInfo.FromDirectoryName(rootPath);var dirs = di.GetDirectories().Where(dir => !(dir.Attributes.HasFlag(FileAttributes.Hidden) || dir.Attributes.HasFlag(FileAttributes.System))).Select(d => d.Name).ToImmutableList();@@ -311,20 +404,26 @@ namespace API.Servicesreturn dirs;}+ /// <summary>+ /// Reads a file's into byte[]. Returns empty array if file doesn't exist.+ /// </summary>+ /// <param name="path"></param>+ /// <returns></returns>public async Task<byte[]> ReadFileAsync(string path){- if (!File.Exists(path)) return Array.Empty<byte>();- return await File.ReadAllBytesAsync(path);+ if (!FileSystem.File.Exists(path)) return Array.Empty<byte>();+ return await FileSystem.File.ReadAllBytesAsync(path);}/// <summary>- /// Finds the highest directories from a set of MangaFiles+ /// Finds the highest directories from a set of file paths. Does not return the root path, will always select the highest non-root path./// </summary>+ /// <remarks>If the file paths do not contain anything from libraryFolders, this returns an empty dictionary back</remarks>/// <param name="libraryFolders">List of top level folders which files belong to</param>/// <param name="filePaths">List of file paths that belong to libraryFolders</param>/// <returns></returns>- public static Dictionary<string, string> FindHighestDirectoriesFromFiles(IEnumerable<string> libraryFolders, IList<string> filePaths)+ public Dictionary<string, string> FindHighestDirectoriesFromFiles(IEnumerable<string> libraryFolders, IList<string> filePaths){var stopLookingForDirectories = false;var dirs = new Dictionary<string, string>();@@ -365,20 +464,19 @@ namespace API.Services/// <param name="searchPattern">Regex pattern to search against</param>/// <param name="logger"></param>/// <exception cref="ArgumentException"></exception>- public static int TraverseTreeParallelForEach(string root, Action<string> action, string searchPattern, ILogger logger)+ public int TraverseTreeParallelForEach(string root, Action<string> action, string searchPattern, ILogger logger){- //Count of files traversed and timer for diagnostic output+ //Count of files traversed and timer for diagnostic outputvar fileCount = 0;- // Determine whether to parallelize file processing on each folder based on processor count.- //var procCount = Environment.ProcessorCount;// Data structure to hold names of subfolders to be examined for files.var dirs = new Stack<string>();- if (!Directory.Exists(root)) {- throw new ArgumentException("The directory doesn't exist");+ if (!FileSystem.Directory.Exists(root)) {+ throw new ArgumentException("The directory doesn't exist");}+dirs.Push(root);while (dirs.Count > 0) {@@ -387,7 +485,7 @@ namespace API.Servicesstring[] files;try {- subDirs = Directory.GetDirectories(currentDir).Where(path => ExcludeDirectories.Matches(path).Count == 0);+ subDirs = FileSystem.Directory.GetDirectories(currentDir).Where(path => ExcludeDirectories.Matches(path).Count == 0);}// Thrown if we do not have discovery permission on the directory.catch (UnauthorizedAccessException e) {@@ -403,7 +501,7 @@ namespace API.Services}try {- files = GetFilesWithCertainExtensions(currentDir, searchPattern)+ files = GetFilesWithCertainExtensions(currentDir, searchPattern).ToArray();}catch (UnauthorizedAccessException e) {@@ -423,22 +521,7 @@ namespace API.Services// Otherwise, execute sequentially. Files are opened and processed// synchronously but this could be modified to perform async I/O.try {- // if (files.Length < procCount) {- // foreach (var file in files) {- // action(file);- // fileCount++;- // }- // }- // else {- // Parallel.ForEach(files, () => 0, (file, _, localCount) =>- // { action(file);- // return ++localCount;- // },- // (c) => {- // Interlocked.Add(ref fileCount, c);- // });- // }- foreach (var file in files) {+ foreach (var file in files) {action(file);fileCount++;}@@ -448,6 +531,7 @@ namespace API.Servicesif (ex is UnauthorizedAccessException) {// Here we just output a message and go on.Console.WriteLine(ex.Message);+ _logger.LogError(ex, "Unauthorized access on file");return true;}// Handle other exceptions here if necessary...@@ -469,13 +553,13 @@ namespace API.Services/// Attempts to delete the files passed to it. Swallows exceptions./// </summary>/// <param name="files">Full path of files to delete</param>- public static void DeleteFiles(IEnumerable<string> files)+ public void DeleteFiles(IEnumerable<string> files){foreach (var file in files){try{- new FileInfo(file).Delete();+ FileSystem.FileInfo.FromFileName(file).Delete();}catch (Exception){@@ -538,5 +622,101 @@ namespace API.Services// Return formatted number with suffixreturn readable.ToString("0.## ") + suffix;}++ /// <summary>+ /// Removes all files except images from the directory. Includes sub directories.+ /// </summary>+ /// <param name="directoryName">Fully qualified directory</param>+ public void RemoveNonImages(string directoryName)+ {+ DeleteFiles(GetFiles(directoryName, searchOption:SearchOption.AllDirectories).Where(file => !Parser.Parser.IsImage(file)));+ }+++ /// <summary>+ /// Flattens all files in subfolders to the passed directory recursively.+ ///+ ///+ /// foo<para />+ /// ├── 1.txt<para />+ /// ├── 2.txt<para />+ /// ├── 3.txt<para />+ /// ├── 4.txt<para />+ /// └── bar<para />+ /// ├── 1.txt<para />+ /// ├── 2.txt<para />+ /// └── 5.txt<para />+ ///+ /// becomes:<para />+ /// foo<para />+ /// ├── 1.txt<para />+ /// ├── 2.txt<para />+ /// ├── 3.txt<para />+ /// ├── 4.txt<para />+ /// ├── bar_1.txt<para />+ /// ├── bar_2.txt<para />+ /// └── bar_5.txt<para />+ /// </summary>+ /// <param name="directoryName">Fully qualified Directory name</param>+ public void Flatten(string directoryName)+ {+ if (string.IsNullOrEmpty(directoryName) || !FileSystem.Directory.Exists(directoryName)) return;++ var directory = FileSystem.DirectoryInfo.FromDirectoryName(directoryName);++ var index = 0;+ FlattenDirectory(directory, directory, ref index);+ }++ /// <summary>+ /// Checks whether a directory has write permissions+ /// </summary>+ /// <param name="directoryName">Fully qualified path</param>+ /// <returns></returns>+ public async Task<bool> CheckWriteAccess(string directoryName)+ {+ try+ {+ ExistOrCreate(directoryName);+ await FileSystem.File.WriteAllTextAsync(+ FileSystem.Path.Join(directoryName, "test.txt"),+ string.Empty);+ }+ catch (Exception ex)+ {+ ClearAndDeleteDirectory(directoryName);+ return false;+ }++ ClearAndDeleteDirectory(directoryName);+ return true;+ }+++ private void FlattenDirectory(IDirectoryInfo root, IDirectoryInfo directory, ref int directoryIndex)+ {+ if (!root.FullName.Equals(directory.FullName))+ {+ var fileIndex = 1;++ foreach (var file in directory.EnumerateFiles().OrderByNatural(file => file.FullName))+ {+ if (file.Directory == null) continue;+ var paddedIndex = Parser.Parser.PadZeros(directoryIndex + "");+ // We need to rename the files so that after flattening, they are in the order we found them+ var newName = $"{paddedIndex}_{Parser.Parser.PadZeros(fileIndex + "")}{file.Extension}";+ var newPath = Path.Join(root.FullName, newName);+ if (!File.Exists(newPath)) file.MoveTo(newPath);+ fileIndex++;+ }++ directoryIndex++;+ }++ foreach (var subDirectory in directory.EnumerateDirectories().OrderByNatural(d => d.FullName))+ {+ FlattenDirectory(root, subDirectory, ref directoryIndex);+ }+ }}}diff --git a/API/Services/DownloadService.cs b/API/Services/DownloadService.csindex 7d0f56b3d..51830f0ab 100644--- a/API/Services/DownloadService.cs+++ b/API/Services/DownloadService.cs@@ -3,56 +3,54 @@ using System.IO;using System.Linq;using System.Threading.Tasks;using API.Entities;-using API.Interfaces.Services;using Microsoft.AspNetCore.StaticFiles;-namespace API.Services+namespace API.Services;++public interface IDownloadService+{+ Task<(byte[], string, string)> GetFirstFileDownload(IEnumerable<MangaFile> files);+ string GetContentTypeFromFile(string filepath);+}+public class DownloadService : IDownloadService{- public interface IDownloadService+ private readonly IDirectoryService _directoryService;+ private readonly FileExtensionContentTypeProvider _fileTypeProvider = new FileExtensionContentTypeProvider();++ public DownloadService(IDirectoryService directoryService){- Task<(byte[], string, string)> GetFirstFileDownload(IEnumerable<MangaFile> files);- string GetContentTypeFromFile(string filepath);+ _directoryService = directoryService;}- public class DownloadService : IDownloadService- {- private readonly IDirectoryService _directoryService;- private readonly FileExtensionContentTypeProvider _fileTypeProvider = new FileExtensionContentTypeProvider();-- public DownloadService(IDirectoryService directoryService)- {- _directoryService = directoryService;- }- /// <summary>- /// Downloads the first file in the file enumerable for download- /// </summary>- /// <param name="files"></param>- /// <returns></returns>- public async Task<(byte[], string, string)> GetFirstFileDownload(IEnumerable<MangaFile> files)- {- var firstFile = files.Select(c => c.FilePath).First();- return (await _directoryService.ReadFileAsync(firstFile), GetContentTypeFromFile(firstFile), Path.GetFileName(firstFile));- }+ /// <summary>+ /// Downloads the first file in the file enumerable for download+ /// </summary>+ /// <param name="files"></param>+ /// <returns></returns>+ public async Task<(byte[], string, string)> GetFirstFileDownload(IEnumerable<MangaFile> files)+ {+ var firstFile = files.Select(c => c.FilePath).First();+ return (await _directoryService.ReadFileAsync(firstFile), GetContentTypeFromFile(firstFile), Path.GetFileName(firstFile));+ }- public string GetContentTypeFromFile(string filepath)+ public string GetContentTypeFromFile(string filepath)+ {+ // Figures out what the content type should be based on the file name.+ if (!_fileTypeProvider.TryGetContentType(filepath, out var contentType)){- // Figures out what the content type should be based on the file name.- if (!_fileTypeProvider.TryGetContentType(filepath, out var contentType))+ contentType = Path.GetExtension(filepath).ToLowerInvariant() switch{- contentType = Path.GetExtension(filepath).ToLowerInvariant() switch- {- ".cbz" => "application/zip",- ".cbr" => "application/vnd.rar",- ".cb7" => "application/x-compressed",- ".epub" => "application/epub+zip",- ".7z" => "application/x-7z-compressed",- ".7zip" => "application/x-7z-compressed",- ".pdf" => "application/pdf",- _ => contentType- };- }-- return contentType;+ ".cbz" => "application/zip",+ ".cbr" => "application/vnd.rar",+ ".cb7" => "application/x-compressed",+ ".epub" => "application/epub+zip",+ ".7z" => "application/x-7z-compressed",+ ".7zip" => "application/x-7z-compressed",+ ".pdf" => "application/pdf",+ _ => contentType+ };}++ return contentType;}}diff --git a/API/Services/FileService.cs b/API/Services/FileService.csnew file mode 100644index 000000000..a4194b820--- /dev/null+++ b/API/Services/FileService.cs@@ -0,0 +1,46 @@+using System;+using System.IO.Abstractions;+using API.Extensions;++namespace API.Services;++public interface IFileService+{+ IFileSystem GetFileSystem();+ bool HasFileBeenModifiedSince(string filePath, DateTime time);+ bool Exists(string filePath);+}++public class FileService : IFileService+{+ private readonly IFileSystem _fileSystem;++ public FileService(IFileSystem fileSystem)+ {+ _fileSystem = fileSystem;+ }++ public FileService() : this(fileSystem: new FileSystem()) { }++ public IFileSystem GetFileSystem()+ {+ return _fileSystem;+ }++ /// <summary>+ /// If the File on disk's last modified time is after passed time+ /// </summary>+ /// <remarks>This has a resolution to the minute. Will ignore seconds and milliseconds</remarks>+ /// <param name="filePath">Full qualified path of file</param>+ /// <param name="time"></param>+ /// <returns></returns>+ public bool HasFileBeenModifiedSince(string filePath, DateTime time)+ {+ return !string.IsNullOrEmpty(filePath) && _fileSystem.File.GetLastWriteTime(filePath).Truncate(TimeSpan.TicksPerMinute) > time.Truncate(TimeSpan.TicksPerMinute);+ }++ public bool Exists(string filePath)+ {+ return _fileSystem.File.Exists(filePath);+ }+}diff --git a/API/Services/HostedServices/StartupTasksHostedService.cs b/API/Services/HostedServices/StartupTasksHostedService.csindex 486b45513..099c44cc8 100644--- a/API/Services/HostedServices/StartupTasksHostedService.cs+++ b/API/Services/HostedServices/StartupTasksHostedService.cs@@ -1,7 +1,6 @@using System;using System.Threading;using System.Threading.Tasks;-using API.Interfaces;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;@@ -21,7 +20,7 @@ namespace API.Services.HostedServicesusing var scope = _provider.CreateScope();var taskScheduler = scope.ServiceProvider.GetRequiredService<ITaskScheduler>();- taskScheduler.ScheduleTasks();+ await taskScheduler.ScheduleTasks();taskScheduler.ScheduleUpdaterTasks();trydiff --git a/API/Services/ImageService.cs b/API/Services/ImageService.csindex 7f663c37d..29a528e71 100644--- a/API/Services/ImageService.cs+++ b/API/Services/ImageService.cs@@ -1,21 +1,32 @@using System;using System.IO;-using System.Linq;-using API.Comparators;-using API.Entities;-using API.Interfaces.Services;using Microsoft.Extensions.Logging;using NetVips;-namespace API.Services+namespace API.Services;++public interface IImageService{+ void ExtractImages(string fileFilePath, string targetDirectory, int fileCount = 1);+ string GetCoverImage(string path, string fileName, string outputDirectory);++ /// <summary>+ /// Creates a Thumbnail version of a base64 image+ /// </summary>+ /// <param name="encodedImage">base64 encoded image</param>+ /// <returns>File name with extension of the file. This will always write to <see cref="DirectoryService.CoverImageDirectory"/></returns>+ string CreateThumbnailFromBase64(string encodedImage, string fileName);++ string WriteCoverThumbnail(Stream stream, string fileName, string outputDirectory);+}- public class ImageService : IImageService- {+public class ImageService : IImageService+{private readonly ILogger<ImageService> _logger;+ private readonly IDirectoryService _directoryService;public const string ChapterCoverImageRegex = @"v\d+_c\d+";- public const string SeriesCoverImageRegex = @"seres\d+";- public const string CollectionTagCoverImageRegex = @"tag\d+";+ public const string SeriesCoverImageRegex = @"series_\d+";+ public const string CollectionTagCoverImageRegex = @"tag_\d+";/// <summary>@@ -23,60 +34,40 @@ namespace API.Services/// </summary>private const int ThumbnailWidth = 320;- public ImageService(ILogger<ImageService> logger)+ public ImageService(ILogger<ImageService> logger, IDirectoryService directoryService){- _logger = logger;+ _logger = logger;+ _directoryService = directoryService;}- /// <summary>- /// Finds the first image in the directory of the first file. Does not check for "cover/folder".ext files to override.- /// </summary>- /// <param name="file"></param>- /// <returns></returns>- public string GetCoverFile(MangaFile file)+ public void ExtractImages(string fileFilePath, string targetDirectory, int fileCount){- var directory = Path.GetDirectoryName(file.FilePath);- if (string.IsNullOrEmpty(directory))- {- _logger.LogError("Could not find Directory for {File}", file.FilePath);- return null;- }-- var firstImage = DirectoryService.GetFilesWithExtension(directory, Parser.Parser.ImageFileExtensions)- .OrderBy(f => f, new NaturalSortComparer()).FirstOrDefault();-- return firstImage;+ _directoryService.ExistOrCreate(targetDirectory);+ if (fileCount == 1)+ {+ _directoryService.CopyFileToDirectory(fileFilePath, targetDirectory);+ }+ else+ {+ _directoryService.CopyDirectoryToDirectory(Path.GetDirectoryName(fileFilePath), targetDirectory,+ Parser.Parser.ImageFileExtensions);+ }}- public string GetCoverImage(string path, string fileName)+ public string GetCoverImage(string path, string fileName, string outputDirectory){- if (string.IsNullOrEmpty(path)) return string.Empty;-- try- {- return CreateThumbnail(path, fileName);- }- catch (Exception ex)- {- _logger.LogWarning(ex, "[GetCoverImage] There was an error and prevented thumbnail generation on {ImageFile}. Defaulting to no cover image", path);- }-- return string.Empty;- }+ if (string.IsNullOrEmpty(path)) return string.Empty;- /// <inheritdoc />- public string CreateThumbnail(string path, string fileName)- {try{using var thumbnail = Image.Thumbnail(path, ThumbnailWidth);var filename = fileName + ".png";- thumbnail.WriteToFile(Path.Join(DirectoryService.CoverImageDirectory, filename));+ thumbnail.WriteToFile(_directoryService.FileSystem.Path.Join(outputDirectory, filename));return filename;}- catch (Exception e)+ catch (Exception ex){- _logger.LogError(e, "Error creating thumbnail from url");+ _logger.LogWarning(ex, "[GetCoverImage] There was an error and prevented thumbnail generation on {ImageFile}. Defaulting to no cover image", path);}return string.Empty;@@ -89,11 +80,16 @@ namespace API.Services/// <param name="stream">Stream to write to disk. Ensure this is rewinded.</param>/// <param name="fileName">filename to save as without extension</param>/// <returns>File name with extension of the file. This will always write to <see cref="DirectoryService.CoverImageDirectory"/></returns>- public static string WriteCoverThumbnail(Stream stream, string fileName)+ public string WriteCoverThumbnail(Stream stream, string fileName, string outputDirectory){using var thumbnail = Image.ThumbnailStream(stream, ThumbnailWidth);var filename = fileName + ".png";- thumbnail.WriteToFile(Path.Join(DirectoryService.CoverImageDirectory, fileName + ".png"));+ _directoryService.ExistOrCreate(outputDirectory);+ try+ {+ _directoryService.FileSystem.File.Delete(_directoryService.FileSystem.Path.Join(outputDirectory, filename));+ } catch (Exception ex) {/* Swallow exception */}+ thumbnail.WriteToFile(_directoryService.FileSystem.Path.Join(outputDirectory, filename));return filename;}@@ -105,7 +101,7 @@ namespace API.Services{using var thumbnail = Image.ThumbnailBuffer(Convert.FromBase64String(encodedImage), ThumbnailWidth);var filename = fileName + ".png";- thumbnail.WriteToFile(Path.Join(DirectoryService.CoverImageDirectory, fileName + ".png"));+ thumbnail.WriteToFile(_directoryService.FileSystem.Path.Join(_directoryService.CoverImageDirectory, fileName + ".png"));return filename;}catch (Exception e)@@ -146,5 +142,4 @@ namespace API.Services{return $"tag{tagId}";}- }}diff --git a/API/Services/MetadataService.cs b/API/Services/MetadataService.csindex 09161f42a..b6d45c77e 100644--- a/API/Services/MetadataService.cs+++ b/API/Services/MetadataService.cs@@ -5,329 +5,364 @@ using System.IO;using System.Linq;using System.Threading.Tasks;using API.Comparators;+using API.Data;using API.Data.Metadata;using API.Data.Repositories;+using API.Data.Scanner;using API.Entities;using API.Entities.Enums;using API.Extensions;using API.Helpers;-using API.Interfaces;-using API.Interfaces.Services;using API.SignalR;using Microsoft.AspNetCore.SignalR;using Microsoft.Extensions.Logging;-namespace API.Services+namespace API.Services;++public interface IMetadataService+{+ /// <summary>+ /// Recalculates metadata for all entities in a library.+ /// </summary>+ /// <param name="libraryId"></param>+ /// <param name="forceUpdate"></param>+ Task RefreshMetadata(int libraryId, bool forceUpdate = false);+ /// <summary>+ /// Performs a forced refresh of metadata just for a series and it's nested entities+ /// </summary>+ /// <param name="libraryId"></param>+ /// <param name="seriesId"></param>+ Task RefreshMetadataForSeries(int libraryId, int seriesId, bool forceUpdate = false);+}++public class MetadataService : IMetadataService{- public class MetadataService : IMetadataService+ private readonly IUnitOfWork _unitOfWork;+ private readonly ILogger<MetadataService> _logger;+ private readonly IHubContext<MessageHub> _messageHub;+ private readonly ICacheHelper _cacheHelper;+ private readonly IReadingItemService _readingItemService;+ private readonly IDirectoryService _directoryService;+ private readonly ChapterSortComparerZeroFirst _chapterSortComparerForInChapterSorting = new ChapterSortComparerZeroFirst();+ public MetadataService(IUnitOfWork unitOfWork, ILogger<MetadataService> logger,+ IHubContext<MessageHub> messageHub, ICacheHelper cacheHelper,+ IReadingItemService readingItemService, IDirectoryService directoryService){- private readonly IUnitOfWork _unitOfWork;- private readonly ILogger<MetadataService> _logger;- private readonly IArchiveService _archiveService;- private readonly IBookService _bookService;- private readonly IImageService _imageService;- private readonly IHubContext<MessageHub> _messageHub;- private readonly ChapterSortComparerZeroFirst _chapterSortComparerForInChapterSorting = new ChapterSortComparerZeroFirst();-- public MetadataService(IUnitOfWork unitOfWork, ILogger<MetadataService> logger,- IArchiveService archiveService, IBookService bookService, IImageService imageService, IHubContext<MessageHub> messageHub)- {- _unitOfWork = unitOfWork;- _logger = logger;- _archiveService = archiveService;- _bookService = bookService;- _imageService = imageService;- _messageHub = messageHub;- }+ _unitOfWork = unitOfWork;+ _logger = logger;+ _messageHub = messageHub;+ _cacheHelper = cacheHelper;+ _readingItemService = readingItemService;+ _directoryService = directoryService;+ }- /// <summary>- /// Determines whether an entity should regenerate cover image.- /// </summary>- /// <remarks>If a cover image is locked but the underlying file has been deleted, this will allow regenerating. </remarks>- /// <param name="coverImage"></param>- /// <param name="firstFile"></param>- /// <param name="forceUpdate"></param>- /// <param name="isCoverLocked"></param>- /// <param name="coverImageDirectory">Directory where cover images are. Defaults to <see cref="DirectoryService.CoverImageDirectory"/></param>- /// <returns></returns>- public static bool ShouldUpdateCoverImage(string coverImage, MangaFile firstFile, bool forceUpdate = false,- bool isCoverLocked = false, string coverImageDirectory = null)- {- if (string.IsNullOrEmpty(coverImageDirectory))- {- coverImageDirectory = DirectoryService.CoverImageDirectory;- }+ /// <summary>+ /// Updates the metadata for a Chapter+ /// </summary>+ /// <param name="chapter"></param>+ /// <param name="forceUpdate">Force updating cover image even if underlying file has not been modified or chapter already has a cover image</param>+ private bool UpdateChapterCoverImage(Chapter chapter, bool forceUpdate)+ {+ var firstFile = chapter.Files.OrderBy(x => x.Chapter).FirstOrDefault();- var fileExists = File.Exists(Path.Join(coverImageDirectory, coverImage));- if (isCoverLocked && fileExists) return false;- if (forceUpdate) return true;- return (firstFile != null && firstFile.HasFileBeenModified()) || !HasCoverImage(coverImage, fileExists);- }+ if (!_cacheHelper.ShouldUpdateCoverImage(_directoryService.FileSystem.Path.Join(_directoryService.CoverImageDirectory, chapter.CoverImage), firstFile, chapter.Created, forceUpdate, chapter.CoverImageLocked))+ return false;+ if (firstFile == null) return false;- private static bool HasCoverImage(string coverImage)- {- return HasCoverImage(coverImage, File.Exists(coverImage));- }+ _logger.LogDebug("[MetadataService] Generating cover image for {File}", firstFile?.FilePath);+ chapter.CoverImage = _readingItemService.GetCoverImage(firstFile.FilePath, ImageService.GetChapterFormat(chapter.Id, chapter.VolumeId), firstFile.Format);- private static bool HasCoverImage(string coverImage, bool fileExists)- {- return !string.IsNullOrEmpty(coverImage) && fileExists;- }+ return true;+ }- private string GetCoverImage(MangaFile file, int volumeId, int chapterId)- {- file.UpdateLastModified();- switch (file.Format)- {- case MangaFormat.Pdf:- case MangaFormat.Epub:- return _bookService.GetCoverImage(file.FilePath, ImageService.GetChapterFormat(chapterId, volumeId));- case MangaFormat.Image:- var coverImage = _imageService.GetCoverFile(file);- return _imageService.GetCoverImage(coverImage, ImageService.GetChapterFormat(chapterId, volumeId));- case MangaFormat.Archive:- return _archiveService.GetCoverImage(file.FilePath, ImageService.GetChapterFormat(chapterId, volumeId));- default:- return string.Empty;- }+ private void UpdateChapterLastModified(Chapter chapter, bool forceUpdate)+ {+ var firstFile = chapter.Files.OrderBy(x => x.Chapter).FirstOrDefault();+ if (firstFile == null || _cacheHelper.HasFileNotChangedSinceCreationOrLastScan(chapter, forceUpdate, firstFile)) return;- }+ firstFile.UpdateLastModified();+ }- /// <summary>- /// Updates the metadata for a Chapter- /// </summary>- /// <param name="chapter"></param>- /// <param name="forceUpdate">Force updating cover image even if underlying file has not been modified or chapter already has a cover image</param>- public bool UpdateMetadata(Chapter chapter, bool forceUpdate)- {- var firstFile = chapter.Files.OrderBy(x => x.Chapter).FirstOrDefault();+ /// <summary>+ /// Updates the cover image for a Volume+ /// </summary>+ /// <param name="volume"></param>+ /// <param name="forceUpdate">Force updating cover image even if underlying file has not been modified or chapter already has a cover image</param>+ private bool UpdateVolumeCoverImage(Volume volume, bool forceUpdate)+ {+ // We need to check if Volume coverImage matches first chapters if forceUpdate is false+ if (volume == null || !_cacheHelper.ShouldUpdateCoverImage(+ _directoryService.FileSystem.Path.Join(_directoryService.CoverImageDirectory, volume.CoverImage),+ null, volume.Created, forceUpdate)) return false;- if (ShouldUpdateCoverImage(chapter.CoverImage, firstFile, forceUpdate, chapter.CoverImageLocked))- {- _logger.LogDebug("[MetadataService] Generating cover image for {File}", firstFile?.FilePath);- chapter.CoverImage = GetCoverImage(firstFile, chapter.VolumeId, chapter.Id);- return true;- }+ volume.Chapters ??= new List<Chapter>();+ var firstChapter = volume.Chapters.OrderBy(x => double.Parse(x.Number), _chapterSortComparerForInChapterSorting).FirstOrDefault();+ if (firstChapter == null) return false;- return false;- }+ volume.CoverImage = firstChapter.CoverImage;+ return true;+ }- /// <summary>- /// Updates the metadata for a Volume- /// </summary>- /// <param name="volume"></param>- /// <param name="forceUpdate">Force updating cover image even if underlying file has not been modified or chapter already has a cover image</param>- public bool UpdateMetadata(Volume volume, bool forceUpdate)- {- // We need to check if Volume coverImage matches first chapters if forceUpdate is false- if (volume == null || !ShouldUpdateCoverImage(volume.CoverImage, null, forceUpdate)) return false;+ /// <summary>+ /// Updates cover image for Series+ /// </summary>+ /// <param name="series"></param>+ /// <param name="forceUpdate">Force updating cover image even if underlying file has not been modified or chapter already has a cover image</param>+ private void UpdateSeriesCoverImage(Series series, bool forceUpdate)+ {+ if (series == null) return;- volume.Chapters ??= new List<Chapter>();- var firstChapter = volume.Chapters.OrderBy(x => double.Parse(x.Number), _chapterSortComparerForInChapterSorting).FirstOrDefault();- if (firstChapter == null) return false;+ if (!_cacheHelper.ShouldUpdateCoverImage(_directoryService.FileSystem.Path.Join(_directoryService.CoverImageDirectory, series.CoverImage),+ null, series.Created, forceUpdate, series.CoverImageLocked))+ return;- volume.CoverImage = firstChapter.CoverImage;- return true;+ series.Volumes ??= new List<Volume>();+ var firstCover = series.Volumes.GetCoverImage(series.Format);+ string coverImage = null;+ if (firstCover == null && series.Volumes.Any())+ {+ // If firstCover is null and one volume, the whole series is Chapters under Vol 0.+ if (series.Volumes.Count == 1)+ {+ coverImage = series.Volumes[0].Chapters.OrderBy(c => double.Parse(c.Number), _chapterSortComparerForInChapterSorting)+ .FirstOrDefault(c => !c.IsSpecial)?.CoverImage;+ }++ if (!_cacheHelper.CoverImageExists(coverImage))+ {+ coverImage = series.Volumes[0].Chapters.OrderBy(c => double.Parse(c.Number), _chapterSortComparerForInChapterSorting)+ .FirstOrDefault()?.CoverImage;+ }}+ series.CoverImage = firstCover?.CoverImage ?? coverImage;+ }- /// <summary>- /// Updates metadata for Series- /// </summary>- /// <param name="series"></param>- /// <param name="forceUpdate">Force updating cover image even if underlying file has not been modified or chapter already has a cover image</param>- public bool UpdateMetadata(Series series, bool forceUpdate)- {- var madeUpdate = false;- if (series == null) return false;- // NOTE: This will fail if we replace the cover of the first volume on a first scan. Because the series will already have a cover image- if (ShouldUpdateCoverImage(series.CoverImage, null, forceUpdate, series.CoverImageLocked))+ /// <summary>+ ///+ /// </summary>+ /// <param name="series"></param>+ /// <param name="forceUpdate"></param>+ private void ProcessSeriesMetadataUpdate(Series series, ICollection<Person> allPeople, ICollection<Genre> allGenres, ICollection<Tag> allTags, bool forceUpdate)+ {+ _logger.LogDebug("[MetadataService] Processing series {SeriesName}", series.OriginalName);+ try+ {+ var volumeIndex = 0;+ var firstVolumeUpdated = false;+ foreach (var volume in series.Volumes){- series.Volumes ??= new List<Volume>();- var firstCover = series.Volumes.GetCoverImage(series.Format);- string coverImage = null;- if (firstCover == null && series.Volumes.Any())+ var firstChapterUpdated = false; // This only needs to be FirstChapter updated+ var index = 0;+ foreach (var chapter in volume.Chapters){- // If firstCover is null and one volume, the whole series is Chapters under Vol 0.- if (series.Volumes.Count == 1)+ var chapterUpdated = UpdateChapterCoverImage(chapter, forceUpdate);+ // If cover was update, either the file has changed or first scan and we should force a metadata update+ UpdateChapterLastModified(chapter, forceUpdate || chapterUpdated);+ if (index == 0 && chapterUpdated){- coverImage = series.Volumes[0].Chapters.OrderBy(c => double.Parse(c.Number), _chapterSortComparerForInChapterSorting)- .FirstOrDefault(c => !c.IsSpecial)?.CoverImage;- madeUpdate = true;+ firstChapterUpdated = true;}- if (!HasCoverImage(coverImage))- {- coverImage = series.Volumes[0].Chapters.OrderBy(c => double.Parse(c.Number), _chapterSortComparerForInChapterSorting)- .FirstOrDefault()?.CoverImage;- madeUpdate = true;- }+ index++;}- series.CoverImage = firstCover?.CoverImage ?? coverImage;++ var volumeUpdated = UpdateVolumeCoverImage(volume, firstChapterUpdated || forceUpdate);+ if (volumeIndex == 0 && volumeUpdated)+ {+ firstVolumeUpdated = true;+ }+ volumeIndex++;}- return UpdateSeriesSummary(series, forceUpdate) || madeUpdate ;+ UpdateSeriesCoverImage(series, firstVolumeUpdated || forceUpdate);}-- private bool UpdateSeriesSummary(Series series, bool forceUpdate)+ catch (Exception ex){- // NOTE: This can be problematic when the file changes and a summary already exists, but it is likely- // better to let the user kick off a refresh metadata on an individual Series than having overhead of- // checking File last write time.- if (!string.IsNullOrEmpty(series.Summary) && !forceUpdate) return false;-- var isBook = series.Library.Type == LibraryType.Book;- var firstVolume = series.Volumes.FirstWithChapters(isBook);- var firstChapter = firstVolume?.Chapters.GetFirstChapterWithFiles();-- var firstFile = firstChapter?.Files.FirstOrDefault();- if (firstFile == null || (!forceUpdate && !firstFile.HasFileBeenModified())) return false;- if (Parser.Parser.IsPdf(firstFile.FilePath)) return false;-- var comicInfo = GetComicInfo(series.Format, firstFile);- if (string.IsNullOrEmpty(comicInfo?.Summary)) return false;-- series.Summary = comicInfo.Summary;- return true;+ _logger.LogError(ex, "[MetadataService] There was an exception during updating metadata for {SeriesName} ", series.Name);}+ }- private ComicInfo GetComicInfo(MangaFormat format, MangaFile firstFile)- {- if (format is MangaFormat.Archive or MangaFormat.Epub)- {- return Parser.Parser.IsEpub(firstFile.FilePath) ? _bookService.GetComicInfo(firstFile.FilePath) : _archiveService.GetComicInfo(firstFile.FilePath);- }- return null;- }+ /// <summary>+ /// Refreshes Metadata for a whole library+ /// </summary>+ /// <remarks>This can be heavy on memory first run</remarks>+ /// <param name="libraryId"></param>+ /// <param name="forceUpdate">Force updating cover image even if underlying file has not been modified or chapter already has a cover image</param>+ public async Task RefreshMetadata(int libraryId, bool forceUpdate = false)+ {+ var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(libraryId, LibraryIncludes.None);+ _logger.LogInformation("[MetadataService] Beginning metadata refresh of {LibraryName}", library.Name);+ var chunkInfo = await _unitOfWork.SeriesRepository.GetChunkInfo(library.Id);+ var stopwatch = Stopwatch.StartNew();+ var totalTime = 0L;+ _logger.LogInformation("[MetadataService] Refreshing Library {LibraryName}. Total Items: {TotalSize}. Total Chunks: {TotalChunks} with {ChunkSize} size", library.Name, chunkInfo.TotalSize, chunkInfo.TotalChunks, chunkInfo.ChunkSize);+ await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,+ MessageFactory.RefreshMetadataProgressEvent(library.Id, 0F));- /// <summary>- /// Refreshes Metadata for a whole library- /// </summary>- /// <remarks>This can be heavy on memory first run</remarks>- /// <param name="libraryId"></param>- /// <param name="forceUpdate">Force updating cover image even if underlying file has not been modified or chapter already has a cover image</param>- public async Task RefreshMetadata(int libraryId, bool forceUpdate = false)+ for (var chunk = 1; chunk <= chunkInfo.TotalChunks; chunk++){- var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(libraryId, LibraryIncludes.None);- _logger.LogInformation("[MetadataService] Beginning metadata refresh of {LibraryName}", library.Name);-- var chunkInfo = await _unitOfWork.SeriesRepository.GetChunkInfo(library.Id);- var stopwatch = Stopwatch.StartNew();- var totalTime = 0L;- _logger.LogInformation("[MetadataService] Refreshing Library {LibraryName}. Total Items: {TotalSize}. Total Chunks: {TotalChunks} with {ChunkSize} size", library.Name, chunkInfo.TotalSize, chunkInfo.TotalChunks, chunkInfo.ChunkSize);- await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,- MessageFactory.RefreshMetadataProgressEvent(library.Id, 0F));-- var i = 0;- for (var chunk = 1; chunk <= chunkInfo.TotalChunks; chunk++, i++)- {- if (chunkInfo.TotalChunks == 0) continue;- totalTime += stopwatch.ElapsedMilliseconds;- stopwatch.Restart();- _logger.LogInformation("[MetadataService] Processing chunk {ChunkNumber} / {TotalChunks} with size {ChunkSize}. Series ({SeriesStart} - {SeriesEnd}",- chunk, chunkInfo.TotalChunks, chunkInfo.ChunkSize, chunk * chunkInfo.ChunkSize, (chunk + 1) * chunkInfo.ChunkSize);-- var nonLibrarySeries = await _unitOfWork.SeriesRepository.GetFullSeriesForLibraryIdAsync(library.Id,- new UserParams()- {- PageNumber = chunk,- PageSize = chunkInfo.ChunkSize- });- _logger.LogDebug("[MetadataService] Fetched {SeriesCount} series for refresh", nonLibrarySeries.Count);+ if (chunkInfo.TotalChunks == 0) continue;+ totalTime += stopwatch.ElapsedMilliseconds;+ stopwatch.Restart();++ _logger.LogInformation("[MetadataService] Processing chunk {ChunkNumber} / {TotalChunks} with size {ChunkSize}. Series ({SeriesStart} - {SeriesEnd}",+ chunk, chunkInfo.TotalChunks, chunkInfo.ChunkSize, chunk * chunkInfo.ChunkSize, (chunk + 1) * chunkInfo.ChunkSize);- Parallel.ForEach(nonLibrarySeries, series =>+ var nonLibrarySeries = await _unitOfWork.SeriesRepository.GetFullSeriesForLibraryIdAsync(library.Id,+ new UserParams(){- try- {- _logger.LogDebug("[MetadataService] Processing series {SeriesName}", series.OriginalName);- var volumeUpdated = false;- foreach (var volume in series.Volumes)- {- var chapterUpdated = false;- foreach (var chapter in volume.Chapters)- {- chapterUpdated = UpdateMetadata(chapter, forceUpdate);- }-- volumeUpdated = UpdateMetadata(volume, chapterUpdated || forceUpdate);- }-- UpdateMetadata(series, volumeUpdated || forceUpdate);- }- catch (Exception)- {- /* Swallow exception */- }+ PageNumber = chunk,+ PageSize = chunkInfo.ChunkSize});+ _logger.LogDebug("[MetadataService] Fetched {SeriesCount} series for refresh", nonLibrarySeries.Count);- if (_unitOfWork.HasChanges() && await _unitOfWork.CommitAsync())- {- _logger.LogInformation(- "[MetadataService] Processed {SeriesStart} - {SeriesEnd} out of {TotalSeries} series in {ElapsedScanTime} milliseconds for {LibraryName}",- chunk * chunkInfo.ChunkSize, (chunk * chunkInfo.ChunkSize) + nonLibrarySeries.Count, chunkInfo.TotalSize, stopwatch.ElapsedMilliseconds, library.Name);+ var allPeople = await _unitOfWork.PersonRepository.GetAllPeople();+ var allGenres = await _unitOfWork.GenreRepository.GetAllGenresAsync();+ var allTags = await _unitOfWork.TagRepository.GetAllTagsAsync();- foreach (var series in nonLibrarySeries)- {- await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadata, MessageFactory.RefreshMetadataEvent(library.Id, series.Id));- }++ var seriesIndex = 0;+ foreach (var series in nonLibrarySeries)+ {+ try+ {+ ProcessSeriesMetadataUpdate(series, allPeople, allGenres, allTags, forceUpdate);}- else+ catch (Exception ex){- _logger.LogInformation(- "[MetadataService] Processed {SeriesStart} - {SeriesEnd} out of {TotalSeries} series in {ElapsedScanTime} milliseconds for {LibraryName}",- chunk * chunkInfo.ChunkSize, (chunk * chunkInfo.ChunkSize) + nonLibrarySeries.Count, chunkInfo.TotalSize, stopwatch.ElapsedMilliseconds, library.Name);+ _logger.LogError(ex, "[MetadataService] There was an exception during metadata refresh for {SeriesName}", series.Name);}- var progress = Math.Max(0F, Math.Min(1F, i * 1F / chunkInfo.TotalChunks));+ var index = chunk * seriesIndex;+ var progress = Math.Max(0F, Math.Min(1F, index * 1F / chunkInfo.TotalSize));+await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,MessageFactory.RefreshMetadataProgressEvent(library.Id, progress));+ seriesIndex++;+ }++ await _unitOfWork.CommitAsync();+ foreach (var series in nonLibrarySeries)+ {+ await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadata, MessageFactory.RefreshMetadataEvent(library.Id, series.Id));}+ _logger.LogInformation(+ "[MetadataService] Processed {SeriesStart} - {SeriesEnd} out of {TotalSeries} series in {ElapsedScanTime} milliseconds for {LibraryName}",+ chunk * chunkInfo.ChunkSize, (chunk * chunkInfo.ChunkSize) + nonLibrarySeries.Count, chunkInfo.TotalSize, stopwatch.ElapsedMilliseconds, library.Name);+ }++ await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,+ MessageFactory.RefreshMetadataProgressEvent(library.Id, 1F));- await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,- MessageFactory.RefreshMetadataProgressEvent(library.Id, 1F));+ await RemoveAbandonedMetadataKeys();- _logger.LogInformation("[MetadataService] Updated metadata for {SeriesNumber} series in library {LibraryName} in {ElapsedMilliseconds} milliseconds total", chunkInfo.TotalSize, library.Name, totalTime);++ _logger.LogInformation("[MetadataService] Updated metadata for {SeriesNumber} series in library {LibraryName} in {ElapsedMilliseconds} milliseconds total", chunkInfo.TotalSize, library.Name, totalTime);+ }++ private async Task RemoveAbandonedMetadataKeys()+ {+ await _unitOfWork.TagRepository.RemoveAllTagNoLongerAssociated();+ await _unitOfWork.PersonRepository.RemoveAllPeopleNoLongerAssociated();+ await _unitOfWork.GenreRepository.RemoveAllGenreNoLongerAssociated();+ }++ // TODO: I can probably refactor RefreshMetadata and RefreshMetadataForSeries to be the same by utilizing chunk size of 1, so most of the code can be the same.+ private async Task PerformScan(Library library, bool forceUpdate, Action<int, Chunk> action)+ {+ var chunkInfo = await _unitOfWork.SeriesRepository.GetChunkInfo(library.Id);+ var stopwatch = Stopwatch.StartNew();+ var totalTime = 0L;+ _logger.LogInformation("[MetadataService] Refreshing Library {LibraryName}. Total Items: {TotalSize}. Total Chunks: {TotalChunks} with {ChunkSize} size", library.Name, chunkInfo.TotalSize, chunkInfo.TotalChunks, chunkInfo.ChunkSize);+ await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,+ MessageFactory.RefreshMetadataProgressEvent(library.Id, 0F));++ for (var chunk = 1; chunk <= chunkInfo.TotalChunks; chunk++)+ {+ if (chunkInfo.TotalChunks == 0) continue;+ totalTime += stopwatch.ElapsedMilliseconds;+ stopwatch.Restart();++ action(chunk, chunkInfo);++ // _logger.LogInformation("[MetadataService] Processing chunk {ChunkNumber} / {TotalChunks} with size {ChunkSize}. Series ({SeriesStart} - {SeriesEnd}",+ // chunk, chunkInfo.TotalChunks, chunkInfo.ChunkSize, chunk * chunkInfo.ChunkSize, (chunk + 1) * chunkInfo.ChunkSize);+ // var nonLibrarySeries = await _unitOfWork.SeriesRepository.GetFullSeriesForLibraryIdAsync(library.Id,+ // new UserParams()+ // {+ // PageNumber = chunk,+ // PageSize = chunkInfo.ChunkSize+ // });+ // _logger.LogDebug("[MetadataService] Fetched {SeriesCount} series for refresh", nonLibrarySeries.Count);+ //+ // var chapterIds = await _unitOfWork.SeriesRepository.GetChapterIdWithSeriesIdForSeriesAsync(nonLibrarySeries.Select(s => s.Id).ToArray());+ // var allPeople = await _unitOfWork.PersonRepository.GetAllPeople();+ // var allGenres = await _unitOfWork.GenreRepository.GetAllGenres();+ //+ //+ // var seriesIndex = 0;+ // foreach (var series in nonLibrarySeries)+ // {+ // try+ // {+ // ProcessSeriesMetadataUpdate(series, chapterIds, allPeople, allGenres, forceUpdate);+ // }+ // catch (Exception ex)+ // {+ // _logger.LogError(ex, "[MetadataService] There was an exception during metadata refresh for {SeriesName}", series.Name);+ // }+ // var index = chunk * seriesIndex;+ // var progress = Math.Max(0F, Math.Min(1F, index * 1F / chunkInfo.TotalSize));+ //+ // await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,+ // MessageFactory.RefreshMetadataProgressEvent(library.Id, progress));+ // seriesIndex++;+ // }++ await _unitOfWork.CommitAsync();}+ }+- /// <summary>- /// Refreshes Metadata for a Series. Will always force updates.- /// </summary>- /// <param name="libraryId"></param>- /// <param name="seriesId"></param>- public async Task RefreshMetadataForSeries(int libraryId, int seriesId, bool forceUpdate = false)+ /// <summary>+ /// Refreshes Metadata for a Series. Will always force updates.+ /// </summary>+ /// <param name="libraryId"></param>+ /// <param name="seriesId"></param>+ public async Task RefreshMetadataForSeries(int libraryId, int seriesId, bool forceUpdate = true)+ {+ var sw = Stopwatch.StartNew();+ var series = await _unitOfWork.SeriesRepository.GetFullSeriesForSeriesIdAsync(seriesId);+ if (series == null){- var sw = Stopwatch.StartNew();- var series = await _unitOfWork.SeriesRepository.GetFullSeriesForSeriesIdAsync(seriesId);- if (series == null)- {- _logger.LogError("[MetadataService] Series {SeriesId} was not found on Library {LibraryId}", seriesId, libraryId);- return;- }- _logger.LogInformation("[MetadataService] Beginning metadata refresh of {SeriesName}", series.Name);- var volumeUpdated = false;- foreach (var volume in series.Volumes)- {- var chapterUpdated = false;- foreach (var chapter in volume.Chapters)- {- chapterUpdated = UpdateMetadata(chapter, forceUpdate);- }+ _logger.LogError("[MetadataService] Series {SeriesId} was not found on Library {LibraryId}", seriesId, libraryId);+ return;+ }- volumeUpdated = UpdateMetadata(volume, chapterUpdated || forceUpdate);- }+ await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,+ MessageFactory.RefreshMetadataProgressEvent(libraryId, 0F));- UpdateMetadata(series, volumeUpdated || forceUpdate);+ var allPeople = await _unitOfWork.PersonRepository.GetAllPeople();+ var allGenres = await _unitOfWork.GenreRepository.GetAllGenresAsync();+ var allTags = await _unitOfWork.TagRepository.GetAllTagsAsync();+ ProcessSeriesMetadataUpdate(series, allPeople, allGenres, allTags, forceUpdate);++ await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadataProgress,+ MessageFactory.RefreshMetadataProgressEvent(libraryId, 1F));- if (_unitOfWork.HasChanges() && await _unitOfWork.CommitAsync())- {- await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadata, MessageFactory.RefreshMetadataEvent(series.LibraryId, series.Id));- }- _logger.LogInformation("[MetadataService] Updated metadata for {SeriesName} in {ElapsedMilliseconds} milliseconds", series.Name, sw.ElapsedMilliseconds);+ if (_unitOfWork.HasChanges() && await _unitOfWork.CommitAsync())+ {+ await _messageHub.Clients.All.SendAsync(SignalREvents.RefreshMetadata, MessageFactory.RefreshMetadataEvent(series.LibraryId, series.Id));}++ await RemoveAbandonedMetadataKeys();++ _logger.LogInformation("[MetadataService] Updated metadata for {SeriesName} in {ElapsedMilliseconds} milliseconds", series.Name, sw.ElapsedMilliseconds);}}diff --git a/API/Services/ReaderService.cs b/API/Services/ReaderService.csnew file mode 100644index 000000000..b9862cf05--- /dev/null+++ b/API/Services/ReaderService.cs@@ -0,0 +1,326 @@+using System;+using System.Collections.Generic;+using System.IO;+using System.Linq;+using System.Threading.Tasks;+using API.Comparators;+using API.Data;+using API.Data.Repositories;+using API.DTOs;+using API.Entities;+using API.Extensions;+using Kavita.Common;+using Microsoft.Extensions.Logging;++namespace API.Services;++public interface IReaderService+{+ void MarkChaptersAsRead(AppUser user, int seriesId, IEnumerable<Chapter> chapters);+ void MarkChaptersAsUnread(AppUser user, int seriesId, IEnumerable<Chapter> chapters);+ Task<bool> SaveReadingProgress(ProgressDto progressDto, int userId);+ Task<int> CapPageToChapter(int chapterId, int page);+ Task<int> GetNextChapterIdAsync(int seriesId, int volumeId, int currentChapterId, int userId);+ Task<int> GetPrevChapterIdAsync(int seriesId, int volumeId, int currentChapterId, int userId);+}++public class ReaderService : IReaderService+{+ private readonly IUnitOfWork _unitOfWork;+ private readonly ILogger<ReaderService> _logger;+ private readonly IDirectoryService _directoryService;+ private readonly ICacheService _cacheService;+ private readonly ChapterSortComparer _chapterSortComparer = new ChapterSortComparer();+ private readonly ChapterSortComparerZeroFirst _chapterSortComparerForInChapterSorting = new ChapterSortComparerZeroFirst();++ public ReaderService(IUnitOfWork unitOfWork, ILogger<ReaderService> logger, IDirectoryService directoryService, ICacheService cacheService)+ {+ _unitOfWork = unitOfWork;+ _logger = logger;+ _directoryService = directoryService;+ _cacheService = cacheService;+ }++ public static string FormatBookmarkFolderPath(string baseDirectory, int userId, int seriesId, int chapterId)+ {+ return Parser.Parser.NormalizePath(Path.Join(baseDirectory, $"{userId}", $"{seriesId}", $"{chapterId}"));+ }++ /// <summary>+ /// Marks all Chapters as Read by creating or updating UserProgress rows. Does not commit.+ /// </summary>+ /// <param name="user"></param>+ /// <param name="seriesId"></param>+ /// <param name="chapters"></param>+ public void MarkChaptersAsRead(AppUser user, int seriesId, IEnumerable<Chapter> chapters)+ {+ foreach (var chapter in chapters)+ {+ var userProgress = GetUserProgressForChapter(user, chapter);++ if (userProgress == null)+ {+ user.Progresses.Add(new AppUserProgress+ {+ PagesRead = chapter.Pages,+ VolumeId = chapter.VolumeId,+ SeriesId = seriesId,+ ChapterId = chapter.Id+ });+ }+ else+ {+ userProgress.PagesRead = chapter.Pages;+ userProgress.SeriesId = seriesId;+ userProgress.VolumeId = chapter.VolumeId;+ }+ }+ }++ /// <summary>+ /// Marks all Chapters as Unread by creating or updating UserProgress rows. Does not commit.+ /// </summary>+ /// <param name="user"></param>+ /// <param name="seriesId"></param>+ /// <param name="chapters"></param>+ public void MarkChaptersAsUnread(AppUser user, int seriesId, IEnumerable<Chapter> chapters)+ {+ foreach (var chapter in chapters)+ {+ var userProgress = GetUserProgressForChapter(user, chapter);++ if (userProgress == null) continue;++ userProgress.PagesRead = 0;+ userProgress.SeriesId = seriesId;+ userProgress.VolumeId = chapter.VolumeId;+ }+ }++ /// <summary>+ /// Gets the User Progress for a given Chapter. This will handle any duplicates that might have occured in past versions and will delete them. Does not commit.+ /// </summary>+ /// <param name="user">Must have Progresses populated</param>+ /// <param name="chapter"></param>+ /// <returns></returns>+ private static AppUserProgress GetUserProgressForChapter(AppUser user, Chapter chapter)+ {+ AppUserProgress userProgress = null;++ if (user.Progresses == null)+ {+ throw new KavitaException("Progresses must exist on user");+ }+ try+ {+ userProgress =+ user.Progresses.SingleOrDefault(x => x.ChapterId == chapter.Id && x.AppUserId == user.Id);+ }+ catch (Exception)+ {+ // There is a very rare chance that user progress will duplicate current row. If that happens delete one with less pages+ var progresses = user.Progresses.Where(x => x.ChapterId == chapter.Id && x.AppUserId == user.Id).ToList();+ if (progresses.Count > 1)+ {+ user.Progresses = new List<AppUserProgress>()+ {+ user.Progresses.First()+ };+ userProgress = user.Progresses.First();+ }+ }++ return userProgress;+ }++ /// <summary>+ /// Saves progress to DB+ /// </summary>+ /// <param name="progressDto"></param>+ /// <param name="userId"></param>+ /// <returns></returns>+ public async Task<bool> SaveReadingProgress(ProgressDto progressDto, int userId)+ {+ // Don't let user save past total pages.+ progressDto.PageNum = await CapPageToChapter(progressDto.ChapterId, progressDto.PageNum);++ try+ {+ var userProgress =+ await _unitOfWork.AppUserProgressRepository.GetUserProgressAsync(progressDto.ChapterId, userId);++ if (userProgress == null)+ {+ // Create a user object+ var userWithProgress =+ await _unitOfWork.UserRepository.GetUserByIdAsync(userId, AppUserIncludes.Progress);+ userWithProgress.Progresses ??= new List<AppUserProgress>();+ userWithProgress.Progresses.Add(new AppUserProgress+ {+ PagesRead = progressDto.PageNum,+ VolumeId = progressDto.VolumeId,+ SeriesId = progressDto.SeriesId,+ ChapterId = progressDto.ChapterId,+ BookScrollId = progressDto.BookScrollId,+ LastModified = DateTime.Now+ });+ _unitOfWork.UserRepository.Update(userWithProgress);+ }+ else+ {+ userProgress.PagesRead = progressDto.PageNum;+ userProgress.SeriesId = progressDto.SeriesId;+ userProgress.VolumeId = progressDto.VolumeId;+ userProgress.BookScrollId = progressDto.BookScrollId;+ userProgress.LastModified = DateTime.Now;+ _unitOfWork.AppUserProgressRepository.Update(userProgress);+ }++ if (await _unitOfWork.CommitAsync())+ {+ return true;+ }+ }+ catch (Exception exception)+ {+ _logger.LogError(exception, "Could not save progress");+ await _unitOfWork.RollbackAsync();+ }++ return false;+ }++ /// <summary>+ /// Ensures that the page is within 0 and total pages for a chapter. Makes one DB call.+ /// </summary>+ /// <param name="chapterId"></param>+ /// <param name="page"></param>+ /// <returns></returns>+ public async Task<int> CapPageToChapter(int chapterId, int page)+ {+ var totalPages = await _unitOfWork.ChapterRepository.GetChapterTotalPagesAsync(chapterId);+ if (page > totalPages)+ {+ page = totalPages;+ }++ if (page < 0)+ {+ page = 0;+ }++ return page;+ }++ /// <summary>+ /// Tries to find the next logical Chapter+ /// </summary>+ /// <example>+ /// V1 → V2 → V3 chapter 0 → V3 chapter 10 → SP 01 → SP 02+ /// </example>+ /// <param name="seriesId"></param>+ /// <param name="volumeId"></param>+ /// <param name="currentChapterId"></param>+ /// <param name="userId"></param>+ /// <returns>-1 if nothing can be found</returns>+ public async Task<int> GetNextChapterIdAsync(int seriesId, int volumeId, int currentChapterId, int userId)+ {+ var volumes = (await _unitOfWork.VolumeRepository.GetVolumesDtoAsync(seriesId, userId)).ToList();+ var currentVolume = volumes.Single(v => v.Id == volumeId);+ var currentChapter = currentVolume.Chapters.Single(c => c.Id == currentChapterId);++ if (currentVolume.Number == 0)+ {+ // Handle specials by sorting on their Filename aka Range+ var chapterId = GetNextChapterId(currentVolume.Chapters.OrderByNatural(x => x.Range), currentChapter.Number);+ if (chapterId > 0) return chapterId;+ }++ foreach (var volume in volumes)+ {+ if (volume.Number == currentVolume.Number && volume.Chapters.Count > 1)+ {+ // Handle Chapters within current Volume+ // In this case, i need 0 first because 0 represents a full volume file.+ var chapterId = GetNextChapterId(currentVolume.Chapters.OrderBy(x => double.Parse(x.Number), _chapterSortComparerForInChapterSorting), currentChapter.Number);+ if (chapterId > 0) return chapterId;+ }++ if (volume.Number != currentVolume.Number + 1) continue;++ // Handle Chapters within next Volume+ // ! When selecting the chapter for the next volume, we need to make sure a c0 comes before a c1++ var chapters = volume.Chapters.OrderBy(x => double.Parse(x.Number), _chapterSortComparer).ToList();+ if (currentChapter.Number.Equals("0") && chapters.Last().Number.Equals("0"))+ {+ return chapters.Last().Id;+ }++ var firstChapter = chapters.FirstOrDefault();+ if (firstChapter == null) return -1;+ return firstChapter.Id;++ }++ return -1;+ }+ /// <summary>+ /// Tries to find the prev logical Chapter+ /// </summary>+ /// <example>+ /// V1 ← V2 ← V3 chapter 0 ← V3 chapter 10 ← SP 01 ← SP 02+ /// </example>+ /// <param name="seriesId"></param>+ /// <param name="volumeId"></param>+ /// <param name="currentChapterId"></param>+ /// <param name="userId"></param>+ /// <returns>-1 if nothing can be found</returns>+ public async Task<int> GetPrevChapterIdAsync(int seriesId, int volumeId, int currentChapterId, int userId)+ {+ var volumes = (await _unitOfWork.VolumeRepository.GetVolumesDtoAsync(seriesId, userId)).Reverse().ToList();+ var currentVolume = volumes.Single(v => v.Id == volumeId);+ var currentChapter = currentVolume.Chapters.Single(c => c.Id == currentChapterId);++ if (currentVolume.Number == 0)+ {+ var chapterId = GetNextChapterId(currentVolume.Chapters.OrderByNatural(x => x.Range).Reverse(), currentChapter.Number);+ if (chapterId > 0) return chapterId;+ }++ foreach (var volume in volumes)+ {+ if (volume.Number == currentVolume.Number)+ {+ var chapterId = GetNextChapterId(currentVolume.Chapters.OrderBy(x => double.Parse(x.Number), _chapterSortComparerForInChapterSorting).Reverse(), currentChapter.Number);+ if (chapterId > 0) return chapterId;+ }+ if (volume.Number == currentVolume.Number - 1)+ {+ var lastChapter = volume.Chapters+ .OrderBy(x => double.Parse(x.Number), _chapterSortComparerForInChapterSorting).LastOrDefault();+ if (lastChapter == null) return -1;+ return lastChapter.Id;+ }+ }+ return -1;+ }+++ private static int GetNextChapterId(IEnumerable<ChapterDto> chapters, string currentChapterNumber)+ {+ var next = false;+ var chaptersList = chapters.ToList();+ foreach (var chapter in chaptersList)+ {+ if (next)+ {+ return chapter.Id;+ }+ if (currentChapterNumber.Equals(chapter.Number)) next = true;+ }++ return -1;+ }+++}diff --git a/API/Services/ReadingItemService.cs b/API/Services/ReadingItemService.csnew file mode 100644index 000000000..d791efd55--- /dev/null+++ b/API/Services/ReadingItemService.cs@@ -0,0 +1,141 @@+using System;+using API.Data.Metadata;+using API.Entities.Enums;+using API.Parser;++namespace API.Services;++public interface IReadingItemService+{+ ComicInfo GetComicInfo(string filePath);+ int GetNumberOfPages(string filePath, MangaFormat format);+ string GetCoverImage(string filePath, string fileName, MangaFormat format);+ void Extract(string fileFilePath, string targetDirectory, MangaFormat format, int imageCount = 1);+ ParserInfo Parse(string path, string rootPath, LibraryType type);+}++public class ReadingItemService : IReadingItemService+{+ private readonly IArchiveService _archiveService;+ private readonly IBookService _bookService;+ private readonly IImageService _imageService;+ private readonly IDirectoryService _directoryService;+ private readonly DefaultParser _defaultParser;++ public ReadingItemService(IArchiveService archiveService, IBookService bookService, IImageService imageService, IDirectoryService directoryService)+ {+ _archiveService = archiveService;+ _bookService = bookService;+ _imageService = imageService;+ _directoryService = directoryService;++ _defaultParser = new DefaultParser(directoryService);+ }++ /// <summary>+ /// Gets the ComicInfo for the file if it exists. Null otherewise.+ /// </summary>+ /// <param name="filePath">Fully qualified path of file</param>+ /// <returns></returns>+ public ComicInfo? GetComicInfo(string filePath)+ {+ if (Parser.Parser.IsEpub(filePath))+ {+ return _bookService.GetComicInfo(filePath);+ }++ if (Parser.Parser.IsComicInfoExtension(filePath))+ {+ return _archiveService.GetComicInfo(filePath);+ }++ return null;+ }++ /// <summary>+ ///+ /// </summary>+ /// <param name="filePath"></param>+ /// <param name="format"></param>+ /// <returns></returns>+ public int GetNumberOfPages(string filePath, MangaFormat format)+ {+ switch (format)+ {+ case MangaFormat.Archive:+ {+ return _archiveService.GetNumberOfPagesFromArchive(filePath);+ }+ case MangaFormat.Pdf:+ case MangaFormat.Epub:+ {+ return _bookService.GetNumberOfPages(filePath);+ }+ case MangaFormat.Image:+ {+ return 1;+ }+ case MangaFormat.Unknown:+ default:+ return 0;+ }+ }++ public string GetCoverImage(string filePath, string fileName, MangaFormat format)+ {+ if (string.IsNullOrEmpty(filePath) || string.IsNullOrEmpty(fileName))+ {+ return string.Empty;+ }++ return format switch+ {+ MangaFormat.Epub => _bookService.GetCoverImage(filePath, fileName, _directoryService.CoverImageDirectory),+ MangaFormat.Archive => _archiveService.GetCoverImage(filePath, fileName, _directoryService.CoverImageDirectory),+ MangaFormat.Image => _imageService.GetCoverImage(filePath, fileName, _directoryService.CoverImageDirectory),+ MangaFormat.Pdf => _bookService.GetCoverImage(filePath, fileName, _directoryService.CoverImageDirectory),+ _ => string.Empty+ };+ }++ /// <summary>+ /// Extracts the reading item to the target directory using the appropriate method+ /// </summary>+ /// <param name="fileFilePath">File to extract</param>+ /// <param name="targetDirectory">Where to extract to. Will be created if does not exist</param>+ /// <param name="format">Format of the File</param>+ /// <param name="imageCount">If the file is of type image, pass number of files needed. If > 0, will copy the whole directory.</param>+ /// <exception cref="ArgumentOutOfRangeException"></exception>+ public void Extract(string fileFilePath, string targetDirectory, MangaFormat format, int imageCount = 1)+ {+ switch (format)+ {+ case MangaFormat.Pdf:+ _bookService.ExtractPdfImages(fileFilePath, targetDirectory);+ break;+ case MangaFormat.Archive:+ _archiveService.ExtractArchive(fileFilePath, targetDirectory);+ break;+ case MangaFormat.Image:+ _imageService.ExtractImages(fileFilePath, targetDirectory, imageCount);+ break;+ case MangaFormat.Unknown:+ case MangaFormat.Epub:+ break;+ default:+ throw new ArgumentOutOfRangeException(nameof(format), format, null);+ }+ }++ /// <summary>+ /// Parses information out of a file. If file is a book (epub), it will use book metadata regardless of LibraryType+ /// </summary>+ /// <param name="path"></param>+ /// <param name="rootPath"></param>+ /// <param name="type"></param>+ /// <returns></returns>+ public ParserInfo Parse(string path, string rootPath, LibraryType type)+ {+ return Parser.Parser.IsEpub(path) ? _bookService.ParseInfo(path) : _defaultParser.Parse(path, rootPath, type);+ }+}diff --git a/API/Services/TaskScheduler.cs b/API/Services/TaskScheduler.csindex 77c745535..9f91bf75c 100644--- a/API/Services/TaskScheduler.cs+++ b/API/Services/TaskScheduler.cs@@ -1,178 +1,187 @@using System;-using System.IO;using System.Threading;using System.Threading.Tasks;+using API.Data;using API.Entities.Enums;using API.Helpers.Converters;-using API.Interfaces;-using API.Interfaces.Services;+using API.Services.Tasks;using Hangfire;using Microsoft.Extensions.Logging;-namespace API.Services+namespace API.Services;++public interface ITaskScheduler+{+ Task ScheduleTasks();+ Task ScheduleStatsTasks();+ void ScheduleUpdaterTasks();+ void ScanLibrary(int libraryId, bool forceUpdate = false);+ void CleanupChapters(int[] chapterIds);+ void RefreshMetadata(int libraryId, bool forceUpdate = true);+ void RefreshSeriesMetadata(int libraryId, int seriesId, bool forceUpdate = false);+ void ScanSeries(int libraryId, int seriesId, bool forceUpdate = false);+ void CancelStatsTasks();+ Task RunStatCollection();+}+public class TaskScheduler : ITaskScheduler{- public class TaskScheduler : ITaskScheduler+ private readonly ICacheService _cacheService;+ private readonly ILogger<TaskScheduler> _logger;+ private readonly IScannerService _scannerService;+ private readonly IUnitOfWork _unitOfWork;+ private readonly IMetadataService _metadataService;+ private readonly IBackupService _backupService;+ private readonly ICleanupService _cleanupService;++ private readonly IStatsService _statsService;+ private readonly IVersionUpdaterService _versionUpdaterService;+ private readonly IDirectoryService _directoryService;++ public static BackgroundJobServer Client => new BackgroundJobServer();+ private static readonly Random Rnd = new Random();+++ public TaskScheduler(ICacheService cacheService, ILogger<TaskScheduler> logger, IScannerService scannerService,+ IUnitOfWork unitOfWork, IMetadataService metadataService, IBackupService backupService,+ ICleanupService cleanupService, IStatsService statsService, IVersionUpdaterService versionUpdaterService,+ IDirectoryService directoryService){- private readonly ICacheService _cacheService;- private readonly ILogger<TaskScheduler> _logger;- private readonly IScannerService _scannerService;- private readonly IUnitOfWork _unitOfWork;- private readonly IMetadataService _metadataService;- private readonly IBackupService _backupService;- private readonly ICleanupService _cleanupService;-- private readonly IStatsService _statsService;- private readonly IVersionUpdaterService _versionUpdaterService;-- public static BackgroundJobServer Client => new BackgroundJobServer();- private static readonly Random Rnd = new Random();+ _cacheService = cacheService;+ _logger = logger;+ _scannerService = scannerService;+ _unitOfWork = unitOfWork;+ _metadataService = metadataService;+ _backupService = backupService;+ _cleanupService = cleanupService;+ _statsService = statsService;+ _versionUpdaterService = versionUpdaterService;+ _directoryService = directoryService;+ }+ public async Task ScheduleTasks()+ {+ _logger.LogInformation("Scheduling reoccurring tasks");- public TaskScheduler(ICacheService cacheService, ILogger<TaskScheduler> logger, IScannerService scannerService,- IUnitOfWork unitOfWork, IMetadataService metadataService, IBackupService backupService,- ICleanupService cleanupService, IStatsService statsService, IVersionUpdaterService versionUpdaterService)+ var setting = (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.TaskScan)).Value;+ if (setting != null){- _cacheService = cacheService;- _logger = logger;- _scannerService = scannerService;- _unitOfWork = unitOfWork;- _metadataService = metadataService;- _backupService = backupService;- _cleanupService = cleanupService;- _statsService = statsService;- _versionUpdaterService = versionUpdaterService;+ var scanLibrarySetting = setting;+ _logger.LogDebug("Scheduling Scan Library Task for {Setting}", scanLibrarySetting);+ RecurringJob.AddOrUpdate("scan-libraries", () => _scannerService.ScanLibraries(),+ () => CronConverter.ConvertToCronNotation(scanLibrarySetting), TimeZoneInfo.Local);}-- public void ScheduleTasks()+ else{- _logger.LogInformation("Scheduling reoccurring tasks");-- var setting = Task.Run(() => _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.TaskScan)).GetAwaiter().GetResult().Value;- if (setting != null)- {- var scanLibrarySetting = setting;- _logger.LogDebug("Scheduling Scan Library Task for {Setting}", scanLibrarySetting);- RecurringJob.AddOrUpdate("scan-libraries", () => _scannerService.ScanLibraries(),- () => CronConverter.ConvertToCronNotation(scanLibrarySetting), TimeZoneInfo.Local);- }- else- {- RecurringJob.AddOrUpdate("scan-libraries", () => _scannerService.ScanLibraries(), Cron.Daily, TimeZoneInfo.Local);- }-- setting = Task.Run(() => _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.TaskBackup)).Result.Value;- if (setting != null)- {- _logger.LogDebug("Scheduling Backup Task for {Setting}", setting);- RecurringJob.AddOrUpdate("backup", () => _backupService.BackupDatabase(), () => CronConverter.ConvertToCronNotation(setting), TimeZoneInfo.Local);- }- else- {- RecurringJob.AddOrUpdate("backup", () => _backupService.BackupDatabase(), Cron.Weekly, TimeZoneInfo.Local);- }-- RecurringJob.AddOrUpdate("cleanup", () => _cleanupService.Cleanup(), Cron.Daily, TimeZoneInfo.Local);-+ RecurringJob.AddOrUpdate("scan-libraries", () => _scannerService.ScanLibraries(), Cron.Daily, TimeZoneInfo.Local);}- #region StatsTasks--- public async Task ScheduleStatsTasks()+ setting = (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.TaskBackup)).Value;+ if (setting != null){- var allowStatCollection = (await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).AllowStatCollection;- if (!allowStatCollection)- {- _logger.LogDebug("User has opted out of stat collection, not registering tasks");- return;- }-- _logger.LogDebug("Scheduling stat collection daily");- RecurringJob.AddOrUpdate("report-stats", () => _statsService.Send(), Cron.Daily(Rnd.Next(0, 22)), TimeZoneInfo.Local);+ _logger.LogDebug("Scheduling Backup Task for {Setting}", setting);+ RecurringJob.AddOrUpdate("backup", () => _backupService.BackupDatabase(), () => CronConverter.ConvertToCronNotation(setting), TimeZoneInfo.Local);}-- public void CancelStatsTasks()+ else{- _logger.LogDebug("Cancelling/Removing StatsTasks");-- RecurringJob.RemoveIfExists("report-stats");+ RecurringJob.AddOrUpdate("backup", () => _backupService.BackupDatabase(), Cron.Weekly, TimeZoneInfo.Local);}- /// <summary>- /// First time run stat collection. Executes immediately on a background thread. Does not block.- /// </summary>- public async Task RunStatCollection()- {- var allowStatCollection = (await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).AllowStatCollection;- if (!allowStatCollection)- {- _logger.LogDebug("User has opted out of stat collection, not sending stats");- return;- }- BackgroundJob.Enqueue(() => _statsService.Send());- }+ RecurringJob.AddOrUpdate("cleanup", () => _cleanupService.Cleanup(), Cron.Daily, TimeZoneInfo.Local);+ RecurringJob.AddOrUpdate("cleanup-db", () => _cleanupService.CleanupDbEntries(), Cron.Daily, TimeZoneInfo.Local);+ }- #endregion+ #region StatsTasks- #region UpdateTasks- public void ScheduleUpdaterTasks()+ public async Task ScheduleStatsTasks()+ {+ var allowStatCollection = (await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).AllowStatCollection;+ if (!allowStatCollection){- _logger.LogInformation("Scheduling Auto-Update tasks");- // Schedule update check between noon and 6pm local time- RecurringJob.AddOrUpdate("check-updates", () => _versionUpdaterService.CheckForUpdate(), Cron.Daily(Rnd.Next(12, 18)), TimeZoneInfo.Local);+ _logger.LogDebug("User has opted out of stat collection, not registering tasks");+ return;}- #endregion- public void ScanLibrary(int libraryId, bool forceUpdate = false)- {- _logger.LogInformation("Enqueuing library scan for: {LibraryId}", libraryId);- BackgroundJob.Enqueue(() => _scannerService.ScanLibrary(libraryId));- // When we do a scan, force cache to re-unpack in case page numbers change- BackgroundJob.Enqueue(() => _cleanupService.CleanupCacheDirectory());- }+ _logger.LogDebug("Scheduling stat collection daily");+ RecurringJob.AddOrUpdate("report-stats", () => _statsService.Send(), Cron.Daily(Rnd.Next(0, 22)), TimeZoneInfo.Local);+ }- public void CleanupChapters(int[] chapterIds)- {- BackgroundJob.Enqueue(() => _cacheService.CleanupChapters(chapterIds));- }+ public void CancelStatsTasks()+ {+ _logger.LogDebug("Cancelling/Removing StatsTasks");- public void RefreshMetadata(int libraryId, bool forceUpdate = true)- {- _logger.LogInformation("Enqueuing library metadata refresh for: {LibraryId}", libraryId);- BackgroundJob.Enqueue(() => _metadataService.RefreshMetadata(libraryId, forceUpdate));- }+ RecurringJob.RemoveIfExists("report-stats");+ }- public void CleanupTemp()+ /// <summary>+ /// First time run stat collection. Executes immediately on a background thread. Does not block.+ /// </summary>+ public async Task RunStatCollection()+ {+ var allowStatCollection = (await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).AllowStatCollection;+ if (!allowStatCollection){- BackgroundJob.Enqueue(() => DirectoryService.ClearDirectory(DirectoryService.TempDirectory));+ _logger.LogDebug("User has opted out of stat collection, not sending stats");+ return;}+ BackgroundJob.Enqueue(() => _statsService.Send());+ }- public void RefreshSeriesMetadata(int libraryId, int seriesId, bool forceUpdate = true)- {- _logger.LogInformation("Enqueuing series metadata refresh for: {SeriesId}", seriesId);- BackgroundJob.Enqueue(() => _metadataService.RefreshMetadataForSeries(libraryId, seriesId, forceUpdate));- }+ #endregion- public void ScanSeries(int libraryId, int seriesId, bool forceUpdate = false)- {- _logger.LogInformation("Enqueuing series scan for: {SeriesId}", seriesId);- BackgroundJob.Enqueue(() => _scannerService.ScanSeries(libraryId, seriesId, CancellationToken.None));- }+ #region UpdateTasks- public void BackupDatabase()- {- BackgroundJob.Enqueue(() => _backupService.BackupDatabase());- }+ public void ScheduleUpdaterTasks()+ {+ _logger.LogInformation("Scheduling Auto-Update tasks");+ // Schedule update check between noon and 6pm local time+ RecurringJob.AddOrUpdate("check-updates", () => CheckForUpdate(), Cron.Daily(Rnd.Next(12, 18)), TimeZoneInfo.Local);+ }+ #endregion- /// <summary>- /// Not an external call. Only public so that we can call this for a Task- /// </summary>- // ReSharper disable once MemberCanBePrivate.Global- public async Task CheckForUpdate()- {- var update = await _versionUpdaterService.CheckForUpdate();- await _versionUpdaterService.PushUpdate(update);- }+ public void ScanLibrary(int libraryId, bool forceUpdate = false)+ {+ _logger.LogInformation("Enqueuing library scan for: {LibraryId}", libraryId);+ BackgroundJob.Enqueue(() => _scannerService.ScanLibrary(libraryId));+ // When we do a scan, force cache to re-unpack in case page numbers change+ BackgroundJob.Enqueue(() => _cleanupService.CleanupCacheDirectory());+ }++ public void CleanupChapters(int[] chapterIds)+ {+ BackgroundJob.Enqueue(() => _cacheService.CleanupChapters(chapterIds));+ }++ public void RefreshMetadata(int libraryId, bool forceUpdate = true)+ {+ _logger.LogInformation("Enqueuing library metadata refresh for: {LibraryId}", libraryId);+ BackgroundJob.Enqueue(() => _metadataService.RefreshMetadata(libraryId, forceUpdate));+ }++ public void RefreshSeriesMetadata(int libraryId, int seriesId, bool forceUpdate = true)+ {+ _logger.LogInformation("Enqueuing series metadata refresh for: {SeriesId}", seriesId);+ BackgroundJob.Enqueue(() => _metadataService.RefreshMetadataForSeries(libraryId, seriesId, forceUpdate));+ }++ public void ScanSeries(int libraryId, int seriesId, bool forceUpdate = false)+ {+ _logger.LogInformation("Enqueuing series scan for: {SeriesId}", seriesId);+ BackgroundJob.Enqueue(() => _scannerService.ScanSeries(libraryId, seriesId, CancellationToken.None));+ }++ public void BackupDatabase()+ {+ BackgroundJob.Enqueue(() => _backupService.BackupDatabase());+ }++ /// <summary>+ /// Not an external call. Only public so that we can call this for a Task+ /// </summary>+ // ReSharper disable once MemberCanBePrivate.Global+ public async Task CheckForUpdate()+ {+ var update = await _versionUpdaterService.CheckForUpdate();+ await _versionUpdaterService.PushUpdate(update);}}diff --git a/API/Services/Tasks/BackupService.cs b/API/Services/Tasks/BackupService.csindex 04cb279ec..12f4f1083 100644--- a/API/Services/Tasks/BackupService.cs+++ b/API/Services/Tasks/BackupService.cs@@ -4,204 +4,195 @@ using System.IO;using System.IO.Compression;using System.Linq;using System.Threading.Tasks;+using API.Data;using API.Entities.Enums;using API.Extensions;-using API.Interfaces;-using API.Interfaces.Services;using API.SignalR;using Hangfire;using Microsoft.AspNetCore.SignalR;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.Logging;-namespace API.Services.Tasks+namespace API.Services.Tasks;++public interface IBackupService+{+ Task BackupDatabase();+ /// <summary>+ /// Returns a list of full paths of the logs files detailed in <see cref="IConfiguration"/>.+ /// </summary>+ /// <param name="maxRollingFiles"></param>+ /// <param name="logFileName"></param>+ /// <returns></returns>+ IEnumerable<string> GetLogFiles(int maxRollingFiles, string logFileName);+}+public class BackupService : IBackupService{- public class BackupService : IBackupService+ private readonly IUnitOfWork _unitOfWork;+ private readonly ILogger<BackupService> _logger;+ private readonly IDirectoryService _directoryService;+ private readonly IHubContext<MessageHub> _messageHub;++ private readonly IList<string> _backupFiles;++ public BackupService(ILogger<BackupService> logger, IUnitOfWork unitOfWork,+ IDirectoryService directoryService, IConfiguration config, IHubContext<MessageHub> messageHub){- private readonly IUnitOfWork _unitOfWork;- private readonly ILogger<BackupService> _logger;- private readonly IDirectoryService _directoryService;- private readonly IHubContext<MessageHub> _messageHub;+ _unitOfWork = unitOfWork;+ _logger = logger;+ _directoryService = directoryService;+ _messageHub = messageHub;++ var maxRollingFiles = config.GetMaxRollingFiles();+ var loggingSection = config.GetLoggingFileName();+ var files = GetLogFiles(maxRollingFiles, loggingSection);- private readonly IList<string> _backupFiles;- public BackupService(IUnitOfWork unitOfWork, ILogger<BackupService> logger,- IDirectoryService directoryService, IConfiguration config, IHubContext<MessageHub> messageHub)+ _backupFiles = new List<string>(){- _unitOfWork = unitOfWork;- _logger = logger;- _directoryService = directoryService;- _messageHub = messageHub;-- var maxRollingFiles = config.GetMaxRollingFiles();- var loggingSection = config.GetLoggingFileName();- var files = LogFiles(maxRollingFiles, loggingSection);--- _backupFiles = new List<string>()- {- "appsettings.json",- "Hangfire.db", // This is not used atm- "Hangfire-log.db", // This is not used atm- "kavita.db",- "kavita.db-shm", // This wont always be there- "kavita.db-wal" // This wont always be there- };-- foreach (var file in files.Select(f => (new FileInfo(f)).Name).ToList())- {- _backupFiles.Add(file);- }+ "appsettings.json",+ "Hangfire.db", // This is not used atm+ "Hangfire-log.db", // This is not used atm+ "kavita.db",+ "kavita.db-shm", // This wont always be there+ "kavita.db-wal" // This wont always be there+ };++ foreach (var file in files.Select(f => (_directoryService.FileSystem.FileInfo.FromFileName(f)).Name).ToList())+ {+ _backupFiles.Add(file);}- public IEnumerable<string> LogFiles(int maxRollingFiles, string logFileName)- {- var multipleFileRegex = maxRollingFiles > 0 ? @"\d*" : string.Empty;- var fi = new FileInfo(logFileName);- var files = maxRollingFiles > 0- ? DirectoryService.GetFiles(DirectoryService.LogDirectory, $@"{Path.GetFileNameWithoutExtension(fi.Name)}{multipleFileRegex}\.log")- : new[] {"kavita.log"};- return files;+ }++ public IEnumerable<string> GetLogFiles(int maxRollingFiles, string logFileName)+ {+ var multipleFileRegex = maxRollingFiles > 0 ? @"\d*" : string.Empty;+ var fi = _directoryService.FileSystem.FileInfo.FromFileName(logFileName);++ var files = maxRollingFiles > 0+ ? _directoryService.GetFiles(_directoryService.LogDirectory,+ $@"{_directoryService.FileSystem.Path.GetFileNameWithoutExtension(fi.Name)}{multipleFileRegex}\.log")+ : new[] {"kavita.log"};+ return files;+ }++ /// <summary>+ /// Will backup anything that needs to be backed up. This includes logs, setting files, bare minimum cover images (just locked and first cover).+ /// </summary>+ [AutomaticRetry(Attempts = 3, LogEvents = false, OnAttemptsExceeded = AttemptsExceededAction.Fail)]+ public async Task BackupDatabase()+ {+ _logger.LogInformation("Beginning backup of Database at {BackupTime}", DateTime.Now);+ var backupDirectory = (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BackupDirectory)).Value;++ _logger.LogDebug("Backing up to {BackupDirectory}", backupDirectory);+ if (!_directoryService.ExistOrCreate(backupDirectory))+ {+ _logger.LogCritical("Could not write to {BackupDirectory}; aborting backup", backupDirectory);+ return;}- /// <summary>- /// Will backup anything that needs to be backed up. This includes logs, setting files, bare minimum cover images (just locked and first cover).- /// </summary>- [AutomaticRetry(Attempts = 3, LogEvents = false, OnAttemptsExceeded = AttemptsExceededAction.Fail)]- public async Task BackupDatabase()+ await SendProgress(0F);++ var dateString = $"{DateTime.Now.ToShortDateString()}_{DateTime.Now.ToLongTimeString()}".Replace("/", "_").Replace(":", "_");+ var zipPath = _directoryService.FileSystem.Path.Join(backupDirectory, $"kavita_backup_{dateString}.zip");++ if (File.Exists(zipPath)){- _logger.LogInformation("Beginning backup of Database at {BackupTime}", DateTime.Now);- var backupDirectory = Task.Run(() => _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BackupDirectory)).Result.Value;+ _logger.LogInformation("{ZipFile} already exists, aborting", zipPath);+ return;+ }- _logger.LogDebug("Backing up to {BackupDirectory}", backupDirectory);- if (!DirectoryService.ExistOrCreate(backupDirectory))- {- _logger.LogCritical("Could not write to {BackupDirectory}; aborting backup", backupDirectory);- return;- }+ var tempDirectory = Path.Join(_directoryService.TempDirectory, dateString);+ _directoryService.ExistOrCreate(tempDirectory);+ _directoryService.ClearDirectory(tempDirectory);- await SendProgress(0F);+ _directoryService.CopyFilesToDirectory(+ _backupFiles.Select(file => _directoryService.FileSystem.Path.Join(_directoryService.ConfigDirectory, file)).ToList(), tempDirectory);- var dateString = $"{DateTime.Now.ToShortDateString()}_{DateTime.Now.ToLongTimeString()}".Replace("/", "_").Replace(":", "_");- var zipPath = Path.Join(backupDirectory, $"kavita_backup_{dateString}.zip");+ await SendProgress(0.25F);- if (File.Exists(zipPath))- {- _logger.LogInformation("{ZipFile} already exists, aborting", zipPath);- return;- }+ await CopyCoverImagesToBackupDirectory(tempDirectory);- var tempDirectory = Path.Join(DirectoryService.TempDirectory, dateString);- DirectoryService.ExistOrCreate(tempDirectory);- DirectoryService.ClearDirectory(tempDirectory);+ await SendProgress(0.5F);- _directoryService.CopyFilesToDirectory(- _backupFiles.Select(file => Path.Join(DirectoryService.ConfigDirectory, file)).ToList(), tempDirectory);+ await CopyBookmarksToBackupDirectory(tempDirectory);- await SendProgress(0.25F);+ await SendProgress(0.75F);- await CopyCoverImagesToBackupDirectory(tempDirectory);+ try+ {+ ZipFile.CreateFromDirectory(tempDirectory, zipPath);+ }+ catch (AggregateException ex)+ {+ _logger.LogError(ex, "There was an issue when archiving library backup");+ }- await SendProgress(0.75F);+ _directoryService.ClearAndDeleteDirectory(tempDirectory);+ _logger.LogInformation("Database backup completed");+ await SendProgress(1F);+ }- try- {- ZipFile.CreateFromDirectory(tempDirectory, zipPath);- }- catch (AggregateException ex)- {- _logger.LogError(ex, "There was an issue when archiving library backup");- }+ private async Task CopyCoverImagesToBackupDirectory(string tempDirectory)+ {+ var outputTempDir = Path.Join(tempDirectory, "covers");+ _directoryService.ExistOrCreate(outputTempDir);- DirectoryService.ClearAndDeleteDirectory(tempDirectory);- _logger.LogInformation("Database backup completed");- await SendProgress(1F);+ try+ {+ var seriesImages = await _unitOfWork.SeriesRepository.GetLockedCoverImagesAsync();+ _directoryService.CopyFilesToDirectory(+ seriesImages.Select(s => _directoryService.FileSystem.Path.Join(_directoryService.CoverImageDirectory, s)), outputTempDir);++ var collectionTags = await _unitOfWork.CollectionTagRepository.GetAllCoverImagesAsync();+ _directoryService.CopyFilesToDirectory(+ collectionTags.Select(s => _directoryService.FileSystem.Path.Join(_directoryService.CoverImageDirectory, s)), outputTempDir);++ var chapterImages = await _unitOfWork.ChapterRepository.GetCoverImagesForLockedChaptersAsync();+ _directoryService.CopyFilesToDirectory(+ chapterImages.Select(s => _directoryService.FileSystem.Path.Join(_directoryService.CoverImageDirectory, s)), outputTempDir);+ }+ catch (IOException)+ {+ // Swallow exception. This can be a duplicate cover being copied as chapter and volumes can share same file.}- private async Task CopyCoverImagesToBackupDirectory(string tempDirectory)+ if (!_directoryService.GetFiles(outputTempDir, searchOption: SearchOption.AllDirectories).Any()){- var outputTempDir = Path.Join(tempDirectory, "covers");- DirectoryService.ExistOrCreate(outputTempDir);-- try- {- var seriesImages = await _unitOfWork.SeriesRepository.GetLockedCoverImagesAsync();- _directoryService.CopyFilesToDirectory(- seriesImages.Select(s => Path.Join(DirectoryService.CoverImageDirectory, s)), outputTempDir);-- var collectionTags = await _unitOfWork.CollectionTagRepository.GetAllCoverImagesAsync();- _directoryService.CopyFilesToDirectory(- collectionTags.Select(s => Path.Join(DirectoryService.CoverImageDirectory, s)), outputTempDir);-- var chapterImages = await _unitOfWork.ChapterRepository.GetCoverImagesForLockedChaptersAsync();- _directoryService.CopyFilesToDirectory(- chapterImages.Select(s => Path.Join(DirectoryService.CoverImageDirectory, s)), outputTempDir);- }- catch (IOException)- {- // Swallow exception. This can be a duplicate cover being copied as chapter and volumes can share same file.- }-- if (!DirectoryService.GetFiles(outputTempDir).Any())- {- DirectoryService.ClearAndDeleteDirectory(outputTempDir);- }+ _directoryService.ClearAndDeleteDirectory(outputTempDir);}+ }++ private async Task CopyBookmarksToBackupDirectory(string tempDirectory)+ {+ var bookmarkDirectory =+ (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BookmarkDirectory)).Value;++ var outputTempDir = Path.Join(tempDirectory, "bookmarks");+ _directoryService.ExistOrCreate(outputTempDir);- private async Task SendProgress(float progress)+ try{- await _messageHub.Clients.All.SendAsync(SignalREvents.BackupDatabaseProgress,- MessageFactory.BackupDatabaseProgressEvent(progress));+ _directoryService.CopyDirectoryToDirectory(bookmarkDirectory, outputTempDir);+ }+ catch (IOException)+ {+ // Swallow exception.}- /// <summary>- /// Removes Database backups older than 30 days. If all backups are older than 30 days, the latest is kept.- /// </summary>- public void CleanupBackups()+ if (!_directoryService.GetFiles(outputTempDir, searchOption: SearchOption.AllDirectories).Any()){- const int dayThreshold = 30;- _logger.LogInformation("Beginning cleanup of Database backups at {Time}", DateTime.Now);- var backupDirectory = Task.Run(() => _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BackupDirectory)).Result.Value;- if (!_directoryService.Exists(backupDirectory)) return;- var deltaTime = DateTime.Today.Subtract(TimeSpan.FromDays(dayThreshold));- var allBackups = DirectoryService.GetFiles(backupDirectory).ToList();- var expiredBackups = allBackups.Select(filename => new FileInfo(filename))- .Where(f => f.CreationTime > deltaTime)- .ToList();- if (expiredBackups.Count == allBackups.Count)- {- _logger.LogInformation("All expired backups are older than {Threshold} days. Removing all but last backup", dayThreshold);- var toDelete = expiredBackups.OrderByDescending(f => f.CreationTime).ToList();- for (var i = 1; i < toDelete.Count; i++)- {- try- {- toDelete[i].Delete();- }- catch (Exception ex)- {- _logger.LogError(ex, "There was an issue deleting {FileName}", toDelete[i].Name);- }- }- }- else- {- foreach (var file in expiredBackups)- {- try- {- file.Delete();- }- catch (Exception ex)- {- _logger.LogError(ex, "There was an issue deleting {FileName}", file.Name);- }- }-- }- _logger.LogInformation("Finished cleanup of Database backups at {Time}", DateTime.Now);+ _directoryService.ClearAndDeleteDirectory(outputTempDir);}+ }+ private async Task SendProgress(float progress)+ {+ await _messageHub.Clients.All.SendAsync(SignalREvents.BackupDatabaseProgress,+ MessageFactory.BackupDatabaseProgressEvent(progress));}+}diff --git a/API/Services/Tasks/CleanupService.cs b/API/Services/Tasks/CleanupService.csindex 1ecc9cec5..d31e50a22 100644--- a/API/Services/Tasks/CleanupService.cs+++ b/API/Services/Tasks/CleanupService.cs@@ -1,7 +1,9 @@-using System.IO;+using System;+using System.IO;+using System.Linq;using System.Threading.Tasks;-using API.Interfaces;-using API.Interfaces.Services;+using API.Data;+using API.Entities.Enums;using API.SignalR;using Hangfire;using Microsoft.AspNetCore.SignalR;@@ -9,32 +11,37 @@ using Microsoft.Extensions.Logging;namespace API.Services.Tasks{+ public interface ICleanupService+ {+ Task Cleanup();+ Task CleanupDbEntries();+ void CleanupCacheDirectory();+ Task DeleteSeriesCoverImages();+ Task DeleteChapterCoverImages();+ Task DeleteTagCoverImages();+ Task CleanupBackups();+ Task CleanupBookmarks();+ }/// <summary>/// Cleans up after operations on reoccurring basis/// </summary>public class CleanupService : ICleanupService{- private readonly ICacheService _cacheService;private readonly ILogger<CleanupService> _logger;- private readonly IBackupService _backupService;private readonly IUnitOfWork _unitOfWork;private readonly IHubContext<MessageHub> _messageHub;+ private readonly IDirectoryService _directoryService;- public CleanupService(ICacheService cacheService, ILogger<CleanupService> logger,- IBackupService backupService, IUnitOfWork unitOfWork, IHubContext<MessageHub> messageHub)+ public CleanupService(ILogger<CleanupService> logger,+ IUnitOfWork unitOfWork, IHubContext<MessageHub> messageHub,+ IDirectoryService directoryService){- _cacheService = cacheService;_logger = logger;- _backupService = backupService;_unitOfWork = unitOfWork;_messageHub = messageHub;+ _directoryService = directoryService;}- public void CleanupCacheDirectory()- {- _logger.LogInformation("Cleaning cache directory");- _cacheService.Cleanup();- }/// <summary>/// Cleans up Temp, cache, deleted cover images, and old database backups@@ -45,12 +52,12 @@ namespace API.Services.Tasks_logger.LogInformation("Starting Cleanup");await SendProgress(0F);_logger.LogInformation("Cleaning temp directory");- DirectoryService.ClearDirectory(DirectoryService.TempDirectory);+ _directoryService.ClearDirectory(_directoryService.TempDirectory);await SendProgress(0.1F);CleanupCacheDirectory();await SendProgress(0.25F);_logger.LogInformation("Cleaning old database backups");- _backupService.CleanupBackups();+ await CleanupBackups();await SendProgress(0.50F);_logger.LogInformation("Cleaning deleted cover images");await DeleteSeriesCoverImages();@@ -58,49 +65,137 @@ namespace API.Services.Tasksawait DeleteChapterCoverImages();await SendProgress(0.7F);await DeleteTagCoverImages();+ await SendProgress(0.8F);+ _logger.LogInformation("Cleaning old bookmarks");+ await CleanupBookmarks();await SendProgress(1F);_logger.LogInformation("Cleanup finished");}+ /// <summary>+ /// Cleans up abandon rows in the DB+ /// </summary>+ public async Task CleanupDbEntries()+ {+ await _unitOfWork.AppUserProgressRepository.CleanupAbandonedChapters();+ await _unitOfWork.PersonRepository.RemoveAllPeopleNoLongerAssociated();+ await _unitOfWork.GenreRepository.RemoveAllGenreNoLongerAssociated();+ await _unitOfWork.CollectionTagRepository.RemoveTagsWithoutSeries();+ }+private async Task SendProgress(float progress){await _messageHub.Clients.All.SendAsync(SignalREvents.CleanupProgress,MessageFactory.CleanupProgressEvent(progress));}- private async Task DeleteSeriesCoverImages()+ /// <summary>+ /// Removes all series images that are not in the database. They must follow <see cref="ImageService.SeriesCoverImageRegex"/> filename pattern.+ /// </summary>+ public async Task DeleteSeriesCoverImages(){var images = await _unitOfWork.SeriesRepository.GetAllCoverImagesAsync();- var files = DirectoryService.GetFiles(DirectoryService.CoverImageDirectory, ImageService.SeriesCoverImageRegex);- foreach (var file in files)- {- if (images.Contains(Path.GetFileName(file))) continue;- File.Delete(file);-- }+ var files = _directoryService.GetFiles(_directoryService.CoverImageDirectory, ImageService.SeriesCoverImageRegex);+ _directoryService.DeleteFiles(files.Where(file => !images.Contains(_directoryService.FileSystem.Path.GetFileName(file))));}- private async Task DeleteChapterCoverImages()+ /// <summary>+ /// Removes all chapter/volume images that are not in the database. They must follow <see cref="ImageService.ChapterCoverImageRegex"/> filename pattern.+ /// </summary>+ public async Task DeleteChapterCoverImages(){var images = await _unitOfWork.ChapterRepository.GetAllCoverImagesAsync();- var files = DirectoryService.GetFiles(DirectoryService.CoverImageDirectory, ImageService.ChapterCoverImageRegex);- foreach (var file in files)- {- if (images.Contains(Path.GetFileName(file))) continue;- File.Delete(file);+ var files = _directoryService.GetFiles(_directoryService.CoverImageDirectory, ImageService.ChapterCoverImageRegex);+ _directoryService.DeleteFiles(files.Where(file => !images.Contains(_directoryService.FileSystem.Path.GetFileName(file))));+ }+ /// <summary>+ /// Removes all collection tag images that are not in the database. They must follow <see cref="ImageService.CollectionTagCoverImageRegex"/> filename pattern.+ /// </summary>+ public async Task DeleteTagCoverImages()+ {+ var images = await _unitOfWork.CollectionTagRepository.GetAllCoverImagesAsync();+ var files = _directoryService.GetFiles(_directoryService.CoverImageDirectory, ImageService.CollectionTagCoverImageRegex);+ _directoryService.DeleteFiles(files.Where(file => !images.Contains(_directoryService.FileSystem.Path.GetFileName(file))));+ }++ /// <summary>+ /// Removes all files and directories in the cache directory+ /// </summary>+ public void CleanupCacheDirectory()+ {+ _logger.LogInformation("Performing cleanup of Cache directory");+ _directoryService.ExistOrCreate(_directoryService.CacheDirectory);++ try+ {+ _directoryService.ClearDirectory(_directoryService.CacheDirectory);+ }+ catch (Exception ex)+ {+ _logger.LogError(ex, "There was an issue deleting one or more folders/files during cleanup");}++ _logger.LogInformation("Cache directory purged");}- private async Task DeleteTagCoverImages()+ /// <summary>+ /// Removes Database backups older than 30 days. If all backups are older than 30 days, the latest is kept.+ /// </summary>+ public async Task CleanupBackups(){- var images = await _unitOfWork.CollectionTagRepository.GetAllCoverImagesAsync();- var files = DirectoryService.GetFiles(DirectoryService.CoverImageDirectory, ImageService.CollectionTagCoverImageRegex);- foreach (var file in files)+ const int dayThreshold = 30;+ _logger.LogInformation("Beginning cleanup of Database backups at {Time}", DateTime.Now);+ var backupDirectory =+ (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BackupDirectory)).Value;+ if (!_directoryService.Exists(backupDirectory)) return;++ var deltaTime = DateTime.Today.Subtract(TimeSpan.FromDays(dayThreshold));+ var allBackups = _directoryService.GetFiles(backupDirectory).ToList();+ var expiredBackups = allBackups.Select(filename => _directoryService.FileSystem.FileInfo.FromFileName(filename))+ .Where(f => f.CreationTime < deltaTime)+ .ToList();++ if (expiredBackups.Count == allBackups.Count){- if (images.Contains(Path.GetFileName(file))) continue;- File.Delete(file);+ _logger.LogInformation("All expired backups are older than {Threshold} days. Removing all but last backup", dayThreshold);+ var toDelete = expiredBackups.OrderByDescending(f => f.CreationTime).ToList();+ _directoryService.DeleteFiles(toDelete.Take(toDelete.Count - 1).Select(f => f.FullName));+ }+ else+ {+ _directoryService.DeleteFiles(expiredBackups.Select(f => f.FullName));+ }+ _logger.LogInformation("Finished cleanup of Database backups at {Time}", DateTime.Now);+ }++ /// <summary>+ /// Removes all files in the BookmarkDirectory that don't currently have bookmarks in the Database+ /// </summary>+ public async Task CleanupBookmarks()+ {+ // Search all files in bookmarks/ except bookmark files and delete those+ var bookmarkDirectory =+ (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BookmarkDirectory)).Value;+ var allBookmarkFiles = _directoryService.GetFiles(bookmarkDirectory, searchOption: SearchOption.AllDirectories).Select(Parser.Parser.NormalizePath);+ var bookmarks = (await _unitOfWork.UserRepository.GetAllBookmarksAsync())+ .Select(b => Parser.Parser.NormalizePath(_directoryService.FileSystem.Path.Join(bookmarkDirectory,+ b.FileName)));++ var filesToDelete = allBookmarkFiles.ToList().Except(bookmarks).ToList();+ _logger.LogDebug("[Bookmarks] Bookmark cleanup wants to delete {Count} files", filesToDelete.Count());++ _directoryService.DeleteFiles(filesToDelete);++ // Clear all empty directories+ foreach (var directory in _directoryService.FileSystem.Directory.GetDirectories(bookmarkDirectory))+ {+ if (_directoryService.FileSystem.Directory.GetFiles(directory).Length == 0 &&+ _directoryService.FileSystem.Directory.GetDirectories(directory).Length == 0)+ {+ _directoryService.FileSystem.Directory.Delete(directory, false);+ }}}}diff --git a/API/Services/Tasks/Scanner/ParseScannedFiles.cs b/API/Services/Tasks/Scanner/ParseScannedFiles.csindex f88caab89..50cb98da9 100644--- a/API/Services/Tasks/Scanner/ParseScannedFiles.cs+++ b/API/Services/Tasks/Scanner/ParseScannedFiles.cs@@ -6,7 +6,7 @@ using System.IO;using System.Linq;using API.Entities;using API.Entities.Enums;-using API.Interfaces.Services;+using API.Helpers;using API.Parser;using Microsoft.Extensions.Logging;@@ -23,34 +23,46 @@ namespace API.Services.Tasks.Scannerpublic class ParseScannedFiles{private readonly ConcurrentDictionary<ParsedSeries, List<ParserInfo>> _scannedSeries;- private readonly IBookService _bookService;private readonly ILogger _logger;+ private readonly IDirectoryService _directoryService;+ private readonly IReadingItemService _readingItemService;+ private readonly DefaultParser _defaultParser;/// <summary>/// An instance of a pipeline for processing files and returning a Map of Series -> ParserInfos./// Each instance is separate from other threads, allowing for no cross over./// </summary>- /// <param name="bookService"></param>- /// <param name="logger"></param>- public ParseScannedFiles(IBookService bookService, ILogger logger)+ /// <param name="logger">Logger of the parent class that invokes this</param>+ /// <param name="directoryService">Directory Service</param>+ /// <param name="readingItemService">ReadingItemService Service for extracting information on a number of formats</param>+ public ParseScannedFiles(ILogger logger, IDirectoryService directoryService,+ IReadingItemService readingItemService){- _bookService = bookService;_logger = logger;+ _directoryService = directoryService;+ _readingItemService = readingItemService;_scannedSeries = new ConcurrentDictionary<ParsedSeries, List<ParserInfo>>();+ _defaultParser = new DefaultParser(_directoryService);}/// <summary>- /// Gets the list of parserInfos given a Series. If the series does not exist within, return empty list.+ /// Gets the list of all parserInfos given a Series (Will match on Name, LocalizedName, OriginalName). If the series does not exist within, return empty list./// </summary>/// <param name="parsedSeries"></param>/// <param name="series"></param>/// <returns></returns>public static IList<ParserInfo> GetInfosByName(Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries, Series series){- var existingKey = parsedSeries.Keys.FirstOrDefault(ps =>- ps.Format == series.Format && ps.NormalizedName.Equals(Parser.Parser.Normalize(series.OriginalName)));+ var allKeys = parsedSeries.Keys.Where(ps =>+ SeriesHelper.FindSeries(series, ps));- return existingKey != null ? parsedSeries[existingKey] : new List<ParserInfo>();+ var infos = new List<ParserInfo>();+ foreach (var key in allKeys)+ {+ infos.AddRange(parsedSeries[key]);+ }++ return infos;}/// <summary>@@ -62,20 +74,12 @@ namespace API.Services.Tasks.Scanner/// <param name="type">Library type to determine parsing to perform</param>private void ProcessFile(string path, string rootPath, LibraryType type){- ParserInfo info;-- if (Parser.Parser.IsEpub(path))- {- info = _bookService.ParseInfo(path);- }- else- {- info = Parser.Parser.Parse(path, rootPath, type);- }+ // TODO: Emit event with what is being processed. It can look like Kavita isn't doing anything during file scan- // If we couldn't match, log. But don't log if the file parses as a cover image+ var info = _readingItemService.Parse(path, rootPath, type);if (info == null){+ // If the file is an image and literally a cover image, skip processing.if (!(Parser.Parser.IsImage(path) && Parser.Parser.IsCoverImage(path))){_logger.LogWarning("[Scanner] Could not parse series from {Path}", path);@@ -83,16 +87,36 @@ namespace API.Services.Tasks.Scannerreturn;}- if (Parser.Parser.IsEpub(path) && Parser.Parser.ParseVolume(info.Series) != Parser.Parser.DefaultVolume)++ // This catches when original library type is Manga/Comic and when parsing with non+ if (Parser.Parser.IsEpub(path) && Parser.Parser.ParseVolume(info.Series) != Parser.Parser.DefaultVolume) // Shouldn't this be info.Volume != DefaultVolume?{- info = Parser.Parser.Parse(path, rootPath, type);- var info2 = _bookService.ParseInfo(path);+ info = _defaultParser.Parse(path, rootPath, LibraryType.Book);+ var info2 = _readingItemService.Parse(path, rootPath, type);info.Merge(info2);}+ info.ComicInfo = _readingItemService.GetComicInfo(path);+ if (info.ComicInfo != null)+ {+ if (!string.IsNullOrEmpty(info.ComicInfo.Volume))+ {+ info.Volumes = info.ComicInfo.Volume;+ }+ if (!string.IsNullOrEmpty(info.ComicInfo.Series))+ {+ info.Series = info.ComicInfo.Series;+ }+ if (!string.IsNullOrEmpty(info.ComicInfo.Number))+ {+ info.Chapters = info.ComicInfo.Number;+ }+ }+TrackSeries(info);}+/// <summary>/// Attempts to either add a new instance of a show mapping to the _scannedSeries bag or adds to an existing./// This will check if the name matches an existing series name (multiple fields) <see cref="MergeName"/>@@ -133,7 +157,7 @@ namespace API.Services.Tasks.Scanner/// same normalized name, it merges into the existing one. This is important as some manga may have a slight difference with punctuation or capitalization./// </summary>/// <param name="info"></param>- /// <returns></returns>+ /// <returns>Series Name to group this info into</returns>public string MergeName(ParserInfo info){var normalizedSeries = Parser.Parser.Normalize(info.Series);@@ -161,12 +185,11 @@ namespace API.Services.Tasks.Scanner{var sw = Stopwatch.StartNew();totalFiles = 0;- var searchPattern = GetLibrarySearchPattern();foreach (var folderPath in folders){try{- totalFiles += DirectoryService.TraverseTreeParallelForEach(folderPath, (f) =>+ totalFiles += _directoryService.TraverseTreeParallelForEach(folderPath, (f) =>{try{@@ -176,7 +199,7 @@ namespace API.Services.Tasks.Scanner{_logger.LogError(exception, "The file {Filename} could not be found", f);}- }, searchPattern, _logger);+ }, Parser.Parser.SupportedExtensions, _logger);}catch (ArgumentException ex){@@ -191,11 +214,6 @@ namespace API.Services.Tasks.Scannerreturn SeriesWithInfos();}- private static string GetLibrarySearchPattern()- {- return Parser.Parser.SupportedExtensions;- }-/// <summary>/// Returns any series where there were parsed infos/// </summary>diff --git a/API/Services/Tasks/ScannerService.cs b/API/Services/Tasks/ScannerService.csindex f1d5a2b96..7c6a51f2c 100644--- a/API/Services/Tasks/ScannerService.cs+++ b/API/Services/Tasks/ScannerService.cs@@ -7,13 +7,12 @@ using System.Threading;using System.Threading.Tasks;using API.Comparators;using API.Data;+using API.Data.Metadata;using API.Data.Repositories;using API.Entities;using API.Entities.Enums;using API.Extensions;using API.Helpers;-using API.Interfaces;-using API.Interfaces.Services;using API.Parser;using API.Services.Tasks.Scanner;using API.SignalR;@@ -21,697 +20,875 @@ using Hangfire;using Microsoft.AspNetCore.SignalR;using Microsoft.Extensions.Logging;-namespace API.Services.Tasks+namespace API.Services.Tasks;+public interface IScannerService{- public class ScannerService : IScannerService+ /// <summary>+ /// Given a library id, scans folders for said library. Parses files and generates DB updates. Will overwrite+ /// cover images if forceUpdate is true.+ /// </summary>+ /// <param name="libraryId">Library to scan against</param>+ Task ScanLibrary(int libraryId);+ Task ScanLibraries();+ Task ScanSeries(int libraryId, int seriesId, CancellationToken token);+}++public class ScannerService : IScannerService+{+ private readonly IUnitOfWork _unitOfWork;+ private readonly ILogger<ScannerService> _logger;+ private readonly IMetadataService _metadataService;+ private readonly ICacheService _cacheService;+ private readonly IHubContext<MessageHub> _messageHub;+ private readonly IFileService _fileService;+ private readonly IDirectoryService _directoryService;+ private readonly IReadingItemService _readingItemService;+ private readonly ICacheHelper _cacheHelper;++ public ScannerService(IUnitOfWork unitOfWork, ILogger<ScannerService> logger,+ IMetadataService metadataService, ICacheService cacheService, IHubContext<MessageHub> messageHub,+ IFileService fileService, IDirectoryService directoryService, IReadingItemService readingItemService,+ ICacheHelper cacheHelper)+ {+ _unitOfWork = unitOfWork;+ _logger = logger;+ _metadataService = metadataService;+ _cacheService = cacheService;+ _messageHub = messageHub;+ _fileService = fileService;+ _directoryService = directoryService;+ _readingItemService = readingItemService;+ _cacheHelper = cacheHelper;+ }++ [DisableConcurrentExecution(timeoutInSeconds: 360)]+ [AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]+ public async Task ScanSeries(int libraryId, int seriesId, CancellationToken token)+ {+ var sw = new Stopwatch();+ var files = await _unitOfWork.SeriesRepository.GetFilesForSeries(seriesId);+ var series = await _unitOfWork.SeriesRepository.GetFullSeriesForSeriesIdAsync(seriesId);+ var chapterIds = await _unitOfWork.SeriesRepository.GetChapterIdsForSeriesAsync(new[] {seriesId});+ var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(libraryId, LibraryIncludes.Folders);+ var folderPaths = library.Folders.Select(f => f.Path).ToList();++ // Check if any of the folder roots are not available (ie disconnected from network, etc) and fail if any of them are+ if (folderPaths.Any(f => !_directoryService.IsDriveMounted(f)))+ {+ _logger.LogError("Some of the root folders for library are not accessible. Please check that drives are connected and rescan. Scan will be aborted");+ return;+ }++ var allPeople = await _unitOfWork.PersonRepository.GetAllPeople();+ var allGenres = await _unitOfWork.GenreRepository.GetAllGenresAsync();+ var allTags = await _unitOfWork.TagRepository.GetAllTagsAsync();++ var dirs = _directoryService.FindHighestDirectoriesFromFiles(folderPaths, files.Select(f => f.FilePath).ToList());++ _logger.LogInformation("Beginning file scan on {SeriesName}", series.Name);+ var scanner = new ParseScannedFiles(_logger, _directoryService, _readingItemService);+ var parsedSeries = scanner.ScanLibrariesForSeries(library.Type, dirs.Keys, out var totalFiles, out var scanElapsedTime);++ // Remove any parsedSeries keys that don't belong to our series. This can occur when users store 2 series in the same folder+ RemoveParsedInfosNotForSeries(parsedSeries, series);++ // If nothing was found, first validate any of the files still exist. If they don't then we have a deletion and can skip the rest of the logic flow+ if (parsedSeries.Count == 0)+ {+ var anyFilesExist =+ (await _unitOfWork.SeriesRepository.GetFilesForSeries(series.Id)).Any(m => File.Exists(m.FilePath));++ if (!anyFilesExist)+ {+ try+ {+ _unitOfWork.SeriesRepository.Remove(series);+ await CommitAndSend(totalFiles, parsedSeries, sw, scanElapsedTime, series);+ }+ catch (Exception ex)+ {+ _logger.LogCritical(ex, "There was an error during ScanSeries to delete the series");+ await _unitOfWork.RollbackAsync();+ }++ }+ else+ {+ // We need to do an additional check for an edge case: If the scan ran and the files do not match the existing Series name, then it is very likely,+ // the files have crap naming and if we don't correct, the series will get deleted due to the parser not being able to fallback onto folder parsing as the root+ // is the series folder.+ var existingFolder = dirs.Keys.FirstOrDefault(key => key.Contains(series.OriginalName));+ if (dirs.Keys.Count == 1 && !string.IsNullOrEmpty(existingFolder))+ {+ dirs = new Dictionary<string, string>();+ var path = Directory.GetParent(existingFolder)?.FullName;+ if (!folderPaths.Contains(path) || !folderPaths.Any(p => p.Contains(path ?? string.Empty)))+ {+ _logger.LogInformation("[ScanService] Aborted: {SeriesName} has bad naming convention and sits at root of library. Cannot scan series without deletion occuring. Correct file names to have Series Name within it or perform Scan Library", series.OriginalName);+ return;+ }+ if (!string.IsNullOrEmpty(path))+ {+ dirs[path] = string.Empty;+ }+ }++ _logger.LogInformation("{SeriesName} has bad naming convention, forcing rescan at a higher directory", series.OriginalName);+ scanner = new ParseScannedFiles(_logger, _directoryService, _readingItemService);+ parsedSeries = scanner.ScanLibrariesForSeries(library.Type, dirs.Keys, out var totalFiles2, out var scanElapsedTime2);+ totalFiles += totalFiles2;+ scanElapsedTime += scanElapsedTime2;+ RemoveParsedInfosNotForSeries(parsedSeries, series);+ }+ }++ // At this point, parsedSeries will have at least one key and we can perform the update. If it still doesn't, just return and don't do anything+ if (parsedSeries.Count == 0) return;++ // Merge any series together that might have different ParsedSeries but belong to another group of ParsedSeries+ try+ {+ UpdateSeries(series, parsedSeries, allPeople, allTags, allGenres, library.Type);++ await CommitAndSend(totalFiles, parsedSeries, sw, scanElapsedTime, series);+ }+ catch (Exception ex)+ {+ _logger.LogCritical(ex, "There was an error during ScanSeries to update the series");+ await _unitOfWork.RollbackAsync();+ }+ // Tell UI that this series is done+ await _messageHub.Clients.All.SendAsync(SignalREvents.ScanSeries, MessageFactory.ScanSeriesEvent(seriesId, series.Name), token);+ await CleanupDbEntities();+ BackgroundJob.Enqueue(() => _cacheService.CleanupChapters(chapterIds));+ BackgroundJob.Enqueue(() => _metadataService.RefreshMetadataForSeries(libraryId, series.Id, false));+ }++ private static void RemoveParsedInfosNotForSeries(Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries, Series series){- private readonly IUnitOfWork _unitOfWork;- private readonly ILogger<ScannerService> _logger;- private readonly IArchiveService _archiveService;- private readonly IMetadataService _metadataService;- private readonly IBookService _bookService;- private readonly ICacheService _cacheService;- private readonly IHubContext<MessageHub> _messageHub;- private readonly NaturalSortComparer _naturalSort = new ();-- public ScannerService(IUnitOfWork unitOfWork, ILogger<ScannerService> logger, IArchiveService archiveService,- IMetadataService metadataService, IBookService bookService, ICacheService cacheService, IHubContext<MessageHub> messageHub)- {- _unitOfWork = unitOfWork;- _logger = logger;- _archiveService = archiveService;- _metadataService = metadataService;- _bookService = bookService;- _cacheService = cacheService;- _messageHub = messageHub;- }-- [DisableConcurrentExecution(timeoutInSeconds: 360)]- [AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]- public async Task ScanSeries(int libraryId, int seriesId, CancellationToken token)- {- var sw = new Stopwatch();- var files = await _unitOfWork.SeriesRepository.GetFilesForSeries(seriesId);- var series = await _unitOfWork.SeriesRepository.GetFullSeriesForSeriesIdAsync(seriesId);- var chapterIds = await _unitOfWork.SeriesRepository.GetChapterIdsForSeriesAsync(new[] {seriesId});- var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(libraryId, LibraryIncludes.Folders);- var folderPaths = library.Folders.Select(f => f.Path).ToList();-- // Check if any of the folder roots are not available (ie disconnected from network, etc) and fail if any of them are- if (folderPaths.Any(f => !DirectoryService.IsDriveMounted(f)))- {- _logger.LogError("Some of the root folders for library are not accessible. Please check that drives are connected and rescan. Scan will be aborted");- return;- }-- var dirs = DirectoryService.FindHighestDirectoriesFromFiles(folderPaths, files.Select(f => f.FilePath).ToList());-- _logger.LogInformation("Beginning file scan on {SeriesName}", series.Name);- var scanner = new ParseScannedFiles(_bookService, _logger);- var parsedSeries = scanner.ScanLibrariesForSeries(library.Type, dirs.Keys, out var totalFiles, out var scanElapsedTime);-- // Remove any parsedSeries keys that don't belong to our series. This can occur when users store 2 series in the same folder- RemoveParsedInfosNotForSeries(parsedSeries, series);-- // If nothing was found, first validate any of the files still exist. If they don't then we have a deletion and can skip the rest of the logic flow- if (parsedSeries.Count == 0)- {- var anyFilesExist =- (await _unitOfWork.SeriesRepository.GetFilesForSeries(series.Id)).Any(m => File.Exists(m.FilePath));-- if (!anyFilesExist)- {- try- {- _unitOfWork.SeriesRepository.Remove(series);- await CommitAndSend(totalFiles, parsedSeries, sw, scanElapsedTime, series);- }- catch (Exception ex)- {- _logger.LogCritical(ex, "There was an error during ScanSeries to delete the series");- await _unitOfWork.RollbackAsync();- }-- }- else- {- // We need to do an additional check for an edge case: If the scan ran and the files do not match the existing Series name, then it is very likely,- // the files have crap naming and if we don't correct, the series will get deleted due to the parser not being able to fallback onto folder parsing as the root- // is the series folder.- var existingFolder = dirs.Keys.FirstOrDefault(key => key.Contains(series.OriginalName));- if (dirs.Keys.Count == 1 && !string.IsNullOrEmpty(existingFolder))- {- dirs = new Dictionary<string, string>();- var path = Directory.GetParent(existingFolder)?.FullName;- if (!folderPaths.Contains(path) || !folderPaths.Any(p => p.Contains(path ?? string.Empty)))- {- _logger.LogInformation("[ScanService] Aborted: {SeriesName} has bad naming convention and sits at root of library. Cannot scan series without deletion occuring. Correct file names to have Series Name within it or perform Scan Library", series.OriginalName);- return;- }- if (!string.IsNullOrEmpty(path))- {- dirs[path] = string.Empty;- }- }-- _logger.LogInformation("{SeriesName} has bad naming convention, forcing rescan at a higher directory", series.OriginalName);- scanner = new ParseScannedFiles(_bookService, _logger);- parsedSeries = scanner.ScanLibrariesForSeries(library.Type, dirs.Keys, out var totalFiles2, out var scanElapsedTime2);- totalFiles += totalFiles2;- scanElapsedTime += scanElapsedTime2;- RemoveParsedInfosNotForSeries(parsedSeries, series);- }- }-- // At this point, parsedSeries will have at least one key and we can perform the update. If it still doesn't, just return and don't do anything- if (parsedSeries.Count == 0) return;-- try- {- UpdateSeries(series, parsedSeries);- await CommitAndSend(totalFiles, parsedSeries, sw, scanElapsedTime, series);- }- catch (Exception ex)- {- _logger.LogCritical(ex, "There was an error during ScanSeries to update the series");- await _unitOfWork.RollbackAsync();- }- // Tell UI that this series is done- await _messageHub.Clients.All.SendAsync(SignalREvents.ScanSeries, MessageFactory.ScanSeriesEvent(seriesId, series.Name), token);- await CleanupDbEntities();- BackgroundJob.Enqueue(() => _cacheService.CleanupChapters(chapterIds));- BackgroundJob.Enqueue(() => _metadataService.RefreshMetadataForSeries(libraryId, series.Id, false));- }-- private static void RemoveParsedInfosNotForSeries(Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries, Series series)- {- var keys = parsedSeries.Keys;- foreach (var key in keys.Where(key =>- !series.NameInParserInfo(parsedSeries[key].FirstOrDefault()) || series.Format != key.Format))- {- parsedSeries.Remove(key);- }- }-- private async Task CommitAndSend(int totalFiles,- Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries, Stopwatch sw, long scanElapsedTime, Series series)- {- if (_unitOfWork.HasChanges())- {- await _unitOfWork.CommitAsync();- _logger.LogInformation(- "Processed {TotalFiles} files and {ParsedSeriesCount} series in {ElapsedScanTime} milliseconds for {SeriesName}",- totalFiles, parsedSeries.Keys.Count, sw.ElapsedMilliseconds + scanElapsedTime, series.Name);- }- }--- [DisableConcurrentExecution(timeoutInSeconds: 360)]- [AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]- public async Task ScanLibraries()- {- _logger.LogInformation("Starting Scan of All Libraries");- var libraries = await _unitOfWork.LibraryRepository.GetLibrariesAsync();- foreach (var lib in libraries)- {- await ScanLibrary(lib.Id);- }- _logger.LogInformation("Scan of All Libraries Finished");- }--- /// <summary>- /// Scans a library for file changes.- /// Will kick off a scheduled background task to refresh metadata,- /// ie) all entities will be rechecked for new cover images and comicInfo.xml changes- /// </summary>- /// <param name="libraryId"></param>- [DisableConcurrentExecution(360)]- [AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]- public async Task ScanLibrary(int libraryId)- {- Library library;- try- {- library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(libraryId, LibraryIncludes.Folders);- }- catch (Exception ex)- {- // This usually only fails if user is not authenticated.- _logger.LogError(ex, "[ScannerService] There was an issue fetching Library {LibraryId}", libraryId);- return;- }-- // Check if any of the folder roots are not available (ie disconnected from network, etc) and fail if any of them are- if (library.Folders.Any(f => !DirectoryService.IsDriveMounted(f.Path)))- {- _logger.LogError("Some of the root folders for library are not accessible. Please check that drives are connected and rescan. Scan will be aborted");- return;- }--- _logger.LogInformation("[ScannerService] Beginning file scan on {LibraryName}", library.Name);- await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,- MessageFactory.ScanLibraryProgressEvent(libraryId, 0));-- var scanner = new ParseScannedFiles(_bookService, _logger);- var series = scanner.ScanLibrariesForSeries(library.Type, library.Folders.Select(fp => fp.Path), out var totalFiles, out var scanElapsedTime);-- foreach (var folderPath in library.Folders)- {- folderPath.LastScanned = DateTime.Now;- }- var sw = Stopwatch.StartNew();-- await UpdateLibrary(library, series);-- library.LastScanned = DateTime.Now;- _unitOfWork.LibraryRepository.Update(library);- if (await _unitOfWork.CommitAsync())- {- _logger.LogInformation(- "[ScannerService] Processed {TotalFiles} files and {ParsedSeriesCount} series in {ElapsedScanTime} milliseconds for {LibraryName}",- totalFiles, series.Keys.Count, sw.ElapsedMilliseconds + scanElapsedTime, library.Name);- }- else- {- _logger.LogCritical(- "[ScannerService] There was a critical error that resulted in a failed scan. Please check logs and rescan");- }-- await CleanupDbEntities();-- BackgroundJob.Enqueue(() => _metadataService.RefreshMetadata(libraryId, false));- await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,- MessageFactory.ScanLibraryProgressEvent(libraryId, 1F));- }-- /// <summary>- /// Remove any user progress rows that no longer exist since scan library ran and deleted series/volumes/chapters- /// </summary>- private async Task CleanupAbandonedChapters()- {- var cleanedUp = await _unitOfWork.AppUserProgressRepository.CleanupAbandonedChapters();- _logger.LogInformation("Removed {Count} abandoned progress rows", cleanedUp);- }--- /// <summary>- /// Cleans up any abandoned rows due to removals from Scan loop- /// </summary>- private async Task CleanupDbEntities()- {- await CleanupAbandonedChapters();- var cleanedUp = await _unitOfWork.CollectionTagRepository.RemoveTagsWithoutSeries();- _logger.LogInformation("Removed {Count} abandoned collection tags", cleanedUp);- }-- private async Task UpdateLibrary(Library library, Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)- {- if (parsedSeries == null) return;-- // Library contains no Series, so we need to fetch series in groups of ChunkSize- var chunkInfo = await _unitOfWork.SeriesRepository.GetChunkInfo(library.Id);- var stopwatch = Stopwatch.StartNew();- var totalTime = 0L;-- // Update existing series- _logger.LogInformation("[ScannerService] Updating existing series for {LibraryName}. Total Items: {TotalSize}. Total Chunks: {TotalChunks} with {ChunkSize} size",- library.Name, chunkInfo.TotalSize, chunkInfo.TotalChunks, chunkInfo.ChunkSize);- for (var chunk = 1; chunk <= chunkInfo.TotalChunks; chunk++)- {- if (chunkInfo.TotalChunks == 0) continue;- totalTime += stopwatch.ElapsedMilliseconds;- stopwatch.Restart();- _logger.LogInformation("[ScannerService] Processing chunk {ChunkNumber} / {TotalChunks} with size {ChunkSize}. Series ({SeriesStart} - {SeriesEnd}",- chunk, chunkInfo.TotalChunks, chunkInfo.ChunkSize, chunk * chunkInfo.ChunkSize, (chunk + 1) * chunkInfo.ChunkSize);- var nonLibrarySeries = await _unitOfWork.SeriesRepository.GetFullSeriesForLibraryIdAsync(library.Id, new UserParams()- {- PageNumber = chunk,- PageSize = chunkInfo.ChunkSize- });-- // First, remove any series that are not in parsedSeries list- var missingSeries = FindSeriesNotOnDisk(nonLibrarySeries, parsedSeries).ToList();-- foreach (var missing in missingSeries)- {- _unitOfWork.SeriesRepository.Remove(missing);- }-- var cleanedSeries = RemoveMissingSeries(nonLibrarySeries, missingSeries, out var removeCount);- if (removeCount > 0)- {- _logger.LogInformation("[ScannerService] Removed {RemoveMissingSeries} series that are no longer on disk:", removeCount);- foreach (var s in missingSeries)- {- _logger.LogDebug("[ScannerService] Removed {SeriesName} ({Format})", s.Name, s.Format);- }- }-- // Now, we only have to deal with series that exist on disk. Let's recalculate the volumes for each series- var librarySeries = cleanedSeries.ToList();- Parallel.ForEach(librarySeries, (series) =>- {- UpdateSeries(series, parsedSeries);- });-- try- {- await _unitOfWork.CommitAsync();- }- catch (Exception ex)- {- _logger.LogCritical(ex, "[ScannerService] There was an issue writing to the DB. Chunk {ChunkNumber} did not save to DB. If debug mode, series to check will be printed", chunk);- foreach (var series in nonLibrarySeries)- {- _logger.LogDebug("[ScannerService] There may be a constraint issue with {SeriesName}", series.OriginalName);- }- await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryError,- MessageFactory.ScanLibraryError(library.Id));- continue;- }- _logger.LogInformation(- "[ScannerService] Processed {SeriesStart} - {SeriesEnd} series in {ElapsedScanTime} milliseconds for {LibraryName}",- chunk * chunkInfo.ChunkSize, (chunk * chunkInfo.ChunkSize) + nonLibrarySeries.Count, totalTime, library.Name);-- // Emit any series removed- foreach (var missing in missingSeries)- {- await _messageHub.Clients.All.SendAsync(SignalREvents.SeriesRemoved, MessageFactory.SeriesRemovedEvent(missing.Id, missing.Name, library.Id));- }-- var progress = Math.Max(0, Math.Min(1, ((chunk + 1F) * chunkInfo.ChunkSize) / chunkInfo.TotalSize));- await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,- MessageFactory.ScanLibraryProgressEvent(library.Id, progress));- }--- // Add new series that have parsedInfos- _logger.LogDebug("[ScannerService] Adding new series");- var newSeries = new List<Series>();- var allSeries = (await _unitOfWork.SeriesRepository.GetSeriesForLibraryIdAsync(library.Id)).ToList();- _logger.LogDebug("[ScannerService] Fetched {AllSeriesCount} series for comparing new series with. There should be {DeltaToParsedSeries} new series",- allSeries.Count, parsedSeries.Count - allSeries.Count);- foreach (var (key, infos) in parsedSeries)- {- // Key is normalized already- Series existingSeries;- try- {- existingSeries = allSeries.SingleOrDefault(s => FindSeries(s, key));- }- catch (Exception e)- {- // NOTE: If I ever want to put Duplicates table, this is where it can go- _logger.LogCritical(e, "[ScannerService] There are multiple series that map to normalized key {Key}. You can manually delete the entity via UI and rescan to fix it. This will be skipped", key.NormalizedName);- var duplicateSeries = allSeries.Where(s => FindSeries(s, key));- foreach (var series in duplicateSeries)- {- _logger.LogCritical("[ScannerService] Duplicate Series Found: {Key} maps with {Series}", key.Name, series.OriginalName);- }-- continue;- }-- if (existingSeries != null) continue;-- var s = DbFactory.Series(infos[0].Series);- s.Format = key.Format;- s.LibraryId = library.Id; // We have to manually set this since we aren't adding the series to the Library's series.- newSeries.Add(s);- }-- var i = 0;- foreach(var series in newSeries)- {- _logger.LogDebug("[ScannerService] Processing series {SeriesName}", series.OriginalName);- UpdateSeries(series, parsedSeries);- _unitOfWork.SeriesRepository.Attach(series);- try- {- await _unitOfWork.CommitAsync();- _logger.LogInformation(- "[ScannerService] Added {NewSeries} series in {ElapsedScanTime} milliseconds for {LibraryName}",- newSeries.Count, stopwatch.ElapsedMilliseconds, library.Name);-- // Inform UI of new series added- await _messageHub.Clients.All.SendAsync(SignalREvents.SeriesAdded, MessageFactory.SeriesAddedEvent(series.Id, series.Name, library.Id));- }- catch (Exception ex)- {- _logger.LogCritical(ex, "[ScannerService] There was a critical exception adding new series entry for {SeriesName} with a duplicate index key: {IndexKey} ",- series.Name, $"{series.Name}_{series.NormalizedName}_{series.LocalizedName}_{series.LibraryId}_{series.Format}");- }-- var progress = Math.Max(0F, Math.Min(1F, i * 1F / newSeries.Count));- await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,- MessageFactory.ScanLibraryProgressEvent(library.Id, progress));- i++;- }-- _logger.LogInformation(- "[ScannerService] Added {NewSeries} series in {ElapsedScanTime} milliseconds for {LibraryName}",- newSeries.Count, stopwatch.ElapsedMilliseconds, library.Name);- }-- private static bool FindSeries(Series series, ParsedSeries parsedInfoKey)- {- return (series.NormalizedName.Equals(parsedInfoKey.NormalizedName) || Parser.Parser.Normalize(series.OriginalName).Equals(parsedInfoKey.NormalizedName))- && (series.Format == parsedInfoKey.Format || series.Format == MangaFormat.Unknown);- }-- private void UpdateSeries(Series series, Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)- {- try- {- _logger.LogInformation("[ScannerService] Processing series {SeriesName}", series.OriginalName);-- var parsedInfos = ParseScannedFiles.GetInfosByName(parsedSeries, series);- UpdateVolumes(series, parsedInfos);- series.Pages = series.Volumes.Sum(v => v.Pages);-- series.NormalizedName = Parser.Parser.Normalize(series.Name);- series.Metadata ??= DbFactory.SeriesMetadata(new List<CollectionTag>());- if (series.Format == MangaFormat.Unknown)- {- series.Format = parsedInfos[0].Format;- }- series.OriginalName ??= parsedInfos[0].Series;- }- catch (Exception ex)- {- _logger.LogError(ex, "[ScannerService] There was an exception updating volumes for {SeriesName}", series.Name);- }- }-- public static IEnumerable<Series> FindSeriesNotOnDisk(IEnumerable<Series> existingSeries, Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)- {- var foundSeries = parsedSeries.Select(s => s.Key.Name).ToList();- return existingSeries.Where(es => !es.NameInList(foundSeries) && !SeriesHasMatchingParserInfoFormat(es, parsedSeries));- }-- /// <summary>- /// Checks each parser info to see if there is a name match and if so, checks if the format matches the Series object.- /// This accounts for if the Series has an Unknown type and if so, considers it matching.- /// </summary>- /// <param name="series"></param>- /// <param name="parsedSeries"></param>- /// <returns></returns>- private static bool SeriesHasMatchingParserInfoFormat(Series series,- Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)- {- var format = MangaFormat.Unknown;- foreach (var pSeries in parsedSeries.Keys)- {- var name = pSeries.Name;- var normalizedName = Parser.Parser.Normalize(name);-- if (normalizedName == series.NormalizedName ||- normalizedName == Parser.Parser.Normalize(series.Name) ||- name == series.Name || name == series.LocalizedName ||- name == series.OriginalName ||- normalizedName == Parser.Parser.Normalize(series.OriginalName))- {- format = pSeries.Format;- break;- }- }-- if (series.Format == MangaFormat.Unknown && format != MangaFormat.Unknown)- {- return true;- }-- return format == series.Format;- }-- /// <summary>- /// Removes all instances of missingSeries' Series from existingSeries Collection. Existing series is updated by- /// reference and the removed element count is returned.- /// </summary>- /// <param name="existingSeries">Existing Series in DB</param>- /// <param name="missingSeries">Series not found on disk or can't be parsed</param>- /// <param name="removeCount"></param>- /// <returns>the updated existingSeries</returns>- public static IEnumerable<Series> RemoveMissingSeries(IList<Series> existingSeries, IEnumerable<Series> missingSeries, out int removeCount)- {- var existingCount = existingSeries.Count;- var missingList = missingSeries.ToList();-- existingSeries = existingSeries.Where(- s => !missingList.Exists(- m => m.NormalizedName.Equals(s.NormalizedName) && m.Format == s.Format)).ToList();-- removeCount = existingCount - existingSeries.Count;-- return existingSeries;- }-- private void UpdateVolumes(Series series, IList<ParserInfo> parsedInfos)- {- var startingVolumeCount = series.Volumes.Count;- // Add new volumes and update chapters per volume- var distinctVolumes = parsedInfos.DistinctVolumes();- _logger.LogDebug("[ScannerService] Updating {DistinctVolumes} volumes on {SeriesName}", distinctVolumes.Count, series.Name);- foreach (var volumeNumber in distinctVolumes)- {- var volume = series.Volumes.SingleOrDefault(s => s.Name == volumeNumber);- if (volume == null)- {+ var keys = parsedSeries.Keys;+ foreach (var key in keys.Where(key =>+ series.Format != key.Format || !SeriesHelper.FindSeries(series, key)))+ {+ parsedSeries.Remove(key);+ }+ }++ private async Task CommitAndSend(int totalFiles,+ Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries, Stopwatch sw, long scanElapsedTime, Series series)+ {+ if (_unitOfWork.HasChanges())+ {+ await _unitOfWork.CommitAsync();+ _logger.LogInformation(+ "Processed {TotalFiles} files and {ParsedSeriesCount} series in {ElapsedScanTime} milliseconds for {SeriesName}",+ totalFiles, parsedSeries.Keys.Count, sw.ElapsedMilliseconds + scanElapsedTime, series.Name);+ }+ }+++ [DisableConcurrentExecution(timeoutInSeconds: 360)]+ [AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]+ public async Task ScanLibraries()+ {+ _logger.LogInformation("Starting Scan of All Libraries");+ var libraries = await _unitOfWork.LibraryRepository.GetLibrariesAsync();+ foreach (var lib in libraries)+ {+ await ScanLibrary(lib.Id);+ }+ _logger.LogInformation("Scan of All Libraries Finished");+ }+++ /// <summary>+ /// Scans a library for file changes.+ /// Will kick off a scheduled background task to refresh metadata,+ /// ie) all entities will be rechecked for new cover images and comicInfo.xml changes+ /// </summary>+ /// <param name="libraryId"></param>+ [DisableConcurrentExecution(360)]+ [AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]+ public async Task ScanLibrary(int libraryId)+ {+ Library library;+ try+ {+ library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(libraryId, LibraryIncludes.Folders);+ }+ catch (Exception ex)+ {+ // This usually only fails if user is not authenticated.+ _logger.LogError(ex, "[ScannerService] There was an issue fetching Library {LibraryId}", libraryId);+ return;+ }++ // Check if any of the folder roots are not available (ie disconnected from network, etc) and fail if any of them are+ if (library.Folders.Any(f => !_directoryService.IsDriveMounted(f.Path)))+ {+ _logger.LogCritical("Some of the root folders for library are not accessible. Please check that drives are connected and rescan. Scan will be aborted");+ await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,+ MessageFactory.ScanLibraryProgressEvent(libraryId, 1F));+ return;+ }++ // For Docker instances check if any of the folder roots are not available (ie disconnected volumes, etc) and fail if any of them are+ if (library.Folders.Any(f => _directoryService.IsDirectoryEmpty(f.Path)))+ {+ _logger.LogCritical("Some of the root folders for the library are empty. " ++ "Either your mount has been disconnected or you are trying to delete all series in the library. " ++ "Scan will be aborted. " ++ "Check that your mount is connected or change the library's root folder and rescan");+ await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,+ MessageFactory.ScanLibraryProgressEvent(libraryId, 1F));+ return;+ }++ _logger.LogInformation("[ScannerService] Beginning file scan on {LibraryName}", library.Name);+ await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,+ MessageFactory.ScanLibraryProgressEvent(libraryId, 0));++ var scanner = new ParseScannedFiles(_logger, _directoryService, _readingItemService);+ var series = scanner.ScanLibrariesForSeries(library.Type, library.Folders.Select(fp => fp.Path), out var totalFiles, out var scanElapsedTime);++ foreach (var folderPath in library.Folders)+ {+ folderPath.LastScanned = DateTime.Now;+ }+ var sw = Stopwatch.StartNew();++ await UpdateLibrary(library, series);++ library.LastScanned = DateTime.Now;+ _unitOfWork.LibraryRepository.Update(library);+ if (await _unitOfWork.CommitAsync())+ {+ _logger.LogInformation(+ "[ScannerService] Processed {TotalFiles} files and {ParsedSeriesCount} series in {ElapsedScanTime} milliseconds for {LibraryName}",+ totalFiles, series.Keys.Count, sw.ElapsedMilliseconds + scanElapsedTime, library.Name);+ }+ else+ {+ _logger.LogCritical(+ "[ScannerService] There was a critical error that resulted in a failed scan. Please check logs and rescan");+ }++ await CleanupDbEntities();++ await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,+ MessageFactory.ScanLibraryProgressEvent(libraryId, 1F));+ BackgroundJob.Enqueue(() => _metadataService.RefreshMetadata(libraryId, false));+ }++ /// <summary>+ /// Remove any user progress rows that no longer exist since scan library ran and deleted series/volumes/chapters+ /// </summary>+ private async Task CleanupAbandonedChapters()+ {+ var cleanedUp = await _unitOfWork.AppUserProgressRepository.CleanupAbandonedChapters();+ _logger.LogInformation("Removed {Count} abandoned progress rows", cleanedUp);+ }+++ /// <summary>+ /// Cleans up any abandoned rows due to removals from Scan loop+ /// </summary>+ private async Task CleanupDbEntities()+ {+ await CleanupAbandonedChapters();+ var cleanedUp = await _unitOfWork.CollectionTagRepository.RemoveTagsWithoutSeries();+ _logger.LogInformation("Removed {Count} abandoned collection tags", cleanedUp);+ }++ private async Task UpdateLibrary(Library library, Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)+ {+ if (parsedSeries == null) return;++ // Library contains no Series, so we need to fetch series in groups of ChunkSize+ var chunkInfo = await _unitOfWork.SeriesRepository.GetChunkInfo(library.Id);+ var stopwatch = Stopwatch.StartNew();+ var totalTime = 0L;++ var allPeople = await _unitOfWork.PersonRepository.GetAllPeople();+ var allGenres = await _unitOfWork.GenreRepository.GetAllGenresAsync();+ var allTags = await _unitOfWork.TagRepository.GetAllTagsAsync();++ // Update existing series+ _logger.LogInformation("[ScannerService] Updating existing series for {LibraryName}. Total Items: {TotalSize}. Total Chunks: {TotalChunks} with {ChunkSize} size",+ library.Name, chunkInfo.TotalSize, chunkInfo.TotalChunks, chunkInfo.ChunkSize);+ for (var chunk = 1; chunk <= chunkInfo.TotalChunks; chunk++)+ {+ if (chunkInfo.TotalChunks == 0) continue;+ totalTime += stopwatch.ElapsedMilliseconds;+ stopwatch.Restart();+ _logger.LogInformation("[ScannerService] Processing chunk {ChunkNumber} / {TotalChunks} with size {ChunkSize}. Series ({SeriesStart} - {SeriesEnd}",+ chunk, chunkInfo.TotalChunks, chunkInfo.ChunkSize, chunk * chunkInfo.ChunkSize, (chunk + 1) * chunkInfo.ChunkSize);+ var nonLibrarySeries = await _unitOfWork.SeriesRepository.GetFullSeriesForLibraryIdAsync(library.Id, new UserParams()+ {+ PageNumber = chunk,+ PageSize = chunkInfo.ChunkSize+ });++ // First, remove any series that are not in parsedSeries list+ var missingSeries = FindSeriesNotOnDisk(nonLibrarySeries, parsedSeries).ToList();++ foreach (var missing in missingSeries)+ {+ _unitOfWork.SeriesRepository.Remove(missing);+ }++ var cleanedSeries = SeriesHelper.RemoveMissingSeries(nonLibrarySeries, missingSeries, out var removeCount);+ if (removeCount > 0)+ {+ _logger.LogInformation("[ScannerService] Removed {RemoveMissingSeries} series that are no longer on disk:", removeCount);+ foreach (var s in missingSeries)+ {+ _logger.LogDebug("[ScannerService] Removed {SeriesName} ({Format})", s.Name, s.Format);+ }+ }++ // Now, we only have to deal with series that exist on disk. Let's recalculate the volumes for each series+ var librarySeries = cleanedSeries.ToList();+ Parallel.ForEach(librarySeries, (series) =>+ {+ UpdateSeries(series, parsedSeries, allPeople, allTags, allGenres, library.Type);+ });++ try+ {+ await _unitOfWork.CommitAsync();+ }+ catch (Exception ex)+ {+ _logger.LogCritical(ex, "[ScannerService] There was an issue writing to the DB. Chunk {ChunkNumber} did not save to DB. If debug mode, series to check will be printed", chunk);+ foreach (var series in nonLibrarySeries)+ {+ _logger.LogDebug("[ScannerService] There may be a constraint issue with {SeriesName}", series.OriginalName);+ }+ await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryError,+ MessageFactory.ScanLibraryError(library.Id));+ continue;+ }+ _logger.LogInformation(+ "[ScannerService] Processed {SeriesStart} - {SeriesEnd} series in {ElapsedScanTime} milliseconds for {LibraryName}",+ chunk * chunkInfo.ChunkSize, (chunk * chunkInfo.ChunkSize) + nonLibrarySeries.Count, totalTime, library.Name);++ // Emit any series removed+ foreach (var missing in missingSeries)+ {+ await _messageHub.Clients.All.SendAsync(SignalREvents.SeriesRemoved, MessageFactory.SeriesRemovedEvent(missing.Id, missing.Name, library.Id));+ }++ var progress = Math.Max(0, Math.Min(1, ((chunk + 1F) * chunkInfo.ChunkSize) / chunkInfo.TotalSize));+ await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,+ MessageFactory.ScanLibraryProgressEvent(library.Id, progress));+ }+++ // Add new series that have parsedInfos+ _logger.LogDebug("[ScannerService] Adding new series");+ var newSeries = new List<Series>();+ var allSeries = (await _unitOfWork.SeriesRepository.GetSeriesForLibraryIdAsync(library.Id)).ToList();+ _logger.LogDebug("[ScannerService] Fetched {AllSeriesCount} series for comparing new series with. There should be {DeltaToParsedSeries} new series",+ allSeries.Count, parsedSeries.Count - allSeries.Count);+ foreach (var (key, infos) in parsedSeries)+ {+ // Key is normalized already+ Series existingSeries;+ try+ {+ existingSeries = allSeries.SingleOrDefault(s => SeriesHelper.FindSeries(s, key));+ }+ catch (Exception e)+ {+ // NOTE: If I ever want to put Duplicates table, this is where it can go+ _logger.LogCritical(e, "[ScannerService] There are multiple series that map to normalized key {Key}. You can manually delete the entity via UI and rescan to fix it. This will be skipped", key.NormalizedName);+ var duplicateSeries = allSeries.Where(s => SeriesHelper.FindSeries(s, key));+ foreach (var series in duplicateSeries)+ {+ _logger.LogCritical("[ScannerService] Duplicate Series Found: {Key} maps with {Series}", key.Name, series.OriginalName);+ }++ continue;+ }++ if (existingSeries != null) continue;++ var s = DbFactory.Series(infos[0].Series);+ if (!string.IsNullOrEmpty(infos[0].SeriesSort))+ {+ s.SortName = infos[0].SeriesSort;+ }+ s.Format = key.Format;+ s.LibraryId = library.Id; // We have to manually set this since we aren't adding the series to the Library's series.+ newSeries.Add(s);+ }+++ var i = 0;+ foreach(var series in newSeries)+ {+ _logger.LogDebug("[ScannerService] Processing series {SeriesName}", series.OriginalName);+ UpdateSeries(series, parsedSeries, allPeople, allTags, allGenres, library.Type);+ _unitOfWork.SeriesRepository.Attach(series);+ try+ {+ await _unitOfWork.CommitAsync();+ _logger.LogInformation(+ "[ScannerService] Added {NewSeries} series in {ElapsedScanTime} milliseconds for {LibraryName}",+ newSeries.Count, stopwatch.ElapsedMilliseconds, library.Name);++ // Inform UI of new series added+ await _messageHub.Clients.All.SendAsync(SignalREvents.SeriesAdded, MessageFactory.SeriesAddedEvent(series.Id, series.Name, library.Id));+ }+ catch (Exception ex)+ {+ _logger.LogCritical(ex, "[ScannerService] There was a critical exception adding new series entry for {SeriesName} with a duplicate index key: {IndexKey} ",+ series.Name, $"{series.Name}_{series.NormalizedName}_{series.LocalizedName}_{series.LibraryId}_{series.Format}");+ }++ var progress = Math.Max(0F, Math.Min(1F, i * 1F / newSeries.Count));+ await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,+ MessageFactory.ScanLibraryProgressEvent(library.Id, progress));+ i++;+ }++ _logger.LogInformation(+ "[ScannerService] Added {NewSeries} series in {ElapsedScanTime} milliseconds for {LibraryName}",+ newSeries.Count, stopwatch.ElapsedMilliseconds, library.Name);+ }++ private void UpdateSeries(Series series, Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries,+ ICollection<Person> allPeople, ICollection<Tag> allTags, ICollection<Genre> allGenres, LibraryType libraryType)+ {+ try+ {+ _logger.LogInformation("[ScannerService] Processing series {SeriesName}", series.OriginalName);++ // Get all associated ParsedInfos to the series. This includes infos that use a different filename that matches Series LocalizedName+ var parsedInfos = ParseScannedFiles.GetInfosByName(parsedSeries, series);+ UpdateVolumes(series, parsedInfos, allPeople, allTags, allGenres);+ series.Pages = series.Volumes.Sum(v => v.Pages);++ series.NormalizedName = Parser.Parser.Normalize(series.Name);+ series.Metadata ??= DbFactory.SeriesMetadata(new List<CollectionTag>());+ if (series.Format == MangaFormat.Unknown)+ {+ series.Format = parsedInfos[0].Format;+ }+ series.OriginalName ??= parsedInfos[0].Series;+ series.SortName ??= parsedInfos[0].SeriesSort;++ UpdateSeriesMetadata(series, allPeople, allGenres, allTags, libraryType);+ }+ catch (Exception ex)+ {+ _logger.LogError(ex, "[ScannerService] There was an exception updating volumes for {SeriesName}", series.Name);+ }+ }++ public static IEnumerable<Series> FindSeriesNotOnDisk(IEnumerable<Series> existingSeries, Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)+ {+ return existingSeries.Where(es => !ParserInfoHelpers.SeriesHasMatchingParserInfoFormat(es, parsedSeries));+ }+++ private static void UpdateSeriesMetadata(Series series, ICollection<Person> allPeople, ICollection<Genre> allGenres, ICollection<Tag> allTags, LibraryType libraryType)+ {+ var isBook = libraryType == LibraryType.Book;+ var firstVolume = series.Volumes.OrderBy(c => c.Number, new ChapterSortComparer()).FirstWithChapters(isBook);+ var firstChapter = firstVolume?.Chapters.GetFirstChapterWithFiles();++ var firstFile = firstChapter?.Files.FirstOrDefault();+ if (firstFile == null) return;+ if (Parser.Parser.IsPdf(firstFile.FilePath)) return;++ var chapters = series.Volumes.SelectMany(volume => volume.Chapters).ToList();++ // Update Metadata based on Chapter metadata+ series.Metadata.ReleaseYear = chapters.Min(c => c.ReleaseDate.Year);++ if (series.Metadata.ReleaseYear < 1000)+ {+ // Not a valid year, default to 0+ series.Metadata.ReleaseYear = 0;+ }++ // Set the AgeRating as highest in all the comicInfos+ series.Metadata.AgeRating = chapters.Max(chapter => chapter.AgeRating);+++ series.Metadata.Count = chapters.Max(chapter => chapter.TotalCount);+ series.Metadata.PublicationStatus = PublicationStatus.OnGoing;+ if (chapters.Max(chapter => chapter.Count) >= series.Metadata.Count && series.Metadata.Count > 0)+ {+ series.Metadata.PublicationStatus = PublicationStatus.Completed;+ }++ if (!string.IsNullOrEmpty(firstChapter.Summary))+ {+ series.Metadata.Summary = firstChapter.Summary;+ }++ if (!string.IsNullOrEmpty(firstChapter.Language))+ {+ series.Metadata.Language = firstChapter.Language;+ }+++ // Handle People+ foreach (var chapter in chapters)+ {+ PersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.Writer).Select(p => p.Name), PersonRole.Writer,+ person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));++ PersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.CoverArtist).Select(p => p.Name), PersonRole.CoverArtist,+ person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));++ PersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.Publisher).Select(p => p.Name), PersonRole.Publisher,+ person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));++ PersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.Character).Select(p => p.Name), PersonRole.Character,+ person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));++ PersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.Colorist).Select(p => p.Name), PersonRole.Colorist,+ person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));++ PersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.Editor).Select(p => p.Name), PersonRole.Editor,+ person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));++ PersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.Inker).Select(p => p.Name), PersonRole.Inker,+ person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));++ PersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.Letterer).Select(p => p.Name), PersonRole.Letterer,+ person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));++ PersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.Penciller).Select(p => p.Name), PersonRole.Penciller,+ person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));++ PersonHelper.UpdatePeople(allPeople, chapter.People.Where(p => p.Role == PersonRole.Translator).Select(p => p.Name), PersonRole.Translator,+ person => PersonHelper.AddPersonIfNotExists(series.Metadata.People, person));++ TagHelper.UpdateTag(allTags, chapter.Tags.Select(t => t.Title), false, (tag, added) =>+ TagHelper.AddTagIfNotExists(series.Metadata.Tags, tag));++ GenreHelper.UpdateGenre(allGenres, chapter.Genres.Select(t => t.Title), false, genre =>+ GenreHelper.AddGenreIfNotExists(series.Metadata.Genres, genre));+ }++ var people = chapters.SelectMany(c => c.People).ToList();+ PersonHelper.KeepOnlySamePeopleBetweenLists(series.Metadata.People,+ people, person => series.Metadata.People.Remove(person));+ }++++ private void UpdateVolumes(Series series, IList<ParserInfo> parsedInfos, ICollection<Person> allPeople, ICollection<Tag> allTags, ICollection<Genre> allGenres)+ {+ var startingVolumeCount = series.Volumes.Count;+ // Add new volumes and update chapters per volume+ var distinctVolumes = parsedInfos.DistinctVolumes();+ _logger.LogDebug("[ScannerService] Updating {DistinctVolumes} volumes on {SeriesName}", distinctVolumes.Count, series.Name);+ foreach (var volumeNumber in distinctVolumes)+ {+ var volume = series.Volumes.SingleOrDefault(s => s.Name == volumeNumber);+ if (volume == null)+ {volume = DbFactory.Volume(volumeNumber);series.Volumes.Add(volume);_unitOfWork.VolumeRepository.Add(volume);- }-- _logger.LogDebug("[ScannerService] Parsing {SeriesName} - Volume {VolumeNumber}", series.Name, volume.Name);- var infos = parsedInfos.Where(p => p.Volumes == volumeNumber).ToArray();- UpdateChapters(volume, infos);- volume.Pages = volume.Chapters.Sum(c => c.Pages);- }-- // Remove existing volumes that aren't in parsedInfos- var nonDeletedVolumes = series.Volumes.Where(v => parsedInfos.Select(p => p.Volumes).Contains(v.Name)).ToList();- if (series.Volumes.Count != nonDeletedVolumes.Count)- {- _logger.LogDebug("[ScannerService] Removed {Count} volumes from {SeriesName} where parsed infos were not mapping with volume name",+ }++ _logger.LogDebug("[ScannerService] Parsing {SeriesName} - Volume {VolumeNumber}", series.Name, volume.Name);+ var infos = parsedInfos.Where(p => p.Volumes == volumeNumber).ToArray();+ UpdateChapters(volume, infos);+ volume.Pages = volume.Chapters.Sum(c => c.Pages);++ // Update all the metadata on the Chapters+ foreach (var chapter in volume.Chapters)+ {+ var firstFile = chapter.Files.OrderBy(x => x.Chapter).FirstOrDefault();+ if (firstFile == null || _cacheHelper.HasFileNotChangedSinceCreationOrLastScan(chapter, false, firstFile)) continue;+ try+ {+ var firstChapterInfo = infos.SingleOrDefault(i => i.FullFilePath.Equals(firstFile.FilePath));+ UpdateChapterFromComicInfo(chapter, allPeople, allTags, allGenres, firstChapterInfo?.ComicInfo);+ }+ catch (Exception ex)+ {+ _logger.LogError(ex, "There was some issue when updating chapter's metadata");+ }+ }+ }++ // Remove existing volumes that aren't in parsedInfos+ var nonDeletedVolumes = series.Volumes.Where(v => parsedInfos.Select(p => p.Volumes).Contains(v.Name)).ToList();+ if (series.Volumes.Count != nonDeletedVolumes.Count)+ {+ _logger.LogDebug("[ScannerService] Removed {Count} volumes from {SeriesName} where parsed infos were not mapping with volume name",(series.Volumes.Count - nonDeletedVolumes.Count), series.Name);- var deletedVolumes = series.Volumes.Except(nonDeletedVolumes);- foreach (var volume in deletedVolumes)- {- var file = volume.Chapters.FirstOrDefault()?.Files?.FirstOrDefault()?.FilePath ?? "";- if (!string.IsNullOrEmpty(file) && File.Exists(file))- {- _logger.LogError(- "[ScannerService] Volume cleanup code was trying to remove a volume with a file still existing on disk. File: {File}",- file);- }-- _logger.LogDebug("[ScannerService] Removed {SeriesName} - Volume {Volume}: {File}", series.Name, volume.Name, file);- }-- series.Volumes = nonDeletedVolumes;- }-- _logger.LogDebug("[ScannerService] Updated {SeriesName} volumes from {StartingVolumeCount} to {VolumeCount}",- series.Name, startingVolumeCount, series.Volumes.Count);- }-- /// <summary>- ///- /// </summary>- /// <param name="volume"></param>- /// <param name="parsedInfos"></param>- private void UpdateChapters(Volume volume, IList<ParserInfo> parsedInfos)- {- // Add new chapters- foreach (var info in parsedInfos)- {- // Specials go into their own chapters with Range being their filename and IsSpecial = True. Non-Specials with Vol and Chap as 0- // also are treated like specials for UI grouping.- Chapter chapter;- try- {+ var deletedVolumes = series.Volumes.Except(nonDeletedVolumes);+ foreach (var volume in deletedVolumes)+ {+ var file = volume.Chapters.FirstOrDefault()?.Files?.FirstOrDefault()?.FilePath ?? "";+ if (!string.IsNullOrEmpty(file) && File.Exists(file))+ {+ _logger.LogError(+ "[ScannerService] Volume cleanup code was trying to remove a volume with a file still existing on disk. File: {File}",+ file);+ }++ _logger.LogDebug("[ScannerService] Removed {SeriesName} - Volume {Volume}: {File}", series.Name, volume.Name, file);+ }++ series.Volumes = nonDeletedVolumes;+ }++ _logger.LogDebug("[ScannerService] Updated {SeriesName} volumes from {StartingVolumeCount} to {VolumeCount}",+ series.Name, startingVolumeCount, series.Volumes.Count);+ }++ private void UpdateChapters(Volume volume, IList<ParserInfo> parsedInfos)+ {+ // Add new chapters+ foreach (var info in parsedInfos)+ {+ // Specials go into their own chapters with Range being their filename and IsSpecial = True. Non-Specials with Vol and Chap as 0+ // also are treated like specials for UI grouping.+ Chapter chapter;+ try+ {chapter = volume.Chapters.GetChapterByRange(info);- }- catch (Exception ex)- {+ }+ catch (Exception ex)+ {_logger.LogError(ex, "{FileName} mapped as '{Series} - Vol {Volume} Ch {Chapter}' is a duplicate, skipping", info.FullFilePath, info.Series, info.Volumes, info.Chapters);continue;- }+ }- if (chapter == null)- {+ if (chapter == null)+ {_logger.LogDebug(- "[ScannerService] Adding new chapter, {Series} - Vol {Volume} Ch {Chapter}", info.Series, info.Volumes, info.Chapters);+ "[ScannerService] Adding new chapter, {Series} - Vol {Volume} Ch {Chapter}", info.Series, info.Volumes, info.Chapters);volume.Chapters.Add(DbFactory.Chapter(info));- }- else- {+ }+ else+ {chapter.UpdateFrom(info);- }+ }- }+ }- // Add files- foreach (var info in parsedInfos)- {- var specialTreatment = info.IsSpecialInfo();- Chapter chapter;- try- {+ // Add files+ foreach (var info in parsedInfos)+ {+ var specialTreatment = info.IsSpecialInfo();+ Chapter chapter;+ try+ {chapter = volume.Chapters.GetChapterByRange(info);- }- catch (Exception ex)- {+ }+ catch (Exception ex)+ {_logger.LogError(ex, "There was an exception parsing chapter. Skipping {SeriesName} Vol {VolumeNumber} Chapter {ChapterNumber} - Special treatment: {NeedsSpecialTreatment}", info.Series, volume.Name, info.Chapters, specialTreatment);continue;- }- if (chapter == null) continue;- AddOrUpdateFileForChapter(chapter, info);- chapter.Number = Parser.Parser.MinimumNumberFromRange(info.Chapters) + string.Empty;- chapter.Range = specialTreatment ? info.Filename : info.Chapters;- }--- // Remove chapters that aren't in parsedInfos or have no files linked- var existingChapters = volume.Chapters.ToList();- foreach (var existingChapter in existingChapters)- {- if (existingChapter.Files.Count == 0 || !parsedInfos.HasInfo(existingChapter))- {+ }+ if (chapter == null) continue;+ AddOrUpdateFileForChapter(chapter, info);+ chapter.Number = Parser.Parser.MinimumNumberFromRange(info.Chapters) + string.Empty;+ chapter.Range = specialTreatment ? info.Filename : info.Chapters;+ }+++ // Remove chapters that aren't in parsedInfos or have no files linked+ var existingChapters = volume.Chapters.ToList();+ foreach (var existingChapter in existingChapters)+ {+ if (existingChapter.Files.Count == 0 || !parsedInfos.HasInfo(existingChapter))+ {_logger.LogDebug("[ScannerService] Removed chapter {Chapter} for Volume {VolumeNumber} on {SeriesName}", existingChapter.Range, volume.Name, parsedInfos[0].Series);volume.Chapters.Remove(existingChapter);- }- else- {+ }+ else+ {// Ensure we remove any files that no longer exist AND orderexistingChapter.Files = existingChapter.Files- .Where(f => parsedInfos.Any(p => p.FullFilePath == f.FilePath))- .OrderBy(f => f.FilePath, _naturalSort).ToList();+ .Where(f => parsedInfos.Any(p => p.FullFilePath == f.FilePath))+ .OrderByNatural(f => f.FilePath).ToList();existingChapter.Pages = existingChapter.Files.Sum(f => f.Pages);- }- }- }-- private MangaFile CreateMangaFile(ParserInfo info)- {- MangaFile mangaFile = null;- switch (info.Format)- {- case MangaFormat.Archive:- {- mangaFile = new MangaFile()- {- FilePath = info.FullFilePath,- Format = info.Format,- Pages = _archiveService.GetNumberOfPagesFromArchive(info.FullFilePath)- };- break;- }- case MangaFormat.Pdf:- case MangaFormat.Epub:- {- mangaFile = new MangaFile()+ }+ }+ }++ private void AddOrUpdateFileForChapter(Chapter chapter, ParserInfo info)+ {+ chapter.Files ??= new List<MangaFile>();+ var existingFile = chapter.Files.SingleOrDefault(f => f.FilePath == info.FullFilePath);+ if (existingFile != null)+ {+ existingFile.Format = info.Format;+ if (!_fileService.HasFileBeenModifiedSince(existingFile.FilePath, existingFile.LastModified) && existingFile.Pages != 0) return;+ existingFile.Pages = _readingItemService.GetNumberOfPages(info.FullFilePath, info.Format);+ // We skip updating DB here with last modified time so that metadata refresh can do it+ }+ else+ {+ var file = DbFactory.MangaFile(info.FullFilePath, info.Format, _readingItemService.GetNumberOfPages(info.FullFilePath, info.Format));+ if (file == null) return;++ chapter.Files.Add(file);+ }+ }++ private void UpdateChapterFromComicInfo(Chapter chapter, ICollection<Person> allPeople, ICollection<Tag> allTags, ICollection<Genre> allGenres, ComicInfo? info)+ {+ var firstFile = chapter.Files.OrderBy(x => x.Chapter).FirstOrDefault();+ if (firstFile == null ||+ _cacheHelper.HasFileNotChangedSinceCreationOrLastScan(chapter, false, firstFile)) return;++ var comicInfo = info;+ if (info == null)+ {+ comicInfo = _readingItemService.GetComicInfo(firstFile.FilePath);+ }++ if (comicInfo == null) return;++ chapter.AgeRating = ComicInfo.ConvertAgeRatingToEnum(comicInfo.AgeRating);++ if (!string.IsNullOrEmpty(comicInfo.Title))+ {+ chapter.TitleName = comicInfo.Title.Trim();+ }++ if (!string.IsNullOrEmpty(comicInfo.Summary))+ {+ chapter.Summary = comicInfo.Summary;+ }++ if (!string.IsNullOrEmpty(comicInfo.LanguageISO))+ {+ chapter.Language = comicInfo.LanguageISO;+ }++ if (comicInfo.Count > 0)+ {+ chapter.TotalCount = comicInfo.Count;+ }++ if (!string.IsNullOrEmpty(comicInfo.Number) && int.Parse(comicInfo.Number) > 0)+ {+ chapter.Count = int.Parse(comicInfo.Number);+ }+++++ if (comicInfo.Year > 0)+ {+ var day = Math.Max(comicInfo.Day, 1);+ var month = Math.Max(comicInfo.Month, 1);+ chapter.ReleaseDate = DateTime.Parse($"{month}/{day}/{comicInfo.Year}");+ }++ if (!string.IsNullOrEmpty(comicInfo.Colorist))+ {+ var people = comicInfo.Colorist.Split(",");+ PersonHelper.RemovePeople(chapter.People, people, PersonRole.Colorist);+ PersonHelper.UpdatePeople(allPeople, people, PersonRole.Colorist,+ person => PersonHelper.AddPersonIfNotExists(chapter.People, person));+ }++ if (!string.IsNullOrEmpty(comicInfo.Characters))+ {+ var people = comicInfo.Characters.Split(",");+ PersonHelper.RemovePeople(chapter.People, people, PersonRole.Character);+ PersonHelper.UpdatePeople(allPeople, people, PersonRole.Character,+ person => PersonHelper.AddPersonIfNotExists(chapter.People, person));+ }++ if (!string.IsNullOrEmpty(comicInfo.Translator))+ {+ var people = comicInfo.Translator.Split(",");+ PersonHelper.RemovePeople(chapter.People, people, PersonRole.Translator);+ PersonHelper.UpdatePeople(allPeople, people, PersonRole.Translator,+ person => PersonHelper.AddPersonIfNotExists(chapter.People, person));+ }++ if (!string.IsNullOrEmpty(comicInfo.Tags))+ {+ var tags = comicInfo.Tags.Split(",").Select(s => s.Trim()).ToList();+ // Remove all tags that aren't matching between chapter tags and metadata+ TagHelper.KeepOnlySameTagBetweenLists(chapter.Tags, tags.Select(t => DbFactory.Tag(t, false)).ToList());+ TagHelper.UpdateTag(allTags, tags, false,+ (tag, added) =>{- FilePath = info.FullFilePath,- Format = info.Format,- Pages = _bookService.GetNumberOfPages(info.FullFilePath)- };- break;- }- case MangaFormat.Image:- {- mangaFile = new MangaFile()- {- FilePath = info.FullFilePath,- Format = info.Format,- Pages = 1- };- break;- }- default:- _logger.LogWarning("[Scanner] Ignoring {Filename}. File type is not supported", info.Filename);- break;- }-- mangaFile?.UpdateLastModified();- return mangaFile;- }-- private void AddOrUpdateFileForChapter(Chapter chapter, ParserInfo info)- {- chapter.Files ??= new List<MangaFile>();- var existingFile = chapter.Files.SingleOrDefault(f => f.FilePath == info.FullFilePath);- if (existingFile != null)- {- existingFile.Format = info.Format;- if (!existingFile.HasFileBeenModified() && existingFile.Pages != 0) return;- switch (existingFile.Format)- {- case MangaFormat.Epub:- case MangaFormat.Pdf:- existingFile.Pages = _bookService.GetNumberOfPages(info.FullFilePath);- break;- case MangaFormat.Image:- existingFile.Pages = 1;- break;- case MangaFormat.Unknown:- existingFile.Pages = 0;- break;- case MangaFormat.Archive:- existingFile.Pages = _archiveService.GetNumberOfPagesFromArchive(info.FullFilePath);- break;- }- existingFile.LastModified = File.GetLastWriteTime(info.FullFilePath);- }- else- {- var file = CreateMangaFile(info);- if (file == null) return;-- chapter.Files.Add(file);- }- }+ chapter.Tags.Add(tag);+ });+ }++ if (!string.IsNullOrEmpty(comicInfo.Writer))+ {+ var people = comicInfo.Writer.Split(",");+ PersonHelper.RemovePeople(chapter.People, people, PersonRole.Writer);+ PersonHelper.UpdatePeople(allPeople, people, PersonRole.Writer,+ person => PersonHelper.AddPersonIfNotExists(chapter.People, person));+ }++ if (!string.IsNullOrEmpty(comicInfo.Editor))+ {+ var people = comicInfo.Editor.Split(",");+ PersonHelper.RemovePeople(chapter.People, people, PersonRole.Editor);+ PersonHelper.UpdatePeople(allPeople, people, PersonRole.Editor,+ person => PersonHelper.AddPersonIfNotExists(chapter.People, person));+ }++ if (!string.IsNullOrEmpty(comicInfo.Inker))+ {+ var people = comicInfo.Inker.Split(",");+ PersonHelper.RemovePeople(chapter.People, people, PersonRole.Inker);+ PersonHelper.UpdatePeople(allPeople, people, PersonRole.Inker,+ person => PersonHelper.AddPersonIfNotExists(chapter.People, person));+ }++ if (!string.IsNullOrEmpty(comicInfo.Letterer))+ {+ var people = comicInfo.Letterer.Split(",");+ PersonHelper.RemovePeople(chapter.People, people, PersonRole.Letterer);+ PersonHelper.UpdatePeople(allPeople, people, PersonRole.Letterer,+ person => PersonHelper.AddPersonIfNotExists(chapter.People, person));+ }++ if (!string.IsNullOrEmpty(comicInfo.Penciller))+ {+ var people = comicInfo.Penciller.Split(",");+ PersonHelper.RemovePeople(chapter.People, people, PersonRole.Penciller);+ PersonHelper.UpdatePeople(allPeople, people, PersonRole.Penciller,+ person => PersonHelper.AddPersonIfNotExists(chapter.People, person));+ }++ if (!string.IsNullOrEmpty(comicInfo.CoverArtist))+ {+ var people = comicInfo.CoverArtist.Split(",");+ PersonHelper.RemovePeople(chapter.People, people, PersonRole.CoverArtist);+ PersonHelper.UpdatePeople(allPeople, people, PersonRole.CoverArtist,+ person => PersonHelper.AddPersonIfNotExists(chapter.People, person));+ }++ if (!string.IsNullOrEmpty(comicInfo.Publisher))+ {+ var people = comicInfo.Publisher.Split(",");+ PersonHelper.RemovePeople(chapter.People, people, PersonRole.Publisher);+ PersonHelper.UpdatePeople(allPeople, people, PersonRole.Publisher,+ person => PersonHelper.AddPersonIfNotExists(chapter.People, person));+ }++ if (!string.IsNullOrEmpty(comicInfo.Genre))+ {+ var genres = comicInfo.Genre.Split(",");+ GenreHelper.KeepOnlySameGenreBetweenLists(chapter.Genres, genres.Select(g => DbFactory.Genre(g, false)).ToList());+ GenreHelper.UpdateGenre(allGenres, genres, false,+ genre => chapter.Genres.Add(genre));+ }}}diff --git a/API/Services/Tasks/StatsService.cs b/API/Services/Tasks/StatsService.csindex 0052e0cb4..1b9f25593 100644--- a/API/Services/Tasks/StatsService.cs+++ b/API/Services/Tasks/StatsService.cs@@ -2,108 +2,111 @@using System.Net.Http;using System.Runtime.InteropServices;using System.Threading.Tasks;+using API.Data;using API.DTOs.Stats;using API.Entities.Enums;-using API.Interfaces;-using API.Interfaces.Services;using Flurl.Http;using Kavita.Common.EnvironmentInfo;using Microsoft.AspNetCore.Http;using Microsoft.Extensions.Logging;-namespace API.Services.Tasks+namespace API.Services.Tasks;++public interface IStatsService{- public class StatsService : IStatsService- {- private readonly ILogger<StatsService> _logger;- private readonly IUnitOfWork _unitOfWork;- private const string ApiUrl = "https://stats.kavitareader.com";+ Task Send();+ Task<ServerInfoDto> GetServerInfo();+}+public class StatsService : IStatsService+{+ private readonly ILogger<StatsService> _logger;+ private readonly IUnitOfWork _unitOfWork;+ private const string ApiUrl = "https://stats.kavitareader.com";- public StatsService(ILogger<StatsService> logger, IUnitOfWork unitOfWork)- {- _logger = logger;- _unitOfWork = unitOfWork;+ public StatsService(ILogger<StatsService> logger, IUnitOfWork unitOfWork)+ {+ _logger = logger;+ _unitOfWork = unitOfWork;- FlurlHttp.ConfigureClient(ApiUrl, cli =>- cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());- }+ FlurlHttp.ConfigureClient(ApiUrl, cli =>+ cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());+ }- /// <summary>- /// Due to all instances firing this at the same time, we can DDOS our server. This task when fired will schedule the task to be run- /// randomly over a 6 hour spread- /// </summary>- public async Task Send()+ /// <summary>+ /// Due to all instances firing this at the same time, we can DDOS our server. This task when fired will schedule the task to be run+ /// randomly over a 6 hour spread+ /// </summary>+ public async Task Send()+ {+ var allowStatCollection = (await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).AllowStatCollection;+ if (!allowStatCollection){- var allowStatCollection = (await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).AllowStatCollection;- if (!allowStatCollection)- {- return;- }-- await SendData();+ return;}- /// <summary>- /// This must be public for Hangfire. Do not call this directly.- /// </summary>- // ReSharper disable once MemberCanBePrivate.Global- public async Task SendData()- {- var data = await GetServerInfo();- await SendDataToStatsServer(data);- }+ await SendData();+ }+ /// <summary>+ /// This must be public for Hangfire. Do not call this directly.+ /// </summary>+ // ReSharper disable once MemberCanBePrivate.Global+ public async Task SendData()+ {+ var data = await GetServerInfo();+ await SendDataToStatsServer(data);+ }- private async Task SendDataToStatsServer(ServerInfoDto data)- {- var responseContent = string.Empty;- try- {- var response = await (ApiUrl + "/api/v2/stats")- .WithHeader("Accept", "application/json")- .WithHeader("User-Agent", "Kavita")- .WithHeader("x-api-key", "MsnvA2DfQqxSK5jh")- .WithHeader("x-kavita-version", BuildInfo.Version)- .WithHeader("Content-Type", "application/json")- .WithTimeout(TimeSpan.FromSeconds(30))- .PostJsonAsync(data);+ private async Task SendDataToStatsServer(ServerInfoDto data)+ {+ var responseContent = string.Empty;- if (response.StatusCode != StatusCodes.Status200OK)- {- _logger.LogError("KavitaStats did not respond successfully. {Content}", response);- }- }- catch (HttpRequestException e)- {- var info = new- {- dataSent = data,- response = responseContent- };+ try+ {+ var response = await (ApiUrl + "/api/v2/stats")+ .WithHeader("Accept", "application/json")+ .WithHeader("User-Agent", "Kavita")+ .WithHeader("x-api-key", "MsnvA2DfQqxSK5jh")+ .WithHeader("x-kavita-version", BuildInfo.Version)+ .WithHeader("Content-Type", "application/json")+ .WithTimeout(TimeSpan.FromSeconds(30))+ .PostJsonAsync(data);- _logger.LogError(e, "KavitaStats did not respond successfully. {Content}", info);- }- catch (Exception e)+ if (response.StatusCode != StatusCodes.Status200OK){- _logger.LogError(e, "An error happened during the request to KavitaStats");+ _logger.LogError("KavitaStats did not respond successfully. {Content}", response);}}-- public async Task<ServerInfoDto> GetServerInfo()+ catch (HttpRequestException e){- var installId = await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.InstallId);- var serverInfo = new ServerInfoDto+ var info = new{- InstallId = installId.Value,- Os = RuntimeInformation.OSDescription,- KavitaVersion = BuildInfo.Version.ToString(),- DotnetVersion = Environment.Version.ToString(),- IsDocker = new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker,- NumOfCores = Math.Max(Environment.ProcessorCount, 1)+ dataSent = data,+ response = responseContent};- return serverInfo;+ _logger.LogError(e, "KavitaStats did not respond successfully. {Content}", info);+ }+ catch (Exception e)+ {+ _logger.LogError(e, "An error happened during the request to KavitaStats");}}++ public async Task<ServerInfoDto> GetServerInfo()+ {+ var installId = await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.InstallId);+ var serverInfo = new ServerInfoDto+ {+ InstallId = installId.Value,+ Os = RuntimeInformation.OSDescription,+ KavitaVersion = BuildInfo.Version.ToString(),+ DotnetVersion = Environment.Version.ToString(),+ IsDocker = new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker,+ NumOfCores = Math.Max(Environment.ProcessorCount, 1)+ };++ return serverInfo;+ }}diff --git a/API/Services/Tasks/VersionUpdaterService.cs b/API/Services/Tasks/VersionUpdaterService.csindex 64e21d39a..178111051 100644--- a/API/Services/Tasks/VersionUpdaterService.cs+++ b/API/Services/Tasks/VersionUpdaterService.cs@@ -4,7 +4,6 @@ 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;@@ -15,159 +14,155 @@ using Microsoft.AspNetCore.SignalR;using Microsoft.Extensions.Hosting;using Microsoft.Extensions.Logging;-namespace API.Services.Tasks+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; }+ /// <summary>+ /// Date Release was Published+ /// </summary>+ // ReSharper disable once InconsistentNaming+ public string Published_At { get; init; }+}++public class UntrustedCertClientFactory : DefaultHttpClientFactory+{+ public override HttpMessageHandler CreateMessageHandler() {+ return new HttpClientHandler {+ ServerCertificateCustomValidationCallback = (_, _, _, _) => true+ };+ }+}++public interface IVersionUpdaterService+{+ Task<UpdateNotificationDto> CheckForUpdate();+ Task PushUpdate(UpdateNotificationDto update);+ Task<IEnumerable<UpdateNotificationDto>> GetAllReleases();+}++public class VersionUpdaterService : IVersionUpdaterService{- internal class GithubReleaseMetadata+ 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){- /// <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; }- /// <summary>- /// Date Release was Published- /// </summary>- // ReSharper disable once InconsistentNaming- public string Published_At { get; init; }+ _logger = logger;+ _messageHub = messageHub;+ _tracker = tracker;++ FlurlHttp.ConfigureClient(GithubLatestReleasesUrl, cli =>+ cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());+ FlurlHttp.ConfigureClient(GithubAllReleasesUrl, cli =>+ cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());}- public class UntrustedCertClientFactory : DefaultHttpClientFactory+ /// <summary>+ /// Fetches the latest release from Github+ /// </summary>+ public async Task<UpdateNotificationDto> CheckForUpdate(){- public override HttpMessageHandler CreateMessageHandler() {- return new HttpClientHandler {- ServerCertificateCustomValidationCallback = (_, _, _, _) => true- };- }+ var update = await GetGithubRelease();+ return CreateDto(update);}- public class VersionUpdaterService : IVersionUpdaterService+ public async Task<IEnumerable<UpdateNotificationDto>> GetAllReleases(){- 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+ var updates = await GetGithubReleases();+ return updates.Select(CreateDto);+ }- 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());- }+ 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();- /// <summary>- /// Fetches the latest release from Github- /// </summary>- public async Task<UpdateNotificationDto> CheckForUpdate()+ if (updateVersion.Revision == -1){- var update = await GetGithubRelease();- return CreateDto(update);+ currentVersion = currentVersion.Substring(0, currentVersion.LastIndexOf(".", StringComparison.Ordinal));}- /// <summary>- ///- /// </summary>- /// <returns></returns>- public async Task<IEnumerable<UpdateNotificationDto>> GetAllReleases()+ return new UpdateNotificationDto(){- var updates = await GetGithubReleases();- return updates.Select(CreateDto);- }+ 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,+ PublishDate = update.Published_At+ };+ }- 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,- PublishDate = update.Published_At- };- }+ public async Task PushUpdate(UpdateNotificationDto update)+ {+ if (update == null) return;++ var admins = await _tracker.GetOnlineAdmins();+ var updateVersion = new Version(update.CurrentVersion);- public async Task PushUpdate(UpdateNotificationDto update)+ if (BuildInfo.Version < updateVersion){- 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);- }+ _logger.LogInformation("Server is out of date. Current: {CurrentVersion}. Available: {AvailableUpdate}", BuildInfo.Version, updateVersion);+ await SendEvent(update, admins);}-- private async Task SendEvent(UpdateNotificationDto update, IReadOnlyList<string> admins)+ else if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == Environments.Development){- 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));+ _logger.LogInformation("Server is up to date. Current: {CurrentVersion}", BuildInfo.Version);+ await SendEvent(update, admins);}+ }+ private async Task SendEvent(UpdateNotificationDto update, IReadOnlyList<string> admins)+ {+ await _messageHub.Clients.Users(admins).SendAsync(SignalREvents.UpdateAvailable, 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<GithubReleaseMetadata> GetGithubRelease()+ {+ var update = await GithubLatestReleasesUrl+ .WithHeader("Accept", "application/json")+ .WithHeader("User-Agent", "Kavita")+ .GetJsonAsync<GithubReleaseMetadata>();- private static async Task<IEnumerable<GithubReleaseMetadata>> GetGithubReleases()- {- var update = await GithubAllReleasesUrl- .WithHeader("Accept", "application/json")- .WithHeader("User-Agent", "Kavita")- .GetJsonAsync<IEnumerable<GithubReleaseMetadata>>();+ return update;+ }- 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;}}diff --git a/API/Services/TokenService.cs b/API/Services/TokenService.csindex 3b292cb8c..8145b330e 100644--- a/API/Services/TokenService.cs+++ b/API/Services/TokenService.cs@@ -6,51 +6,54 @@ using System.Security.Claims;using System.Text;using System.Threading.Tasks;using API.Entities;-using API.Interfaces.Services;using Microsoft.AspNetCore.Identity;using Microsoft.Extensions.Configuration;using Microsoft.IdentityModel.Tokens;using JwtRegisteredClaimNames = Microsoft.IdentityModel.JsonWebTokens.JwtRegisteredClaimNames;-namespace API.Services+namespace API.Services;++public interface ITokenService+{+ Task<string> CreateToken(AppUser user);+}++public class TokenService : ITokenService{- public class TokenService : ITokenService+ private readonly UserManager<AppUser> _userManager;+ private readonly SymmetricSecurityKey _key;++ public TokenService(IConfiguration config, UserManager<AppUser> userManager){- private readonly UserManager<AppUser> _userManager;- private readonly SymmetricSecurityKey _key;- public TokenService(IConfiguration config, UserManager<AppUser> userManager)+ _userManager = userManager;+ _key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config["TokenKey"]));+ }++ public async Task<string> CreateToken(AppUser user)+ {+ var claims = new List<Claim>{-- _userManager = userManager;- _key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config["TokenKey"]));- }+ new Claim(JwtRegisteredClaimNames.NameId, user.UserName)+ };++ var roles = await _userManager.GetRolesAsync(user);++ claims.AddRange(roles.Select(role => new Claim(ClaimTypes.Role, role)));- public async Task<string> CreateToken(AppUser user)+ var creds = new SigningCredentials(_key, SecurityAlgorithms.HmacSha512Signature);++ var tokenDescriptor = new SecurityTokenDescriptor(){- var claims = new List<Claim>- {- new Claim(JwtRegisteredClaimNames.NameId, user.UserName)- };-- var roles = await _userManager.GetRolesAsync(user);-- claims.AddRange(roles.Select(role => new Claim(ClaimTypes.Role, role)));-- var creds = new SigningCredentials(_key, SecurityAlgorithms.HmacSha512Signature);-- var tokenDescriptor = new SecurityTokenDescriptor()- {- Subject = new ClaimsIdentity(claims),- Expires = DateTime.Now.AddDays(7),- SigningCredentials = creds- };-- var tokenHandler = new JwtSecurityTokenHandler();- var token = tokenHandler.CreateToken(tokenDescriptor);-- return tokenHandler.WriteToken(token);- }+ Subject = new ClaimsIdentity(claims),+ Expires = DateTime.Now.AddDays(7),+ SigningCredentials = creds+ };++ var tokenHandler = new JwtSecurityTokenHandler();+ var token = tokenHandler.CreateToken(tokenDescriptor);++ return tokenHandler.WriteToken(token);}-}\ No newline at end of file+}diff --git a/API/Services/WarmupServiceStartupTask.cs b/API/Services/WarmupServiceStartupTask.csdeleted file mode 100644index 36463451a..000000000--- a/API/Services/WarmupServiceStartupTask.cs+++ /dev/null@@ -1,43 +0,0 @@-using System;-using System.Collections.Generic;-using System.Linq;-using System.Threading;-using System.Threading.Tasks;-using API.Interfaces.Services;-using Microsoft.Extensions.DependencyInjection;--namespace API.Services-{- public class WarmupServicesStartupTask : IStartupTask- {- private readonly IServiceCollection _services;- private readonly IServiceProvider _provider;- public WarmupServicesStartupTask(IServiceCollection services, IServiceProvider provider)- {- _services = services;- _provider = provider;- }-- public Task ExecuteAsync(CancellationToken cancellationToken = default)- {- using var scope = _provider.CreateScope();- foreach (var singleton in GetServices(_services))- {- Console.WriteLine("DI preloading of " + singleton.FullName);- scope.ServiceProvider.GetServices(singleton);- }-- return Task.CompletedTask;- }-- static IEnumerable<Type> GetServices(IServiceCollection services)- {- return services- .Where(descriptor => descriptor.ImplementationType != typeof(WarmupServicesStartupTask))- .Where(descriptor => !descriptor.ServiceType.ContainsGenericParameters)- .Select(descriptor => descriptor.ServiceType)- .Distinct();- }- }--}\ No newline at end of filediff --git a/API/SignalR/MessageFactory.cs b/API/SignalR/MessageFactory.csindex 3ab6c646c..25262430a 100644--- a/API/SignalR/MessageFactory.cs+++ b/API/SignalR/MessageFactory.cs@@ -50,7 +50,7 @@ namespace API.SignalR{return new SignalRMessage(){- Name = SignalREvents.ScanLibrary,+ Name = SignalREvents.ScanLibraryProgress,Body = new{LibraryId = libraryId,@@ -118,7 +118,7 @@ namespace API.SignalR{return new SignalRMessage{- Name = SignalREvents.UpdateVersion,+ Name = SignalREvents.UpdateAvailable,Body = update};}@@ -127,7 +127,7 @@ namespace API.SignalR{return new SignalRMessage{- Name = SignalREvents.UpdateVersion,+ Name = SignalREvents.UpdateAvailable,Body = new{TagId = tagId,@@ -147,5 +147,19 @@ namespace API.SignalR}};}++ public static SignalRMessage DownloadProgressEvent(string username, string downloadName, float progress)+ {+ return new SignalRMessage()+ {+ Name = SignalREvents.DownloadProgress,+ Body = new+ {+ UserName = username,+ DownloadName = downloadName,+ Progress = progress+ }+ };+ }}}diff --git a/API/SignalR/Presence/PresenceTracker.cs b/API/SignalR/Presence/PresenceTracker.csindex 1453bd0f7..73d6479ff 100644--- a/API/SignalR/Presence/PresenceTracker.cs+++ b/API/SignalR/Presence/PresenceTracker.cs@@ -2,7 +2,7 @@using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;-using API.Interfaces;+using API.Data;namespace API.SignalR.Presence{diff --git a/API/SignalR/SignalREvents.cs b/API/SignalR/SignalREvents.csindex 06908c2be..15590f426 100644--- a/API/SignalR/SignalREvents.cs+++ b/API/SignalR/SignalREvents.cs@@ -2,7 +2,7 @@{public static class SignalREvents{- public const string UpdateVersion = "UpdateVersion";+ public const string UpdateAvailable = "UpdateAvailable";public const string ScanSeries = "ScanSeries";/// <summary>/// Event during Refresh Metadata for cover image change@@ -12,12 +12,29 @@/// Event sent out during Refresh Metadata for progress tracking/// </summary>public const string RefreshMetadataProgress = "RefreshMetadataProgress";- public const string ScanLibrary = "ScanLibrary";+ /// <summary>+ /// Series is added to server+ /// </summary>public const string SeriesAdded = "SeriesAdded";+ /// <summary>+ /// Series is removed from server+ /// </summary>public const string SeriesRemoved = "SeriesRemoved";+ /// <summary>+ /// Progress event for Scan library+ /// </summary>public const string ScanLibraryProgress = "ScanLibraryProgress";+ /// <summary>+ /// When a user is connects/disconnects from server+ /// </summary>public const string OnlineUsers = "OnlineUsers";+ /// <summary>+ /// When a series is added to a collection+ /// </summary>public const string SeriesAddedToCollection = "SeriesAddedToCollection";+ /// <summary>+ /// When an error occurs during a scan library task+ /// </summary>public const string ScanLibraryError = "ScanLibraryError";/// <summary>/// Event sent out during backing up the database@@ -27,5 +44,10 @@/// Event sent out during cleaning up temp and cache folders/// </summary>public const string CleanupProgress = "CleanupProgress";+ /// <summary>+ /// Event sent out during downloading of files+ /// </summary>+ public const string DownloadProgress = "DownloadProgress";+}}diff --git a/API/SignalR/SignalRMessage.cs b/API/SignalR/SignalRMessage.csindex 89b992b4b..dfb181105 100644--- a/API/SignalR/SignalRMessage.cs+++ b/API/SignalR/SignalRMessage.cs@@ -1,5 +1,8 @@namespace API.SignalR{+ /// <summary>+ /// Payload for SignalR messages to Frontend+ /// </summary>public class SignalRMessage{public object Body { get; set; }diff --git a/API/Startup.cs b/API/Startup.csindex 6668927b4..00bfdd589 100644--- a/API/Startup.cs+++ b/API/Startup.cs@@ -4,12 +4,14 @@ using System.IO.Compression;using System.Linq;using System.Net;using System.Net.Sockets;+using System.Threading.Tasks;+using API.Data;+using API.Entities;using API.Extensions;-using API.Interfaces;-using API.Interfaces.Repositories;using API.Middleware;using API.Services;using API.Services.HostedServices;+using API.Services.Tasks;using API.SignalR;using Hangfire;using Hangfire.MemoryStorage;@@ -19,13 +21,16 @@ using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.HttpOverrides;+using Microsoft.AspNetCore.Identity;using Microsoft.AspNetCore.ResponseCompression;using Microsoft.AspNetCore.StaticFiles;+using Microsoft.EntityFrameworkCore;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;using Microsoft.Extensions.Logging;using Microsoft.OpenApi.Models;+using TaskScheduler = API.Services.TaskScheduler;namespace API{@@ -128,8 +133,66 @@ namespace API// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.public void Configure(IApplicationBuilder app, IBackgroundJobClient backgroundJobs, IWebHostEnvironment env,- IHostApplicationLifetime applicationLifetime, IServiceProvider serviceProvider)+ IHostApplicationLifetime applicationLifetime, IServiceProvider serviceProvider, ICacheService cacheService,+ IDirectoryService directoryService, IUnitOfWork unitOfWork, IBackupService backupService, IImageService imageService){++ // Apply Migrations+ try+ {+ Task.Run(async () =>+ {+ // Apply all migrations on startup+ // If we have pending migrations, make a backup first+ //var isDocker = new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker;+ var logger = serviceProvider.GetRequiredService<ILogger<Program>>();+ var context = serviceProvider.GetRequiredService<DataContext>();+ // var pendingMigrations = await context.Database.GetPendingMigrationsAsync();+ // if (pendingMigrations.Any())+ // {+ // logger.LogInformation("Performing backup as migrations are needed");+ // await backupService.BackupDatabase();+ // }+ //+ // await context.Database.MigrateAsync();+ // var roleManager = serviceProvider.GetRequiredService<RoleManager<AppRole>>();+ //+ // await Seed.SeedRoles(roleManager);+ // await Seed.SeedSettings(context, directoryService);+ // await Seed.SeedUserApiKeys(context);++ await MigrateBookmarks.Migrate(directoryService, unitOfWork,+ logger, cacheService);++ var requiresCoverImageMigration = !Directory.Exists(directoryService.CoverImageDirectory);+ try+ {+ // If this is a new install, tables wont exist yet+ if (requiresCoverImageMigration)+ {+ MigrateCoverImages.ExtractToImages(context, directoryService, imageService);+ }+ }+ catch (Exception)+ {+ requiresCoverImageMigration = false;+ }++ if (requiresCoverImageMigration)+ {+ await MigrateCoverImages.UpdateDatabaseWithImages(context, directoryService);+ }+ }).GetAwaiter()+ .GetResult();+ }+ catch (Exception ex)+ {+ var logger = serviceProvider.GetRequiredService<ILogger<Program>>();+ logger.LogCritical(ex, "An error occurred during migration");+ }+++app.UseMiddleware<ExceptionMiddleware>();if (env.IsDevelopment())@@ -146,7 +209,7 @@ namespace APIapp.UseForwardedHeaders(new ForwardedHeadersOptions{- ForwardedHeaders = ForwardedHeaders.All+ ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost});app.UseRouting();diff --git a/Kavita.Common/Configuration.cs b/Kavita.Common/Configuration.csindex 6e6899f3f..7593ae84a 100644--- a/Kavita.Common/Configuration.cs+++ b/Kavita.Common/Configuration.cs@@ -1,5 +1,6 @@using System;using System.IO;+using System.Linq;using System.Text.Json;using Kavita.Common.EnvironmentInfo;using Microsoft.Extensions.Hosting;@@ -193,12 +194,9 @@ namespace Kavita.Commonforeach (var property in tokenElement.EnumerateObject()){if (!property.Name.Equals("LogLevel")) continue;- foreach (var logProperty in property.Value.EnumerateObject())+ foreach (var logProperty in property.Value.EnumerateObject().Where(logProperty => logProperty.Name.Equals("Default"))){- if (logProperty.Name.Equals("Default"))- {- return logProperty.Value.GetString();- }+ return logProperty.Value.GetString();}}}diff --git a/Kavita.Common/Kavita.Common.csproj b/Kavita.Common/Kavita.Common.csprojindex 005b8a5b8..8285453bb 100644--- a/Kavita.Common/Kavita.Common.csproj+++ b/Kavita.Common/Kavita.Common.csproj@@ -1,17 +1,17 @@<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup>- <TargetFramework>net5.0</TargetFramework>+ <TargetFramework>net6.0</TargetFramework><Company>kavitareader.com</Company><Product>Kavita</Product>- <AssemblyVersion>0.4.9.2</AssemblyVersion>+ <AssemblyVersion>0.5.0.0</AssemblyVersion><NeutralLanguage>en</NeutralLanguage></PropertyGroup><ItemGroup>- <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />- <PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />- <PackageReference Include="SonarAnalyzer.CSharp" Version="8.29.0.36737">+ <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />+ <PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />+ <PackageReference Include="SonarAnalyzer.CSharp" Version="8.33.0.40503"><PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets></PackageReference>diff --git a/UI/Web/package-lock.json b/UI/Web/package-lock.jsonindex 5f8160aba..8a71fcd8b 100644--- a/UI/Web/package-lock.json+++ b/UI/Web/package-lock.json@@ -5326,9 +5326,9 @@"dev": true},"decimal.js": {- "version": "10.2.1",- "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.2.1.tgz",- "integrity": "sha512-KaL7+6Fw6i5A2XSnsbhm/6B+NuEA7TZ4vqxnd5tXz9sbKtrN9Srj8ab4vKVdK8YAqZO9P1kg45Y6YLoduPf+kw==",+ "version": "10.3.1",+ "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.3.1.tgz",+ "integrity": "sha512-V0pfhfr8suzyPGOx3nmq4aHqabehUZn6Ch9kyFpV79TGDTWFmHqUqXdabR7QHqxzrYolF4+tVmJhUG4OURg5dQ==","dev": true},"decode-uri-component": {@@ -5352,9 +5352,9 @@}},"deep-is": {- "version": "0.1.3",- "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",- "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=",+ "version": "0.1.4",+ "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",+ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==","dev": true},"deepmerge": {@@ -5956,18 +5956,24 @@"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="},"escodegen": {- "version": "1.14.3",- "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.14.3.tgz",- "integrity": "sha512-qFcX0XJkdg+PB3xjZZG/wKSuT1PnQWx57+TVSjIMmILd2yC/6ByYElPwJnslDsuWuSAp4AwJGumarAAmJch5Kw==",+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-2.0.0.tgz",+ "integrity": "sha512-mmHKys/C8BFUGI+MAWNcSYoORYLMdPzjrknd2Vc+bUsjN5bXcr8EhrNB+UTqfL1y3I9c4fw2ihgtMPQLBRiQxw==","dev": true,"requires": {"esprima": "^4.0.1",- "estraverse": "^4.2.0",+ "estraverse": "^5.2.0","esutils": "^2.0.2","optionator": "^0.8.1","source-map": "~0.6.1"},"dependencies": {+ "estraverse": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz",+ "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==",+ "dev": true+ },"source-map": {"version": "0.6.1","resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",@@ -6623,9 +6629,9 @@}},"follow-redirects": {- "version": "1.13.0",- "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz",- "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==",+ "version": "1.14.7",+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",+ "integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==","dev": true},"for-in": {@@ -7856,9 +7862,9 @@}},"is-potential-custom-element-name": {- "version": "1.0.0",- "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.0.tgz",- "integrity": "sha1-DFLlS8yjkbssSUsh6GJtczbG45c=",+ "version": "1.0.1",+ "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz",+ "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==","dev": true},"is-regex": {@@ -9593,66 +9599,91 @@"dev": true},"jsdom": {- "version": "16.4.0",- "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-16.4.0.tgz",- "integrity": "sha512-lYMm3wYdgPhrl7pDcRmvzPhhrGVBeVhPIqeHjzeiHN3DFmD1RBpbExbi8vU7BJdH8VAZYovR8DMt0PNNDM7k8w==",+ "version": "16.7.0",+ "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-16.7.0.tgz",+ "integrity": "sha512-u9Smc2G1USStM+s/x1ru5Sxrl6mPYCbByG1U/hUmqaVsm4tbNyS7CicOSRyuGQYZhTu0h84qkZZQ/I+dzizSVw==","dev": true,"requires": {- "abab": "^2.0.3",- "acorn": "^7.1.1",+ "abab": "^2.0.5",+ "acorn": "^8.2.4","acorn-globals": "^6.0.0","cssom": "^0.4.4",- "cssstyle": "^2.2.0",+ "cssstyle": "^2.3.0","data-urls": "^2.0.0",- "decimal.js": "^10.2.0",+ "decimal.js": "^10.2.1","domexception": "^2.0.1",- "escodegen": "^1.14.1",+ "escodegen": "^2.0.0",+ "form-data": "^3.0.0","html-encoding-sniffer": "^2.0.1",- "is-potential-custom-element-name": "^1.0.0",+ "http-proxy-agent": "^4.0.1",+ "https-proxy-agent": "^5.0.0",+ "is-potential-custom-element-name": "^1.0.1","nwsapi": "^2.2.0",- "parse5": "5.1.1",- "request": "^2.88.2",- "request-promise-native": "^1.0.8",- "saxes": "^5.0.0",+ "parse5": "6.0.1",+ "saxes": "^5.0.1","symbol-tree": "^3.2.4",- "tough-cookie": "^3.0.1",+ "tough-cookie": "^4.0.0","w3c-hr-time": "^1.0.2","w3c-xmlserializer": "^2.0.0","webidl-conversions": "^6.1.0","whatwg-encoding": "^1.0.5","whatwg-mimetype": "^2.3.0",- "whatwg-url": "^8.0.0",- "ws": "^7.2.3",+ "whatwg-url": "^8.5.0",+ "ws": "^7.4.6","xml-name-validator": "^3.0.0"},"dependencies": {"acorn": {- "version": "7.4.1",- "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz",- "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==",+ "version": "8.6.0",+ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.6.0.tgz",+ "integrity": "sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw==","dev": true},- "parse5": {- "version": "5.1.1",- "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.1.tgz",- "integrity": "sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==",- "dev": true+ "agent-base": {+ "version": "6.0.2",+ "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",+ "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",+ "dev": true,+ "requires": {+ "debug": "4"+ }},- "tough-cookie": {+ "form-data": {"version": "3.0.1",- "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-3.0.1.tgz",- "integrity": "sha512-yQyJ0u4pZsv9D4clxO69OEjLWYw+jbgspjTue4lTQZLfV0c5l1VmK2y1JK8E9ahdpltPOaAThPcp5nKPUgSnsg==",+ "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",+ "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",+ "dev": true,+ "requires": {+ "asynckit": "^0.4.0",+ "combined-stream": "^1.0.8",+ "mime-types": "^2.1.12"+ }+ },+ "https-proxy-agent": {+ "version": "5.0.0",+ "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",+ "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==",+ "dev": true,+ "requires": {+ "agent-base": "6",+ "debug": "4"+ }+ },+ "tough-cookie": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz",+ "integrity": "sha512-tHdtEpQCMrc1YLrMaqXXcj6AxhYi/xgit6mZu1+EDWUn+qhUf8wMQoFIy9NXuq23zAwtcB0t/MjACGR18pcRbg==","dev": true,"requires": {- "ip-regex": "^2.1.0",- "psl": "^1.1.28",- "punycode": "^2.1.1"+ "psl": "^1.1.33",+ "punycode": "^2.1.1",+ "universalify": "^0.1.2"}},"ws": {- "version": "7.5.5",- "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz",- "integrity": "sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w==",+ "version": "7.5.6",+ "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.6.tgz",+ "integrity": "sha512-6GLgCqo2cy2A2rjCNFlxQS6ZljG/coZfZXclldI8FB/1G3CCI36Zd8xy2HrFVACi8tfk5XrgLQEk+P0Tnz9UcA==","dev": true}}@@ -9675,9 +9706,9 @@"dev": true},"json-schema": {- "version": "0.2.3",- "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz",- "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=",+ "version": "0.4.0",+ "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",+ "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==","dev": true},"json-schema-traverse": {@@ -9728,14 +9759,14 @@"dev": true},"jsprim": {- "version": "1.4.1",- "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",- "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=",+ "version": "1.4.2",+ "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz",+ "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==","dev": true,"requires": {"assert-plus": "1.0.0","extsprintf": "1.3.0",- "json-schema": "0.2.3",+ "json-schema": "0.4.0","verror": "1.10.0"}},@@ -9955,12 +9986,6 @@"integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=","dev": true},- "lodash.sortby": {- "version": "4.7.0",- "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",- "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=",- "dev": true- },"lodash.uniq": {"version": "4.5.0","resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz",@@ -13093,26 +13118,6 @@}}},- "request-promise-core": {- "version": "1.1.4",- "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.4.tgz",- "integrity": "sha512-TTbAfBBRdWD7aNNOoVOBH4pN/KigV6LyapYNNlAPA8JwbovRti1E88m3sYAwsLi5ryhPKsE9APwnjFTgdUjTpw==",- "dev": true,- "requires": {- "lodash": "^4.17.19"- }- },- "request-promise-native": {- "version": "1.0.9",- "resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.9.tgz",- "integrity": "sha512-wcW+sIUiWnKgNY0dqCpOZkUbF/I+YPi+f09JZIDa39Ec+q82CpSYniDp+ISgTTbKmnpJWASeJBPZmoxH84wt3g==",- "dev": true,- "requires": {- "request-promise-core": "1.1.4",- "stealthy-require": "^1.1.1",- "tough-cookie": "^2.3.3"- }- },"require-directory": {"version": "2.1.1","resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",@@ -14442,12 +14447,6 @@"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=","dev": true},- "stealthy-require": {- "version": "1.1.1",- "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz",- "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=",- "dev": true- },"stream-browserify": {"version": "2.0.2","resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.2.tgz",@@ -15009,9 +15008,9 @@}},"tr46": {- "version": "2.0.2",- "resolved": "https://registry.npmjs.org/tr46/-/tr46-2.0.2.tgz",- "integrity": "sha512-3n1qG+/5kg+jrbTzwAykB5yRYtQCTqOGKq5U5PE3b0a1/mzo6snDhjGS0zJVJunO0NrT3Dg1MLy5TjWP/UJppg==",+ "version": "2.1.0",+ "resolved": "https://registry.npmjs.org/tr46/-/tr46-2.1.0.tgz",+ "integrity": "sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==","dev": true,"requires": {"punycode": "^2.1.1"@@ -16651,13 +16650,13 @@"dev": true},"whatwg-url": {- "version": "8.4.0",- "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.4.0.tgz",- "integrity": "sha512-vwTUFf6V4zhcPkWp/4CQPr1TW9Ml6SF4lVyaIMBdJw5i6qUUJ1QWM4Z6YYVkfka0OUIzVo/0aNtGVGk256IKWw==",+ "version": "8.7.0",+ "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.7.0.tgz",+ "integrity": "sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg==","dev": true,"requires": {- "lodash.sortby": "^4.7.0",- "tr46": "^2.0.2",+ "lodash": "^4.7.0",+ "tr46": "^2.1.0","webidl-conversions": "^6.1.0"}},@@ -16819,9 +16818,9 @@}},"ws": {- "version": "6.2.1",- "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz",- "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==",+ "version": "6.2.2",+ "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz",+ "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==","requires": {"async-limiter": "~1.0.0"}diff --git a/UI/Web/src/app/_models/chapter-metadata.ts b/UI/Web/src/app/_models/chapter-metadata.tsnew file mode 100644index 000000000..56f400210--- /dev/null+++ b/UI/Web/src/app/_models/chapter-metadata.ts@@ -0,0 +1,16 @@+import { Person } from "./person";++export interface ChapterMetadata {+ id: number;+ chapterId: number;+ title: string;+ year: string;+ writers: Array<Person>;+ penciller: Array<Person>;+ inker: Array<Person>;+ colorist: Array<Person>;+ letterer: Array<Person>;+ coverArtist: Array<Person>;+ editor: Array<Person>;+ publishers: Array<Person>;+}\ No newline at end of filediff --git a/UI/Web/src/app/_models/chapter.ts b/UI/Web/src/app/_models/chapter.tsindex 4a9399489..1a66e2471 100644--- a/UI/Web/src/app/_models/chapter.ts+++ b/UI/Web/src/app/_models/chapter.ts@@ -1,4 +1,6 @@import { MangaFile } from './manga-file';+import { Person } from './person';+import { Tag } from './tag';export interface Chapter {id: number;@@ -16,4 +18,19 @@ export interface Chapter {isSpecial: boolean;title: string;created: string;++ titleName: string;+ /**+ * This is only Year and Month, Day is not supported from underlying sources+ */+ releaseDate: string;+ writers: Array<Person>;+ penciller: Array<Person>;+ inker: Array<Person>;+ colorist: Array<Person>;+ letterer: Array<Person>;+ coverArtist: Array<Person>;+ editor: Array<Person>;+ publisher: Array<Person>;+ tags: Array<Tag>;}diff --git a/UI/Web/src/app/_models/genre.ts b/UI/Web/src/app/_models/genre.tsnew file mode 100644index 000000000..f1160230d--- /dev/null+++ b/UI/Web/src/app/_models/genre.ts@@ -0,0 +1,4 @@+export interface Genre {+ id: number,+ title: string;+}\ No newline at end of filediff --git a/UI/Web/src/app/_models/metadata/age-rating-dto.ts b/UI/Web/src/app/_models/metadata/age-rating-dto.tsnew file mode 100644index 000000000..ebf0728b9--- /dev/null+++ b/UI/Web/src/app/_models/metadata/age-rating-dto.ts@@ -0,0 +1,6 @@+import { AgeRating } from "./age-rating";++export interface AgeRatingDto {+ value: AgeRating;+ title: string;+}\ No newline at end of filediff --git a/UI/Web/src/app/_models/metadata/age-rating.ts b/UI/Web/src/app/_models/metadata/age-rating.tsnew file mode 100644index 000000000..d44a8e250--- /dev/null+++ b/UI/Web/src/app/_models/metadata/age-rating.ts@@ -0,0 +1,15 @@+export enum AgeRating {+ Unknown = 0,+ AdultsOnly = 1,+ EarlyChildhood = 2,+ Everyone = 3,+ Everyone10Plus = 4,+ G = 5,+ KidsToAdults = 6,+ Mature = 7,+ Mature15Plus = 8,+ Mature17Plus = 9,+ RatingPending = 10,+ Teen = 11,+ X18Plus = 12+}\ No newline at end of filediff --git a/UI/Web/src/app/_models/metadata/language.ts b/UI/Web/src/app/_models/metadata/language.tsnew file mode 100644index 000000000..c88ff3939--- /dev/null+++ b/UI/Web/src/app/_models/metadata/language.ts@@ -0,0 +1,4 @@+export interface Language {+ isoCode: string;+ title: string;+}\ No newline at end of filediff --git a/UI/Web/src/app/_models/metadata/publication-status-dto.ts b/UI/Web/src/app/_models/metadata/publication-status-dto.tsnew file mode 100644index 000000000..74281c2d2--- /dev/null+++ b/UI/Web/src/app/_models/metadata/publication-status-dto.ts@@ -0,0 +1,6 @@+import { PublicationStatus } from "./publication-status";++export interface PublicationStatusDto {+ value: PublicationStatus;+ title: string;+}\ No newline at end of filediff --git a/UI/Web/src/app/_models/metadata/publication-status.ts b/UI/Web/src/app/_models/metadata/publication-status.tsnew file mode 100644index 000000000..7881da383--- /dev/null+++ b/UI/Web/src/app/_models/metadata/publication-status.ts@@ -0,0 +1,5 @@+export enum PublicationStatus {+ OnGoing = 0,+ Hiatus = 1,+ Completed = 2+}\ No newline at end of filediff --git a/UI/Web/src/app/_models/page-bookmark.ts b/UI/Web/src/app/_models/page-bookmark.tsindex 6d46bfe4d..e47ef0a06 100644--- a/UI/Web/src/app/_models/page-bookmark.ts+++ b/UI/Web/src/app/_models/page-bookmark.ts@@ -4,4 +4,5 @@ export interface PageBookmark {seriesId: number;volumeId: number;chapterId: number;+ fileName: string;}\ No newline at end of filediff --git a/UI/Web/src/app/_models/person.ts b/UI/Web/src/app/_models/person.tsindex a8a60436d..e23925cef 100644--- a/UI/Web/src/app/_models/person.ts+++ b/UI/Web/src/app/_models/person.ts@@ -1,10 +1,20 @@export enum PersonRole {- Other = 0,- Author = 1,- Artist = 2+ Other = 1,+ Artist = 2,+ Writer = 3,+ Penciller = 4,+ Inker = 5,+ Colorist = 6,+ Letterer = 7,+ CoverArtist = 8,+ Editor = 9,+ Publisher = 10,+ Character = 11,+ Translator = 12}export interface Person {+ id: number;name: string;role: PersonRole;}\ No newline at end of filediff --git a/UI/Web/src/app/_models/preferences/preferences.ts b/UI/Web/src/app/_models/preferences/preferences.tsindex 7e44dbbee..664afb7f7 100644--- a/UI/Web/src/app/_models/preferences/preferences.ts+++ b/UI/Web/src/app/_models/preferences/preferences.ts@@ -1,3 +1,4 @@+import { PageSplitOption } from './page-split-option';import { READER_MODE } from './reader-mode';import { ReadingDirection } from './reading-direction';diff --git a/UI/Web/src/app/_models/series-filter.ts b/UI/Web/src/app/_models/series-filter.tsindex a81cfe381..068054a27 100644--- a/UI/Web/src/app/_models/series-filter.ts+++ b/UI/Web/src/app/_models/series-filter.ts@@ -1,38 +1,70 @@import { MangaFormat } from "./manga-format";-export interface FilterItem {+export interface FilterItem<T> {title: string;- value: any;+ value: T;selected: boolean;}export interface SeriesFilter {- mangaFormat: MangaFormat | null;+ formats: Array<MangaFormat>;+ libraries: Array<number>,+ readStatus: ReadStatus;+ genres: Array<number>;+ writers: Array<number>;+ penciller: Array<number>;+ inker: Array<number>;+ colorist: Array<number>;+ letterer: Array<number>;+ coverArtist: Array<number>;+ editor: Array<number>;+ publisher: Array<number>;+ character: Array<number>;+ translators: Array<number>;+ collectionTags: Array<number>;+ rating: number;+ ageRating: Array<number>;+ sortOptions: SortOptions | null;+ tags: Array<number>;+ languages: Array<string>;+ publicationStatus: Array<number>;+}++export interface SortOptions {+ sortField: SortField;+ isAscending: boolean;+}++export enum SortField {+ SortName = 1,+ Created = 2,+ LastModified = 3+}++export interface ReadStatus {+ notRead: boolean,+ inProgress: boolean,+ read: boolean,}export const mangaFormatFilters = [{- title: 'Format: All',- value: null,- selected: false- },- {- title: 'Format: Images',+ title: 'Images',value: MangaFormat.IMAGE,selected: false},{- title: 'Format: EPUB',+ title: 'EPUB',value: MangaFormat.EPUB,selected: false},{- title: 'Format: PDF',+ title: 'PDF',value: MangaFormat.PDF,selected: false},{- title: 'Format: ARCHIVE',+ title: 'ARCHIVE',value: MangaFormat.ARCHIVE,selected: false}diff --git a/UI/Web/src/app/_models/series-metadata.ts b/UI/Web/src/app/_models/series-metadata.tsindex 4cba7848f..e143a9639 100644--- a/UI/Web/src/app/_models/series-metadata.ts+++ b/UI/Web/src/app/_models/series-metadata.ts@@ -1,10 +1,29 @@import { CollectionTag } from "./collection-tag";+import { Genre } from "./genre";+import { AgeRating } from "./metadata/age-rating";+import { PublicationStatus } from "./metadata/publication-status";import { Person } from "./person";+import { Tag } from "./tag";export interface SeriesMetadata {publisher: string;- genres: Array<string>;- tags: Array<CollectionTag>;- persons: Array<Person>;+ summary: string;+ genres: Array<Genre>;+ tags: Array<Tag>;+ collectionTags: Array<CollectionTag>;+ writers: Array<Person>;+ coverArtists: Array<Person>;+ publishers: Array<Person>;+ characters: Array<Person>;+ pencillers: Array<Person>;+ inkers: Array<Person>;+ colorists: Array<Person>;+ letterers: Array<Person>;+ editors: Array<Person>;+ translators: Array<Person>;+ ageRating: AgeRating;+ releaseYear: number;+ language: string;seriesId: number;+ publicationStatus: PublicationStatus;}\ No newline at end of filediff --git a/UI/Web/src/app/_models/series.ts b/UI/Web/src/app/_models/series.tsindex be233122b..332407105 100644--- a/UI/Web/src/app/_models/series.ts+++ b/UI/Web/src/app/_models/series.ts@@ -7,7 +7,6 @@ export interface Series {originalName: string; // This is not shown to userlocalizedName: string;sortName: string;- summary: string;coverImageLocked: boolean;volumes: Volume[];pages: number; // Total pages in seriesdiff --git a/UI/Web/src/app/_models/tag.ts b/UI/Web/src/app/_models/tag.tsnew file mode 100644index 000000000..c75d48be6--- /dev/null+++ b/UI/Web/src/app/_models/tag.ts@@ -0,0 +1,4 @@+export interface Tag {+ id: number,+ title: string;+}\ No newline at end of filediff --git a/UI/Web/src/app/_services/action-factory.service.ts b/UI/Web/src/app/_services/action-factory.service.tsindex 0df929e8f..a0d1609ff 100644--- a/UI/Web/src/app/_services/action-factory.service.ts+++ b/UI/Web/src/app/_services/action-factory.service.ts@@ -79,7 +79,7 @@ export class ActionFactoryService {this.seriesActions.push({action: Action.RefreshMetadata,- title: 'Refresh Metadata',+ title: 'Refresh Covers',callback: this.dummyCallback,requiresAdmin: true});@@ -114,7 +114,7 @@ export class ActionFactoryService {this.libraryActions.push({action: Action.RefreshMetadata,- title: 'Refresh Metadata',+ title: 'Refresh Covers',callback: this.dummyCallback,requiresAdmin: true});diff --git a/UI/Web/src/app/_services/action.service.ts b/UI/Web/src/app/_services/action.service.tsindex 5ada05dc2..66615388c 100644--- a/UI/Web/src/app/_services/action.service.ts+++ b/UI/Web/src/app/_services/action.service.ts@@ -23,6 +23,7 @@ export type VolumeActionCallback = (volume: Volume) => void;export type ChapterActionCallback = (chapter: Chapter) => void;export type ReadingListActionCallback = (readingList: ReadingList) => void;export type VoidActionCallback = () => void;+export type BooleanActionCallback = (result: boolean) => void;/*** Responsible for executing actions@@ -57,7 +58,7 @@ export class ActionService implements OnDestroy {return;}this.libraryService.scan(library?.id).pipe(take(1)).subscribe((res: any) => {- this.toastr.success('Scan started for ' + library.name);+ this.toastr.success('Scan queued for ' + library.name);if (callback) {callback(library);}@@ -75,12 +76,15 @@ export class ActionService implements OnDestroy {return;}- if (!await this.confirmService.confirm('Refresh metadata will force all cover images and metadata to be recalculated. This is a heavy operation. Are you sure you don\'t want to perform a Scan instead?')) {+ if (!await this.confirmService.confirm('Refresh covers will force all cover images to be recalculated. This is a heavy operation. Are you sure you don\'t want to perform a Scan instead?')) {+ if (callback) {+ callback(library);+ }return;}this.libraryService.refreshMetadata(library?.id).pipe(take(1)).subscribe((res: any) => {- this.toastr.success('Scan started for ' + library.name);+ this.toastr.success('Scan queued for ' + library.name);if (callback) {callback(library);}@@ -124,7 +128,7 @@ export class ActionService implements OnDestroy {*/scanSeries(series: Series, callback?: SeriesActionCallback) {this.seriesService.scan(series.libraryId, series.id).pipe(take(1)).subscribe((res: any) => {- this.toastr.success('Scan started for ' + series.name);+ this.toastr.success('Scan queued for ' + series.name);if (callback) {callback(series);}@@ -137,7 +141,10 @@ export class ActionService implements OnDestroy {* @param callback Optional callback to perform actions after API completes*/async refreshMetdata(series: Series, callback?: SeriesActionCallback) {- if (!await this.confirmService.confirm('Refresh metadata will force all cover images and metadata to be recalculated. This is a heavy operation. Are you sure you don\'t want to perform a Scan instead?')) {+ if (!await this.confirmService.confirm('Refresh covers will force all cover images and metadata to be recalculated. This is a heavy operation. Are you sure you don\'t want to perform a Scan instead?')) {+ if (callback) {+ callback(series);+ }return;}@@ -484,4 +491,20 @@ export class ActionService implements OnDestroy {});}+ async deleteSeries(series: Series, callback?: BooleanActionCallback) {+ if (!await this.confirmService.confirm('Are you sure you want to delete this series? It will not modify files on disk.')) {+ if (callback) {+ callback(false);+ }+ return;+ }++ this.seriesService.delete(series.id).subscribe((res: boolean) => {+ if (callback) {+ this.toastr.success('Series deleted');+ callback(res);+ }+ });+ }+}diff --git a/UI/Web/src/app/_services/image.service.ts b/UI/Web/src/app/_services/image.service.tsindex 2141d3e4d..4cb21c299 100644--- a/UI/Web/src/app/_services/image.service.ts+++ b/UI/Web/src/app/_services/image.service.ts@@ -1,18 +1,24 @@-import { Injectable } from '@angular/core';+import { Injectable, OnDestroy } from '@angular/core';+import { Subject } from 'rxjs';+import { takeUntil } from 'rxjs/operators';import { environment } from 'src/environments/environment';+import { AccountService } from './account.service';import { NavService } from './nav.service';@Injectable({providedIn: 'root'})-export class ImageService {+export class ImageService implements OnDestroy {baseUrl = environment.apiUrl;+ apiKey: string = '';public placeholderImage = 'assets/images/image-placeholder-min.png';public errorImage = 'assets/images/error-placeholder2-min.png';public resetCoverImage = 'assets/images/image-reset-cover-min.png';- constructor(private navSerivce: NavService) {+ private onDestroy: Subject<void> = new Subject();++ constructor(private navSerivce: NavService, private accountService: AccountService) {this.navSerivce.darkMode$.subscribe(res => {if (res) {this.placeholderImage = 'assets/images/image-placeholder.dark-min.png';@@ -22,6 +28,17 @@ export class ImageService {this.errorImage = 'assets/images/error-placeholder2-min.png';}});++ this.accountService.currentUser$.pipe(takeUntil(this.onDestroy)).subscribe(user => {+ if (user) {+ this.apiKey = user.apiKey;+ }+ });+ }++ ngOnDestroy(): void {+ this.onDestroy.next();+ this.onDestroy.complete();}getVolumeCoverImage(volumeId: number) {@@ -41,7 +58,7 @@ export class ImageService {}getBookmarkedImage(chapterId: number, pageNum: number) {- return this.baseUrl + 'image/chapter-cover?chapterId=' + chapterId + '&pageNum=' + pageNum;+ return this.baseUrl + 'image/bookmark?chapterId=' + chapterId + '&pageNum=' + pageNum + '&apiKey=' + encodeURIComponent(this.apiKey);}updateErroredImage(event: any) {diff --git a/UI/Web/src/app/_services/message-hub.service.ts b/UI/Web/src/app/_services/message-hub.service.tsindex 85a543322..259f2a4c1 100644--- a/UI/Web/src/app/_services/message-hub.service.ts+++ b/UI/Web/src/app/_services/message-hub.service.ts@@ -24,7 +24,8 @@ export enum EVENTS {SeriesAddedToCollection = 'SeriesAddedToCollection',ScanLibraryError = 'ScanLibraryError',BackupDatabaseProgress = 'BackupDatabaseProgress',- CleanupProgress = 'CleanupProgress'+ CleanupProgress = 'CleanupProgress',+ DownloadProgress = 'DownloadProgress'}export interface Message<T> {@@ -38,7 +39,6 @@ export interface Message<T> {export class MessageHubService {hubUrl = environment.hubUrl;private hubConnection!: HubConnection;- private updateNotificationModalRef: NgbModalRef | null = null;private messagesSource = new ReplaySubject<Message<any>>(1);public messages$ = this.messagesSource.asObservable();@@ -53,7 +53,7 @@ export class MessageHubService {isAdmin: boolean = false;- constructor(private modalService: NgbModal, private toastr: ToastrService, private router: Router) {+ constructor(private toastr: ToastrService, private router: Router) {}@@ -106,6 +106,13 @@ export class MessageHubService {});});+ this.hubConnection.on(EVENTS.DownloadProgress, resp => {+ this.messagesSource.next({+ event: EVENTS.DownloadProgress,+ payload: resp.body+ });+ });+this.hubConnection.on(EVENTS.RefreshMetadataProgress, resp => {this.messagesSource.next({event: EVENTS.RefreshMetadataProgress,@@ -162,16 +169,6 @@ export class MessageHubService {event: EVENTS.UpdateAvailable,payload: resp.body});- // Ensure only 1 instance of UpdateNotificationModal can be open at once- if (this.updateNotificationModalRef != null) { return; }- this.updateNotificationModalRef = this.modalService.open(UpdateNotificationModalComponent, { scrollable: true, size: 'lg' });- this.updateNotificationModalRef.componentInstance.updateData = resp.body;- this.updateNotificationModalRef.closed.subscribe(() => {- this.updateNotificationModalRef = null;- });- this.updateNotificationModalRef.dismissed.subscribe(() => {- this.updateNotificationModalRef = null;- });});}diff --git a/UI/Web/src/app/_services/metadata.service.ts b/UI/Web/src/app/_services/metadata.service.tsnew file mode 100644index 000000000..4d64a7920--- /dev/null+++ b/UI/Web/src/app/_services/metadata.service.ts@@ -0,0 +1,87 @@+import { HttpClient } from '@angular/common/http';+import { Injectable } from '@angular/core';+import { of } from 'rxjs';+import { map } from 'rxjs/operators';+import { environment } from 'src/environments/environment';+import { ChapterMetadata } from '../_models/chapter-metadata';+import { Genre } from '../_models/genre';+import { AgeRating } from '../_models/metadata/age-rating';+import { AgeRatingDto } from '../_models/metadata/age-rating-dto';+import { Language } from '../_models/metadata/language';+import { PublicationStatusDto } from '../_models/metadata/publication-status-dto';+import { Person } from '../_models/person';+import { Tag } from '../_models/tag';++@Injectable({+ providedIn: 'root'+})+export class MetadataService {++ baseUrl = environment.apiUrl;++ private ageRatingTypes: {[key: number]: string} | undefined = undefined;++ constructor(private httpClient: HttpClient) { }++ getAgeRating(ageRating: AgeRating) {+ if (this.ageRatingTypes != undefined && this.ageRatingTypes.hasOwnProperty(ageRating)) {+ return of(this.ageRatingTypes[ageRating]);+ }+ return this.httpClient.get<string>(this.baseUrl + 'series/age-rating?ageRating=' + ageRating, {responseType: 'text' as 'json'}).pipe(map(ratingString => {+ if (this.ageRatingTypes === undefined) {+ this.ageRatingTypes = {};+ }++ this.ageRatingTypes[ageRating] = ratingString;+ return this.ageRatingTypes[ageRating];+ }));+ }++ getAllAgeRatings(libraries?: Array<number>) {+ let method = 'metadata/age-ratings'+ if (libraries != undefined && libraries.length > 0) {+ method += '?libraryIds=' + libraries.join(',');+ }+ return this.httpClient.get<Array<AgeRatingDto>>(this.baseUrl + method);;+ }++ getAllPublicationStatus(libraries?: Array<number>) {+ let method = 'metadata/publication-status'+ if (libraries != undefined && libraries.length > 0) {+ method += '?libraryIds=' + libraries.join(',');+ }+ return this.httpClient.get<Array<PublicationStatusDto>>(this.baseUrl + method);;+ }++ getAllTags(libraries?: Array<number>) {+ let method = 'metadata/tags'+ if (libraries != undefined && libraries.length > 0) {+ method += '?libraryIds=' + libraries.join(',');+ }+ return this.httpClient.get<Array<Tag>>(this.baseUrl + method);;+ }++ getAllGenres(libraries?: Array<number>) {+ let method = 'metadata/genres'+ if (libraries != undefined && libraries.length > 0) {+ method += '?libraryIds=' + libraries.join(',');+ }+ return this.httpClient.get<Genre[]>(this.baseUrl + method);+ }++ getAllLanguages(libraries?: Array<number>) {+ let method = 'metadata/languages'+ if (libraries != undefined && libraries.length > 0) {+ method += '?libraryIds=' + libraries.join(',');+ }+ return this.httpClient.get<Language[]>(this.baseUrl + method);+ }++ getAllPeople(libraries?: Array<number>) {+ let method = 'metadata/people'+ if (libraries != undefined && libraries.length > 0) {+ method += '?libraryIds=' + libraries.join(',');+ }+ return this.httpClient.get<Person[]>(this.baseUrl + method);+ }+}diff --git a/UI/Web/src/app/_services/nav.service.ts b/UI/Web/src/app/_services/nav.service.tsindex 2412c794a..74ccc3339 100644--- a/UI/Web/src/app/_services/nav.service.ts+++ b/UI/Web/src/app/_services/nav.service.ts@@ -1,4 +1,4 @@-import { Injectable } from '@angular/core';+import { Injectable, Renderer2, RendererFactory2 } from '@angular/core';import { ReplaySubject } from 'rxjs';@Injectable({@@ -13,7 +13,10 @@ export class NavService {private darkModeSource = new ReplaySubject<boolean>(1);darkMode$ = this.darkModeSource.asObservable();- constructor() {+ private renderer: Renderer2;++ constructor(rendererFactory: RendererFactory2) {+ this.renderer = rendererFactory.createRenderer(null, null);this.showNavBar();}@@ -27,13 +30,23 @@ export class NavService {toggleDarkMode() {this.darkMode = !this.darkMode;+ this.updateColorScheme();this.darkModeSource.next(this.darkMode);}setDarkMode(mode: boolean) {this.darkMode = mode;+ this.updateColorScheme();this.darkModeSource.next(this.darkMode);}+ private updateColorScheme() {+ if (this.darkMode) {+ this.renderer.setStyle(document.querySelector('html'), 'color-scheme', 'dark');+ } else {+ this.renderer.setStyle(document.querySelector('html'), 'color-scheme', 'light');+ }+ }+}diff --git a/UI/Web/src/app/_services/reader.service.ts b/UI/Web/src/app/_services/reader.service.tsindex 8281ab9e9..16c2ea656 100644--- a/UI/Web/src/app/_services/reader.service.ts+++ b/UI/Web/src/app/_services/reader.service.ts@@ -193,4 +193,34 @@ export class ReaderService {}return params;}++ enterFullscreen(el: Element, callback?: VoidFunction) {+ if (!document.fullscreenElement) {+ if (el.requestFullscreen) {+ el.requestFullscreen().then(() => {+ if (callback) {+ callback();+ }+ });+ }+ }+ }++ exitFullscreen(callback?: VoidFunction) {+ if (document.exitFullscreen && this.checkFullscreenMode()) {+ document.exitFullscreen().then(() => {+ if (callback) {+ callback();+ }+ });+ }+ }++ /**+ *+ * @returns If document is in fullscreen mode+ */+ checkFullscreenMode() {+ return document.fullscreenElement != null;+ }}diff --git a/UI/Web/src/app/_services/reading-list.service.ts b/UI/Web/src/app/_services/reading-list.service.tsindex e520154d6..3ad5255f6 100644--- a/UI/Web/src/app/_services/reading-list.service.ts+++ b/UI/Web/src/app/_services/reading-list.service.ts@@ -75,7 +75,7 @@ export class ReadingListService {}removeRead(readingListId: number) {- return this.httpClient.post(this.baseUrl + 'readinglist/remove-read?readingListId=' + readingListId, { responseType: 'text' as 'json' });+ return this.httpClient.post<string>(this.baseUrl + 'readinglist/remove-read?readingListId=' + readingListId, {}, { responseType: 'text' as 'json' });}actionListFilter(action: ActionItem<ReadingList>, readingList: ReadingList, isAdmin: boolean) {diff --git a/UI/Web/src/app/_services/series.service.ts b/UI/Web/src/app/_services/series.service.tsindex 8ed258c45..af02b8e88 100644--- a/UI/Web/src/app/_services/series.service.ts+++ b/UI/Web/src/app/_services/series.service.ts@@ -8,7 +8,7 @@ import { CollectionTag } from '../_models/collection-tag';import { InProgressChapter } from '../_models/in-progress-chapter';import { PaginatedResult } from '../_models/pagination';import { Series } from '../_models/series';-import { SeriesFilter } from '../_models/series-filter';+import { ReadStatus, SeriesFilter } from '../_models/series-filter';import { SeriesMetadata } from '../_models/series-metadata';import { Volume } from '../_models/volume';import { ImageService } from './image.service';@@ -39,6 +39,18 @@ export class SeriesService {return paginatedVariable;}+ getAllSeries(pageNum?: number, itemsPerPage?: number, filter?: SeriesFilter) {+ let params = new HttpParams();+ params = this._addPaginationIfExists(params, pageNum, itemsPerPage);+ const data = this.createSeriesFilter(filter);++ return this.httpClient.post<PaginatedResult<Series[]>>(this.baseUrl + 'series/all', data, {observe: 'response', params}).pipe(+ map((response: any) => {+ return this._cachePaginatedResults(response, this.paginatedResults);+ })+ );+ }+getSeriesForLibrary(libraryId: number, pageNum?: number, itemsPerPage?: number, filter?: SeriesFilter) {let params = new HttpParams();params = this._addPaginationIfExists(params, pageNum, itemsPerPage);@@ -137,7 +149,7 @@ export class SeriesService {getMetadata(seriesId: number) {return this.httpClient.get<SeriesMetadata>(this.baseUrl + 'series/metadata?seriesId=' + seriesId).pipe(map(items => {- items?.tags.forEach(tag => tag.coverImage = this.imageService.getCollectionCoverImage(tag.id));+ items?.collectionTags.forEach(tag => tag.coverImage = this.imageService.getCollectionCoverImage(tag.id));return items;}));}@@ -177,13 +189,35 @@ export class SeriesService {createSeriesFilter(filter?: SeriesFilter) {const data: SeriesFilter = {- mangaFormat: null+ formats: [],+ libraries: [],+ genres: [],+ writers: [],+ penciller: [],+ inker: [],+ colorist: [],+ letterer: [],+ coverArtist: [],+ editor: [],+ publisher: [],+ character: [],+ translators: [],+ collectionTags: [],+ rating: 0,+ readStatus: {+ read: true,+ inProgress: true,+ notRead: true+ },+ sortOptions: null,+ ageRating: [],+ tags: [],+ languages: [],+ publicationStatus: [],};- if (filter) {- data.mangaFormat = filter.mangaFormat;- }+ if (filter === undefined) return data;- return data;+ return filter;}}diff --git a/UI/Web/src/app/admin/_modals/directory-picker/directory-picker.component.html b/UI/Web/src/app/admin/_modals/directory-picker/directory-picker.component.htmlindex 6f6d02630..60debc54d 100644--- a/UI/Web/src/app/admin/_modals/directory-picker/directory-picker.component.html+++ b/UI/Web/src/app/admin/_modals/directory-picker/directory-picker.component.html@@ -36,6 +36,7 @@<i class="fa fa-arrow-left mr-2" aria-hidden="true"></i>Back</button>+<button type="button" class="btn btn-primary float-right" [disabled]="routeStack.peek() === undefined" (click)="shareFolder('', $event)">Share</button></div></ul>@@ -50,6 +51,6 @@</ul></div><div class="modal-footer">- <a class="btn btn-info" href="https://wiki.kavitareader.com/en/guides/adding-a-library" target="_blank">Help</a>+ <a class="btn btn-info" *ngIf="helpUrl.length > 0" href="{{helpUrl}}" target="_blank">Help</a><button type="button" class="btn btn-secondary" (click)="close()">Cancel</button></div>diff --git a/UI/Web/src/app/admin/_modals/directory-picker/directory-picker.component.ts b/UI/Web/src/app/admin/_modals/directory-picker/directory-picker.component.tsindex 85fa530bb..2885c40de 100644--- a/UI/Web/src/app/admin/_modals/directory-picker/directory-picker.component.ts+++ b/UI/Web/src/app/admin/_modals/directory-picker/directory-picker.component.ts@@ -1,4 +1,4 @@-import { Component, OnInit } from '@angular/core';+import { Component, Input, OnInit } from '@angular/core';import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';import { Stack } from 'src/app/shared/data-structures/stack';import { LibraryService } from '../../../_services/library.service';@@ -17,6 +17,12 @@ export interface DirectoryPickerResult {})export class DirectoryPickerComponent implements OnInit {+ @Input() startingFolder: string = '';+ /**+ * Url to give more information about selecting directories. Passing nothing will suppress.+ */+ @Input() helpUrl: string = 'https://wiki.kavitareader.com/en/guides/adding-a-library';+currentRoot = '';folders: string[] = [];routeStack: Stack<string> = new Stack<string>();@@ -27,7 +33,22 @@ export class DirectoryPickerComponent implements OnInit {}ngOnInit(): void {- this.loadChildren(this.currentRoot);+ if (this.startingFolder && this.startingFolder.length > 0) {+ let folders = this.startingFolder.split('/');+ let folders2 = this.startingFolder.split('\\');+ if (folders.length === 1 && folders2.length > 1) {+ folders = folders2;+ }+ if (!folders[0].endsWith('/')) {+ folders[0] = folders[0] + '/';+ }+ folders.forEach(folder => this.routeStack.push(folder));++ const fullPath = this.routeStack.items.join('/');+ this.loadChildren(fullPath);+ } else {+ this.loadChildren(this.currentRoot);+ }}filterFolder = (folder: string) => {@@ -38,7 +59,7 @@ export class DirectoryPickerComponent implements OnInit {this.currentRoot = folderName;this.routeStack.push(folderName);const fullPath = this.routeStack.items.join('/');- this.loadChildren(fullPath);+ this.loadChildren(fullPath);}goBack() {@@ -86,7 +107,7 @@ export class DirectoryPickerComponent implements OnInit {if (lastPath && lastPath != path) {let replaced = path.replace(lastPath, '');if (replaced.startsWith('/') || replaced.startsWith('\\')) {- replaced = replaced.substr(1, replaced.length);+ replaced = replaced.substring(1, replaced.length);}return replaced;}@@ -95,14 +116,11 @@ export class DirectoryPickerComponent implements OnInit {}navigateTo(index: number) {- const numberOfPops = this.routeStack.items.length - index;- if (this.routeStack.items.length - numberOfPops > this.routeStack.items.length) {- this.routeStack.items = [];- }- for (let i = 0; i < numberOfPops; i++) {+ while(this.routeStack.items.length - 1 > index) {this.routeStack.pop();}-- this.loadChildren(this.routeStack.peek() || '');++ const fullPath = this.routeStack.items.join('/');+ this.loadChildren(fullPath);}}diff --git a/UI/Web/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.html b/UI/Web/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.htmlindex 867be0a4a..a972328c3 100644--- a/UI/Web/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.html+++ b/UI/Web/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.html@@ -16,8 +16,10 @@</div><div class="form-group">- <label for="library-type">Type</label>- <select class="form-control" id="library-type" formControlName="type" [attr.disabled]="this.library">+ <label for="library-type">Type</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="typeTooltip" role="button" tabindex="0"></i>+ <ng-template #typeTooltip>Library type determines how filenames are parsed and if the UI shows Chapters (Manga) vs Issues (Comics). Book work the same way as Manga but fall back to embedded data.</ng-template>+ <span class="sr-only" id="library-type-help">Library type determines how filenames are parsed and if the UI shows Chapters (Manga) vs Issues (Comics). Book work the same way as Manga but fall back to embedded data.</span>+ <select class="form-control" id="library-type" formControlName="type" [attr.disabled]="this.library" aria-describedby="library-type-help"><option [value]="i" *ngFor="let opt of libraryTypes; let i = index">{{opt}}</option></select></div>diff --git a/UI/Web/src/app/admin/_models/server-settings.ts b/UI/Web/src/app/admin/_models/server-settings.tsindex fbcb2a0f0..1f5b398e9 100644--- a/UI/Web/src/app/admin/_models/server-settings.ts+++ b/UI/Web/src/app/admin/_models/server-settings.ts@@ -8,4 +8,5 @@ export interface ServerSettings {enableOpds: boolean;enableAuthentication: boolean;baseUrl: string;+ bookmarksDirectory: string;}diff --git a/UI/Web/src/app/admin/changelog/changelog.component.html b/UI/Web/src/app/admin/changelog/changelog.component.htmlindex 9655fe18e..10709f0ed 100644--- a/UI/Web/src/app/admin/changelog/changelog.component.html+++ b/UI/Web/src/app/admin/changelog/changelog.component.html@@ -3,11 +3,11 @@<div class="card w-100 mb-2" style="width: 18rem;"><div class="card-body"><h4 class="card-title">{{update.updateTitle}} - <span class="badge badge-secondary" *ngIf="update.updateVersion === update.currentVersion">Installed</span>- <span class="badge badge-secondary" *ngIf="update.updateVersion > update.currentVersion">Available</span>+ <span class="badge badge-secondary" *ngIf="update.updateVersion === installedVersion">Installed</span>+ <span class="badge badge-secondary" *ngIf="update.updateVersion > installedVersion">Available</span></h4><h6 class="card-subtitle mb-2 text-muted">Published: {{update.publishDate | date: 'short'}}</h6>-+<pre class="card-text update-body" [innerHtml]="update.updateBody | safeHtml"></pre><a *ngIf="!update.isDocker" href="{{update.updateUrl}}" class="btn btn-{{indx === 0 ? 'primary' : 'secondary'}} float-right" target="_blank">Download</a></div>diff --git a/UI/Web/src/app/admin/changelog/changelog.component.ts b/UI/Web/src/app/admin/changelog/changelog.component.tsindex e24ad9845..86724e92e 100644--- a/UI/Web/src/app/admin/changelog/changelog.component.ts+++ b/UI/Web/src/app/admin/changelog/changelog.component.ts@@ -11,13 +11,26 @@ export class ChangelogComponent implements OnInit {updates: Array<UpdateVersionEvent> = [];isLoading: boolean = true;+ installedVersion: string = '';constructor(private serverService: ServerService) { }ngOnInit(): void {- this.serverService.getChangelog().subscribe(updates => {- this.updates = updates;- this.isLoading = false;++ this.serverService.getServerInfo().subscribe(info => {+ this.installedVersion = info.kavitaVersion;+ this.serverService.getChangelog().subscribe(updates => {+ this.updates = updates;+ this.isLoading = false;++ if (this.updates.filter(u => u.updateVersion === this.installedVersion).length === 0) {+ // User is on a nightly version. Tell them the last stable is installed+ this.installedVersion = this.updates[0].updateVersion;+ }+ });});+++}}diff --git a/UI/Web/src/app/admin/manage-library/manage-library.component.ts b/UI/Web/src/app/admin/manage-library/manage-library.component.tsindex d7a694ac1..d6e5a2364 100644--- a/UI/Web/src/app/admin/manage-library/manage-library.component.ts+++ b/UI/Web/src/app/admin/manage-library/manage-library.component.ts@@ -39,14 +39,16 @@ export class ManageLibraryComponent implements OnInit, OnDestroy {// when a progress event comes in, show it on the UI next to librarythis.hubService.messages$.pipe(takeUntil(this.onDestroy)).subscribe((event) => {if (event.event !== EVENTS.ScanLibraryProgress) return;++ console.log('scan event: ', event.payload);const scanEvent = event.payload as ProgressEvent;- this.scanInProgress[scanEvent.libraryId] = {progress: scanEvent.progress !== 100};+ this.scanInProgress[scanEvent.libraryId] = {progress: scanEvent.progress !== 1};if (scanEvent.progress === 0) {this.scanInProgress[scanEvent.libraryId].timestamp = scanEvent.eventTime;}- if (this.scanInProgress[scanEvent.libraryId].progress === false && scanEvent.progress === 100) {+ if (this.scanInProgress[scanEvent.libraryId].progress === false && scanEvent.progress === 1) {this.libraryService.getLibraries().pipe(take(1)).subscribe(libraries => {const newLibrary = libraries.find(lib => lib.id === scanEvent.libraryId);const existingLibrary = this.libraries.find(lib => lib.id === scanEvent.libraryId);diff --git a/UI/Web/src/app/admin/manage-settings/manage-settings.component.html b/UI/Web/src/app/admin/manage-settings/manage-settings.component.htmlindex 727d1069f..ecda0b4ac 100644--- a/UI/Web/src/app/admin/manage-settings/manage-settings.component.html+++ b/UI/Web/src/app/admin/manage-settings/manage-settings.component.html@@ -8,6 +8,20 @@<input readonly id="settings-cachedir" aria-describedby="settings-cachedir-help" class="form-control" formControlName="cacheDirectory" type="text"></div>+ <div class="form-group">+ <label for="settings-bookmarksdir">Bookmarks Directory</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="bookmarksDirectoryTooltip" role="button" tabindex="0"></i>+ <ng-template #bookmarksDirectoryTooltip>Location where bookmarks will be stored. Bookmarks are source files and can be large. Choose a location with adequate storage. Directory is managed, other files within directory will be deleted.</ng-template>+ <span class="sr-only" id="settings-bookmarksdir-help"><ng-container [ngTemplateOutlet]="bookmarksDirectoryTooltip"></ng-container></span>+ <div class="input-group">+ <input readonly id="settings-bookmarksdir" aria-describedby="settings-bookmarksdir-help" class="form-control" formControlName="bookmarksDirectory" type="text" aria-describedby="change-bookmarks-dir">+ <div class="input-group-append">+ <button id="change-bookmarks-dir" class="btn btn-primary" (click)="openDirectoryChooser(settingsForm.get('bookmarksDirectory')?.value, 'bookmarksDirectory')">+ Change+ </button>+ </div>+ </div>+ </div>+<!-- <div class="form-group"><label for="settings-baseurl">Base Url</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="baseUrlTooltip" role="button" tabindex="0"></i><ng-template #baseUrlTooltip>Use this if you want to host Kavita on a base url ie) yourdomain.com/kavita</ng-template>@@ -15,20 +29,22 @@<input id="settings-baseurl" aria-describedby="settings-baseurl-help" class="form-control" formControlName="baseUrl" type="text"></div> -->- <div class="form-group">- <label for="settings-port">Port</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="portTooltip" role="button" tabindex="0"></i>- <ng-template #portTooltip>Port the server listens on. This is fixed if you are running on Docker. Requires restart to take effect.</ng-template>- <span class="sr-only" id="settings-port-help">Port the server listens on. This is fixed if you are running on Docker. Requires restart to take effect.</span>- <input id="settings-port" aria-describedby="settings-port-help" class="form-control" formControlName="port" type="number" step="1" min="1" onkeypress="return event.charCode >= 48 && event.charCode <= 57">- </div>-- <div class="form-group">- <label for="logging-level-port">Logging Level</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="loggingLevelTooltip" role="button" tabindex="0"></i>- <ng-template #loggingLevelTooltip>Use debug to help identify issues. Debug can eat up a lot of disk space. Requires restart to take effect.</ng-template>- <span class="sr-only" id="logging-level-port-help">Port the server listens on. Requires restart to take effect.</span>- <select id="logging-level-port" aria-describedby="logging-level-port-help" class="form-control" aria-describedby="settings-tasks-scan-help" formControlName="loggingLevel">- <option *ngFor="let level of logLevels" [value]="level">{{level | titlecase}}</option>- </select>+ <div class="row no-gutters">+ <div class="form-group col-md-6 col-sm-12 pr-2">+ <label for="settings-port">Port</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="portTooltip" role="button" tabindex="0"></i>+ <ng-template #portTooltip>Port the server listens on. This is fixed if you are running on Docker. Requires restart to take effect.</ng-template>+ <span class="sr-only" id="settings-port-help">Port the server listens on. This is fixed if you are running on Docker. Requires restart to take effect.</span>+ <input id="settings-port" aria-describedby="settings-port-help" class="form-control" formControlName="port" type="number" step="1" min="1" onkeypress="return event.charCode >= 48 && event.charCode <= 57">+ </div>++ <div class="form-group col-md-6 col-sm-12">+ <label for="logging-level-port">Logging Level</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="loggingLevelTooltip" role="button" tabindex="0"></i>+ <ng-template #loggingLevelTooltip>Use debug to help identify issues. Debug can eat up a lot of disk space. Requires restart to take effect.</ng-template>+ <span class="sr-only" id="logging-level-port-help">Port the server listens on. Requires restart to take effect.</span>+ <select id="logging-level-port" aria-describedby="logging-level-port-help" class="form-control" aria-describedby="settings-tasks-scan-help" formControlName="loggingLevel">+ <option *ngFor="let level of logLevels" [value]="level">{{level | titlecase}}</option>+ </select>+ </div></div><div class="form-group">@@ -78,6 +94,7 @@</div><div class="float-right">+ <button type="button" class="btn btn-secondary mr-2" (click)="resetToDefaults()">Reset to Default</button><button type="button" class="btn btn-secondary mr-2" (click)="resetForm()">Reset</button><button type="submit" class="btn btn-primary" (click)="saveSettings()" [disabled]="!settingsForm.touched && !settingsForm.dirty">Save</button></div>diff --git a/UI/Web/src/app/admin/manage-settings/manage-settings.component.ts b/UI/Web/src/app/admin/manage-settings/manage-settings.component.tsindex 94509776a..eadfe5b71 100644--- a/UI/Web/src/app/admin/manage-settings/manage-settings.component.ts+++ b/UI/Web/src/app/admin/manage-settings/manage-settings.component.ts@@ -1,9 +1,11 @@import { Component, OnInit } from '@angular/core';import { FormGroup, FormControl, Validators } from '@angular/forms';+import { NgbModal } from '@ng-bootstrap/ng-bootstrap';import { ToastrService } from 'ngx-toastr';import { take } from 'rxjs/operators';import { ConfirmService } from 'src/app/shared/confirm.service';import { SettingsService } from '../settings.service';+import { DirectoryPickerComponent, DirectoryPickerResult } from '../_modals/directory-picker/directory-picker.component';import { ServerSettings } from '../_models/server-settings';@Component({@@ -18,7 +20,8 @@ export class ManageSettingsComponent implements OnInit {taskFrequencies: Array<string> = [];logLevels: Array<string> = [];- constructor(private settingsService: SettingsService, private toastr: ToastrService, private confirmService: ConfirmService) { }+ constructor(private settingsService: SettingsService, private toastr: ToastrService, private confirmService: ConfirmService,+ private modalService: NgbModal) { }ngOnInit(): void {this.settingsService.getTaskFrequencies().pipe(take(1)).subscribe(frequencies => {@@ -30,6 +33,7 @@ export class ManageSettingsComponent implements OnInit {this.settingsService.getServerSettings().pipe(take(1)).subscribe((settings: ServerSettings) => {this.serverSettings = settings;this.settingsForm.addControl('cacheDirectory', new FormControl(this.serverSettings.cacheDirectory, [Validators.required]));+ this.settingsForm.addControl('bookmarksDirectory', new FormControl(this.serverSettings.bookmarksDirectory, [Validators.required]));this.settingsForm.addControl('taskScan', new FormControl(this.serverSettings.taskScan, [Validators.required]));this.settingsForm.addControl('taskBackup', new FormControl(this.serverSettings.taskBackup, [Validators.required]));this.settingsForm.addControl('port', new FormControl(this.serverSettings.port, [Validators.required]));@@ -43,6 +47,7 @@ export class ManageSettingsComponent implements OnInit {resetForm() {this.settingsForm.get('cacheDirectory')?.setValue(this.serverSettings.cacheDirectory);+ this.settingsForm.get('bookmarksDirectory')?.setValue(this.serverSettings.bookmarksDirectory);this.settingsForm.get('scanTask')?.setValue(this.serverSettings.taskScan);this.settingsForm.get('taskBackup')?.setValue(this.serverSettings.taskBackup);this.settingsForm.get('port')?.setValue(this.serverSettings.port);@@ -77,4 +82,26 @@ export class ManageSettingsComponent implements OnInit {});}+ resetToDefaults() {+ this.settingsService.resetServerSettings().pipe(take(1)).subscribe(async (settings: ServerSettings) => {+ this.serverSettings = settings;+ this.resetForm();+ this.toastr.success('Server settings updated');+ }, (err: any) => {+ console.error('error: ', err);+ });+ }++ openDirectoryChooser(existingDirectory: string, formControl: string) {+ const modalRef = this.modalService.open(DirectoryPickerComponent, { scrollable: true, size: 'lg' });+ modalRef.componentInstance.startingFolder = existingDirectory || '';+ modalRef.componentInstance.helpUrl = '';+ modalRef.closed.subscribe((closeResult: DirectoryPickerResult) => {+ if (closeResult.success) {+ this.settingsForm.get(formControl)?.setValue(closeResult.folderPath);+ this.settingsForm.markAsTouched();+ }+ });+ }+}diff --git a/UI/Web/src/app/admin/settings.service.ts b/UI/Web/src/app/admin/settings.service.tsindex 9f0de0b3f..646fde087 100644--- a/UI/Web/src/app/admin/settings.service.ts+++ b/UI/Web/src/app/admin/settings.service.ts@@ -21,6 +21,10 @@ export class SettingsService {return this.http.post<ServerSettings>(this.baseUrl + 'settings', model);}+ resetServerSettings() {+ return this.http.post<ServerSettings>(this.baseUrl + 'settings/reset', {});+ }+getTaskFrequencies() {return this.http.get<string[]>(this.baseUrl + 'settings/task-frequencies');}diff --git a/UI/Web/src/app/all-series/all-series.component.html b/UI/Web/src/app/all-series/all-series.component.htmlnew file mode 100644index 000000000..dc589e566--- /dev/null+++ b/UI/Web/src/app/all-series/all-series.component.html@@ -0,0 +1,14 @@+<app-bulk-operations [actionCallback]="bulkActionCallback"></app-bulk-operations>+<app-card-detail-layout header="All Series"+ [isLoading]="loadingSeries"+ [items]="series"+ [actions]="actions"+ [pagination]="pagination"+ [filterSettings]="filterSettings"+ (applyFilter)="updateFilter($event)"+ (pageChange)="onPageChange($event)"+ >+ <ng-template #cardItem let-item let-position="idx">+ <app-series-card [data]="item" [libraryId]="item.libraryId" (reload)="loadPage()" (selection)="bulkSelectionService.handleCardSelection('series', position, series.length, $event)" [selected]="bulkSelectionService.isCardSelected('series', position)" [allowSelection]="true"></app-series-card>+ </ng-template>+</app-card-detail-layout>diff --git a/UI/Web/src/app/all-series/all-series.component.scss b/UI/Web/src/app/all-series/all-series.component.scssnew file mode 100644index 000000000..e69de29bbdiff --git a/UI/Web/src/app/all-series/all-series.component.ts b/UI/Web/src/app/all-series/all-series.component.tsnew file mode 100644index 000000000..51a37fc59--- /dev/null+++ b/UI/Web/src/app/all-series/all-series.component.ts@@ -0,0 +1,145 @@+import { Component, HostListener, OnDestroy, OnInit } from '@angular/core';+import { Title } from '@angular/platform-browser';+import { Router } from '@angular/router';+import { Subject } from 'rxjs';+import { take, debounceTime, takeUntil } from 'rxjs/operators';+import { BulkSelectionService } from '../cards/bulk-selection.service';+import { FilterSettings } from '../cards/card-detail-layout/card-detail-layout.component';+import { KEY_CODES } from '../shared/_services/utility.service';+import { SeriesAddedEvent } from '../_models/events/series-added-event';+import { Library } from '../_models/library';+import { Pagination } from '../_models/pagination';+import { Series } from '../_models/series';+import { SeriesFilter } from '../_models/series-filter';+import { ActionItem, Action } from '../_services/action-factory.service';+import { ActionService } from '../_services/action.service';+import { MessageHubService } from '../_services/message-hub.service';+import { SeriesService } from '../_services/series.service';++@Component({+ selector: 'app-all-series',+ templateUrl: './all-series.component.html',+ styleUrls: ['./all-series.component.scss']+})+export class AllSeriesComponent implements OnInit, OnDestroy {++ series: Series[] = [];+ loadingSeries = false;+ pagination!: Pagination;+ actions: ActionItem<Library>[] = [];+ filter: SeriesFilter | undefined = undefined;+ onDestroy: Subject<void> = new Subject<void>();+ filterSettings: FilterSettings = new FilterSettings();++ bulkActionCallback = (action: Action, data: any) => {+ const selectedSeriesIndexies = this.bulkSelectionService.getSelectedCardsForSource('series');+ const selectedSeries = this.series.filter((series, index: number) => selectedSeriesIndexies.includes(index + ''));++ switch (action) {+ case Action.AddToReadingList:+ this.actionService.addMultipleSeriesToReadingList(selectedSeries, () => {+ this.bulkSelectionService.deselectAll();+ });+ break;+ case Action.AddToCollection:+ this.actionService.addMultipleSeriesToCollectionTag(selectedSeries, () => {+ this.bulkSelectionService.deselectAll();+ });+ break;+ case Action.MarkAsRead:+ this.actionService.markMultipleSeriesAsRead(selectedSeries, () => {+ this.loadPage();+ this.bulkSelectionService.deselectAll();+ });++ break;+ case Action.MarkAsUnread:+ this.actionService.markMultipleSeriesAsUnread(selectedSeries, () => {+ this.loadPage();+ this.bulkSelectionService.deselectAll();+ });+ break;+ case Action.Delete:+ this.actionService.deleteMultipleSeries(selectedSeries, () => {+ this.loadPage();+ this.bulkSelectionService.deselectAll();+ });+ break;+ }+ }++ constructor(private router: Router, private seriesService: SeriesService,+ private titleService: Title, private actionService: ActionService,+ public bulkSelectionService: BulkSelectionService, private hubService: MessageHubService) {++ this.router.routeReuseStrategy.shouldReuseRoute = () => false;++ this.titleService.setTitle('Kavita - All Series');+ this.pagination = {currentPage: 0, itemsPerPage: 30, totalItems: 0, totalPages: 1};++ this.loadPage();+ }++ ngOnInit(): void {+ this.hubService.seriesAdded.pipe(debounceTime(6000), takeUntil(this.onDestroy)).subscribe((event: SeriesAddedEvent) => {+ this.loadPage();+ });+ }++ ngOnDestroy() {+ this.onDestroy.next();+ this.onDestroy.complete();+ }++ @HostListener('document:keydown.shift', ['$event'])+ handleKeypress(event: KeyboardEvent) {+ if (event.key === KEY_CODES.SHIFT) {+ this.bulkSelectionService.isShiftDown = true;+ }+ }++ @HostListener('document:keyup.shift', ['$event'])+ handleKeyUp(event: KeyboardEvent) {+ if (event.key === KEY_CODES.SHIFT) {+ this.bulkSelectionService.isShiftDown = false;+ }+ }++ updateFilter(data: SeriesFilter) {+ this.filter = data;+ if (this.pagination !== undefined && this.pagination !== null) {+ this.pagination.currentPage = 1;+ this.onPageChange(this.pagination);+ } else {+ this.loadPage();+ }+ }++ loadPage() {+ const page = this.getPage();+ if (page != null) {+ this.pagination.currentPage = parseInt(page, 10);+ }+ this.loadingSeries = true;++ this.seriesService.getAllSeries(this.pagination?.currentPage, this.pagination?.itemsPerPage, this.filter).pipe(take(1)).subscribe(series => {+ this.series = series.result;+ this.pagination = series.pagination;+ this.loadingSeries = false;+ window.scrollTo(0, 0);+ });+ }++ onPageChange(pagination: Pagination) {+ window.history.replaceState(window.location.href, '', window.location.href.split('?')[0] + '?page=' + this.pagination.currentPage);+ this.loadPage();+ }++ trackByIdentity = (index: number, item: Series) => `${item.name}_${item.originalName}_${item.localizedName}_${item.pagesRead}`;++ getPage() {+ const urlParams = new URLSearchParams(window.location.search);+ return urlParams.get('page');+ }++}diff --git a/UI/Web/src/app/app-routing.module.ts b/UI/Web/src/app/app-routing.module.tsindex 39800d8cd..7f8bd88f7 100644--- a/UI/Web/src/app/app-routing.module.ts+++ b/UI/Web/src/app/app-routing.module.ts@@ -9,6 +9,8 @@ import { AuthGuard } from './_guards/auth.guard';import { LibraryAccessGuard } from './_guards/library-access.guard';import { OnDeckComponent } from './on-deck/on-deck.component';import { DashboardComponent } from './dashboard/dashboard.component';+import { AllSeriesComponent } from './all-series/all-series.component';+import { AdminGuard } from './_guards/admin.guard';// TODO: Once we modularize the components, use this and measure performance impact: https://angular.io/guide/lazy-loading-ngmodules#preloading-modules@@ -16,18 +18,22 @@ const routes: Routes = [{path: '', component: UserLoginComponent},{path: 'admin',+ canActivate: [AdminGuard],loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule)},{path: 'collections',+ canActivate: [AuthGuard],loadChildren: () => import('./collections/collections.module').then(m => m.CollectionsModule)},{path: 'preferences',+ canActivate: [AuthGuard],loadChildren: () => import('./user-settings/user-settings.module').then(m => m.UserSettingsModule)},{path: 'lists',+ canActivate: [AuthGuard],loadChildren: () => import('./reading-list/reading-list.module').then(m => m.ReadingListModule)},{@@ -55,6 +61,8 @@ const routes: Routes = [{path: 'library', component: DashboardComponent},{path: 'recently-added', component: RecentlyAddedComponent},{path: 'on-deck', component: OnDeckComponent},+ {path: 'all-series', component: AllSeriesComponent},+]},{path: 'login', component: UserLoginComponent},diff --git a/UI/Web/src/app/app.component.ts b/UI/Web/src/app/app.component.tsindex d1e778d3c..c4a8cd863 100644--- a/UI/Web/src/app/app.component.ts+++ b/UI/Web/src/app/app.component.ts@@ -6,7 +6,7 @@ import { LibraryService } from './_services/library.service';import { MessageHubService } from './_services/message-hub.service';import { NavService } from './_services/nav.service';import { filter } from 'rxjs/operators';-import { NgbModal } from '@ng-bootstrap/ng-bootstrap';+import { NgbModal, NgbRatingConfig } from '@ng-bootstrap/ng-bootstrap';@Component({selector: 'app-root',@@ -17,7 +17,11 @@ export class AppComponent implements OnInit {constructor(private accountService: AccountService, public navService: NavService,private messageHub: MessageHubService, private libraryService: LibraryService,- private router: Router, private ngbModal: NgbModal) {+ private router: Router, private ngbModal: NgbModal, private ratingConfig: NgbRatingConfig) {++ // Setup default rating config+ ratingConfig.max = 5;+ ratingConfig.resettable = true;// Close any open modals when a route change occursrouter.eventsdiff --git a/UI/Web/src/app/app.module.ts b/UI/Web/src/app/app.module.tsindex a9cb82151..89be77453 100644--- a/UI/Web/src/app/app.module.ts+++ b/UI/Web/src/app/app.module.ts@@ -22,7 +22,6 @@ import { AutocompleteLibModule } from 'angular-ng-autocomplete';import { ReviewSeriesModalComponent } from './_modals/review-series-modal/review-series-modal.component';import { CarouselModule } from './carousel/carousel.module';-import { PersonBadgeComponent } from './person-badge/person-badge.component';import { TypeaheadModule } from './typeahead/typeahead.module';import { RecentlyAddedComponent } from './recently-added/recently-added.component';import { OnDeckComponent } from './on-deck/on-deck.component';@@ -33,6 +32,10 @@ import { ReadingListModule } from './reading-list/reading-list.module';import { SAVER, getSaver } from './shared/_providers/saver.provider';import { ConfigData } from './_models/config-data';import { NavEventsToggleComponent } from './nav-events-toggle/nav-events-toggle.component';+import { PersonRolePipe } from './person-role.pipe';+import { SeriesMetadataDetailComponent } from './series-metadata-detail/series-metadata-detail.component';+import { AllSeriesComponent } from './all-series/all-series.component';+import { PublicationStatusPipe } from './publication-status.pipe';@NgModule({@@ -45,11 +48,14 @@ import { NavEventsToggleComponent } from './nav-events-toggle/nav-events-toggle.SeriesDetailComponent,NotConnectedComponent, // Move into ExtrasModuleReviewSeriesModalComponent,- PersonBadgeComponent,RecentlyAddedComponent,OnDeckComponent,DashboardComponent,NavEventsToggleComponent,+ PersonRolePipe,+ PublicationStatusPipe,+ SeriesMetadataDetailComponent,+ AllSeriesComponent,],imports: [HttpClientModule,diff --git a/UI/Web/src/app/book-reader/book-reader/book-reader.component.html b/UI/Web/src/app/book-reader/book-reader/book-reader.component.htmlindex 181de7cea..44e05dd86 100644--- a/UI/Web/src/app/book-reader/book-reader/book-reader.component.html+++ b/UI/Web/src/app/book-reader/book-reader/book-reader.component.html@@ -1,4 +1,4 @@-<div class="container-flex {{darkMode ? 'dark-mode' : ''}}">+<div class="container-flex {{darkMode ? 'dark-mode' : ''}} reader-container" tabindex="0" #reader><div class="fixed-top" #stickyTop><a class="sr-only sr-only-focusable focus-visible" href="javascript:void(0);" (click)="moveFocus()">Skip to main content</a><ng-container [ngTemplateOutlet]="actionBar"></ng-container>@@ -57,6 +57,17 @@<span class="sr-only" id="tap-pagination-help">The ability to click the sides of the page to page left and right</span><button (click)="toggleClickToPaginate()" class="btn btn-icon" aria-labelledby="tap-pagination"><i class="fa fa-arrows-alt-h {{clickToPaginate ? 'icon-primary-color' : ''}}" aria-hidden="true"></i><span *ngIf="darkMode"> {{clickToPaginate ? 'On' : 'Off'}}</span></button></div>+ <div class="controls">+ <label id="fullscreen">Fullscreen <i class="fa fa-info-circle" aria-hidden="true" placement="top" [ngbTooltip]="fullscreenTooltip" role="button" tabindex="0" aria-describedby="fullscreen-help"></i></label>+ <ng-template #fullscreenTooltip>Put reader in fullscreen mode</ng-template>+ <span class="sr-only" id="fullscreen-help">+ <ng-container [ngTemplateOutlet]="fullscreenTooltip"></ng-container>+ </span>+ <button (click)="toggleFullscreen()" class="btn btn-icon" aria-labelledby="fullscreen">+ <i class="fa {{this.isFullscreen ? 'fa-compress-alt' : 'fa-expand-alt'}} {{isFullscreen ? 'icon-primary-color' : ''}}" aria-hidden="true"></i>+ <span *ngIf="darkMode"> {{isFullscreen ? 'Exit' : 'Enter'}}</span>+ </button>+ </div><div class="row no-gutters justify-content-between"><button (click)="resetSettings()" class="btn btn-primary col">Reset to Defaults</button></div>@@ -83,7 +94,7 @@</ul></div><ng-template #nestedChildren>- <ul *ngFor="let chapterGroup of chapters" style="padding-inline-start: 0px">+ <ul *ngFor="let chapterGroup of chapters" class="chapter-title"><li class="{{chapterGroup.page == pageNum ? 'active': ''}}" (click)="loadChapterPage(chapterGroup.page, '')">{{chapterGroup.title}}</li>@@ -99,13 +110,14 @@</app-drawer></div>- <div #readingSection class="reading-section" [ngStyle]="{'padding-top': topOffset + 20 + 'px'}" [@isLoading]="isLoading ? true : false" (click)="handleReaderClick($event)">- <div #readingHtml class="book-content" [ngStyle]="{'padding-bottom': topOffset + 20 + 'px', 'margin': '0px 0px'}" [innerHtml]="page" *ngIf="page !== undefined"></div>+ <div #readingSection class="reading-section" [ngStyle]="{'padding-top': topOffset + 20 + 'px'}"+ [@isLoading]="isLoading ? true : false" (click)="handleReaderClick($event)">- <div class="left {{clickOverlayClass('left')}} no-observe" (click)="prevPage()" *ngIf="clickToPaginate">- </div>- <div class="right {{clickOverlayClass('right')}} no-observe" (click)="nextPage()" *ngIf="clickToPaginate">- </div>+ <div #readingHtml class="book-content" [ngStyle]="{'padding-bottom': topOffset + 20 + 'px', 'margin': '0px 0px'}"+ [innerHtml]="page" *ngIf="page !== undefined"></div>++ <div class="left {{clickOverlayClass('left')}} no-observe" (click)="prevPage()" *ngIf="clickToPaginate" tabindex="-1"></div>+ <div class="right {{clickOverlayClass('right')}} no-observe" (click)="nextPage()" *ngIf="clickToPaginate" tabindex="-1"></div><div *ngIf="page !== undefined && scrollbarNeeded"><ng-container [ngTemplateOutlet]="actionBar"></ng-container>diff --git a/UI/Web/src/app/book-reader/book-reader/book-reader.component.scss b/UI/Web/src/app/book-reader/book-reader/book-reader.component.scssindex 7132626f9..12823f996 100644--- a/UI/Web/src/app/book-reader/book-reader/book-reader.component.scss+++ b/UI/Web/src/app/book-reader/book-reader/book-reader.component.scss@@ -154,18 +154,40 @@ $primary-color: #0062cc;}.reading-section {- height: 100vh;+ max-height: 100vh;width: 100%;+ //overflow: auto; // This will break progress reporting+}++.reader-container {+ outline: none; // Only the reading section itself shouldn't receive any outline. We use it to shift focus in fullscreen mode+ overflow: auto;}.book-content {position: relative;}+// A bunch of resets so books render correctly+::ng-deep .book-content {+ & a, & :link {+ color: blue;+ }+}+.drawer-body {padding-bottom: 20px;}+.chapter-title {+ padding-inline-start: 0px+}++::ng-deep .scale-width {+ max-width: 100%;+ object-fit: contain;+ object-position: top center;+}// Click to Paginate stylesdiff --git a/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts b/UI/Web/src/app/book-reader/book-reader/book-reader.component.tsindex e5019010f..74120972e 100644--- a/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts+++ b/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts@@ -1,5 +1,5 @@-import { AfterViewInit, Component, ElementRef, HostListener, OnDestroy, OnInit, Renderer2, RendererStyleFlags2, ViewChild } from '@angular/core';-import {Location} from '@angular/common';+import { AfterViewInit, Component, ElementRef, HostListener, Inject, OnDestroy, OnInit, Renderer2, RendererStyleFlags2, ViewChild } from '@angular/core';+import {DOCUMENT, Location} from '@angular/common';import { FormControl, FormGroup } from '@angular/forms';import { ActivatedRoute, Router } from '@angular/router';import { ToastrService } from 'ngx-toastr';@@ -111,6 +111,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {@ViewChild('readingHtml', {static: false}) readingHtml!: ElementRef<HTMLDivElement>;@ViewChild('readingSection', {static: false}) readingSectionElemRef!: ElementRef<HTMLDivElement>;@ViewChild('stickyTop', {static: false}) stickyTopElemRef!: ElementRef<HTMLDivElement>;+ @ViewChild('reader', {static: true}) reader!: ElementRef;/*** Next Chapter Id. This is not garunteed to be a valid ChapterId. Prefetched on page load (non-blocking).@@ -185,6 +186,11 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {*/originalBodyColor: string | undefined;+ /**+ * If the web browser is in fullscreen mode+ */+ isFullscreen: boolean = false;+darkModeStyles = `*:not(input), *:not(select), *:not(code), *:not(:link), *:not(.ngx-toastr) {color: #dcdcdc !important;@@ -237,7 +243,8 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {private seriesService: SeriesService, private readerService: ReaderService, private location: Location,private renderer: Renderer2, private navService: NavService, private toastr: ToastrService,private domSanitizer: DomSanitizer, private bookService: BookService, private memberService: MemberService,- private scrollService: ScrollService, private utilityService: UtilityService, private libraryService: LibraryService) {+ private scrollService: ScrollService, private utilityService: UtilityService, private libraryService: LibraryService,+ @Inject(DOCUMENT) private document: Document) {this.navService.hideNavBar();this.darkModeStyleElem = this.renderer.createElement('style');@@ -275,7 +282,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {});}- const bodyNode = document.querySelector('body');+ const bodyNode = this.document.querySelector('body');if (bodyNode !== undefined && bodyNode !== null) {this.originalBodyColor = bodyNode.style.background;}@@ -290,14 +297,14 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {*/ngAfterViewInit() {// check scroll offset and if offset is after any of the "id" markers, save progress- fromEvent(window, 'scroll')+ fromEvent(this.reader.nativeElement, 'scroll').pipe(debounceTime(200), takeUntil(this.onDestroy)).subscribe((event) => {if (this.isLoading) return;// Highlight the current chapter we are onif (Object.keys(this.pageAnchors).length !== 0) {// get the height of the document so we can capture markers that are halfway on the document viewport- const verticalOffset = this.scrollService.scrollPosition + (document.body.offsetHeight / 2);+ const verticalOffset = this.scrollService.scrollPosition + (this.document.body.offsetHeight / 2);const alreadyReached = Object.values(this.pageAnchors).filter((i: number) => i <= verticalOffset);if (alreadyReached.length > 0) {@@ -344,7 +351,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {}ngOnDestroy(): void {- const bodyNode = document.querySelector('body');+ const bodyNode = this.document.querySelector('body');if (bodyNode !== undefined && bodyNode !== null && this.originalBodyColor !== undefined) {bodyNode.style.background = this.originalBodyColor;if (this.user.preferences.siteDarkMode) {@@ -353,7 +360,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {}this.navService.showNavBar();- const head = document.querySelector('head');+ const head = this.document.querySelector('head');this.renderer.removeChild(head, this.darkModeStyleElem);if (this.clickToPaginateVisualOverlayTimeout !== undefined) {@@ -365,6 +372,8 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.clickToPaginateVisualOverlayTimeout2 = undefined;}+ this.readerService.exitFullscreen();+this.onDestroy.next();this.onDestroy.complete();}@@ -573,8 +582,8 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {resetSettings() {const windowWidth = window.innerWidth- || document.documentElement.clientWidth- || document.body.clientWidth;+ || this.document.documentElement.clientWidth+ || this.document.body.clientWidth;let margin = '15%';if (windowWidth <= 700) {@@ -623,7 +632,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {}moveFocus() {- const elems = document.getElementsByClassName('reading-section');+ const elems = this.document.getElementsByClassName('reading-section');if (elems.length > 0) {(elems[0] as HTMLDivElement).focus();}@@ -671,10 +680,10 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {getPageMarkers(ids: Array<string>) {try {- return document.querySelectorAll(ids.map(id => '#' + this.cleanIdSelector(id)).join(', '));+ return this.document.querySelectorAll(ids.map(id => '#' + this.cleanIdSelector(id)).join(', '));} catch (Exception) {// Fallback to anchors instead. Some books have ids that are not valid for querySelectors, so anchors should be used instead- return document.querySelectorAll(ids.map(id => '[href="#' + id + '"]').join(', '));+ return this.document.querySelectorAll(ids.map(id => '[href="#' + id + '"]').join(', '));}}@@ -709,6 +718,10 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.setupPage(part, scrollTop);return;}++ // Apply scaling class to all images to ensure they scale down to max width to not blow out the reader+ Array.from(imgs).forEach(img => this.renderer.addClass(img, 'scale-width'));+Promise.all(Array.from(imgs).filter(img => !img.complete).map(img => new Promise(resolve => { img.onload = img.onerror = resolve; })))@@ -730,16 +743,19 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {if (part !== undefined && part !== '') {this.scrollTo(part);} else if (scrollTop !== undefined && scrollTop !== 0) {- this.scrollService.scrollTo(scrollTop);+ this.scrollService.scrollTo(scrollTop, this.reader.nativeElement);} else {- this.scrollService.scrollTo(0);+ this.scrollService.scrollTo(0, this.reader.nativeElement);}++ // we need to click the document before arrow keys will scroll down.+ this.reader.nativeElement.focus();}setPageNum(pageNum: number) {if (pageNum < 0) {this.pageNum = 0;- } else if (pageNum >= this.maxPages - 1) {+ } else if (pageNum >= this.maxPages) {this.pageNum = this.maxPages - 1;} else {this.pageNum = pageNum;@@ -799,13 +815,14 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.setPageNum(this.pageNum - 1);}- if (this.pageNum >= this.maxPages - 1) {+ if (oldPageNum + 1 === this.maxPages) {// Move to next volume/chapter automaticallythis.loadNextChapter();}if (oldPageNum === this.pageNum) { return; }+this.loadPage();}@@ -860,13 +877,27 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {updateReaderStyles() {if (this.readingHtml != undefined && this.readingHtml.nativeElement) {+ Object.entries(this.pageStyles).forEach(item => {+ if (item[1] == '100%' || item[1] == '0px' || item[1] == 'inherit') {+ // Remove the style or skip+ this.renderer.removeStyle(this.readingHtml.nativeElement, item[0]);+ return;+ }+ this.renderer.setStyle(this.readingHtml.nativeElement, item[0], item[1], RendererStyleFlags2.Important);+ });+for(let i = 0; i < this.readingHtml.nativeElement.children.length; i++) {const elem = this.readingHtml.nativeElement.children.item(i);- if (elem?.tagName != 'STYLE') {+ if (elem?.tagName === 'STYLE') continue;Object.entries(this.pageStyles).forEach(item => {+ if (item[1] == '100%' || item[1] == '0px' || item[1] == 'inherit') {+ // Remove the style or skip+ this.renderer.removeStyle(elem, item[0]);+ return;+ }this.renderer.setStyle(elem, item[0], item[1], RendererStyleFlags2.Important);});- }+}}}@@ -895,7 +926,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {}setOverrideStyles() {- const bodyNode = document.querySelector('body');+ const bodyNode = this.document.querySelector('body');if (bodyNode !== undefined && bodyNode !== null) {if (this.user.preferences.siteDarkMode) {bodyNode.classList.remove('bg-dark');@@ -904,7 +935,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {bodyNode.style.background = this.getDarkModeBackgroundColor();}this.backgroundColor = this.getDarkModeBackgroundColor();- const head = document.querySelector('head');+ const head = this.document.querySelector('head');if (this.darkMode) {this.renderer.appendChild(head, this.darkModeStyleElem)} else {@@ -940,12 +971,12 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {// Part selector is a XPATHelement = this.getElementFromXPath(partSelector);} else {- element = document.querySelector('*[id="' + partSelector + '"]');+ element = this.document.querySelector('*[id="' + partSelector + '"]');}if (element === null) return;- this.scrollService.scrollTo(element.getBoundingClientRect().top + window.pageYOffset + TOP_OFFSET);+ this.scrollService.scrollTo(element.getBoundingClientRect().top + window.pageYOffset + TOP_OFFSET, this.reader.nativeElement);}toggleClickToPaginate() {@@ -976,7 +1007,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {}getElementFromXPath(path: string) {- const node = document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;+ const node = this.document.evaluate(path, this.document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;if (node?.nodeType === Node.ELEMENT_NODE) {return node as Element;}@@ -986,7 +1017,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {getXPathTo(element: any): string {if (element === null) return '';if (element.id !== '') { return 'id("' + element.id + '")'; }- if (element === document.body) { return element.tagName; }+ if (element === this.document.body) { return element.tagName; }let ix = 0;@@ -1014,4 +1045,21 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.readerService.saveProgress(this.seriesId, this.volumeId, this.chapterId, this.pageNum).pipe(take(1)).subscribe(() => {/* No operation */});}+ toggleFullscreen() {+ this.isFullscreen = this.readerService.checkFullscreenMode();+ if (this.isFullscreen) {+ this.readerService.exitFullscreen(() => {+ this.isFullscreen = false;+ this.renderer.removeStyle(this.reader.nativeElement, 'background');+ });+ } else {+ this.readerService.enterFullscreen(this.reader.nativeElement, () => {+ this.isFullscreen = true;+ // HACK: This is a bug with how browsers change the background color for fullscreen mode+ if (!this.darkMode) {+ this.renderer.setStyle(this.reader.nativeElement, 'background', 'white');+ }+ });+ }+ }}diff --git a/UI/Web/src/app/cards/_modals/bookmarks-modal/bookmarks-modal.component.html b/UI/Web/src/app/cards/_modals/bookmarks-modal/bookmarks-modal.component.htmlindex 2318b61e3..2dd4b93e1 100644--- a/UI/Web/src/app/cards/_modals/bookmarks-modal/bookmarks-modal.component.html+++ b/UI/Web/src/app/cards/_modals/bookmarks-modal/bookmarks-modal.component.html@@ -5,15 +5,16 @@</button></div><div class="modal-body">-- <ul class="list-unstyled">- <li class="list-group-item" *ngIf="bookmarks.length > 0">- There are {{bookmarks.length}} pages bookmarked over {{uniqueChapters}} files.- </li>- <li class="list-group-item" *ngIf="bookmarks.length === 0">- No bookmarks yet- </li>- </ul>+ <p *ngIf="bookmarks.length > 0; else noBookmarks">+ There are {{bookmarks.length}} pages bookmarked over {{uniqueChapters}} files.+ </p>+ <ng-template #noBookmarks>No bookmarks yet</ng-template>++ <div class="row no-gutters">+ <div *ngFor="let bookmark of bookmarks; let idx = index">+ <app-bookmark [bookmark]="bookmark" (bookmarkRemoved)="removeBookmark(bookmark, idx)" class="col-auto"></app-bookmark>+ </div>+ </div></div><div class="modal-footer"><button type="button" class="btn btn-secondary" (click)="clearBookmarks()" [disabled]="(isDownloading || isClearing) || bookmarks.length === 0">diff --git a/UI/Web/src/app/cards/_modals/bookmarks-modal/bookmarks-modal.component.ts b/UI/Web/src/app/cards/_modals/bookmarks-modal/bookmarks-modal.component.tsindex 8e3393fc7..780882f1a 100644--- a/UI/Web/src/app/cards/_modals/bookmarks-modal/bookmarks-modal.component.ts+++ b/UI/Web/src/app/cards/_modals/bookmarks-modal/bookmarks-modal.component.ts@@ -51,6 +51,10 @@ export class BookmarksModalComponent implements OnInit {this.modal.close();}+ removeBookmark(bookmark: PageBookmark, index: number) {+ this.bookmarks.splice(index, 1);+ }+downloadBookmarks() {this.isDownloading = true;this.downloadService.downloadBookmarks(this.bookmarks).pipe(diff --git a/UI/Web/src/app/cards/_modals/card-details-modal/card-details-modal.component.html b/UI/Web/src/app/cards/_modals/card-details-modal/card-details-modal.component.htmlindex 62a40f9e0..8bdaf5731 100644--- a/UI/Web/src/app/cards/_modals/card-details-modal/card-details-modal.component.html+++ b/UI/Web/src/app/cards/_modals/card-details-modal/card-details-modal.component.html@@ -9,7 +9,12 @@<span aria-hidden="true">×</span></button></div>- <div class="modal-body scrollable-modal">+ <div class="modal-body scrollable-modal" *ngIf="utilityService.isChapter(data)">+ <ng-container *ngIf="utilityService.isChapter(data)">+ <app-chapter-metadata-detail [chapter]="data"></app-chapter-metadata-detail>+ </ng-container>+ </div>+ <div class="modal-body scrollable-modal" *ngIf="utilityService.isVolume(data)"><h4 *ngIf="utilityService.isVolume(data)">Information</h4><ng-container *ngIf="utilityService.isVolume(data) || utilityService.isChapter(data)">diff --git a/UI/Web/src/app/cards/_modals/card-details-modal/card-details-modal.component.ts b/UI/Web/src/app/cards/_modals/card-details-modal/card-details-modal.component.tsindex e1501cd9b..a5a655f8f 100644--- a/UI/Web/src/app/cards/_modals/card-details-modal/card-details-modal.component.ts+++ b/UI/Web/src/app/cards/_modals/card-details-modal/card-details-modal.component.ts@@ -160,6 +160,9 @@ export class CardDetailsModalComponent implements OnInit {case(Action.MarkAsUnread):this.markChapterAsUnread(chapter);break;+ case(Action.AddToReadingList):+ this.actionService.addChapterToReadingList(chapter, this.seriesId);+ break;default:break;}diff --git a/UI/Web/src/app/cards/_modals/edit-series-modal/edit-series-modal.component.ts b/UI/Web/src/app/cards/_modals/edit-series-modal/edit-series-modal.component.tsindex dd3be4ead..ff1123797 100644--- a/UI/Web/src/app/cards/_modals/edit-series-modal/edit-series-modal.component.ts+++ b/UI/Web/src/app/cards/_modals/edit-series-modal/edit-series-modal.component.ts@@ -69,7 +69,7 @@ export class EditSeriesModalComponent implements OnInit, OnDestroy {this.editSeriesForm = this.fb.group({id: new FormControl(this.series.id, []),- summary: new FormControl(this.series.summary, []),+ summary: new FormControl('', []),name: new FormControl(this.series.name, []),localizedName: new FormControl(this.series.localizedName, []),sortName: new FormControl(this.series.sortName, []),@@ -86,8 +86,9 @@ export class EditSeriesModalComponent implements OnInit, OnDestroy {this.seriesService.getMetadata(this.series.id).subscribe(metadata => {if (metadata) {this.metadata = metadata;- this.settings.savedData = metadata.tags;- this.tags = metadata.tags;+ this.settings.savedData = metadata.collectionTags;+ this.tags = metadata.collectionTags;+ this.editSeriesForm.get('summary')?.setValue(this.metadata.summary);}});diff --git a/UI/Web/src/app/cards/bookmark/bookmark.component.html b/UI/Web/src/app/cards/bookmark/bookmark.component.htmlnew file mode 100644index 000000000..005d703a6--- /dev/null+++ b/UI/Web/src/app/cards/bookmark/bookmark.component.html@@ -0,0 +1,28 @@+<div class="card" *ngIf="bookmark != undefined">+ <img class="img-top lazyload" [src]="imageService.placeholderImage" [attr.data-src]="imageService.getBookmarkedImage(bookmark.chapterId, bookmark.page)"+ (error)="imageService.updateErroredImage($event)" aria-hidden="true" height="230px" width="170px">++ <div class="card-body" *ngIf="bookmark.page >= 0">+ <div class="header-row">+ <span class="card-title" tabindex="0">+ Page {{bookmark.page + 1}}+ </span>+ <span class="card-actions float-right" *ngIf="series != undefined">+ <button attr.aria-labelledby="series--{{series.name}}" class="btn btn-danger btn-sm" (click)="removeBookmark()"+ [disabled]="isClearing" placement="top" ngbTooltip="Remove Bookmark" attr.aria-label="Remove Bookmark">+ <ng-container *ngIf="isClearing; else notClearing">+ <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>+ <span class="sr-only">Loading...</span>+ </ng-container>+ <ng-template #notClearing>+ <i class="fa fa-trash-alt" aria-hidden="true"></i>+ </ng-template>+ </button>+ </span>+ </div>+ <div>+ <a *ngIf="series != undefined" class="title-overflow library" href="/library/{{series.libraryId}}/series/{{series.id}}"+ placement="top" id="bookmark_card_{{series.name}}_{{bookmark.id}}" [ngbTooltip]="series.name | titlecase">{{series.name | titlecase}}</a>+ </div>+ </div>+</div>\ No newline at end of filediff --git a/UI/Web/src/app/cards/bookmark/bookmark.component.scss b/UI/Web/src/app/cards/bookmark/bookmark.component.scssnew file mode 100644index 000000000..b64b52e8d--- /dev/null+++ b/UI/Web/src/app/cards/bookmark/bookmark.component.scss@@ -0,0 +1,25 @@+.card-body {+ padding: 5px;+}++.card {+ margin-left: 5px;+ margin-right: 5px;+}++.header-row {+ display: flex;+ justify-content: space-between;+ align-items: flex-start;+}++.title-overflow {+ font-size: 13px;+ width: 130px;+ text-overflow: ellipsis;+ white-space: nowrap;+ overflow: hidden;+ display: block;+ margin-top: 2px;+ margin-bottom: 0px;+}\ No newline at end of filediff --git a/UI/Web/src/app/cards/bookmark/bookmark.component.ts b/UI/Web/src/app/cards/bookmark/bookmark.component.tsnew file mode 100644index 000000000..437eb2227--- /dev/null+++ b/UI/Web/src/app/cards/bookmark/bookmark.component.ts@@ -0,0 +1,43 @@+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';+import { Series } from 'src/app/_models/series';+import { ImageService } from 'src/app/_services/image.service';+import { ReaderService } from 'src/app/_services/reader.service';+import { SeriesService } from 'src/app/_services/series.service';+import { PageBookmark } from '../../_models/page-bookmark';++@Component({+ selector: 'app-bookmark',+ templateUrl: './bookmark.component.html',+ styleUrls: ['./bookmark.component.scss']+})+export class BookmarkComponent implements OnInit {++ @Input() bookmark: PageBookmark | undefined;+ @Output() bookmarkRemoved: EventEmitter<PageBookmark> = new EventEmitter<PageBookmark>();+ series: Series | undefined;++ isClearing: boolean = false;+ isDownloading: boolean = false;++ constructor(public imageService: ImageService, private seriesService: SeriesService, private readerService: ReaderService) { }++ ngOnInit(): void {+ if (this.bookmark) {+ this.seriesService.getSeries(this.bookmark.seriesId).subscribe(series => {+ this.series = series;+ });+ }+ }++ handleClick(event: any) {++ }++ removeBookmark() {+ if (this.bookmark === undefined) return;+ this.readerService.unbookmark(this.bookmark.seriesId, this.bookmark.volumeId, this.bookmark.chapterId, this.bookmark.page).subscribe(res => {+ this.bookmarkRemoved.emit(this.bookmark);+ this.bookmark = undefined;+ });+ }+}diff --git a/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.html b/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.htmlindex 7f85064e3..7ecb8d71a 100644--- a/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.html+++ b/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.html@@ -10,24 +10,350 @@</h2></div>- <button *ngIf="filters !== undefined && filters.length > 0" class="btn btn-secondary btn-small" (click)="collapse.toggle()" [attr.aria-expanded]="!filteringCollapsed" placement="left" ngbTooltip="{{filteringCollapsed ? 'Open' : 'Close'}} Filtering and Sorting" attr.aria-label="{{filteringCollapsed ? 'Open' : 'Close'}} Filtering and Sorting">+ <button class="btn btn-secondary btn-small" (click)="collapse.toggle()" [attr.aria-expanded]="!filteringCollapsed" placement="left" ngbTooltip="{{filteringCollapsed ? 'Open' : 'Close'}} Filtering and Sorting" attr.aria-label="{{filteringCollapsed ? 'Open' : 'Close'}} Filtering and Sorting"><i class="fa fa-filter" aria-hidden="true"></i><span class="sr-only">Sort / Filter</span></button></div>- <div class="row no-gutters filter-section" #collapse="ngbCollapse" [(ngbCollapse)]="filteringCollapsed">- <div class="col">- <form class="ml-2" [formGroup]="filterForm">- <div class="form-group" *ngIf="filters.length > 0">- <label for="series-filter">Filter</label>- <select class="form-control" id="series-filter" formControlName="filter" (ngModelChange)="handleFilterChange($event)" style="max-width: 200px;">- <option [value]="i" *ngFor="let opt of filters; let i = index">{{opt.title}}</option>- </select>- </div>- </form>+ <div class="phone-hidden">+ <div #collapse="ngbCollapse" [(ngbCollapse)]="filteringCollapsed">+ <ng-container [ngTemplateOutlet]="filterSection"></ng-container></div>-</div>++ <div class="not-phone-hidden">+ <app-drawer #commentDrawer="drawer" [isOpen]="!filteringCollapsed" [style.--drawer-width]="'300px'" [style.--drawer-background-color]="'#010409'" (drawerClosed)="filteringCollapsed = !filteringCollapsed">+ <div header>+ <h2 style="margin-top: 0.5rem">Book Settings+ <button type="button" class="close" aria-label="Close" (click)="commentDrawer.close()">+ <span aria-hidden="true">×</span>+ </button>+ </h2>++ </div>+ <div body class="drawer-body">+ <ng-container [ngTemplateOutlet]="filterSection"></ng-container>+ </div>+ </app-drawer>+ </div>++ <ng-template #filterSection>+ <ng-template #globalFilterTooltip>This is library agnostic</ng-template>+ <div class="filter-section mx-auto pb-3">+ <div class="row justify-content-center no-gutters">+ <div class="col-md-2 mr-3" *ngIf="!filterSettings.formatDisabled">+ <div class="form-group">+ <label for="format">Format</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="globalFilterTooltip" role="button" tabindex="0"></i>+ <span class="sr-only" id="filter-global-format-help"><ng-container [ngTemplateOutlet]="globalFilterTooltip"></ng-container></span>+ <app-typeahead (selectedData)="updateFormatFilters($event)" [settings]="formatSettings" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3"*ngIf="!filterSettings.libraryDisabled">+ <div class="form-group">+ <label for="libraries">Libraries</label>+ <app-typeahead (selectedData)="updateLibraryFilters($event)" [settings]="librarySettings" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="!filterSettings.collectionDisabled">+ <div class="form-group">+ <label for="collections">Collections</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="globalFilterTooltip" role="button" tabindex="0"></i>+ <span class="sr-only" id="filter-global-collections-help"><ng-container [ngTemplateOutlet]="globalFilterTooltip"></ng-container></span>+ <app-typeahead (selectedData)="updateCollectionFilters($event)" [settings]="collectionSettings" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="!filterSettings.genresDisabled">+ <div class="form-group">+ <label for="genres">Genres</label>+ <app-typeahead (selectedData)="updateGenreFilters($event)" [settings]="genreSettings" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="!filterSettings.tagsDisabled">+ <div class="form-group">+ <label for="tags">Tags</label>+ <app-typeahead (selectedData)="updateTagFilters($event)" [settings]="tagsSettings" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>+ </div>+ <div class="row justify-content-center no-gutters">+ <!-- The People row -->+ <div class="col-md-2 mr-3" *ngIf="peopleSettings.hasOwnProperty(PersonRole.CoverArtist)">+ <div class="form-group">+ <label for="cover-artist">Cover Artists</label>+ <app-typeahead (selectedData)="updatePersonFilters($event, PersonRole.CoverArtist)" [settings]="getPersonsSettings(PersonRole.CoverArtist)" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="peopleSettings.hasOwnProperty(PersonRole.Writer)">+ <div class="form-group">+ <label for="writers">Writers</label>+ <app-typeahead (selectedData)="updatePersonFilters($event, PersonRole.Writer)" [settings]="getPersonsSettings(PersonRole.Writer)" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="peopleSettings.hasOwnProperty(PersonRole.Publisher)">+ <div class="form-group">+ <label for="publisher">Publisher</label>+ <app-typeahead (selectedData)="updatePersonFilters($event, PersonRole.Publisher)" [settings]="getPersonsSettings(PersonRole.Publisher)" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="peopleSettings.hasOwnProperty(PersonRole.Penciller)">+ <div class="form-group">+ <label for="penciller">Penciller</label>+ <app-typeahead (selectedData)="updatePersonFilters($event, PersonRole.Penciller)" [settings]="getPersonsSettings(PersonRole.Penciller)" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="peopleSettings.hasOwnProperty(PersonRole.Letterer)">+ <div class="form-group">+ <label for="letterer">Letterer</label>+ <app-typeahead (selectedData)="updatePersonFilters($event, PersonRole.Letterer)" [settings]="getPersonsSettings(PersonRole.Letterer)" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="peopleSettings.hasOwnProperty(PersonRole.Inker)">+ <div class="form-group">+ <label for="inker">Inker</label>+ <app-typeahead (selectedData)="updatePersonFilters($event, PersonRole.Inker)" [settings]="getPersonsSettings(PersonRole.Inker)" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="peopleSettings.hasOwnProperty(PersonRole.Editor)">+ <div class="form-group">+ <label for="editor">Editor</label>+ <app-typeahead (selectedData)="updatePersonFilters($event, PersonRole.Editor)" [settings]="getPersonsSettings(PersonRole.Editor)" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="peopleSettings.hasOwnProperty(PersonRole.Colorist)">+ <div class="form-group">+ <label for="colorist">Colorist</label>+ <app-typeahead (selectedData)="updatePersonFilters($event, PersonRole.Colorist)" [settings]="getPersonsSettings(PersonRole.Colorist)" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="peopleSettings.hasOwnProperty(PersonRole.Character)">+ <div class="form-group">+ <label for="character">Character</label>+ <app-typeahead (selectedData)="updatePersonFilters($event, PersonRole.Character)" [settings]="getPersonsSettings(PersonRole.Character)" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>++ <div class="col-md-2 mr-3" *ngIf="peopleSettings.hasOwnProperty(PersonRole.Translator)">+ <div class="form-group">+ <label for="translators">Translators</label>+ <app-typeahead (selectedData)="updatePersonFilters($event, PersonRole.Translator)" [settings]="getPersonsSettings(PersonRole.Translator)" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.name}}+ </ng-template>+ </app-typeahead>+ </div>+ </div>+ </div>+ <div class="row justify-content-center no-gutters">+ <div class="col-md-2 mr-3" *ngIf="!filterSettings.readProgressDisabled">+ <label>Read Progress</label>+ <form [formGroup]="readProgressGroup">+ <div class="form-check form-check-inline">+ <input class="form-check-input" type="checkbox" id="notread" formControlName="notRead">+ <label class="form-check-label" for="notread">Unread</label>+ </div>+ <div class="form-check form-check-inline">+ <input class="form-check-input" type="checkbox" id="inprogress" formControlName="inProgress">+ <label class="form-check-label" for="inprogress">In Progress</label>+ </div>+ <div class="form-check form-check-inline">+ <input class="form-check-input" type="checkbox" id="read" formControlName="read">+ <label class="form-check-label" for="read">Read</label>+ </div>+ </form>+ </div>++ <div class="col-md-2 mr-3" *ngIf="!filterSettings.ratingDisabled">+ <label for="ratings">Rating</label>+ <form class="form-inline">+ <ngb-rating class="rating-star" [(rate)]="filter.rating" (rateChange)="updateRating($event)" [resettable]="true">+ <ng-template let-fill="fill" let-index="index">+ <span class="star" [class.filled]="(index >= (filter.rating - 1)) && filter.rating > 0" [ngbTooltip]="(index + 1) + ' and up'">★</span>+ </ng-template>+ </ngb-rating>+ </form>+ </div>++ <div class="col-md-2 mr-3" *ngIf="!filterSettings.ageRatingDisabled">+ <label for="age-rating">Age Rating</label>+ <app-typeahead (selectedData)="updateAgeRating($event)" [settings]="ageRatingSettings" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ </app-typeahead>+ </div>++ <div class="col-md-2 mr-3" *ngIf="!filterSettings.languageDisabled">+ <label for="languages">Language</label>+ <app-typeahead (selectedData)="updateLanguageRating($event)" [settings]="languageSettings" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ </app-typeahead>+ </div>++ <div class="col-md-2 mr-3" *ngIf="!filterSettings.publicationStatusDisabled">+ <label for="publication-status">Publication Status</label>+ <app-typeahead (selectedData)="updatePublicationStatus($event)" [settings]="publicationStatusSettings" [reset]="resetTypeaheads">+ <ng-template #badgeItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ <ng-template #optionItem let-item let-position="idx">+ {{item.title}}+ </ng-template>+ </app-typeahead>+ </div>+ <div class="col-md-2 mr-3"></div>+ </div>+ <div class="row justify-content-center no-gutters">+ <div class="col-md-2 mr-3" *ngIf="!filterSettings.sortDisabled">+ <form [formGroup]="sortGroup">+ <div class="form-group">+ <label for="sort-options">Sort By</label>+ <button class="btn btn-sm btn-secondary-outline" (click)="updateSortOrder()" style="height: 25px; padding-bottom: 0px;">+ <i class="fa fa-arrow-up" title="Ascending" *ngIf="isAscendingSort; else descSort"></i>+ <ng-template #descSort>+ <i class="fa fa-arrow-down" title="Descending"></i>+ </ng-template>+ </button>+ <select id="sort-options" class="form-control" formControlName="sortField" style="height: 38px;">+ <option [value]="SortField.SortName">Sort Name</option>+ <option [value]="SortField.Created">Created</option>+ <option [value]="SortField.LastModified">Last Modified</option>+ </select>+ </div>+ </form>+ </div>+ <div class="col-md-2 mr-3" *ngIf="filterSettings.sortDisabled"></div>+ <div class="col-md-2 mr-3"></div>+ <div class="col-md-2 mr-3"></div>+ <div class="col-md-2 mr-3 mt-4">+ <button class="btn btn-secondary btn-block" (click)="clear()">Clear</button>+ </div>+ <div class="col-md-2 mr-3 mt-4">+ <button class="btn btn-primary btn-block" (click)="apply()">Apply</button>+ </div>+ </div>+ </div>+ </ng-template>+<ng-container [ngTemplateOutlet]="paginationTemplate" [ngTemplateOutletContext]="{ id: 'top' }"></ng-container>diff --git a/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.scss b/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.scssindex e69de29bb..23d8c738a 100644--- a/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.scss+++ b/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.scss@@ -0,0 +1,9 @@+@use '../../../theme/colors';++.star {+ font-size: 1.5rem;+ color: colors.$rating-empty;+}+.filled {+ color: colors.$rating-filled;+}\ No newline at end of filediff --git a/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.ts b/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.tsindex aab49eff7..1bece3ff6 100644--- a/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.ts+++ b/UI/Web/src/app/cards/card-detail-layout/card-detail-layout.component.ts@@ -1,39 +1,57 @@-import { Component, ContentChild, EventEmitter, Input, OnInit, Output, TemplateRef } from '@angular/core';-import { FormGroup, FormControl } from '@angular/forms';+import { Component, ContentChild, EventEmitter, Input, OnDestroy, OnInit, Output, TemplateRef } from '@angular/core';+import { FormControl, FormGroup } from '@angular/forms';+import { forkJoin, Observable, of, ReplaySubject, Subject } from 'rxjs';+import { map, takeUntil } from 'rxjs/operators';+import { UtilityService } from 'src/app/shared/_services/utility.service';+import { TypeaheadSettings } from 'src/app/typeahead/typeahead-settings';+import { CollectionTag } from 'src/app/_models/collection-tag';+import { Genre } from 'src/app/_models/genre';+import { Library } from 'src/app/_models/library';+import { MangaFormat } from 'src/app/_models/manga-format';+import { AgeRating } from 'src/app/_models/metadata/age-rating';+import { AgeRatingDto } from 'src/app/_models/metadata/age-rating-dto';+import { Language } from 'src/app/_models/metadata/language';+import { PublicationStatusDto } from 'src/app/_models/metadata/publication-status-dto';import { Pagination } from 'src/app/_models/pagination';-import { FilterItem } from 'src/app/_models/series-filter';+import { Person, PersonRole } from 'src/app/_models/person';+import { FilterItem, mangaFormatFilters, SeriesFilter, SortField } from 'src/app/_models/series-filter';+import { Tag } from 'src/app/_models/tag';import { ActionItem } from 'src/app/_services/action-factory.service';+import { CollectionTagService } from 'src/app/_services/collection-tag.service';+import { LibraryService } from 'src/app/_services/library.service';+import { MetadataService } from 'src/app/_services/metadata.service';+import { SeriesService } from 'src/app/_services/series.service';const FILTER_PAG_REGEX = /[^0-9]/g;-export enum FilterAction {- /**- * If an option is selected on a multi select component- */- Added = 0,- /**- * If an option is unselected on a multi select component- */- Removed = 1,+const ANIMATION_SPEED = 300;++export class FilterSettings {+ libraryDisabled = false;+ formatDisabled = false;+ collectionDisabled = false;+ genresDisabled = false;+ peopleDisabled = false;+ readProgressDisabled = false;+ ratingDisabled = false;+ sortDisabled = false;+ ageRatingDisabled = false;+ tagsDisabled = false;+ languageDisabled = false;+ publicationStatusDisabled = false;+ presets: SeriesFilter | undefined;/**- * If an option is selected on a single select component+ * Should the filter section be open by default*/- Selected = 2-}--export interface UpdateFilterEvent {- filterItem: FilterItem;- action: FilterAction;+ openByDefault = false;}-const ANIMATION_SPEED = 300;-@Component({selector: 'app-card-detail-layout',templateUrl: './card-detail-layout.component.html',styleUrls: ['./card-detail-layout.component.scss']})-export class CardDetailLayoutComponent implements OnInit {+export class CardDetailLayoutComponent implements OnInit, OnDestroy {@Input() header: string = '';@Input() isLoading: boolean = false;@@ -43,32 +61,382 @@ export class CardDetailLayoutComponent implements OnInit {* Any actions to exist on the header for the parent collection (library, collection)*/@Input() actions: ActionItem<any>[] = [];- /**- * A list of Filters which can filter the data of the page. If nothing is passed, the control will not show.- */- @Input() filters: Array<FilterItem> = [];@Input() trackByIdentity!: (index: number, item: any) => string;+ @Input() filterSettings!: FilterSettings;@Output() itemClicked: EventEmitter<any> = new EventEmitter();@Output() pageChange: EventEmitter<Pagination> = new EventEmitter();- @Output() applyFilter: EventEmitter<UpdateFilterEvent> = new EventEmitter();+ @Output() applyFilter: EventEmitter<SeriesFilter> = new EventEmitter();@ContentChild('cardItem') itemTemplate!: TemplateRef<any>;-- filterForm: FormGroup = new FormGroup({- filter: new FormControl(0, []),- });++ formatSettings: TypeaheadSettings<FilterItem<MangaFormat>> = new TypeaheadSettings();+ librarySettings: TypeaheadSettings<Library> = new TypeaheadSettings();+ genreSettings: TypeaheadSettings<Genre> = new TypeaheadSettings();+ collectionSettings: TypeaheadSettings<CollectionTag> = new TypeaheadSettings();+ ageRatingSettings: TypeaheadSettings<AgeRatingDto> = new TypeaheadSettings();+ publicationStatusSettings: TypeaheadSettings<PublicationStatusDto> = new TypeaheadSettings();+ tagsSettings: TypeaheadSettings<Tag> = new TypeaheadSettings();+ languageSettings: TypeaheadSettings<Language> = new TypeaheadSettings();+ peopleSettings: {[PersonRole: string]: TypeaheadSettings<Person>} = {};+ resetTypeaheads: Subject<boolean> = new ReplaySubject(1);/*** Controls the visiblity of extended controls that sit below the main header.*/filteringCollapsed: boolean = true;- constructor() { }+ filter!: SeriesFilter;+ libraries: Array<FilterItem<Library>> = [];+++ readProgressGroup!: FormGroup;+ sortGroup!: FormGroup;+ isAscendingSort: boolean = true;++ updateApplied: number = 0;++ private onDestory: Subject<void> = new Subject();++ get PersonRole(): typeof PersonRole {+ return PersonRole;+ }++ get SortField(): typeof SortField {+ return SortField;+ }++ constructor(private libraryService: LibraryService, private metadataService: MetadataService, private seriesService: SeriesService,+ private utilityService: UtilityService, private collectionTagService: CollectionTagService) {+ this.filter = this.seriesService.createSeriesFilter();+ this.readProgressGroup = new FormGroup({+ read: new FormControl(this.filter.readStatus.read, []),+ notRead: new FormControl(this.filter.readStatus.notRead, []),+ inProgress: new FormControl(this.filter.readStatus.inProgress, []),+ });++ this.sortGroup = new FormGroup({+ sortField: new FormControl(this.filter.sortOptions?.sortField || SortField.SortName, []),+ });++ this.readProgressGroup.valueChanges.pipe(takeUntil(this.onDestory)).subscribe(changes => {+ this.filter.readStatus.read = this.readProgressGroup.get('read')?.value;+ this.filter.readStatus.inProgress = this.readProgressGroup.get('inProgress')?.value;+ this.filter.readStatus.notRead = this.readProgressGroup.get('notRead')?.value;++ let sum = 0;+ sum += (this.filter.readStatus.read ? 1 : 0);+ sum += (this.filter.readStatus.inProgress ? 1 : 0);+ sum += (this.filter.readStatus.notRead ? 1 : 0);++ if (sum === 1) {+ if (this.filter.readStatus.read) this.readProgressGroup.get('read')?.disable({ emitEvent: false });+ if (this.filter.readStatus.notRead) this.readProgressGroup.get('notRead')?.disable({ emitEvent: false });+ if (this.filter.readStatus.inProgress) this.readProgressGroup.get('inProgress')?.disable({ emitEvent: false });+ } else {+ this.readProgressGroup.get('read')?.enable({ emitEvent: false });+ this.readProgressGroup.get('notRead')?.enable({ emitEvent: false });+ this.readProgressGroup.get('inProgress')?.enable({ emitEvent: false });+ }+ });++ this.sortGroup.valueChanges.pipe(takeUntil(this.onDestory)).subscribe(changes => {+ if (this.filter.sortOptions == null) {+ this.filter.sortOptions = {+ isAscending: this.isAscendingSort,+ sortField: parseInt(this.sortGroup.get('sortField')?.value, 10)+ };+ }+ this.filter.sortOptions.sortField = parseInt(this.sortGroup.get('sortField')?.value, 10);+ });+ }ngOnInit(): void {- this.trackByIdentity = (index: number, item: any) => `${this.header}_${this.pagination?.currentPage}_${this.filterForm.get('filter')?.value}_${item.id}_${index}`;+ this.trackByIdentity = (index: number, item: any) => `${this.header}_${this.pagination?.currentPage}_${this.updateApplied}`;++ if (this.filterSettings === undefined) {+ this.filterSettings = new FilterSettings();+ }++ this.setupTypeaheads();+ }++ ngOnDestroy() {+ this.onDestory.next();+ this.onDestory.complete();}+ setupTypeaheads() {++ this.setupFormatTypeahead();++ forkJoin([+ this.setupLibraryTypeahead(),+ this.setupCollectionTagTypeahead(),+ this.setupAgeRatingSettings(),+ this.setupPublicationStatusSettings(),+ this.setupTagSettings(),+ this.setupLanguageSettings(),+ this.setupGenreTypeahead(),+ this.setupPersonTypeahead(),+ ]).subscribe(results => {+ this.resetTypeaheads.next(true);+ if (this.filterSettings.openByDefault) {+ this.filteringCollapsed = false;+ }+ this.apply();+ });+ }+++ setupFormatTypeahead() {+ this.formatSettings.minCharacters = 0;+ this.formatSettings.multiple = true;+ this.formatSettings.id = 'format';+ this.formatSettings.unique = true;+ this.formatSettings.addIfNonExisting = false;+ this.formatSettings.fetchFn = (filter: string) => of(mangaFormatFilters);+ this.formatSettings.compareFn = (options: FilterItem<MangaFormat>[], filter: string) => {+ const f = filter.toLowerCase();+ return options.filter(m => m.title.toLowerCase() === f);+ }++ if (this.filterSettings.presets?.formats && this.filterSettings.presets?.formats.length > 0) {+ this.formatSettings.savedData = mangaFormatFilters.filter(item => this.filterSettings.presets?.formats.includes(item.value));+ this.filter.formats = this.formatSettings.savedData.map(item => item.value);+ this.resetTypeaheads.next(true);+ }+ }++ setupLibraryTypeahead() {+ this.librarySettings.minCharacters = 0;+ this.librarySettings.multiple = true;+ this.librarySettings.id = 'libraries';+ this.librarySettings.unique = true;+ this.librarySettings.addIfNonExisting = false;+ this.librarySettings.fetchFn = (filter: string) => {+ return this.libraryService.getLibrariesForMember();+ };+ this.librarySettings.compareFn = (options: Library[], filter: string) => {+ const f = filter.toLowerCase();+ return options.filter(m => m.name.toLowerCase() === f);+ }++ if (this.filterSettings.presets?.libraries && this.filterSettings.presets?.libraries.length > 0) {+ return this.librarySettings.fetchFn('').pipe(map(libraries => {+ this.librarySettings.savedData = libraries.filter(item => this.filterSettings.presets?.libraries.includes(item.id));+ this.filter.libraries = this.librarySettings.savedData.map(item => item.id);+ return of(true);+ }));+ }+ return of(true);+ }++ setupGenreTypeahead() {+ this.genreSettings.minCharacters = 0;+ this.genreSettings.multiple = true;+ this.genreSettings.id = 'genres';+ this.genreSettings.unique = true;+ this.genreSettings.addIfNonExisting = false;+ this.genreSettings.fetchFn = (filter: string) => {+ return this.metadataService.getAllGenres(this.filter.libraries);+ };+ this.genreSettings.compareFn = (options: Genre[], filter: string) => {+ const f = filter.toLowerCase();+ return options.filter(m => m.title.toLowerCase() === f);+ }++ if (this.filterSettings.presets?.genres && this.filterSettings.presets?.genres.length > 0) {+ return this.genreSettings.fetchFn('').pipe(map(genres => {+ this.genreSettings.savedData = genres.filter(item => this.filterSettings.presets?.genres.includes(item.id));+ this.filter.genres = this.genreSettings.savedData.map(item => item.id);+ return of(true);+ }));+ }+ return of(true);+ }++ setupAgeRatingSettings() {+ this.ageRatingSettings.minCharacters = 0;+ this.ageRatingSettings.multiple = true;+ this.ageRatingSettings.id = 'age-rating';+ this.ageRatingSettings.unique = true;+ this.ageRatingSettings.addIfNonExisting = false;+ this.ageRatingSettings.fetchFn = (filter: string) => {+ return this.metadataService.getAllAgeRatings(this.filter.libraries);+ };+ this.ageRatingSettings.compareFn = (options: AgeRatingDto[], filter: string) => {+ const f = filter.toLowerCase();+ return options.filter(m => m.title.toLowerCase() === f && this.utilityService.filter(m.title, filter));+ }++ if (this.filterSettings.presets?.ageRating && this.filterSettings.presets?.ageRating.length > 0) {+ return this.ageRatingSettings.fetchFn('').pipe(map(rating => {+ this.ageRatingSettings.savedData = rating.filter(item => this.filterSettings.presets?.ageRating.includes(item.value));+ this.filter.ageRating = this.ageRatingSettings.savedData.map(item => item.value);+ return of(true);+ }));+ }+ return of(true);+ }++ setupPublicationStatusSettings() {+ this.publicationStatusSettings.minCharacters = 0;+ this.publicationStatusSettings.multiple = true;+ this.publicationStatusSettings.id = 'publication-status';+ this.publicationStatusSettings.unique = true;+ this.publicationStatusSettings.addIfNonExisting = false;+ this.publicationStatusSettings.fetchFn = (filter: string) => {+ return this.metadataService.getAllPublicationStatus(this.filter.libraries);+ };+ this.publicationStatusSettings.compareFn = (options: PublicationStatusDto[], filter: string) => {+ const f = filter.toLowerCase();+ return options.filter(m => m.title.toLowerCase() === f && this.utilityService.filter(m.title, filter));+ }++ if (this.filterSettings.presets?.publicationStatus && this.filterSettings.presets?.publicationStatus.length > 0) {+ return this.publicationStatusSettings.fetchFn('').pipe(map(statuses => {+ this.publicationStatusSettings.savedData = statuses.filter(item => this.filterSettings.presets?.publicationStatus.includes(item.value));+ this.filter.publicationStatus = this.publicationStatusSettings.savedData.map(item => item.value);+ return of(true);+ }));+ }+ return of(true);+ }++ setupTagSettings() {+ this.tagsSettings.minCharacters = 0;+ this.tagsSettings.multiple = true;+ this.tagsSettings.id = 'tags';+ this.tagsSettings.unique = true;+ this.tagsSettings.addIfNonExisting = false;+ this.tagsSettings.fetchFn = (filter: string) => {+ return this.metadataService.getAllTags(this.filter.libraries);+ };+ this.tagsSettings.compareFn = (options: Tag[], filter: string) => {+ const f = filter.toLowerCase();+ return options.filter(m => m.title.toLowerCase() === f && this.utilityService.filter(m.title, filter));+ }++ if (this.filterSettings.presets?.tags && this.filterSettings.presets?.tags.length > 0) {+ return this.tagsSettings.fetchFn('').pipe(map(tags => {+ this.tagsSettings.savedData = tags.filter(item => this.filterSettings.presets?.tags.includes(item.id));+ this.filter.tags = this.tagsSettings.savedData.map(item => item.id);+ return of(true);+ }));+ }+ return of(true);+ }++ setupLanguageSettings() {+ this.languageSettings.minCharacters = 0;+ this.languageSettings.multiple = true;+ this.languageSettings.id = 'languages';+ this.languageSettings.unique = true;+ this.languageSettings.addIfNonExisting = false;+ this.languageSettings.fetchFn = (filter: string) => {+ return this.metadataService.getAllLanguages(this.filter.libraries);+ };+ this.languageSettings.compareFn = (options: Language[], filter: string) => {+ const f = filter.toLowerCase();+ return options.filter(m => m.title.toLowerCase() === f && this.utilityService.filter(m.title, filter));+ }++ if (this.filterSettings.presets?.languages && this.filterSettings.presets?.languages.length > 0) {+ return this.languageSettings.fetchFn('').pipe(map(languages => {+ this.languageSettings.savedData = languages.filter(item => this.filterSettings.presets?.languages.includes(item.isoCode));+ this.filter.languages = this.languageSettings.savedData.map(item => item.isoCode);+ return of(true);+ }));+ }+ return of(true);+ }++ setupCollectionTagTypeahead() {+ this.collectionSettings.minCharacters = 0;+ this.collectionSettings.multiple = true;+ this.collectionSettings.id = 'collections';+ this.collectionSettings.unique = true;+ this.collectionSettings.addIfNonExisting = false;+ this.collectionSettings.fetchFn = (filter: string) => {+ return this.collectionTagService.allTags();+ };+ this.collectionSettings.compareFn = (options: CollectionTag[], filter: string) => {+ const f = filter.toLowerCase();+ return options.filter(m => m.title.toLowerCase() === f);+ }++ if (this.filterSettings.presets?.collectionTags && this.filterSettings.presets?.collectionTags.length > 0) {+ return this.collectionSettings.fetchFn('').pipe(map(tags => {+ this.collectionSettings.savedData = tags.filter(item => this.filterSettings.presets?.collectionTags.includes(item.id));+ this.filter.collectionTags = this.collectionSettings.savedData.map(item => item.id);+ return of(true);+ }));+ }+ return of(true);+ }++ updateFromPreset(id: string, peopleFilterField: Array<any>, presetField: Array<any> | undefined, role: PersonRole) {+ const personSettings = this.createBlankPersonSettings(id, role)+ if (presetField && presetField.length > 0) {+ const fetch = personSettings.fetchFn as ((filter: string) => Observable<Person[]>);+ return fetch('').pipe(map(people => {+ personSettings.savedData = people.filter(item => presetField.includes(item.id));+ peopleFilterField = personSettings.savedData.map(item => item.id);+ this.resetTypeaheads.next(true);+ this.peopleSettings[role] = personSettings;+ this.updatePersonFilters(personSettings.savedData as Person[], role);+ return true;+ }));+ } else {+ this.peopleSettings[role] = personSettings;+ return of(true);+ }+ }++ setupPersonTypeahead() {+ this.peopleSettings = {};++ return forkJoin([+ this.updateFromPreset('writers', this.filter.writers, this.filterSettings.presets?.writers, PersonRole.Writer),+ this.updateFromPreset('character', this.filter.character, this.filterSettings.presets?.character, PersonRole.Character),+ this.updateFromPreset('colorist', this.filter.colorist, this.filterSettings.presets?.colorist, PersonRole.Colorist),+ this.updateFromPreset('cover-artist', this.filter.coverArtist, this.filterSettings.presets?.coverArtist, PersonRole.CoverArtist),+ this.updateFromPreset('editor', this.filter.editor, this.filterSettings.presets?.editor, PersonRole.Editor),+ this.updateFromPreset('inker', this.filter.inker, this.filterSettings.presets?.inker, PersonRole.Inker),+ this.updateFromPreset('letterer', this.filter.letterer, this.filterSettings.presets?.letterer, PersonRole.Letterer),+ this.updateFromPreset('penciller', this.filter.penciller, this.filterSettings.presets?.penciller, PersonRole.Penciller),+ this.updateFromPreset('publisher', this.filter.publisher, this.filterSettings.presets?.publisher, PersonRole.Publisher),+ this.updateFromPreset('translators', this.filter.translators, this.filterSettings.presets?.translators, PersonRole.Translator)+ ]).pipe(map(results => {+ this.resetTypeaheads.next(true);+ return of(true);+ }));+ }++ fetchPeople(role: PersonRole, filter: string) {+ return this.metadataService.getAllPeople(this.filter.libraries).pipe(map(people => {+ return people.filter(p => p.role == role && this.utilityService.filter(p.name, filter));+ }));+ }++ createBlankPersonSettings(id: string, role: PersonRole) {+ var personSettings = new TypeaheadSettings<Person>();+ personSettings.minCharacters = 0;+ personSettings.multiple = true;+ personSettings.unique = true;+ personSettings.addIfNonExisting = false;+ personSettings.id = id;+ personSettings.compareFn = (options: Person[], filter: string) => {+ const f = filter.toLowerCase();+ return options.filter(m => m.name.toLowerCase() === f);+ }+ personSettings.fetchFn = (filter: string) => {+ return this.fetchPeople(role, filter);+ };+ return personSettings;+ }++onPageChange(page: number) {this.pageChange.emit(this.pagination);}@@ -88,11 +456,118 @@ export class CardDetailLayoutComponent implements OnInit {}}- handleFilterChange(index: string) {- this.applyFilter.emit({- filterItem: this.filters[parseInt(index, 10)],- action: FilterAction.Selected- });++ updateFormatFilters(formats: MangaFormat[]) {+ this.filter.formats = formats.map(item => item) || [];+ }++ updateLibraryFilters(libraries: Library[]) {+ this.filter.libraries = libraries.map(item => item.id) || [];+ }++ updateGenreFilters(genres: Genre[]) {+ this.filter.genres = genres.map(item => item.id) || [];+ }++ updateTagFilters(tags: Tag[]) {+ this.filter.tags = tags.map(item => item.id) || [];+ }++ updatePersonFilters(persons: Person[], role: PersonRole) {+ switch (role) {+ case PersonRole.CoverArtist:+ this.filter.coverArtist = persons.map(p => p.id);+ break;+ case PersonRole.Character:+ this.filter.character = persons.map(p => p.id);+ break;+ case PersonRole.Colorist:+ this.filter.colorist = persons.map(p => p.id);+ break;+ case PersonRole.Editor:+ this.filter.editor = persons.map(p => p.id);+ break;+ case PersonRole.Inker:+ this.filter.inker = persons.map(p => p.id);+ break;+ case PersonRole.Letterer:+ this.filter.letterer = persons.map(p => p.id);+ break;+ case PersonRole.Penciller:+ this.filter.penciller = persons.map(p => p.id);+ break;+ case PersonRole.Publisher:+ this.filter.publisher = persons.map(p => p.id);+ break;+ case PersonRole.Writer:+ this.filter.writers = persons.map(p => p.id);+ break;+ case PersonRole.Translator:+ this.filter.translators = persons.map(p => p.id);++ }+ }++ updateCollectionFilters(tags: CollectionTag[]) {+ this.filter.collectionTags = tags.map(item => item.id) || [];+ }++ updateRating(rating: any) {+ this.filter.rating = rating;+ }++ updateAgeRating(ratingDtos: AgeRatingDto[]) {+ this.filter.ageRating = ratingDtos.map(item => item.value) || [];+ }++ updatePublicationStatus(dtos: PublicationStatusDto[]) {+ this.filter.publicationStatus = dtos.map(item => item.value) || [];+ }++ updateLanguageRating(languages: Language[]) {+ this.filter.languages = languages.map(item => item.isoCode) || [];+ }++ updateReadStatus(status: string) {+ if (status === 'read') {+ this.filter.readStatus.read = !this.filter.readStatus.read;+ } else if (status === 'inProgress') {+ this.filter.readStatus.inProgress = !this.filter.readStatus.inProgress;+ } else if (status === 'notRead') {+ this.filter.readStatus.notRead = !this.filter.readStatus.notRead;+ }+ }++ updateSortOrder() {+ this.isAscendingSort = !this.isAscendingSort;+ if (this.filter.sortOptions === null) {+ this.filter.sortOptions = {+ isAscending: this.isAscendingSort,+ sortField: SortField.SortName+ }+ }++ this.filter.sortOptions.isAscending = this.isAscendingSort;+ }++ getPersonsSettings(role: PersonRole) {+ return this.peopleSettings[role];+ }++ clear() {+ this.filter = this.seriesService.createSeriesFilter();+ this.readProgressGroup.get('read')?.setValue(true);+ this.readProgressGroup.get('notRead')?.setValue(true);+ this.readProgressGroup.get('inProgress')?.setValue(true);+ this.sortGroup.get('sortField')?.setValue(SortField.SortName);+ this.isAscendingSort = true;+ // Apply any presets which will trigger the apply+ this.setupTypeaheads();+ }++ apply() {+ this.applyFilter.emit(this.filter);+ this.updateApplied++;}}diff --git a/UI/Web/src/app/cards/card-item/card-item.component.html b/UI/Web/src/app/cards/card-item/card-item.component.htmlindex 7fee96b23..c096aac5b 100644--- a/UI/Web/src/app/cards/card-item/card-item.component.html+++ b/UI/Web/src/app/cards/card-item/card-item.component.html@@ -1,4 +1,4 @@-<div class="card">+<div class="card {{selected ? 'selected-highlight' : ''}}"><div class="overlay" (click)="handleClick($event)"><img *ngIf="total > 0 || supressArchiveWarning" class="img-top lazyload" [src]="imageService.placeholderImage" [attr.data-src]="imageUrl"(error)="imageService.updateErroredImage($event)" aria-hidden="true" height="230px" width="158px">@@ -20,13 +20,13 @@<div class="not-read-badge" *ngIf="read === 0 && total > 0"></div><div class="bulk-mode {{bulkSelectionService.hasSelections() ? 'always-show' : ''}}" (click)="handleSelection($event)" *ngIf="allowSelection">- <input type="checkbox" attr.aria-labelledby="{{title}}_{{entity.id}}" [ngModel]="selected" [ngModelOptions]="{standalone: true}">+ <input type="checkbox" attr.aria-labelledby="{{title}}_{{entity?.id}}" [ngModel]="selected" [ngModelOptions]="{standalone: true}"></div></div><div class="card-body" *ngIf="title.length > 0 || actions.length > 0"><div>- <span class="card-title" placement="top" id="{{title}}_{{entity.id}}" ngbTooltip="{{title}}" (click)="handleClick()" tabindex="0">+ <span class="card-title" placement="top" id="{{title}}_{{entity?.id}}" [ngbTooltip]="tooltipTitle" (click)="handleClick()" tabindex="0"><span *ngIf="isPromoted()"><i class="fa fa-angle-double-up" aria-hidden="true"></i><span class="sr-only">(promoted)</span>diff --git a/UI/Web/src/app/cards/card-item/card-item.component.scss b/UI/Web/src/app/cards/card-item/card-item.component.scssindex 0aa5c8ef6..d1c81c155 100644--- a/UI/Web/src/app/cards/card-item/card-item.component.scss+++ b/UI/Web/src/app/cards/card-item/card-item.component.scss@@ -1,13 +1,13 @@-@import '../../../theme/colors';+@use '../../../theme/colors';-$triangle-size: 40px;+$triangle-size: 30px;$image-height: 230px;$image-width: 160px;.error-banner {width: 160px;height: 18px;- background-color: $error-color;+ background-color: colors.$error-color;font-size: 12px;color: white;text-transform: uppercase;@@ -38,6 +38,9 @@ $image-width: 160px;margin-bottom: 0px;}+.selected-highlight {+ outline: 2px solid colors.$primary-color;+}.img-top {@@ -49,7 +52,7 @@ $image-width: 160px;height: 5px;.progress {- color: $primary-color;+ color: colors.$primary-color;background-color: transparent;}}@@ -70,7 +73,7 @@ $image-width: 160px;height: 0;border-style: solid;border-width: 0 $triangle-size $triangle-size 0;- border-color: transparent $primary-color transparent transparent;+ border-color: transparent colors.$primary-color transparent transparent;}diff --git a/UI/Web/src/app/cards/card-item/card-item.component.ts b/UI/Web/src/app/cards/card-item/card-item.component.tsindex b0974ba5a..6788881a3 100644--- a/UI/Web/src/app/cards/card-item/card-item.component.ts+++ b/UI/Web/src/app/cards/card-item/card-item.component.ts@@ -8,6 +8,7 @@ import { UtilityService } from 'src/app/shared/_services/utility.service';import { Chapter } from 'src/app/_models/chapter';import { CollectionTag } from 'src/app/_models/collection-tag';import { MangaFormat } from 'src/app/_models/manga-format';+import { PageBookmark } from 'src/app/_models/page-bookmark';import { Series } from 'src/app/_models/series';import { Volume } from 'src/app/_models/volume';import { Action, ActionItem } from 'src/app/_services/action-factory.service';@@ -49,7 +50,7 @@ export class CardItemComponent implements OnInit, OnDestroy {/*** This is the entity we are representing. It will be returned if an action is executed.*/- @Input() entity!: Series | Volume | Chapter | CollectionTag;+ @Input() entity!: Series | Volume | Chapter | CollectionTag | PageBookmark;/*** If the entity is selected or not.*/@@ -79,12 +80,18 @@ export class CardItemComponent implements OnInit, OnDestroy {* Format of the entity (only applies to Series)*/format: MangaFormat = MangaFormat.UNKNOWN;+ chapterTitle: string = '';download$: Observable<Download> | null = null;downloadInProgress: boolean = false;isShiftDown: boolean = false;++ get tooltipTitle() {+ if (this.chapterTitle === '' || this.chapterTitle === null) return this.title;+ return this.chapterTitle;+ }get MangaFormat(): typeof MangaFormat {@@ -111,6 +118,15 @@ export class CardItemComponent implements OnInit, OnDestroy {});}this.format = (this.entity as Series).format;++ if (this.utilityService.isChapter(this.entity)) {+ this.chapterTitle = this.utilityService.asChapter(this.entity).titleName;+ } else if (this.utilityService.isVolume(this.entity)) {+ const vol = this.utilityService.asVolume(this.entity);+ if (vol.chapters !== undefined && vol.chapters.length > 0) {+ this.chapterTitle = vol.chapters[0].titleName;+ }+ }}ngOnDestroy() {diff --git a/UI/Web/src/app/cards/cards.module.ts b/UI/Web/src/app/cards/cards.module.tsindex dc1a23134..8b21fe1ac 100644--- a/UI/Web/src/app/cards/cards.module.ts+++ b/UI/Web/src/app/cards/cards.module.ts@@ -8,7 +8,7 @@ import { EditCollectionTagsComponent } from './_modals/edit-collection-tags/editimport { ChangeCoverImageModalComponent } from './_modals/change-cover-image/change-cover-image-modal.component';import { BookmarksModalComponent } from './_modals/bookmarks-modal/bookmarks-modal.component';import { LazyLoadImageModule } from 'ng-lazyload-image';-import { NgbTooltipModule, NgbCollapseModule, NgbPaginationModule, NgbDropdownModule, NgbProgressbarModule, NgbNavModule, NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap';+import { NgbTooltipModule, NgbCollapseModule, NgbPaginationModule, NgbDropdownModule, NgbProgressbarModule, NgbNavModule, NgbRatingModule } from '@ng-bootstrap/ng-bootstrap';import { CardActionablesComponent } from './card-item/card-actionables/card-actionables.component';import { FormsModule, ReactiveFormsModule } from '@angular/forms';import { NgxFileDropModule } from 'ngx-file-drop';@@ -21,6 +21,9 @@ import { CardDetailsModalComponent } from './_modals/card-details-modal/card-detimport { BulkOperationsComponent } from './bulk-operations/bulk-operations.component';import { BulkAddToCollectionComponent } from './_modals/bulk-add-to-collection/bulk-add-to-collection.component';import { PipeModule } from '../pipe/pipe.module';+import { ChapterMetadataDetailComponent } from './chapter-metadata-detail/chapter-metadata-detail.component';+import { FileInfoComponent } from './file-info/file-info.component';+import { BookmarkComponent } from './bookmark/bookmark.component';@@ -38,7 +41,10 @@ import { PipeModule } from '../pipe/pipe.module';CardDetailLayoutComponent,CardDetailsModalComponent,BulkOperationsComponent,- BulkAddToCollectionComponent+ BulkAddToCollectionComponent,+ ChapterMetadataDetailComponent,+ FileInfoComponent,+ BookmarkComponent,],imports: [CommonModule,@@ -52,6 +58,7 @@ import { PipeModule } from '../pipe/pipe.module';NgbNavModule,NgbTooltipModule, // Card itemNgbCollapseModule,+ NgbRatingModule,NgbNavModule, //Series DetailLazyLoadImageModule,@@ -75,7 +82,8 @@ import { PipeModule } from '../pipe/pipe.module';CardActionablesComponent,CardDetailLayoutComponent,CardDetailsModalComponent,- BulkOperationsComponent+ BulkOperationsComponent,+ ChapterMetadataDetailComponent]})export class CardsModule { }diff --git a/UI/Web/src/app/cards/chapter-metadata-detail/chapter-metadata-detail.component.html b/UI/Web/src/app/cards/chapter-metadata-detail/chapter-metadata-detail.component.htmlnew file mode 100644index 000000000..24d7b0aed--- /dev/null+++ b/UI/Web/src/app/cards/chapter-metadata-detail/chapter-metadata-detail.component.html@@ -0,0 +1,114 @@+<ng-container *ngIf="chapter !== undefined">+ <div class="container-fluid">+ <!-- <h4>{{libraryType !== LibraryType.Comic ? 'Chapter ' : 'Issue #'}} {{chapter.number}} <span title="Id">({{chapter.id}})</span></h4> -->+++ <!-- Arc Information -->+++ <div class="row no-gutters">+ <div class="col">+ Title: {{chapter.titleName || '-'}}+ </div>+ <div class="col">+ Pages: {{chapter.pages}}+ </div>+ </div>++ <div class="row no-gutters">+ <div class="col" *ngIf="chapter.hasOwnProperty('created')">+ Added: {{(chapter.created | date: 'short') || '-'}}+ </div>+ <div class="col">+ Release Date: {{(chapter.releaseDate | date: 'shortDate') || '-'}}+ </div>+ </div>+ </div>++ <ul class="list-unstyled" >+ <li class="media my-4">+ <a (click)="readChapter(chapter)" href="javascript:void(0);" title="Read {{libraryType !== LibraryType.Comic ? 'Chapter ' : 'Issue #'}} {{chapter.number}}">+ <img class="mr-3" style="width: 74px" [src]="chapter.coverImage">+ </a>+ <div class="media-body">+ <h5 class="mt-0 mb-1">+ <span *ngIf="chapter.number !== '0'; else specialHeader">+ <!-- TODO: Add back in+ <span>+ <app-card-actionables (actionHandler)="performAction($event, chapter)" [actions]="chapterActions" [labelBy]="utilityService.formatChapterName(libraryType, true, true) + formatChapterNumber(chapter)"></app-card-actionables> + {{utilityService.formatChapterName(libraryType, true, false) }} {{formatChapterNumber(chapter)}}+ </span> -->+ <span class="badge badge-primary badge-pill">+ <span *ngIf="chapter.pagesRead > 0 && chapter.pagesRead < chapter.pages">{{chapter.pagesRead}} / {{chapter.pages}}</span>+ <span *ngIf="chapter.pagesRead === 0">UNREAD</span>+ <span *ngIf="chapter.pagesRead === chapter.pages">READ</span>+ </span>+ </span>+ <ng-template #specialHeader>Files</ng-template>+ </h5>+ <ul class="list-group file-list">+ <app-file-info *ngFor="let file of chapter.files" [file]="file" [created]="chapter.created"></app-file-info>+ </ul>+++ <ng-container>+ <div class="row no-gutters mt-1" *ngIf="chapter.writers && chapter.writers.length > 0">+ <div class="col-md-4">+ <h5>Writers</h5>+ </div>+ <div class="col-md-8">+ <app-person-badge *ngFor="let person of chapter.writers" [person]="person"></app-person-badge>+ </div>+ </div>++ <div class="row no-gutters mt-1" *ngIf="chapter.coverArtist && chapter.coverArtist.length > 0">+ <div class="col-md-4">+ <h5>Artists</h5>+ </div>+ <div class="col-md-8">+ <app-person-badge *ngFor="let person of chapter.coverArtist" [person]="person"></app-person-badge>+ </div>+ </div>++ <div class="row no-gutters mt-1" *ngIf="chapter.publisher && chapter.publisher.length > 0">+ <div class="col-md-4">+ <h5>Publishers</h5>+ </div>+ <div class="col-md-8">+ <app-person-badge *ngFor="let person of chapter.publisher" [person]="person"></app-person-badge>+ </div>+ </div>+ </ng-container>+ </div>+ </li>+ </ul>+</ng-container>+++<!--++<div class="container-fluid" *ngIf="metadata !== undefined">+ Chapter {{chapter.range}} {{metadata.title.length > 0 ? ' - ' + metadata.title : ''}}+ Title: {{metadata.title || '-'}}+ Year: {{metadata.year || '-'}}+ Arc Information+++ <div class="row no-gutters">+ <div class="col">+ Id: {{chapter.id}}+ </div>+ <div class="col">+ Pages: {{chapter.pages}}+ </div>+ </div>++ <div class="row no-gutters">+ <div class="col" *ngIf="chapter.hasOwnProperty('created')">+ Added: {{(chapter.created | date: 'short') || '-'}}+ </div>+ <div class="col">+ Pages: {{chapter.pages}}+ </div>+ </div>+</div> -->\ No newline at end of filediff --git a/UI/Web/src/app/cards/chapter-metadata-detail/chapter-metadata-detail.component.scss b/UI/Web/src/app/cards/chapter-metadata-detail/chapter-metadata-detail.component.scssnew file mode 100644index 000000000..e69de29bbdiff --git a/UI/Web/src/app/cards/chapter-metadata-detail/chapter-metadata-detail.component.ts b/UI/Web/src/app/cards/chapter-metadata-detail/chapter-metadata-detail.component.tsnew file mode 100644index 000000000..2c203aed0--- /dev/null+++ b/UI/Web/src/app/cards/chapter-metadata-detail/chapter-metadata-detail.component.ts@@ -0,0 +1,53 @@+import { Component, Input, OnInit } from '@angular/core';+import { MetadataService } from 'src/app/_services/metadata.service';+import { Chapter } from 'src/app/_models/chapter';+import { ChapterMetadata } from 'src/app/_models/chapter-metadata';+import { UtilityService } from 'src/app/shared/_services/utility.service';+import { LibraryType } from 'src/app/_models/library';+import { ActionItem } from 'src/app/_services/action-factory.service';++@Component({+ selector: 'app-chapter-metadata-detail',+ templateUrl: './chapter-metadata-detail.component.html',+ styleUrls: ['./chapter-metadata-detail.component.scss']+})+export class ChapterMetadataDetailComponent implements OnInit {++ @Input() chapter!: Chapter;+ @Input() libraryType: LibraryType = LibraryType.Manga;+ //metadata!: ChapterMetadata;++ get LibraryType(): typeof LibraryType {+ return LibraryType;+ }++ constructor(private metadataService: MetadataService, public utilityService: UtilityService) { }++ ngOnInit(): void {+ // this.metadataService.getChapterMetadata(this.chapter.id).subscribe(metadata => {+ // console.log('Chapter ', this.chapter.number, ' metadata: ', metadata);+ // this.metadata = metadata;+ // })+ }++ performAction(action: ActionItem<Chapter>, chapter: Chapter) {+ if (typeof action.callback === 'function') {+ action.callback(action.action, chapter);+ }+ }++ readChapter(chapter: Chapter) {+ // if (chapter.pages === 0) {+ // this.toastr.error('There are no pages. Kavita was not able to read this archive.');+ // return;+ // }++ // if (chapter.files.length > 0 && chapter.files[0].format === MangaFormat.EPUB) {+ // this.router.navigate(['library', this.libraryId, 'series', this.seriesId, 'book', chapter.id]);+ // } else {+ // this.router.navigate(['library', this.libraryId, 'series', this.seriesId, 'manga', chapter.id]);+ // }+ }+++}diff --git a/UI/Web/src/app/cards/file-info/file-info.component.html b/UI/Web/src/app/cards/file-info/file-info.component.htmlnew file mode 100644index 000000000..f409c2f09--- /dev/null+++ b/UI/Web/src/app/cards/file-info/file-info.component.html@@ -0,0 +1,11 @@+<li class="list-group-item">+ <span>{{file.filePath}}</span>+ <div class="row no-gutters">+ <div class="col">+ Pages: {{file.pages}}+ </div>+ <div class="col" *ngIf="created != undefined">+ Added: {{(created | date: 'short') || '-'}}+ </div>+ </div>+</li>\ No newline at end of filediff --git a/UI/Web/src/app/cards/file-info/file-info.component.scss b/UI/Web/src/app/cards/file-info/file-info.component.scssnew file mode 100644index 000000000..e69de29bbdiff --git a/UI/Web/src/app/cards/file-info/file-info.component.ts b/UI/Web/src/app/cards/file-info/file-info.component.tsnew file mode 100644index 000000000..ce275bc45--- /dev/null+++ b/UI/Web/src/app/cards/file-info/file-info.component.ts@@ -0,0 +1,25 @@+import { Component, Input, OnInit } from '@angular/core';+import { MangaFile } from 'src/app/_models/manga-file';++@Component({+ selector: 'app-file-info',+ templateUrl: './file-info.component.html',+ styleUrls: ['./file-info.component.scss']+})+export class FileInfoComponent implements OnInit {++ /**+ * MangaFile to display+ */+ @Input() file!: MangaFile;+ /**+ * DateTime the entity this file belongs to was created+ */+ @Input() created: string | undefined = undefined;++ constructor() { }++ ngOnInit(): void {+ }++}diff --git a/UI/Web/src/app/cards/series-card/series-card.component.ts b/UI/Web/src/app/cards/series-card/series-card.component.tsindex 11d869401..8966cc1be 100644--- a/UI/Web/src/app/cards/series-card/series-card.component.ts+++ b/UI/Web/src/app/cards/series-card/series-card.component.ts@@ -109,6 +109,9 @@ export class SeriesCardComponent implements OnInit, OnChanges, OnDestroy {case(Action.AddToReadingList):this.actionService.addSeriesToReadingList(series, (series) => {/* No Operation */ });break;+ case(Action.AddToCollection):+ this.actionService.addMultipleSeriesToCollectionTag([series], () => {/* No Operation */ });+ break;default:break;}@@ -132,35 +135,26 @@ export class SeriesCardComponent implements OnInit, OnChanges, OnDestroy {});}- refreshMetdata(series: Series) {- this.seriesService.refreshMetadata(series).subscribe((res: any) => {- this.toastr.success('Refresh started for ' + series.name);- });+ async refreshMetdata(series: Series) {+ this.actionService.refreshMetdata(series);}- scanLibrary(series: Series) {+ async scanLibrary(series: Series) {this.seriesService.scan(series.libraryId, series.id).subscribe((res: any) => {- this.toastr.success('Scan started for ' + series.name);+ this.toastr.success('Scan queued for ' + series.name);});}async deleteSeries(series: Series) {- if (!await this.confirmService.confirm('Are you sure you want to delete this series? It will not modify files on disk.')) {- return;- }-- this.seriesService.delete(series.id).subscribe((res: boolean) => {- if (res) {- this.toastr.success('Series deleted');+ this.actionService.deleteSeries(series, (result: boolean) => {+ if (result) {this.reload.emit(true);}});}markAsUnread(series: Series) {- this.seriesService.markUnread(series.id).subscribe(res => {- this.toastr.success(series.name + ' is now unread');- series.pagesRead = 0;+ this.actionService.markSeriesAsUnread(series, () => {if (this.data) {this.data.pagesRead = 0;}@@ -170,9 +164,7 @@ export class SeriesCardComponent implements OnInit, OnChanges, OnDestroy {}markAsRead(series: Series) {- this.seriesService.markRead(series.id).subscribe(res => {- this.toastr.success(series.name + ' is now read');- series.pagesRead = series.pages;+ this.actionService.markSeriesAsRead(series, () => {if (this.data) {this.data.pagesRead = series.pages;}diff --git a/UI/Web/src/app/collections/collection-detail/collection-detail.component.html b/UI/Web/src/app/collections/collection-detail/collection-detail.component.htmlindex 431680257..0e8516cf8 100644--- a/UI/Web/src/app/collections/collection-detail/collection-detail.component.html+++ b/UI/Web/src/app/collections/collection-detail/collection-detail.component.html@@ -32,8 +32,8 @@[isLoading]="isLoading"[items]="series"[pagination]="seriesPagination"+ [filterSettings]="filterSettings"(pageChange)="onPageChange($event)"- [filters]="filters"(applyFilter)="updateFilter($event)"><ng-template #cardItem let-item let-position="idx">diff --git a/UI/Web/src/app/collections/collection-detail/collection-detail.component.scss b/UI/Web/src/app/collections/collection-detail/collection-detail.component.scssindex 7e13a843c..b392abee1 100644--- a/UI/Web/src/app/collections/collection-detail/collection-detail.component.scss+++ b/UI/Web/src/app/collections/collection-detail/collection-detail.component.scss@@ -1,4 +1,4 @@-@import '~bootstrap/scss/mixins/_breakpoints.scss';+@import '~bootstrap/scss/mixins/breakpoints';.poster {width: 100%;diff --git a/UI/Web/src/app/collections/collection-detail/collection-detail.component.ts b/UI/Web/src/app/collections/collection-detail/collection-detail.component.tsindex 2b4f6c4a4..02f897451 100644--- a/UI/Web/src/app/collections/collection-detail/collection-detail.component.ts+++ b/UI/Web/src/app/collections/collection-detail/collection-detail.component.ts@@ -6,15 +6,14 @@ import { ToastrService } from 'ngx-toastr';import { Subject } from 'rxjs';import { debounceTime, take, takeUntil, takeWhile } from 'rxjs/operators';import { BulkSelectionService } from 'src/app/cards/bulk-selection.service';-import { UpdateFilterEvent } from 'src/app/cards/card-detail-layout/card-detail-layout.component';+import { FilterSettings } from 'src/app/cards/card-detail-layout/card-detail-layout.component';import { EditCollectionTagsComponent } from 'src/app/cards/_modals/edit-collection-tags/edit-collection-tags.component';-import { KEY_CODES } from 'src/app/shared/_services/utility.service';+import { KEY_CODES, UtilityService } from 'src/app/shared/_services/utility.service';import { CollectionTag } from 'src/app/_models/collection-tag';import { SeriesAddedToCollectionEvent } from 'src/app/_models/events/series-added-to-collection-event';-import { SeriesRemovedEvent } from 'src/app/_models/events/series-removed-event';import { Pagination } from 'src/app/_models/pagination';import { Series } from 'src/app/_models/series';-import { FilterItem, mangaFormatFilters, SeriesFilter } from 'src/app/_models/series-filter';+import { SeriesFilter } from 'src/app/_models/series-filter';import { AccountService } from 'src/app/_services/account.service';import { Action, ActionFactoryService, ActionItem } from 'src/app/_services/action-factory.service';import { ActionService } from 'src/app/_services/action.service';@@ -39,10 +38,8 @@ export class CollectionDetailComponent implements OnInit, OnDestroy {seriesPagination!: Pagination;collectionTagActions: ActionItem<CollectionTag>[] = [];isAdmin: boolean = false;- filters: Array<FilterItem> = mangaFormatFilters;- filter: SeriesFilter = {- mangaFormat: null- };+ filter: SeriesFilter | undefined = undefined;+ filterSettings: FilterSettings = new FilterSettings();private onDestory: Subject<void> = new Subject<void>();@@ -85,7 +82,8 @@ export class CollectionDetailComponent implements OnInit, OnDestroy {constructor(public imageService: ImageService, private collectionService: CollectionTagService, private router: Router, private route: ActivatedRoute,private seriesService: SeriesService, private toastr: ToastrService, private actionFactoryService: ActionFactoryService,private modalService: NgbModal, private titleService: Title, private accountService: AccountService,- public bulkSelectionService: BulkSelectionService, private actionService: ActionService, private messageHub: MessageHubService) {+ public bulkSelectionService: BulkSelectionService, private actionService: ActionService, private messageHub: MessageHubService,+ private utilityService: UtilityService) {this.router.routeReuseStrategy.shouldReuseRoute = () => false;this.accountService.currentUser$.pipe(take(1)).subscribe(user => {@@ -100,6 +98,10 @@ export class CollectionDetailComponent implements OnInit, OnDestroy {return;}const tagId = parseInt(routeId, 10);++ [this.filterSettings.presets, this.filterSettings.openByDefault] = this.utilityService.filterPresetsFromUrl(this.route.snapshot, this.seriesService.createSeriesFilter());+ this.filterSettings.presets.collectionTags = [tagId];+this.updateTag(tagId);}@@ -149,7 +151,6 @@ export class CollectionDetailComponent implements OnInit, OnDestroy {this.collectionTag = matchingTags[0];this.tagImage = this.imageService.randomize(this.imageService.getCollectionCoverImage(this.collectionTag.id));this.titleService.setTitle('Kavita - ' + this.collectionTag.title + ' Collection');- this.loadPage();});}@@ -174,8 +175,8 @@ export class CollectionDetailComponent implements OnInit, OnDestroy {});}- updateFilter(data: UpdateFilterEvent) {- this.filter.mangaFormat = data.filterItem.value;+ updateFilter(data: SeriesFilter) {+ this.filter = data;if (this.seriesPagination !== undefined && this.seriesPagination !== null) {this.seriesPagination.currentPage = 1;this.onPageChange(this.seriesPagination);diff --git a/UI/Web/src/app/library-detail/library-detail.component.html b/UI/Web/src/app/library-detail/library-detail.component.htmlindex d01cec915..cebeac178 100644--- a/UI/Web/src/app/library-detail/library-detail.component.html+++ b/UI/Web/src/app/library-detail/library-detail.component.html@@ -1,10 +1,10 @@<app-bulk-operations [actionCallback]="bulkActionCallback"></app-bulk-operations>-<app-card-detail-layout header="{{libraryName}}"+<app-card-detail-layout [header]="libraryName"[isLoading]="loadingSeries"[items]="series"[actions]="actions"[pagination]="pagination"- [filters]="filters"+ [filterSettings]="filterSettings"(applyFilter)="updateFilter($event)"(pageChange)="onPageChange($event)">diff --git a/UI/Web/src/app/library-detail/library-detail.component.ts b/UI/Web/src/app/library-detail/library-detail.component.tsindex 810f20131..13fc0e885 100644--- a/UI/Web/src/app/library-detail/library-detail.component.ts+++ b/UI/Web/src/app/library-detail/library-detail.component.ts@@ -4,13 +4,13 @@ import { ActivatedRoute, Router } from '@angular/router';import { Subject } from 'rxjs';import { debounceTime, take, takeUntil, takeWhile } from 'rxjs/operators';import { BulkSelectionService } from '../cards/bulk-selection.service';-import { UpdateFilterEvent } from '../cards/card-detail-layout/card-detail-layout.component';-import { KEY_CODES } from '../shared/_services/utility.service';+import { FilterSettings } from '../cards/card-detail-layout/card-detail-layout.component';+import { KEY_CODES, UtilityService } from '../shared/_services/utility.service';import { SeriesAddedEvent } from '../_models/events/series-added-event';import { Library } from '../_models/library';import { Pagination } from '../_models/pagination';import { Series } from '../_models/series';-import { FilterItem, mangaFormatFilters, SeriesFilter } from '../_models/series-filter';+import { SeriesFilter } from '../_models/series-filter';import { Action, ActionFactoryService, ActionItem } from '../_services/action-factory.service';import { ActionService } from '../_services/action.service';import { LibraryService } from '../_services/library.service';@@ -30,11 +30,9 @@ export class LibraryDetailComponent implements OnInit, OnDestroy {loadingSeries = false;pagination!: Pagination;actions: ActionItem<Library>[] = [];- filters: Array<FilterItem> = mangaFormatFilters;- filter: SeriesFilter = {- mangaFormat: null- };+ filter: SeriesFilter | undefined = undefined;onDestroy: Subject<void> = new Subject<void>();+ filterSettings: FilterSettings = new FilterSettings();bulkActionCallback = (action: Action, data: any) => {const selectedSeriesIndexies = this.bulkSelectionService.getSelectedCardsForSource('series');@@ -75,12 +73,14 @@ export class LibraryDetailComponent implements OnInit, OnDestroy {constructor(private route: ActivatedRoute, private router: Router, private seriesService: SeriesService,private libraryService: LibraryService, private titleService: Title, private actionFactoryService: ActionFactoryService,- private actionService: ActionService, public bulkSelectionService: BulkSelectionService, private hubService: MessageHubService) {+ private actionService: ActionService, public bulkSelectionService: BulkSelectionService, private hubService: MessageHubService,+ private utilityService: UtilityService) {const routeId = this.route.snapshot.paramMap.get('id');if (routeId === null) {this.router.navigateByUrl('/libraries');return;}+this.router.routeReuseStrategy.shouldReuseRoute = () => false;this.libraryId = parseInt(routeId, 10);this.libraryService.getLibraryNames().pipe(take(1)).subscribe(names => {@@ -89,7 +89,11 @@ export class LibraryDetailComponent implements OnInit, OnDestroy {});this.actions = this.actionFactoryService.getLibraryActions(this.handleAction.bind(this));this.pagination = {currentPage: 0, itemsPerPage: 30, totalItems: 0, totalPages: 1};- this.loadPage();++ [this.filterSettings.presets, this.filterSettings.openByDefault] = this.utilityService.filterPresetsFromUrl(this.route.snapshot, this.seriesService.createSeriesFilter());+ this.filterSettings.presets.libraries = [this.libraryId];++ //this.loadPage();}ngOnInit(): void {@@ -134,8 +138,8 @@ export class LibraryDetailComponent implements OnInit, OnDestroy {}}- updateFilter(data: UpdateFilterEvent) {- this.filter.mangaFormat = data.filterItem.value;+ updateFilter(data: SeriesFilter) {+ this.filter = data;if (this.pagination !== undefined && this.pagination !== null) {this.pagination.currentPage = 1;this.onPageChange(this.pagination);@@ -151,7 +155,13 @@ export class LibraryDetailComponent implements OnInit, OnDestroy {}this.loadingSeries = true;- this.seriesService.getSeriesForLibrary(this.libraryId, this.pagination?.currentPage, this.pagination?.itemsPerPage, this.filter).pipe(take(1)).subscribe(series => {+ // The filter is out of sync with the presets from typeaheads on first load but syncs afterwards+ if (this.filter == undefined) {+ this.filter = this.seriesService.createSeriesFilter();+ this.filter.libraries.push(this.libraryId);+ }++ this.seriesService.getSeriesForLibrary(0, this.pagination?.currentPage, this.pagination?.itemsPerPage, this.filter).pipe(take(1)).subscribe(series => {this.series = series.result;this.pagination = series.pagination;this.loadingSeries = false;@@ -160,7 +170,7 @@ export class LibraryDetailComponent implements OnInit, OnDestroy {}onPageChange(pagination: Pagination) {- window.history.replaceState(window.location.href, '', window.location.href.split('?')[0] + '?page=' + this.pagination.currentPage);+ window.history.replaceState(window.location.href, '', window.location.href.split('?')[0] + '?' + 'page=' + this.pagination.currentPage);this.loadPage();}diff --git a/UI/Web/src/app/library/library.component.html b/UI/Web/src/app/library/library.component.htmlindex 3157a7d80..52c642743 100644--- a/UI/Web/src/app/library/library.component.html+++ b/UI/Web/src/app/library/library.component.html@@ -17,7 +17,7 @@</ng-template></app-carousel-reel>-<app-carousel-reel [items]="libraries" title="Libraries">+<app-carousel-reel [items]="libraries" title="Libraries" (sectionClick)="handleSectionClick($event)"><ng-template #carouselItem let-item let-position="idx"><app-library-card [data]="item"></app-library-card></ng-template>diff --git a/UI/Web/src/app/library/library.component.ts b/UI/Web/src/app/library/library.component.tsindex dc5ff3228..83ff53e80 100644--- a/UI/Web/src/app/library/library.component.ts+++ b/UI/Web/src/app/library/library.component.ts@@ -110,6 +110,8 @@ export class LibraryComponent implements OnInit, OnDestroy {this.router.navigate(['recently-added']);} else if (sectionTitle.toLowerCase() === 'on deck') {this.router.navigate(['on-deck']);+ } else if (sectionTitle.toLowerCase() === 'libraries') {+ this.router.navigate(['all-series']);}}diff --git a/UI/Web/src/app/manga-reader/_models/reader-enums.ts b/UI/Web/src/app/manga-reader/_models/reader-enums.tsindex 9738edf9f..37ab08054 100644--- a/UI/Web/src/app/manga-reader/_models/reader-enums.ts+++ b/UI/Web/src/app/manga-reader/_models/reader-enums.ts@@ -15,8 +15,3 @@ export enum PAGING_DIRECTION {BACKWARDS = -1,}-export enum COLOR_FILTER {- NONE = '',- SEPIA = 'filter-sepia',- DARK = 'filter-dark'-}diff --git a/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.html b/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.htmlindex 6bc608c11..a2c1f61e1 100644--- a/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.html+++ b/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.html@@ -26,7 +26,10 @@</div></div><ng-container *ngFor="let item of webtoonImages | async; let index = index;">- <img src="{{item.src}}" style="display: block" class="mx-auto {{pageNum === item.page && showDebugOutline() ? 'active': ''}} {{areImagesWiderThanWindow ? 'full-width' : ''}}" *ngIf="pageNum >= pageNum - bufferPages && pageNum <= pageNum + bufferPages" rel="nofollow" alt="image" (load)="onImageLoad($event)" id="page-{{item.page}}" [attr.page]="item.page" ondragstart="return false;" onselectstart="return false;">+ <img src="{{item.src}}" style="display: block"+ class="mx-auto {{pageNum === item.page && showDebugOutline() ? 'active': ''}} {{areImagesWiderThanWindow ? 'full-width' : ''}}"+ *ngIf="pageNum >= pageNum - bufferPages && pageNum <= pageNum + bufferPages" rel="nofollow" alt="image"+ (load)="onImageLoad($event)" id="page-{{item.page}}" [attr.page]="item.page" ondragstart="return false;" onselectstart="return false;"></ng-container><div *ngIf="atBottom" class="spacer bottom" role="alert" (click)="loadNextChapter.emit()"><div>diff --git a/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.scss b/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.scssindex 15dbd8b5c..c723bbcb2 100644--- a/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.scss+++ b/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.scss@@ -25,6 +25,10 @@width: 100% !important;}+// .img-container {+// overflow: auto;+// }+@keyframes move-up-down {0%, 100% {diff --git a/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.ts b/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.tsindex 7b4ff0712..fd9d01106 100644--- a/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.ts+++ b/UI/Web/src/app/manga-reader/infinite-scroller/infinite-scroller.component.ts@@ -1,6 +1,6 @@-import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, Renderer2, SimpleChanges } from '@angular/core';-import { BehaviorSubject, fromEvent, ReplaySubject, Subject } from 'rxjs';-import { debounceTime, takeUntil } from 'rxjs/operators';+import { Component, ElementRef, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, Renderer2, SimpleChanges } from '@angular/core';+import { BehaviorSubject, fromEvent, merge, ReplaySubject, Subject } from 'rxjs';+import { debounceTime, take, takeUntil } from 'rxjs/operators';import { ReaderService } from '../../_services/reader.service';import { PAGING_DIRECTION } from '../_models/reader-enums';import { WebtoonImage } from '../_models/webtoon-image';@@ -63,7 +63,10 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {@Input() goToPage: ReplaySubject<number> = new ReplaySubject<number>();@Input() bookmarkPage: ReplaySubject<number> = new ReplaySubject<number>();-+ @Input() fullscreenToggled: ReplaySubject<boolean> = new ReplaySubject<boolean>();++ readerElemRef!: ElementRef<HTMLDivElement>;+/*** Stores and emits all the src urls*/@@ -110,6 +113,10 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {* If the user has scrolled all the way to the top. This is used solely for continuous reading*/atTop: boolean = false;+ /**+ * If the manga reader is in fullscreen. Some math changes based on this value.+ */+ isFullscreenMode: boolean = false;/*** Keeps track of the previous scrolling height for restoring scroll position after we inject spacer block*/@@ -128,7 +135,8 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {}get areImagesWiderThanWindow() {- return this.webtoonImageWidth > (window.innerWidth || document.documentElement.clientWidth);+ let [innerWidth, _] = this.getInnerDimensions();+ return this.webtoonImageWidth > (innerWidth || document.documentElement.clientWidth);}@@ -136,7 +144,13 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {private readonly onDestroy = new Subject<void>();- constructor(private readerService: ReaderService, private renderer: Renderer2) {}+ constructor(private readerService: ReaderService, private renderer: Renderer2) {+ // This will always exist at this point in time since this is used within manga reader+ const reader = document.querySelector('.reader');+ if (reader !== null) {+ this.readerElemRef = new ElementRef(reader as HTMLDivElement);+ }+ }ngOnChanges(changes: SimpleChanges): void {if (changes.hasOwnProperty('totalPages') && changes['totalPages'].previousValue != changes['totalPages'].currentValue) {@@ -151,11 +165,21 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {this.onDestroy.complete();}- ngOnInit(): void {- fromEvent(window, 'scroll')- .pipe(debounceTime(20), takeUntil(this.onDestroy))+ /**+ * Responsible for binding the scroll handler to the correct event. On non-fullscreen, window is correct. However, on fullscreen, we must use the reader as that is what+ * gets promoted to fullscreen.+ */+ initScrollHandler() {+ fromEvent(this.isFullscreenMode ? this.readerElemRef.nativeElement : window, 'scroll')+ .pipe(debounceTime(20), takeUntil(this.onDestroy)).subscribe((event) => this.handleScrollEvent(event));++ }++ ngOnInit(): void {+ this.initScrollHandler();+if (this.goToPage) {this.goToPage.pipe(takeUntil(this.onDestroy)).subscribe(page => {this.debugLog('[GoToPage] jump has occured from ' + this.pageNum + ' to ' + page);@@ -183,6 +207,32 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {}});}++ if (this.fullscreenToggled) {+ this.fullscreenToggled.pipe(takeUntil(this.onDestroy)).subscribe(isFullscreen => {+ this.debugLog('[FullScreen] Fullscreen mode: ', isFullscreen);+ this.isFullscreenMode = isFullscreen;+ const [innerWidth, _] = this.getInnerDimensions();+ this.webtoonImageWidth = innerWidth || document.documentElement.clientWidth || document.body.clientWidth;+ this.initScrollHandler();+ this.setPageNum(this.pageNum, true);+ });+ }+ }++ getVerticalOffset() {+ const reader = this.isFullscreenMode ? this.readerElemRef.nativeElement : window;++ let offset = 0;+ if (reader instanceof Window) {+ offset = reader.scrollY;+ } else {+ offset = reader.scrollTop;+ }++ return (offset+ || document.documentElement.scrollTop+ || document.body.scrollTop || 0);}/**@@ -191,9 +241,9 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {* @param event Scroll Event*/handleScrollEvent(event?: any) {- const verticalOffset = (window.pageYOffset- || document.documentElement.scrollTop- || document.body.scrollTop || 0);+ // Need a fullscreen handler here too+ let verticalOffset = this.getVerticalOffset();+if (verticalOffset > this.prevScrollPosition) {this.scrollingDirection = PAGING_DIRECTION.FORWARD;@@ -202,6 +252,10 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {}this.prevScrollPosition = verticalOffset;+ console.log('CurrentPageElem: ', this.currentPageElem);+ if (this.currentPageElem != null) {+ console.log('Element Visible: ', this.isElementVisible(this.currentPageElem));+ }if (this.isScrolling && this.currentPageElem != null && this.isElementVisible(this.currentPageElem)) {this.debugLog('[Scroll] Image is visible from scroll, isScrolling is now false');this.isScrolling = false;@@ -230,9 +284,15 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {return totalHeight;}getTotalScroll() {+ if (this.isFullscreenMode) {+ return this.readerElemRef.nativeElement.offsetHeight + this.readerElemRef.nativeElement.scrollTop;+ }return document.documentElement.offsetHeight + document.documentElement.scrollTop;}getScrollTop() {+ if (this.isFullscreenMode) {+ return this.readerElemRef.nativeElement.scrollTop;+ }return document.documentElement.scrollTop;}@@ -267,7 +327,7 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {this.atTop = true;// Scroll user back to original locationthis.previousScrollHeightMinusTop = document.documentElement.scrollHeight - document.documentElement.scrollTop;- requestAnimationFrame(() => window.scrollTo(0, SPACER_SCROLL_INTO_PX));+ requestAnimationFrame(() => window.scrollTo(0, SPACER_SCROLL_INTO_PX)); // TODO: does this need to be fullscreen protected?} else if (this.getScrollTop() < 5 && this.pageNum === 0 && this.atTop) {// If already at top, then we moving onthis.loadPrevChapter.emit();@@ -276,6 +336,17 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {}+ getInnerDimensions() {+ let innerHeight = window.innerHeight;+ let innerWidth = window.innerWidth;++ if (this.isFullscreenMode) {+ innerHeight = this.readerElemRef.nativeElement.clientHeight;+ innerWidth = this.readerElemRef.nativeElement.clientWidth;+ }+ return [innerHeight, innerWidth];+ }+/*** Is any part of the element visible in the scrollport. Does not take into account* style properites, just scroll port visibility.@@ -288,10 +359,16 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {// NOTE: This will say an element is visible if it is 1 px offscreen on topvar rect = elem.getBoundingClientRect();+ let [innerHeight, innerWidth] = this.getInnerDimensions();+++ console.log('innerHeight: ', innerHeight);+ console.log('innerWidth: ', innerWidth);+return (rect.bottom >= 0 &&rect.right >= 0 &&- rect.top <= (window.innerHeight || document.documentElement.clientHeight) &&- rect.left <= (window.innerWidth || document.documentElement.clientWidth)+ rect.top <= (innerHeight || document.documentElement.clientHeight) &&+ rect.left <= (innerWidth || document.documentElement.clientWidth));}@@ -306,12 +383,15 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {var rect = elem.getBoundingClientRect();+ let [innerHeight, innerWidth] = this.getInnerDimensions();++if (rect.bottom >= 0 &&rect.right >= 0 &&- rect.top <= (window.innerHeight || document.documentElement.clientHeight) &&- rect.left <= (window.innerWidth || document.documentElement.clientWidth)+ rect.top <= (innerHeight || document.documentElement.clientHeight) &&+ rect.left <= (innerWidth || document.documentElement.clientWidth)) {- const topX = (window.innerHeight || document.documentElement.clientHeight);+ const topX = (innerHeight || document.documentElement.clientHeight);return Math.abs(rect.top / topX) <= 0.25;}return false;@@ -319,6 +399,8 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {initWebtoonReader() {+ const [innerWidth, _] = this.getInnerDimensions();+ this.webtoonImageWidth = innerWidth || document.documentElement.clientWidth || document.body.clientWidth;this.imagesLoaded = {};this.webtoonImages.next([]);this.atBottom = false;@@ -415,7 +497,6 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {* Performs the scroll for the current page element. Updates any state variables needed.*/scrollToCurrentPage() {- this.debugLog('Scrolling to ', this.pageNum);this.currentPageElem = document.querySelector('img#page-' + this.pageNum);if (!this.currentPageElem) { return; }diff --git a/UI/Web/src/app/manga-reader/manga-reader.component.html b/UI/Web/src/app/manga-reader/manga-reader.component.htmlindex 0353d29aa..ca95853bc 100644--- a/UI/Web/src/app/manga-reader/manga-reader.component.html+++ b/UI/Web/src/app/manga-reader/manga-reader.component.html@@ -1,4 +1,4 @@-<div class="reader">+<div class="reader" #reader [ngStyle]="{overflow: (isFullscreen ? 'auto' : 'visible')}"><div class="fixed-top overlay" *ngIf="menuOpen" [@slideFromTop]="menuOpen"><div style="display: flex; margin-top: 5px;"><button class="btn btn-icon" style="height: 100%" title="Back" (click)="closeReader()">@@ -24,7 +24,7 @@</ng-container><div (click)="toggleMenu()" class="reading-area">- <canvas #content class="{{getFittingOptionClass()}} {{this.colorMode}} {{readerMode === READER_MODE.MANGA_LR || readerMode === READER_MODE.MANGA_UD ? '' : 'd-none'}} "+ <canvas #content class="{{getFittingOptionClass()}} {{readerMode === READER_MODE.MANGA_LR || readerMode === READER_MODE.MANGA_UD ? '' : 'd-none'}} {{showClickOverlay ? 'blur' : ''}}"ondragstart="return false;" onselectstart="return false;"></canvas><div class="webtoon-images" *ngIf="readerMode === READER_MODE.WEBTOON && !isLoading">@@ -36,11 +36,22 @@[urlProvider]="getPageUrl"(loadNextChapter)="loadNextChapter()"(loadPrevChapter)="loadPrevChapter()"- [bookmarkPage]="showBookmarkEffectEvent"></app-infinite-scroller>+ [bookmarkPage]="showBookmarkEffectEvent"+ [fullscreenToggled]="fullscreenEvent"></app-infinite-scroller></div><ng-container *ngIf="readerMode === READER_MODE.MANGA_LR || readerMode === READER_MODE.MANGA_UD">- <div class="{{readerMode === READER_MODE.MANGA_LR ? 'right' : 'bottom'}} {{clickOverlayClass('right')}}" (click)="handlePageChange($event, 'right')"></div>- <div class="{{readerMode === READER_MODE.MANGA_LR ? 'left' : 'top'}} {{clickOverlayClass('left')}}" (click)="handlePageChange($event, 'left')"></div>+ <div class="pagination-area {{readerMode === READER_MODE.MANGA_LR ? 'right' : 'bottom'}} {{clickOverlayClass('right')}}" (click)="handlePageChange($event, 'right')">+ <div *ngIf="showClickOverlay">+ <i class="fa fa-angle-{{readingDirection === ReadingDirection.LeftToRight ? 'double-' : ''}}{{readerMode === READER_MODE.MANGA_LR ? 'right' : 'down'}}"+ title="Next Page" aria-hidden="true"></i>+ </div>+ </div>+ <div class="pagination-area {{readerMode === READER_MODE.MANGA_LR ? 'left' : 'top'}} {{clickOverlayClass('left')}}" (click)="handlePageChange($event, 'left')">+ <div *ngIf="showClickOverlay">+ <i class="fa fa-angle-{{readingDirection === ReadingDirection.RightToLeft ? 'double-' : ''}}{{readerMode === READER_MODE.MANGA_LR ? 'left' : 'up'}}"+ title="Previous Page" aria-hidden="true"></i>+ </div>+ </div></ng-container></div>@@ -78,9 +89,9 @@</button></div><div class="col">- <button class="btn btn-icon {{this.colorMode}}" [disabled]="readerMode === READER_MODE.WEBTOON" title="Color Options: {{colorOptionName}}" (click)="toggleColorMode();resetMenuCloseTimer();">- <i class="fa fa-palette" aria-hidden="true"></i>- <span class="sr-only"></span>+ <button class="btn btn-icon" title="{{this.isFullscreen ? 'Collapse' : 'Fullscreen'}}" (click)="toggleFullscreen();resetMenuCloseTimer();">+ <i class="fa {{this.isFullscreen ? 'fa-compress-alt' : 'fa-expand-alt'}}" aria-hidden="true"></i>+ <span class="sr-only">{{this.isFullscreen ? 'Collapse' : 'Fullscreen'}}</span></button></div><div class="col">diff --git a/UI/Web/src/app/manga-reader/manga-reader.component.scss b/UI/Web/src/app/manga-reader/manga-reader.component.scssindex 6caec0857..451f5ff0c 100644--- a/UI/Web/src/app/manga-reader/manga-reader.component.scss+++ b/UI/Web/src/app/manga-reader/manga-reader.component.scss@@ -6,8 +6,6 @@ $side-width: 25%;$dash-width: 3px;$pointer-offset: 5px;-$secondary-color: #CCC;-@media(min-width: 600px) {.overlay .left .i {@@ -18,7 +16,6 @@ $secondary-color: #CCC;}}-.btn-icon {color: white;}@@ -29,12 +26,17 @@ canvas {.reader {background-color: black;+ overflow: auto;img {align-items: center;}}++++.loading {position: absolute;left: 48%;@@ -48,21 +50,16 @@ canvas {white-space: nowrap;}-.filter-dark {- filter: brightness(0.65);-}--.filter-sepia {- filter: sepia(80%) hue-rotate(349deg) saturate(200%) brightness(0.65);-}-.bottom-menu {padding: 20px 20px;}++.overlay {background-color: rgba(0,0,0,0.5);+ backdrop-filter: blur(10px); // BUG: This doesn't work on Firefoxcolor: white;}@@ -226,15 +223,28 @@ canvas {width: 100%;}- .highlight {- background-color: rgba(65, 225, 100, 0.5) !important;- animation: fadein .5s both;- }- .highlight-2 {- background-color: rgba(65, 105, 225, 0.5) !important;- animation: fadein .5s both;+ .pagination-area {+ display: flex;+ align-items: center;+ justify-content: center;++ i {+ color: white;+ font-size: 42px;+ }}+.highlight {+ background-color: rgba(65, 225, 100, 0.5) !important;+ animation: fadein .5s both;+ backdrop-filter: blur(10px);+}+.highlight-2 {+ background-color: rgba(65, 105, 225, 0.5) !important;+ animation: fadein .5s both;+ backdrop-filter: blur(10px);+}+.bookmark-effect {animation: bookmark 0.7s cubic-bezier(0.165, 0.84, 0.44, 1);diff --git a/UI/Web/src/app/manga-reader/manga-reader.component.ts b/UI/Web/src/app/manga-reader/manga-reader.component.tsindex 3ab56c1b7..98883657c 100644--- a/UI/Web/src/app/manga-reader/manga-reader.component.ts+++ b/UI/Web/src/app/manga-reader/manga-reader.component.ts@@ -1,5 +1,5 @@-import { AfterViewInit, Component, ElementRef, EventEmitter, HostListener, OnDestroy, OnInit, Renderer2, SimpleChanges, ViewChild } from '@angular/core';-import { Location } from '@angular/common';+import { AfterViewInit, Component, ElementRef, EventEmitter, HostListener, Inject, OnDestroy, OnInit, Renderer2, SimpleChanges, ViewChild } from '@angular/core';+import { DOCUMENT, Location } from '@angular/common';import { ActivatedRoute, Router } from '@angular/router';import { take, takeUntil } from 'rxjs/operators';import { User } from '../_models/user';@@ -19,7 +19,7 @@ import { Stack } from '../shared/data-structures/stack';import { ChangeContext, LabelType, Options } from '@angular-slider/ngx-slider';import { trigger, state, style, transition, animate } from '@angular/animations';import { ChapterInfo } from './_models/chapter-info';-import { COLOR_FILTER, FITTING_OPTION, PAGING_DIRECTION, SPLIT_PAGE_PART } from './_models/reader-enums';+import { FITTING_OPTION, PAGING_DIRECTION, SPLIT_PAGE_PART } from './_models/reader-enums';import { pageSplitOptions, scalingOptions } from '../_models/preferences/preferences';import { READER_MODE } from '../_models/preferences/reader-mode';import { MangaFormat } from '../_models/manga-format';@@ -32,7 +32,7 @@ const CHAPTER_ID_NOT_FETCHED = -2;const CHAPTER_ID_DOESNT_EXIST = -1;const ANIMATION_SPEED = 200;-const OVERLAY_AUTO_CLOSE_TIME = 6000;+const OVERLAY_AUTO_CLOSE_TIME = 3000;const CLICK_OVERLAY_TIMEOUT = 3000;@@ -79,7 +79,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {incognitoMode: boolean = false;/**- * If this is true, chapters will be fetched in the order of a reading list, rather than natural series order.+ * If this is true, chapters will be fetched in the order of a reading list, rather than natural series order.*/readingListMode: boolean = false;/**@@ -99,14 +99,15 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {pageSplitOption = PageSplitOption.FitSplit;currentImageSplitPart: SPLIT_PAGE_PART = SPLIT_PAGE_PART.NO_SPLIT;pagingDirection: PAGING_DIRECTION = PAGING_DIRECTION.FORWARD;- colorMode: COLOR_FILTER = COLOR_FILTER.NONE;+ isFullscreen: boolean = false;autoCloseMenu: boolean = true;readerMode: READER_MODE = READER_MODE.MANGA_LR;pageSplitOptions = pageSplitOptions;-- isLoading = true;+ isLoading = true;++ @ViewChild('reader') reader!: ElementRef;@ViewChild('content') canvas: ElementRef | undefined;private ctx!: CanvasRenderingContext2D;private canvasImage = new Image();@@ -130,6 +131,10 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {* An event emiter when a bookmark on a page change occurs. Used soley by the webtoon reader.*/showBookmarkEffectEvent: ReplaySubject<number> = new ReplaySubject<number>();+ /**+ * An event emiter when fullscreen mode is toggled. Used soley by the webtoon reader.+ */+ fullscreenEvent: ReplaySubject<boolean> = new ReplaySubject<boolean>();/*** If the menu is open/visible.*/@@ -219,21 +224,21 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {private readonly onDestroy = new Subject<void>();-+getPageUrl = (pageNum: number) => this.readerService.getPageUrl(this.chapterId, pageNum);-+get pageBookmarked() {return this.bookmarks.hasOwnProperty(this.pageNum);}-+get splitIconClass() {if (this.isSplitLeftToRight()) {return 'left-side';} else if (this.isNoSplit()) {- return 'none';+ return 'none';}return 'right-side';}@@ -249,17 +254,6 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {}}- get colorOptionName() {- switch(this.colorMode) {- case COLOR_FILTER.NONE:- return 'None';- case COLOR_FILTER.DARK:- return 'Dark';- case COLOR_FILTER.SEPIA:- return 'Sepia';- }- }-get READER_MODE(): typeof READER_MODE {return READER_MODE;}@@ -274,10 +268,10 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {constructor(private route: ActivatedRoute, private router: Router, private accountService: AccountService,public readerService: ReaderService, private location: Location,- private formBuilder: FormBuilder, private navService: NavService,+ private formBuilder: FormBuilder, private navService: NavService,private toastr: ToastrService, private memberService: MemberService,- private libraryService: LibraryService, private utilityService: UtilityService,- private renderer: Renderer2) {+ private libraryService: LibraryService, private utilityService: UtilityService,+ private renderer: Renderer2, @Inject(DOCUMENT) private document: Document) {this.navService.hideNavBar();}@@ -295,13 +289,13 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.seriesId = parseInt(seriesId, 10);this.chapterId = parseInt(chapterId, 10);this.incognitoMode = this.route.snapshot.queryParamMap.get('incognitoMode') === 'true';-+const readingListId = this.route.snapshot.queryParamMap.get('readingListId');if (readingListId != null) {this.readingListMode = true;this.readingListId = parseInt(readingListId, 10);}-+this.continuousChaptersStack.push(this.chapterId);@@ -325,10 +319,11 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.updateForm();+this.generalSettingsForm.valueChanges.pipe(takeUntil(this.onDestroy)).subscribe((changes: SimpleChanges) => {this.autoCloseMenu = this.generalSettingsForm.get('autoCloseMenu')?.value;const needsSplitting = this.isCoverImage();- // If we need to split on a menu change, then we need to re-render.+ // If we need to split on a menu change, then we need to re-render.if (needsSplitting) {this.loadPage();}@@ -341,7 +336,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {}});} else {- // If no user, we can't render+ // If no user, we can't renderthis.router.navigateByUrl('/login');}});@@ -365,6 +360,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.onDestroy.complete();this.goToPageEvent.complete();this.showBookmarkEffectEvent.complete();+ this.readerService.exitFullscreen();}@HostListener('window:keyup', ['$event'])@@ -407,6 +403,17 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {}}+ clickOverlayClass(side: 'right' | 'left') {+ if (!this.showClickOverlay) {+ return '';+ }++ if (this.readingDirection === ReadingDirection.LeftToRight) {+ return side === 'right' ? 'highlight' : 'highlight-2';+ }+ return side === 'right' ? 'highlight-2' : 'highlight';+ }+init() {this.nextChapterId = CHAPTER_ID_NOT_FETCHED;this.prevChapterId = CHAPTER_ID_NOT_FETCHED;@@ -414,6 +421,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.prevChapterDisabled = false;this.nextChapterPrefetched = false;this.pageNum = 0;+ this.pagingDirection = PAGING_DIRECTION.FORWARD;forkJoin({progress: this.readerService.getProgress(this.chapterId),@@ -422,7 +430,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {}).pipe(take(1)).subscribe(results => {if (this.readingListMode && results.chapterInfo.seriesFormat === MangaFormat.EPUB) {- // Redirect to the book reader.+ // Redirect to the book reader.const params = this.readerService.getQueryParamsObject(this.incognitoMode, this.readingListMode, this.readingListId);this.router.navigate(['library', results.chapterInfo.libraryId, 'series', results.chapterInfo.seriesId, 'book', this.chapterId], {queryParams: params});return;@@ -432,11 +440,11 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.maxPages = results.chapterInfo.pages;let page = results.progress.pageNum;if (page > this.maxPages) {- page = this.maxPages;+ page = this.maxPages - 1;}this.setPageNum(page);--++// Due to change detection rules in Angular, we need to re-create the options object to apply the changeconst newOptions: Options = Object.assign({}, this.pageOptions);@@ -448,7 +456,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.updateTitle(results.chapterInfo, type);});-+// From bookmarks, create map of pages to make lookup time O(1)this.bookmarks = {};@@ -504,7 +512,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {updateTitle(chapterInfo: ChapterInfo, type: LibraryType) {this.title = chapterInfo.seriesName;- if (chapterInfo.chapterTitle.length > 0) {+ if (chapterInfo.chapterTitle != null && chapterInfo.chapterTitle.length > 0) {this.title += ' - ' + chapterInfo.chapterTitle;}@@ -562,7 +570,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {getFittingIcon() {const value = this.getFit();-+switch(value) {case FITTING_OPTION.HEIGHT:return 'fa-arrows-alt-v';@@ -608,10 +616,10 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {}, OVERLAY_AUTO_CLOSE_TIME);}-+toggleMenu() {this.menuOpen = !this.menuOpen;-+if (this.menuTimeout) {clearTimeout(this.menuTimeout);}@@ -629,8 +637,9 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {}/**- *+ ** @returns If the current model reflects no split of fit split+ * @remarks Fit to Screen falls under no split*/isNoSplit() {const splitValue = parseInt(this.generalSettingsForm?.get('pageSplitOption')?.value, 10);@@ -717,7 +726,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {if (this.readerMode !== READER_MODE.WEBTOON) {this.loadPage();- }+ }}prevPage(event?: any) {@@ -745,7 +754,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {if (this.readerMode !== READER_MODE.WEBTOON) {this.loadPage();- }+ }}loadNextChapter() {@@ -789,7 +798,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {loadChapter(chapterId: number, direction: 'Next' | 'Prev') {if (chapterId >= 0) {this.chapterId = chapterId;- this.continuousChaptersStack.push(chapterId);+ this.continuousChaptersStack.push(chapterId);// Load chapter Id onto route but don't reloadconst newRoute = this.readerService.getNextChapterUrl(this.router.url, this.chapterId, this.incognitoMode, this.readingListMode, this.readingListId);window.history.replaceState({}, '', newRoute);@@ -804,14 +813,14 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {} else {this.nextPageDisabled = true;}-+}}/*** There are some hard limits on the size of canvas' that we must cap at. https://github.com/jhildenbiddle/canvas-size#test-results* For Safari, it's 16,777,216, so we cap at 4096x4096 when this happens. The drawImage in render will perform bi-cubic scaling for us.- * @returns If we should continue to the render loop+ * @returns If we should continue to the render loop*/setCanvasSize() {if (this.ctx && this.canvas) {@@ -832,9 +841,6 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {if (needsScaling) {this.canvas.nativeElement.width = isSafari ? 4_096 : 16_384;this.canvas.nativeElement.height = isSafari ? 4_096 : 16_384;- } else if (this.isCoverImage()) {- //this.canvas.nativeElement.width = this.canvasImage.width / 2;- //this.canvas.nativeElement.height = this.canvasImage.height;} else {this.canvas.nativeElement.width = this.canvasImage.width;this.canvas.nativeElement.height = this.canvasImage.height;@@ -843,61 +849,67 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {}renderPage() {- if (this.ctx && this.canvas) {- this.canvasImage.onload = null;+ if (!this.ctx || !this.canvas) { return; }- this.setCanvasSize();+ this.canvasImage.onload = null;- const needsSplitting = this.isCoverImage();- this.updateSplitPage();-- if (needsSplitting && this.currentImageSplitPart === SPLIT_PAGE_PART.LEFT_PART) {- this.canvas.nativeElement.width = this.canvasImage.width / 2;- this.ctx.drawImage(this.canvasImage, 0, 0, this.canvasImage.width, this.canvasImage.height, 0, 0, this.canvasImage.width, this.canvasImage.height);- } else if (needsSplitting && this.currentImageSplitPart === SPLIT_PAGE_PART.RIGHT_PART) {- this.canvas.nativeElement.width = this.canvasImage.width / 2;- this.ctx.drawImage(this.canvasImage, 0, 0, this.canvasImage.width, this.canvasImage.height, -this.canvasImage.width / 2, 0, this.canvasImage.width, this.canvasImage.height);- } else {- if (!this.firstPageRendered && this.scalingOption === ScalingOption.Automatic) {- this.updateScalingForFirstPageRender();- }+ this.setCanvasSize();- // Fit Split on a page that needs splitting- if (this.shouldRenderAsFitSplit()) {- const windowWidth = window.innerWidth- || document.documentElement.clientWidth- || document.body.clientWidth;- const windowHeight = window.innerHeight- || document.documentElement.clientHeight- || document.body.clientHeight;- // If the user's screen is wider than the image, just pretend this is no split, as it will render nicer- this.canvas.nativeElement.width = windowWidth;- this.canvas.nativeElement.height = windowHeight;- const ratio = this.canvasImage.width / this.canvasImage.height;- let newWidth = windowWidth;- let newHeight = newWidth / ratio;- if (newHeight > windowHeight) {- newHeight = windowHeight;- newWidth = newHeight * ratio;- }+ const needsSplitting = this.isCoverImage();+ this.updateSplitPage();++ if (needsSplitting && this.currentImageSplitPart === SPLIT_PAGE_PART.LEFT_PART) {+ this.canvas.nativeElement.width = this.canvasImage.width / 2;+ this.ctx.drawImage(this.canvasImage, 0, 0, this.canvasImage.width, this.canvasImage.height, 0, 0, this.canvasImage.width, this.canvasImage.height);+ } else if (needsSplitting && this.currentImageSplitPart === SPLIT_PAGE_PART.RIGHT_PART) {+ this.canvas.nativeElement.width = this.canvasImage.width / 2;+ this.ctx.drawImage(this.canvasImage, 0, 0, this.canvasImage.width, this.canvasImage.height, -this.canvasImage.width / 2, 0, this.canvasImage.width, this.canvasImage.height);+ } else {+ if (!this.firstPageRendered && this.scalingOption === ScalingOption.Automatic) {+ this.updateScalingForFirstPageRender();+ }- // Optimization: When the screen is larger than newWidth, allow no split rendering to occur for a better fit- if (windowWidth > newWidth) {- this.ctx.drawImage(this.canvasImage, 0, 0);- } else {- this.ctx.drawImage(this.canvasImage, 0, 0, newWidth, newHeight);- }- } else {- this.ctx.drawImage(this.canvasImage, 0, 0);- }+ // Fit Split on a page that needs splitting+ if (!this.shouldRenderAsFitSplit()) {+ this.setCanvasSize();+ this.ctx.drawImage(this.canvasImage, 0, 0);+ this.isLoading = false;+ return;}- // Reset scroll on non HEIGHT Fits- if (this.getFit() !== FITTING_OPTION.HEIGHT) {- window.scrollTo(0, 0);+ const windowWidth = window.innerWidth+ || document.documentElement.clientWidth+ || document.body.clientWidth;+ const windowHeight = window.innerHeight+ || document.documentElement.clientHeight+ || document.body.clientHeight;+ // If the user's screen is wider than the image, just pretend this is no split, as it will render nicer+ this.canvas.nativeElement.width = windowWidth;+ this.canvas.nativeElement.height = windowHeight;+ const ratio = this.canvasImage.width / this.canvasImage.height;+ let newWidth = windowWidth;+ let newHeight = newWidth / ratio;+ if (newHeight > windowHeight) {+ newHeight = windowHeight;+ newWidth = newHeight * ratio;}+ // Optimization: When the screen is larger than newWidth, allow no split rendering to occur for a better fit+ if (windowWidth > newWidth) {+ this.setCanvasSize();+ this.ctx.drawImage(this.canvasImage, 0, 0);+ } else {+ this.ctx.fillRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);+ this.ctx.drawImage(this.canvasImage, 0, 0, newWidth, newHeight);+ }}++ // Reset scroll on non HEIGHT Fits+ if (this.getFit() !== FITTING_OPTION.HEIGHT) {+ window.scrollTo(0, 0);+ }++this.isLoading = false;}@@ -908,13 +920,13 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {const windowHeight = window.innerHeight|| document.documentElement.clientHeight|| document.body.clientHeight;-+const needsSplitting = this.isCoverImage();let newScale = this.generalSettingsForm.get('fittingOption')?.value;const widthRatio = windowWidth / (this.canvasImage.width / (needsSplitting ? 2 : 1));const heightRatio = windowHeight / (this.canvasImage.height);- // Given that we now have image dimensions, assuming this isn't a split image,+ // Given that we now have image dimensions, assuming this isn't a split image,// Try to reset one time based on who's dimension (width/height) is smallerif (widthRatio < heightRatio) {newScale = FITTING_OPTION.WIDTH;@@ -932,7 +944,9 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {shouldRenderAsFitSplit() {- if (!this.isCoverImage() || parseInt(this.generalSettingsForm?.get('pageSplitOption')?.value, 10) !== PageSplitOption.FitSplit) return false;+ // Some pages aren't cover images but might need fit split renderings+ if (parseInt(this.generalSettingsForm?.get('pageSplitOption')?.value, 10) !== PageSplitOption.FitSplit) return false;+ //if (!this.isCoverImage() || parseInt(this.generalSettingsForm?.get('pageSplitOption')?.value, 10) !== PageSplitOption.FitSplit) return false;return true;}@@ -952,7 +966,6 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {index += 1;}}, this.cachedImages.size() - 3);- //console.log('prefetched images: ', this.cachedImages.arr.map(item => this.readerService.imageUrlToPageNum(item.src) + (item.complete ? ' (c)' : '')));}loadPage() {@@ -984,19 +997,9 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {}}- clickOverlayClass(side: 'right' | 'left') {- if (!this.showClickOverlay) {- return '';- }-- if (this.readingDirection === ReadingDirection.LeftToRight) {- return side === 'right' ? 'highlight' : 'highlight-2';- }- return side === 'right' ? 'highlight-2' : 'highlight';- }sliderDragUpdate(context: ChangeContext) {- // This will update the value for value except when in webtoon due to how the webtoon reader+ // This will update the value for value except when in webtoon due to how the webtoon reader// responds to page changesif (this.readerMode !== READER_MODE.WEBTOON) {this.setPageNum(context.value);@@ -1005,7 +1008,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {sliderPageUpdate(context: ChangeContext) {const page = context.value;-+if (page > this.pageNum) {this.pagingDirection = PAGING_DIRECTION.FORWARD;} else {@@ -1038,7 +1041,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {// Due to the fact that we start at image 0, but page 1, we need the last page to have progress as page + 1 to be completedlet tempPageNum = this.pageNum;- if (this.pageNum == this.maxPages - 1) {+ if (this.pageNum == this.maxPages - 1 && this.pagingDirection === PAGING_DIRECTION.FORWARD) {tempPageNum = this.pageNum + 1;}@@ -1049,7 +1052,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {goToPage(pageNum: number) {let page = pageNum;-+if (page === undefined || this.pageNum === page) { return; }if (page > this.maxPages) {@@ -1079,20 +1082,26 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {return goToPageNum;}- toggleColorMode() {- switch(this.colorMode) {- case COLOR_FILTER.NONE:- this.colorMode = COLOR_FILTER.DARK;- break;- case COLOR_FILTER.DARK:- this.colorMode = COLOR_FILTER.SEPIA;- break;- case COLOR_FILTER.SEPIA:- this.colorMode = COLOR_FILTER.NONE;- break;+ toggleFullscreen() {+ this.isFullscreen = this.readerService.checkFullscreenMode();+ if (this.isFullscreen) {+ this.readerService.exitFullscreen(() => {+ this.isFullscreen = false;+ this.firstPageRendered = false;+ this.fullscreenEvent.next(false);+ this.render();+ });+ } else {+ this.readerService.enterFullscreen(this.reader.nativeElement, () => {+ this.isFullscreen = true;+ this.firstPageRendered = false;+ this.fullscreenEvent.next(true);+ this.render();+ });}}+toggleReaderMode() {switch(this.readerMode) {case READER_MODE.MANGA_LR:@@ -1163,4 +1172,14 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.toastr.info('Incognito mode is off. Progress will now start being tracked.');this.readerService.saveProgress(this.seriesId, this.volumeId, this.chapterId, this.pageNum).pipe(take(1)).subscribe(() => {/* No operation */});}++ getWindowDimensions() {+ const windowWidth = window.innerWidth+ || document.documentElement.clientWidth+ || document.body.clientWidth;+ const windowHeight = window.innerHeight+ || document.documentElement.clientHeight+ || document.body.clientHeight;+ return [windowWidth, windowHeight];+ }}diff --git a/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.html b/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.htmlindex 36da7d079..69be1191f 100644--- a/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.html+++ b/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.html@@ -1,6 +1,6 @@<ng-container>- <button type="button" class="btn btn-icon {{progressEventsSource.getValue().length > 0 ? 'colored' : ''}}"+ <button type="button" class="btn btn-icon {{(progressEventsSource.getValue().length > 0 || updateAvailable) ? 'colored' : ''}}"[ngbPopover]="popContent" title="Activity" placement="bottom" [popoverClass]="'nav-events'"><i aria-hidden="true" class="fa fa-wave-square"></i></button>@@ -14,9 +14,12 @@<span class="sr-only">Scan for {{event.libraryName}} in progress</span></div>{{prettyPrintProgress(event.progress)}}%- {{prettyPrintEvent(event.eventType)}} {{event.libraryName}}+ {{prettyPrintEvent(event.eventType, event)}} {{event.libraryName}}+ </li>+ <li class="list-group-item dark-menu-item" *ngIf="progressEventsSource.getValue().length === 0 && !updateAvailable">Not much going on here</li>+ <li class="list-group-item dark-menu-item update-available" *ngIf="updateAvailable" (click)="handleUpdateAvailableClick()">+ <i class="fa fa-chevron-circle-up" aria-hidden="true"></i> Update available</li>- <li class="list-group-item dark-menu-item" *ngIf="progressEventsSource.getValue().length === 0">Not much going on here</li></ul></ng-template></ng-container>\ No newline at end of filediff --git a/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.scss b/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.scssindex 49fa7ed63..7ab851b81 100644--- a/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.scss+++ b/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.scss@@ -1,4 +1,4 @@-@import "../../theme/colors";+@use "../../theme/colors";.small-spinner {width: 1rem;@@ -18,6 +18,15 @@}.colored {- background-color: $primary-color;+ background-color: colors.$primary-color;border-radius: 60px;+}++.update-available {+ cursor: pointer;++ i.fa {+ color: colors.$primary-color !important;+ }+ color: colors.$primary-color;}\ No newline at end of filediff --git a/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.ts b/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.tsindex 26b77bbfd..294f1a9b0 100644--- a/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.ts+++ b/UI/Web/src/app/nav-events-toggle/nav-events-toggle.component.ts@@ -1,6 +1,8 @@import { Component, Input, OnDestroy, OnInit } from '@angular/core';+import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';import { BehaviorSubject, Subject } from 'rxjs';import { takeUntil } from 'rxjs/operators';+import { UpdateNotificationModalComponent } from '../shared/update-notification/update-notification-modal.component';import { ProgressEvent } from '../_models/events/scan-library-progress-event';import { User } from '../_models/user';import { LibraryService } from '../_services/library.service';@@ -16,6 +18,8 @@ interface ProcessedEvent {type ProgressType = EVENTS.ScanLibraryProgress | EVENTS.RefreshMetadataProgress | EVENTS.BackupDatabaseProgress | EVENTS.CleanupProgress;+const acceptedEvents = [EVENTS.ScanLibraryProgress, EVENTS.RefreshMetadataProgress, EVENTS.BackupDatabaseProgress, EVENTS.CleanupProgress, EVENTS.DownloadProgress];+@Component({selector: 'app-nav-events-toggle',templateUrl: './nav-events-toggle.component.html',@@ -33,7 +37,11 @@ export class NavEventsToggleComponent implements OnInit, OnDestroy {progressEventsSource = new BehaviorSubject<ProcessedEvent[]>([]);progressEvents$ = this.progressEventsSource.asObservable();- constructor(private messageHub: MessageHubService, private libraryService: LibraryService) { }+ updateAvailable: boolean = false;+ updateBody: any;+ private updateNotificationModalRef: NgbModalRef | null = null;++ constructor(private messageHub: MessageHubService, private libraryService: LibraryService, private modalService: NgbModal) { }ngOnDestroy(): void {this.onDestroy.next();@@ -43,8 +51,11 @@ export class NavEventsToggleComponent implements OnInit, OnDestroy {ngOnInit(): void {this.messageHub.messages$.pipe(takeUntil(this.onDestroy)).subscribe(event => {- if (event.event === EVENTS.ScanLibraryProgress || event.event === EVENTS.RefreshMetadataProgress || event.event === EVENTS.BackupDatabaseProgress || event.event === EVENTS.CleanupProgress) {+ if (acceptedEvents.includes(event.event)) {this.processProgressEvent(event, event.event);+ } else if (event.event === EVENTS.UpdateAvailable) {+ this.updateAvailable = true;+ this.updateBody = event.payload;}});}@@ -64,7 +75,7 @@ export class NavEventsToggleComponent implements OnInit, OnDestroy {if (scanEvent.progress !== 1) {const libraryName = names[scanEvent.libraryId] || '';- const newEvent = {eventType: eventType, timestamp: scanEvent.eventTime, progress: scanEvent.progress, libraryId: scanEvent.libraryId, libraryName};+ const newEvent = {eventType: eventType, timestamp: scanEvent.eventTime, progress: scanEvent.progress, libraryId: scanEvent.libraryId, libraryName, rawBody: event.payload};data.push(newEvent);}@@ -73,16 +84,29 @@ export class NavEventsToggleComponent implements OnInit, OnDestroy {});}+ handleUpdateAvailableClick() {+ if (this.updateNotificationModalRef != null) { return; }+ this.updateNotificationModalRef = this.modalService.open(UpdateNotificationModalComponent, { scrollable: true, size: 'lg' });+ this.updateNotificationModalRef.componentInstance.updateData = this.updateBody;+ this.updateNotificationModalRef.closed.subscribe(() => {+ this.updateNotificationModalRef = null;+ });+ this.updateNotificationModalRef.dismissed.subscribe(() => {+ this.updateNotificationModalRef = null;+ });+ }+prettyPrintProgress(progress: number) {return Math.trunc(progress * 100);}- prettyPrintEvent(eventType: string) {+ prettyPrintEvent(eventType: string, event: any) {switch(eventType) {case (EVENTS.ScanLibraryProgress): return 'Scanning ';- case (EVENTS.RefreshMetadataProgress): return 'Refreshing ';+ case (EVENTS.RefreshMetadataProgress): return 'Refreshing Covers for ';case (EVENTS.CleanupProgress): return 'Clearing Cache';case (EVENTS.BackupDatabaseProgress): return 'Backing up Database';+ case (EVENTS.DownloadProgress): return event.rawBody.userName.charAt(0).toUpperCase() + event.rawBody.userName.substr(1) + ' is downloading ' + event.rawBody.downloadName;default: return eventType;}}diff --git a/UI/Web/src/app/nav-header/nav-header.component.scss b/UI/Web/src/app/nav-header/nav-header.component.scssindex 1bcdcb871..c0d170b06 100644--- a/UI/Web/src/app/nav-header/nav-header.component.scss+++ b/UI/Web/src/app/nav-header/nav-header.component.scss@@ -1,4 +1,4 @@-@import '~bootstrap/scss/mixins/_breakpoints.scss'; // TODO: Use @forwards for this?+@import '~bootstrap/scss/mixins/_breakpoints.scss';$primary-color: white;$bg-color: rgb(22, 27, 34);diff --git a/UI/Web/src/app/on-deck/on-deck.component.html b/UI/Web/src/app/on-deck/on-deck.component.htmlindex 2d8eded75..d03b4b696 100644--- a/UI/Web/src/app/on-deck/on-deck.component.html+++ b/UI/Web/src/app/on-deck/on-deck.component.html@@ -2,11 +2,10 @@<app-card-detail-layout header="On Deck"[isLoading]="isLoading"[items]="series"- [filters]="filters"[pagination]="pagination"+ [filterSettings]="filterSettings"(pageChange)="onPageChange($event)"(applyFilter)="updateFilter($event)"-><ng-template #cardItem let-item let-position="idx"><app-series-card [data]="item" [libraryId]="item.libraryId" (reload)="loadPage()" (selection)="bulkSelectionService.handleCardSelection('series', position, series.length, $event)" [selected]="bulkSelectionService.isCardSelected('series', position)" [allowSelection]="true"></app-series-card>diff --git a/UI/Web/src/app/on-deck/on-deck.component.ts b/UI/Web/src/app/on-deck/on-deck.component.tsindex 6ed72561b..0d8d23ee5 100644--- a/UI/Web/src/app/on-deck/on-deck.component.ts+++ b/UI/Web/src/app/on-deck/on-deck.component.ts@@ -3,11 +3,11 @@ import { Title } from '@angular/platform-browser';import { Router, ActivatedRoute } from '@angular/router';import { take } from 'rxjs/operators';import { BulkSelectionService } from '../cards/bulk-selection.service';-import { UpdateFilterEvent } from '../cards/card-detail-layout/card-detail-layout.component';+import { FilterSettings } from '../cards/card-detail-layout/card-detail-layout.component';import { KEY_CODES } from '../shared/_services/utility.service';import { Pagination } from '../_models/pagination';import { Series } from '../_models/series';-import { FilterItem, SeriesFilter, mangaFormatFilters } from '../_models/series-filter';+import { SeriesFilter} from '../_models/series-filter';import { Action } from '../_services/action-factory.service';import { ActionService } from '../_services/action.service';import { SeriesService } from '../_services/series.service';@@ -23,10 +23,8 @@ export class OnDeckComponent implements OnInit {series: Series[] = [];pagination!: Pagination;libraryId!: number;- filters: Array<FilterItem> = mangaFormatFilters;- filter: SeriesFilter = {- mangaFormat: null- };+ filter: SeriesFilter | undefined = undefined;+ filterSettings: FilterSettings = new FilterSettings();constructor(private router: Router, private route: ActivatedRoute, private seriesService: SeriesService, private titleService: Title,private actionService: ActionService, public bulkSelectionService: BulkSelectionService) {@@ -35,6 +33,8 @@ export class OnDeckComponent implements OnInit {if (this.pagination === undefined || this.pagination === null) {this.pagination = {currentPage: 0, itemsPerPage: 30, totalItems: 0, totalPages: 1};}+ this.filterSettings.readProgressDisabled = true;+ this.filterSettings.sortDisabled = true;this.loadPage();}@@ -63,8 +63,8 @@ export class OnDeckComponent implements OnInit {this.loadPage();}- updateFilter(data: UpdateFilterEvent) {- this.filter.mangaFormat = data.filterItem.value;+ updateFilter(data: SeriesFilter) {+ this.filter = data;if (this.pagination !== undefined && this.pagination !== null) {this.pagination.currentPage = 1;this.onPageChange(this.pagination);diff --git a/UI/Web/src/app/person-badge/person-badge.component.html b/UI/Web/src/app/person-badge/person-badge.component.htmldeleted file mode 100644index 31b2b84bb..000000000--- a/UI/Web/src/app/person-badge/person-badge.component.html+++ /dev/null@@ -1,12 +0,0 @@-<div class="badge">- <!-- Put a person image container here -->- <div class="img">-- </div>- <div class="">- <ng-content select="[name]"></ng-content>- <div style="font-size: 12px">- <ng-content select="[role]"></ng-content>- </div>- </div>-</div>diff --git a/UI/Web/src/app/person-role.pipe.ts b/UI/Web/src/app/person-role.pipe.tsnew file mode 100644index 000000000..69190fcf6--- /dev/null+++ b/UI/Web/src/app/person-role.pipe.ts@@ -0,0 +1,26 @@+import { Pipe, PipeTransform } from '@angular/core';+import { PersonRole } from './_models/person';++@Pipe({+ name: 'personRole'+})+export class PersonRolePipe implements PipeTransform {++ transform(value: PersonRole): string {+ switch (value) {+ case PersonRole.Artist: return 'Artist';+ case PersonRole.Character: return 'Character';+ case PersonRole.Colorist: return 'Colorist';+ case PersonRole.CoverArtist: return 'CoverArtist';+ case PersonRole.Editor: return 'Editor';+ case PersonRole.Inker: return 'Inker';+ case PersonRole.Letterer: return 'Letterer';+ case PersonRole.Penciller: return 'Penciller';+ case PersonRole.Publisher: return 'Publisher';+ case PersonRole.Writer: return 'Writer';+ case PersonRole.Other: return '';+ default: return '';+ }+ }++}diff --git a/UI/Web/src/app/publication-status.pipe.ts b/UI/Web/src/app/publication-status.pipe.tsnew file mode 100644index 000000000..6aa7516ca--- /dev/null+++ b/UI/Web/src/app/publication-status.pipe.ts@@ -0,0 +1,19 @@+import { Pipe, PipeTransform } from '@angular/core';+import { PublicationStatus } from './_models/metadata/publication-status';++@Pipe({+ name: 'publicationStatus'+})+export class PublicationStatusPipe implements PipeTransform {++ transform(value: PublicationStatus): string {+ switch (value) {+ case PublicationStatus.OnGoing: return 'On Going';+ case PublicationStatus.Hiatus: return 'Hiatus';+ case PublicationStatus.Completed: return 'Completed';++ default: return '';+ }+ }++}diff --git a/UI/Web/src/app/reading-list/reading-list-detail/reading-list-detail.component.ts b/UI/Web/src/app/reading-list/reading-list-detail/reading-list-detail.component.tsindex c9716bac7..dd96914cd 100644--- a/UI/Web/src/app/reading-list/reading-list-detail/reading-list-detail.component.ts+++ b/UI/Web/src/app/reading-list/reading-list-detail/reading-list-detail.component.ts@@ -157,7 +157,11 @@ export class ReadingListDetailComponent implements OnInit {removeRead() {this.isLoading = true;- this.readingListService.removeRead(this.readingList.id).subscribe(() => {+ this.readingListService.removeRead(this.readingList.id).subscribe((resp) => {+ if (resp === 'Nothing to remove') {+ this.toastr.info(resp);+ return;+ }this.getListItems();});}diff --git a/UI/Web/src/app/recently-added/recently-added.component.html b/UI/Web/src/app/recently-added/recently-added.component.htmlindex 93952f73e..71db9dbfd 100644--- a/UI/Web/src/app/recently-added/recently-added.component.html+++ b/UI/Web/src/app/recently-added/recently-added.component.html@@ -3,8 +3,8 @@[isLoading]="isLoading"[items]="series"[pagination]="pagination"-[filters]="filters"-(applyFilter)="updateFilter($event)"+[filterSettings]="filterSettings"+(applyFilter)="applyFilter($event)"(pageChange)="onPageChange($event)"><ng-template #cardItem let-item let-position="idx">diff --git a/UI/Web/src/app/recently-added/recently-added.component.ts b/UI/Web/src/app/recently-added/recently-added.component.tsindex 5f3164cf4..f7b6f146a 100644--- a/UI/Web/src/app/recently-added/recently-added.component.ts+++ b/UI/Web/src/app/recently-added/recently-added.component.ts@@ -4,12 +4,12 @@ import { ActivatedRoute, Router } from '@angular/router';import { Subject } from 'rxjs';import { debounceTime, take, takeUntil, takeWhile } from 'rxjs/operators';import { BulkSelectionService } from '../cards/bulk-selection.service';-import { UpdateFilterEvent } from '../cards/card-detail-layout/card-detail-layout.component';+import { FilterSettings } from '../cards/card-detail-layout/card-detail-layout.component';import { KEY_CODES } from '../shared/_services/utility.service';import { SeriesAddedEvent } from '../_models/events/series-added-event';import { Pagination } from '../_models/pagination';import { Series } from '../_models/series';-import { FilterItem, mangaFormatFilters, SeriesFilter } from '../_models/series-filter';+import { SeriesFilter } from '../_models/series-filter';import { Action } from '../_services/action-factory.service';import { ActionService } from '../_services/action.service';import { MessageHubService } from '../_services/message-hub.service';@@ -30,10 +30,8 @@ export class RecentlyAddedComponent implements OnInit, OnDestroy {pagination!: Pagination;libraryId!: number;- filters: Array<FilterItem> = mangaFormatFilters;- filter: SeriesFilter = {- mangaFormat: null- };+ filter: SeriesFilter | undefined = undefined;+ filterSettings: FilterSettings = new FilterSettings();onDestroy: Subject<void> = new Subject();@@ -44,6 +42,8 @@ export class RecentlyAddedComponent implements OnInit, OnDestroy {if (this.pagination === undefined || this.pagination === null) {this.pagination = {currentPage: 0, itemsPerPage: 30, totalItems: 0, totalPages: 1};}+ this.filterSettings.sortDisabled = true;+this.loadPage();}@@ -81,8 +81,8 @@ export class RecentlyAddedComponent implements OnInit, OnDestroy {this.loadPage();}- updateFilter(data: UpdateFilterEvent) {- this.filter.mangaFormat = data.filterItem.value;+ applyFilter(data: SeriesFilter) {+ this.filter = data;if (this.pagination !== undefined && this.pagination !== null) {this.pagination.currentPage = 1;this.onPageChange(this.pagination);diff --git a/UI/Web/src/app/register-member/register-member.component.html b/UI/Web/src/app/register-member/register-member.component.htmlindex 84a7983a8..5b757f889 100644--- a/UI/Web/src/app/register-member/register-member.component.html+++ b/UI/Web/src/app/register-member/register-member.component.html@@ -12,8 +12,12 @@</div><div class="form-group" *ngIf="registerForm.get('isAdmin')?.value || !authDisabled">- <label for="password">Password</label>- <input id="password" class="form-control" formControlName="password" type="password">+ <label for="password">Password</label> <i class="fa fa-info-circle" placement="right" [ngbTooltip]="passwordTooltip" role="button" tabindex="0"></i>+ <ng-template #passwordTooltip>+ Password must be between 6 and 32 characters in length+ </ng-template>+ <span class="sr-only" id="password-help"><ng-container [ngTemplateOutlet]="passwordTooltip"></ng-container></span>+ <input id="password" class="form-control" formControlName="password" type="password" aria-describedby="password-help"></div><div class="form-check" *ngIf="!firstTimeFlow">diff --git a/UI/Web/src/app/scroll.service.ts b/UI/Web/src/app/scroll.service.tsindex b49de4584..15e00b89d 100644--- a/UI/Web/src/app/scroll.service.ts+++ b/UI/Web/src/app/scroll.service.ts@@ -1,4 +1,4 @@-import { Injectable } from '@angular/core';+import { ElementRef, Injectable } from '@angular/core';@Injectable({providedIn: 'root'@@ -13,8 +13,8 @@ export class ScrollService {|| document.body.scrollTop || 0);}- scrollTo(top: number) {- window.scroll({+ scrollTo(top: number, el: Element | Window = window) {+ el.scroll({top: top,behavior: 'smooth'});diff --git a/UI/Web/src/app/series-detail/series-detail.component.html b/UI/Web/src/app/series-detail/series-detail.component.htmlindex a80694687..a5ec40dd4 100644--- a/UI/Web/src/app/series-detail/series-detail.component.html+++ b/UI/Web/src/app/series-detail/series-detail.component.html@@ -49,50 +49,14 @@</div></div><div class="row no-gutters">+ <!-- TODO: This will be the first of reviews section. Reviews will show your plus other peoples reviews in media cards like Plex does and this will be below metadata --><app-read-more class="user-review {{userReview ? 'mt-1' : ''}}" [text]="series?.userReview || ''" [maxLength]="250"></app-read-more></div>- <div class="row no-gutters {{series?.userReview ? '' : 'mt-2'}}">- <app-read-more [text]="seriesSummary" [maxLength]="250"></app-read-more>- </div><div *ngIf="seriesMetadata" class="mt-2">- <div class="row no-gutters" *ngIf="seriesMetadata.genres && seriesMetadata.genres.length > 0">- <div class="col-md-4">- <h5>Genres</h5>- </div>- <div class="col-md-8">- <app-tag-badge *ngFor="let genre of seriesMetadata.genres" [selectionMode]="TagBadgeCursor.Clickable">{{genre}}</app-tag-badge>- </div>- </div>- <div class="row no-gutters mt-1" *ngIf="seriesMetadata.tags && seriesMetadata.tags.length > 0">- <div class="col-md-4">- <h5>Collections</h5>- </div>- <div class="col-md-8">- <app-tag-badge *ngFor="let tag of seriesMetadata.tags" a11y-click="13,32" class="clickable" routerLink="/collections/{{tag.id}}" [selectionMode]="TagBadgeCursor.Clickable">- {{tag.title}}- </app-tag-badge>- </div>- </div>- <div class="row no-gutters mt-1" *ngIf="seriesMetadata.persons && seriesMetadata.persons.length > 0">- <div class="col-md-4">- <h5>People</h5>- </div>- <div class="col-md-8">- <app-person-badge *ngFor="let person of seriesMetadata.persons">- <div name>{{person.name}}</div>- <div role>{{person.role}}</div>- </app-person-badge>- </div>- </div>- <div class="row no-gutters mt-1" *ngIf="series.format != MangaFormat.UNKNOWN">- <div class="col-md-4">- <h5>Type</h5>- </div>- <div class="col-md-8">- <app-tag-badge [selectionMode]="TagBadgeCursor.NotAllowed"><app-series-format [format]="series.format">{{utilityService.mangaFormat(series.format)}}</app-series-format></app-tag-badge>- </div>- </div>+ <app-series-metadata-detail [seriesMetadata]="seriesMetadata" [series]="series"></app-series-metadata-detail></div>++</div></div>@@ -116,12 +80,12 @@<ng-template ngbNavContent><div class="row no-gutters"><div *ngFor="let volume of volumes; let idx = index; trackBy: trackByVolumeIdentity">- <app-card-item class="col-auto" *ngIf="volume.number != 0" [entity]="volume" [title]="'Volume ' + volume.name" (click)="openVolume(volume)"+ <app-card-item class="col-auto" *ngIf="volume.number != 0" [entity]="volume" [title]="formatVolumeTitle(volume)" (click)="openVolume(volume)"[imageUrl]="imageService.getVolumeCoverImage(volume.id) + '&offset=' + coverImageOffset"[read]="volume.pagesRead" [total]="volume.pages" [actions]="volumeActions" (selection)="bulkSelectionService.handleCardSelection('volume', idx, volumes.length, $event)" [selected]="bulkSelectionService.isCardSelected('volume', idx)" [allowSelection]="true"></app-card-item></div><div *ngFor="let chapter of chapters; let idx = index; trackBy: trackByChapterIdentity">- <app-card-item class="col-auto" *ngIf="!chapter.isSpecial" [entity]="chapter" [title]="utilityService.formatChapterName(libraryType, true, true) + chapter.range" (click)="openChapter(chapter)"+ <app-card-item class="col-auto" *ngIf="!chapter.isSpecial" [entity]="chapter" [title]="formatChapterTitle(chapter)" (click)="openChapter(chapter)"[imageUrl]="imageService.getChapterCoverImage(chapter.id) + '&offset=' + coverImageOffset"[read]="chapter.pagesRead" [total]="chapter.pages" [actions]="chapterActions" (selection)="bulkSelectionService.handleCardSelection('chapter', idx, chapters.length, $event)" [selected]="bulkSelectionService.isCardSelected('chapter', idx)" [allowSelection]="true"></app-card-item></div>diff --git a/UI/Web/src/app/series-detail/series-detail.component.ts b/UI/Web/src/app/series-detail/series-detail.component.tsindex 356d99657..42319c549 100644--- a/UI/Web/src/app/series-detail/series-detail.component.ts+++ b/UI/Web/src/app/series-detail/series-detail.component.ts@@ -3,7 +3,7 @@ import { Title } from '@angular/platform-browser';import { ActivatedRoute, Router } from '@angular/router';import { NgbModal, NgbRatingConfig } from '@ng-bootstrap/ng-bootstrap';import { ToastrService } from 'ngx-toastr';-import { Subject } from 'rxjs';+import { forkJoin, Subject } from 'rxjs';import { finalize, take, takeUntil, takeWhile } from 'rxjs/operators';import { BulkSelectionService } from '../cards/bulk-selection.service';import { CardDetailsModalComponent } from '../cards/_modals/card-details-modal/card-details-modal.component';@@ -15,6 +15,7 @@ import { DownloadService } from '../shared/_services/download.service';import { KEY_CODES, UtilityService } from '../shared/_services/utility.service';import { ReviewSeriesModalComponent } from '../_modals/review-series-modal/review-series-modal.component';import { Chapter } from '../_models/chapter';+import { RefreshMetadataEvent } from '../_models/events/refresh-metadata-event';import { ScanSeriesEvent } from '../_models/events/scan-series-event';import { SeriesRemovedEvent } from '../_models/events/series-removed-event';import { LibraryType } from '../_models/library';@@ -62,7 +63,6 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {activeTabId = 2;hasNonSpecialVolumeChapters = true;- seriesSummary: string = '';userReview: string = '';libraryType: LibraryType = LibraryType.Manga;seriesMetadata: SeriesMetadata | null = null;@@ -147,7 +147,7 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {}constructor(private route: ActivatedRoute, private seriesService: SeriesService,- private ratingConfig: NgbRatingConfig, private router: Router,+ private router: Router, public bulkSelectionService: BulkSelectionService,private modalService: NgbModal, public readerService: ReaderService,public utilityService: UtilityService, private toastr: ToastrService,private accountService: AccountService, public imageService: ImageService,@@ -155,8 +155,7 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {private confirmService: ConfirmService, private titleService: Title,private downloadService: DownloadService, private actionService: ActionService,public imageSerivce: ImageService, private messageHub: MessageHubService,- public bulkSelectionService: BulkSelectionService) {- ratingConfig.max = 5;+ ) {this.router.routeReuseStrategy.shouldReuseRoute = () => false;this.accountService.currentUser$.pipe(take(1)).subscribe(user => {if (user) {@@ -188,16 +187,21 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {this.toastr.info('This series no longer exists');this.router.navigateByUrl('/libraries');}+ } else if (event.event === EVENTS.RefreshMetadata) {+ const seriesRemovedEvent = event.payload as RefreshMetadataEvent;+ if (seriesRemovedEvent.seriesId === this.series.id) {+ this.seriesService.getMetadata(this.series.id).pipe(take(1)).subscribe(metadata => {+ this.seriesMetadata = metadata;+ this.createHTML();+ })+ }}});const seriesId = parseInt(routeId, 10);this.libraryId = parseInt(libraryId, 10);this.seriesImage = this.imageService.getSeriesCoverImage(seriesId);- this.libraryService.getLibraryType(this.libraryId).subscribe(type => {- this.libraryType = type;- this.loadSeries(seriesId);- });+ this.loadSeries(seriesId);}ngOnDestroy() {@@ -249,6 +253,9 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {case(Action.AddToReadingList):this.actionService.addSeriesToReadingList(series, () => this.actionInProgress = false);break;+ case(Action.AddToCollection):+ this.actionService.addMultipleSeriesToCollectionTag([series], () => this.actionInProgress = false);+ break;default:break;}@@ -302,17 +309,11 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {async deleteSeries(series: Series) {- if (!await this.confirmService.confirm('Are you sure you want to delete this series? It will not modify files on disk.')) {+ this.actionService.deleteSeries(series, (result: boolean) => {this.actionInProgress = false;- return;- }-- this.seriesService.delete(series.id).subscribe((res: boolean) => {- if (res) {- this.toastr.success('Series deleted');+ if (result) {this.router.navigate(['library', this.libraryId]);}- this.actionInProgress = false;});}@@ -334,11 +335,16 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {loadSeries(seriesId: number) {this.coverImageOffset = 0;- this.seriesService.getMetadata(seriesId).subscribe(metadata => {- this.seriesMetadata = metadata;- });- this.seriesService.getSeries(seriesId).subscribe(series => {- this.series = series;++ forkJoin([+ this.libraryService.getLibraryType(this.libraryId),+ this.seriesService.getMetadata(seriesId),+ this.seriesService.getSeries(seriesId)+ ]).subscribe(results => {+ this.libraryType = results[0];+ this.seriesMetadata = results[1];+ this.series = results[2];+this.createHTML();this.titleService.setTitle('Kavita - ' + this.series.name + ' Details');@@ -387,7 +393,6 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {}createHTML() {- this.seriesSummary = (this.series.summary === null ? '' : this.series.summary).replace(/\n/g, '<br>');this.userReview = (this.series.userReview === null ? '' : this.series.userReview).replace(/\n/g, '<br>');}@@ -572,4 +577,12 @@ export class SeriesDetailComponent implements OnInit, OnDestroy {})).subscribe(() => {/* No Operation */});;});}++ formatChapterTitle(chapter: Chapter) {+ return this.utilityService.formatChapterName(this.libraryType, true, true) + chapter.range;+ }++ formatVolumeTitle(volume: Volume) {+ return 'Volume ' + volume.name;+ }}diff --git a/UI/Web/src/app/series-metadata-detail/series-metadata-detail.component.html b/UI/Web/src/app/series-metadata-detail/series-metadata-detail.component.htmlnew file mode 100644index 000000000..4969261a5--- /dev/null+++ b/UI/Web/src/app/series-metadata-detail/series-metadata-detail.component.html@@ -0,0 +1,192 @@+<div class="row no-gutters mt-2 mb-2">+ <app-read-more [text]="seriesSummary" [maxLength]="250"></app-read-more>+</div>++<!-- This first row will have random information about the series-->+<div class="row no-gutters mb-2">+ <app-tag-badge title="Age Rating" *ngIf="seriesMetadata.ageRating" a11y-click="13,32" class="clickable" (click)="goTo('ageRating', seriesMetadata.ageRating)" [selectionMode]="TagBadgeCursor.Clickable">{{metadataService.getAgeRating(this.seriesMetadata.ageRating) | async}}</app-tag-badge>+ <ng-container *ngIf="series">+ <!-- Maybe we can put the library this resides in to make it easier to get back -->+ <!-- tooltip here explaining how this is year of first issue -->+ <app-tag-badge *ngIf="seriesMetadata.releaseYear > 0" title="Release date">{{seriesMetadata.releaseYear}}</app-tag-badge>+ <app-tag-badge *ngIf="seriesMetadata.language !== null && seriesMetadata.language !== ''" title="Language" a11y-click="13,32" class="clickable" (click)="goTo('languages', seriesMetadata.language)" [selectionMode]="TagBadgeCursor.Clickable">{{seriesMetadata.language}}</app-tag-badge>+ <app-tag-badge title="Publication Status" a11y-click="13,32" class="clickable" (click)="goTo('publicationStatus', seriesMetadata.publicationStatus)" [selectionMode]="TagBadgeCursor.Clickable">{{seriesMetadata.publicationStatus | publicationStatus}}</app-tag-badge>+ <app-tag-badge a11y-click="13,32" class="clickable" (click)="goTo('format', series.format)" [selectionMode]="TagBadgeCursor.Clickable">+ <app-series-format [format]="series.format">{{utilityService.mangaFormat(series.format)}}</app-series-format>+ </app-tag-badge>+ </ng-container>+</div>++<div class="row no-gutters" *ngIf="seriesMetadata.genres && seriesMetadata.genres.length > 0">+ <div class="col-md-4">+ <h5>Genres</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.genres">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-tag-badge a11y-click="13,32" class="clickable" (click)="goTo('genres', item.id)" [selectionMode]="TagBadgeCursor.Clickable">{{item.title}}</app-tag-badge>+ </ng-template>+ </app-badge-expander>+ </div>+</div>+<div class="row no-gutters mt-1" *ngIf="seriesMetadata.collectionTags && seriesMetadata.collectionTags.length > 0">+ <div class="col-md-4">+ <h5>Collections</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.collectionTags">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-tag-badge a11y-click="13,32" class="clickable" routerLink="/collections/{{item.id}}" [selectionMode]="TagBadgeCursor.Clickable">+ {{item.title}}+ </app-tag-badge>+ </ng-template>+ </app-badge-expander>+ </div>+</div>+<div class="row no-gutters mt-1" *ngIf="seriesMetadata.writers && seriesMetadata.writers.length > 0">+ <div class="col-md-4">+ <h5>Writers/Authors</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.writers">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-person-badge a11y-click="13,32" class="clickable" (click)="goTo('writers', item.id)" [person]="item"></app-person-badge>+ </ng-template>+ </app-badge-expander>+ </div>+</div>++<div class="row no-gutters">+ <hr class="col-md-11" *ngIf="hasExtendedProperites" >+ <a [class.hidden]="hasExtendedProperites" *ngIf="hasExtendedProperites" class="col-md-1 read-more-link" (click)="toggleView()"> <i aria-hidden="true" class="fa fa-caret-{{isCollapsed ? 'down' : 'up'}}" aria-controls="extended-series-metadata"></i> See {{isCollapsed ? 'More' : 'Less'}}</a>+</div>++<div #collapse="ngbCollapse" [(ngbCollapse)]="isCollapsed" id="extended-series-metadata">+ <div class="row no-gutters mt-1" *ngIf="seriesMetadata.coverArtists && seriesMetadata.coverArtists.length > 0">+ <div class="col-md-4">+ <h5>Cover Artists</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.coverArtists">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-person-badge a11y-click="13,32" class="clickable" (click)="goTo('coverArtists', item.id)" [person]="item"></app-person-badge>+ </ng-template>+ </app-badge-expander>+ </div>+ </div>++ <div class="row no-gutters mt-1" *ngIf="seriesMetadata.characters && seriesMetadata.characters.length > 0">+ <div class="col-md-4">+ <h5>Characters</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.characters">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-person-badge a11y-click="13,32" class="clickable" (click)="goTo('character', item.id)" [person]="item"></app-person-badge>+ </ng-template>+ </app-badge-expander>+ </div>+ </div>++ <div class="row no-gutters mt-1" *ngIf="seriesMetadata.colorists && seriesMetadata.colorists.length > 0">+ <div class="col-md-4">+ <h5>Colorists</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.colorists">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-person-badge a11y-click="13,32" class="clickable" (click)="goTo('colorist', item.id)" [person]="item"></app-person-badge>+ </ng-template>+ </app-badge-expander>+ </div>+ </div>++ <div class="row no-gutters mt-1" *ngIf="seriesMetadata.editors && seriesMetadata.editors.length > 0">+ <div class="col-md-4">+ <h5>Editors</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.editors">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-person-badge a11y-click="13,32" class="clickable" (click)="goTo('editor', item.id)" [person]="item"></app-person-badge>+ </ng-template>+ </app-badge-expander>+ </div>+ </div>++ <div class="row no-gutters mt-1" *ngIf="seriesMetadata.inkers && seriesMetadata.inkers.length > 0">+ <div class="col-md-4">+ <h5>Inkers</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.inkers">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-person-badge a11y-click="13,32" class="clickable" (click)="goTo('inker', item.id)" [person]="item"></app-person-badge>+ </ng-template>+ </app-badge-expander>+ </div>+ </div>++ <div class="row no-gutters mt-1" *ngIf="seriesMetadata.letterers && seriesMetadata.letterers.length > 0">+ <div class="col-md-4">+ <h5>Letterers</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.letterers">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-person-badge a11y-click="13,32" class="clickable" (click)="goTo('letterer', item.id)" [person]="item"></app-person-badge>+ </ng-template>+ </app-badge-expander>+ </div>+ </div>+ <div class="row no-gutters" *ngIf="seriesMetadata.tags && seriesMetadata.tags.length > 0">+ <div class="col-md-4">+ <h5>Tags</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.tags">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-tag-badge a11y-click="13,32" class="clickable" (click)="goTo('tags', item.id)" [selectionMode]="TagBadgeCursor.Clickable">{{item.title}}</app-tag-badge>+ </ng-template>+ </app-badge-expander>+ </div>+ </div>+ <div class="row no-gutters mt-1" *ngIf="seriesMetadata.translators && seriesMetadata.translators.length > 0">+ <div class="col-md-4">+ <h5>Translators</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.translators">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-person-badge a11y-click="13,32" class="clickable" (click)="goTo('translators', item.id)" [person]="item"></app-person-badge>+ </ng-template>+ </app-badge-expander>+ </div>+ </div>++ <div class="row no-gutters mt-1" *ngIf="seriesMetadata.pencillers && seriesMetadata.pencillers.length > 0">+ <div class="col-md-4">+ <h5>Pencillers</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.pencillers">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-person-badge a11y-click="13,32" class="clickable" (click)="goTo('penciller', item.id)" [person]="item"></app-person-badge>+ </ng-template>+ </app-badge-expander>+ </div>+ </div>++ <div class="row no-gutters mt-1" *ngIf="seriesMetadata.publishers && seriesMetadata.publishers.length > 0">+ <div class="col-md-4">+ <h5>Publishers</h5>+ </div>+ <div class="col-md-8">+ <app-badge-expander [items]="seriesMetadata.publishers">+ <ng-template #badgeExpanderItem let-item let-position="idx">+ <app-person-badge a11y-click="13,32" class="clickable" (click)="goTo('publisher', item.id)" [person]="item"></app-person-badge>+ </ng-template>+ </app-badge-expander>+ </div>+ </div>+</div>\ No newline at end of filediff --git a/UI/Web/src/app/series-metadata-detail/series-metadata-detail.component.scss b/UI/Web/src/app/series-metadata-detail/series-metadata-detail.component.scssnew file mode 100644index 000000000..ec1ed15b0--- /dev/null+++ b/UI/Web/src/app/series-metadata-detail/series-metadata-detail.component.scss@@ -0,0 +1,6 @@+.read-more-link {+ font-weight: bold;+ text-decoration: none;+ color: black;+ cursor: pointer;+}\ No newline at end of filediff --git a/UI/Web/src/app/series-metadata-detail/series-metadata-detail.component.ts b/UI/Web/src/app/series-metadata-detail/series-metadata-detail.component.tsnew file mode 100644index 000000000..d5e4fd8fc--- /dev/null+++ b/UI/Web/src/app/series-metadata-detail/series-metadata-detail.component.ts@@ -0,0 +1,69 @@+import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';+import { Router } from '@angular/router';+import { TagBadgeCursor } from '../shared/tag-badge/tag-badge.component';+import { UtilityService } from '../shared/_services/utility.service';+import { MangaFormat } from '../_models/manga-format';+import { Series } from '../_models/series';+import { SeriesMetadata } from '../_models/series-metadata';+import { MetadataService } from '../_services/metadata.service';++@Component({+ selector: 'app-series-metadata-detail',+ templateUrl: './series-metadata-detail.component.html',+ styleUrls: ['./series-metadata-detail.component.scss']+})+export class SeriesMetadataDetailComponent implements OnInit, OnChanges {++ @Input() seriesMetadata!: SeriesMetadata;+ @Input() series!: Series;++ isCollapsed: boolean = true;+ hasExtendedProperites: boolean = false;++ /**+ * Html representation of Series Summary+ */+ seriesSummary: string = '';++ get MangaFormat(): typeof MangaFormat {+ return MangaFormat;+ }++ get TagBadgeCursor(): typeof TagBadgeCursor {+ return TagBadgeCursor;+ }++ constructor(public utilityService: UtilityService, public metadataService: MetadataService, private router: Router) { }++ ngOnChanges(changes: SimpleChanges): void {+ this.hasExtendedProperites = this.seriesMetadata.colorists.length > 0 ||+ this.seriesMetadata.editors.length > 0 ||+ this.seriesMetadata.coverArtists.length > 0 ||+ this.seriesMetadata.inkers.length > 0 ||+ this.seriesMetadata.letterers.length > 0 ||+ this.seriesMetadata.pencillers.length > 0 ||+ this.seriesMetadata.publishers.length > 0 ||+ this.seriesMetadata.translators.length > 0 ||+ this.seriesMetadata.tags.length > 0;++ if (this.seriesMetadata !== null) {+ this.seriesSummary = (this.seriesMetadata.summary === null ? '' : this.seriesMetadata.summary).replace(/\n/g, '<br>');+ }++ }++ ngOnInit(): void {+ }++ toggleView() {+ this.isCollapsed = !this.isCollapsed;+ }++ goTo(queryParamName: string, filter: any) {+ let params: any = {};+ params[queryParamName] = filter;+ params['page'] = 1;+ this.router.navigate(['library', this.series.libraryId], {queryParams: params});+ }++}diff --git a/UI/Web/src/app/shared/_services/utility.service.ts b/UI/Web/src/app/shared/_services/utility.service.tsindex 18a7098cc..7712ec509 100644--- a/UI/Web/src/app/shared/_services/utility.service.ts+++ b/UI/Web/src/app/shared/_services/utility.service.ts@@ -1,8 +1,12 @@import { Injectable } from '@angular/core';+import { ActivatedRouteSnapshot } from '@angular/router';+import { FilterSettings } from 'src/app/cards/card-detail-layout/card-detail-layout.component';import { Chapter } from 'src/app/_models/chapter';import { LibraryType } from 'src/app/_models/library';import { MangaFormat } from 'src/app/_models/manga-format';+import { AgeRating } from 'src/app/_models/metadata/age-rating';import { Series } from 'src/app/_models/series';+import { SeriesFilter } from 'src/app/_models/series-filter';import { Volume } from 'src/app/_models/volume';export enum KEY_CODES {@@ -87,6 +91,122 @@ export class UtilityService {return cleaned;}+ filter(input: string, filter: string): boolean {+ if (input === null || filter === null) return false;+ const reg = /[_\.\-]/gi;+ return input.toUpperCase().replace(reg, '').includes(filter.toUpperCase().replace(reg, ''));+ }++ /**+ * Returns a new instance of a filterSettings that is populated with filter presets from URL+ * @param snapshot+ * @param blankFilter Filter to start with+ * @returns The Preset filter and if something was set within+ */+ filterPresetsFromUrl(snapshot: ActivatedRouteSnapshot, blankFilter: SeriesFilter): [SeriesFilter, boolean] {+ const filter = Object.assign({}, blankFilter);+ let anyChanged = false;++ const format = snapshot.queryParamMap.get('format');+ if (format !== undefined && format !== null) {+ filter.formats = [...filter.formats, ...format.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const genres = snapshot.queryParamMap.get('genres');+ if (genres !== undefined && genres !== null) {+ filter.genres = [...filter.genres, ...genres.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const ageRating = snapshot.queryParamMap.get('ageRating');+ if (ageRating !== undefined && ageRating !== null) {+ filter.ageRating = [...filter.ageRating, ...ageRating.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const publicationStatus = snapshot.queryParamMap.get('publicationStatus');+ if (publicationStatus !== undefined && publicationStatus !== null) {+ filter.publicationStatus = [...filter.publicationStatus, ...publicationStatus.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const tags = snapshot.queryParamMap.get('tags');+ if (tags !== undefined && tags !== null) {+ filter.tags = [...filter.tags, ...tags.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const languages = snapshot.queryParamMap.get('languages');+ if (languages !== undefined && languages !== null) {+ filter.languages = [...filter.languages, ...languages.split(',')];+ anyChanged = true;+ }++ const writers = snapshot.queryParamMap.get('writers');+ if (writers !== undefined && writers !== null) {+ filter.writers = [...filter.writers, ...writers.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const character = snapshot.queryParamMap.get('character');+ if (character !== undefined && character !== null) {+ filter.character = [...filter.character, ...character.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const colorist = snapshot.queryParamMap.get('colorist');+ if (colorist !== undefined && colorist !== null) {+ filter.colorist = [...filter.colorist, ...colorist.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const coverArtists = snapshot.queryParamMap.get('coverArtists');+ if (coverArtists !== undefined && coverArtists !== null) {+ filter.coverArtist = [...filter.coverArtist, ...coverArtists.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const editor = snapshot.queryParamMap.get('editor');+ if (editor !== undefined && editor !== null) {+ filter.editor = [...filter.editor, ...editor.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const inker = snapshot.queryParamMap.get('inker');+ if (inker !== undefined && inker !== null) {+ filter.inker = [...filter.inker, ...inker.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const letterer = snapshot.queryParamMap.get('letterer');+ if (letterer !== undefined && letterer !== null) {+ filter.letterer = [...filter.letterer, ...letterer.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const penciller = snapshot.queryParamMap.get('penciller');+ if (penciller !== undefined && penciller !== null) {+ filter.penciller = [...filter.penciller, ...penciller.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const publisher = snapshot.queryParamMap.get('publisher');+ if (publisher !== undefined && publisher !== null) {+ filter.publisher = [...filter.publisher, ...publisher.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }++ const translators = snapshot.queryParamMap.get('translators');+ if (translators !== undefined && translators !== null) {+ filter.translators = [...filter.translators, ...translators.split(',').map(item => parseInt(item, 10))];+ anyChanged = true;+ }+++ return [filter, anyChanged];+ }+mangaFormat(format: MangaFormat): string {switch (format) {case MangaFormat.EPUB:diff --git a/UI/Web/src/app/shared/badge-expander/badge-expander.component.html b/UI/Web/src/app/shared/badge-expander/badge-expander.component.htmlnew file mode 100644index 000000000..c17188530--- /dev/null+++ b/UI/Web/src/app/shared/badge-expander/badge-expander.component.html@@ -0,0 +1,8 @@+<div class="badge-expander">+ <div class="content">+ <ng-container *ngFor="let item of visibleItems; index as i;" [ngTemplateOutlet]="itemTemplate" [ngTemplateOutletContext]="{ $implicit: item, idx: i }"></ng-container>+ <button type="button" *ngIf="!isCollapsed && itemsLeft !== 0" class="btn btn-outline-primary" (click)="toggleVisible()" [attr.aria-expanded]="!isCollapsed">+ and {{itemsLeft}} more+ </button>+ </div>+</div>\ No newline at end of filediff --git a/UI/Web/src/app/shared/badge-expander/badge-expander.component.scss b/UI/Web/src/app/shared/badge-expander/badge-expander.component.scssnew file mode 100644index 000000000..8ed3de4f4--- /dev/null+++ b/UI/Web/src/app/shared/badge-expander/badge-expander.component.scss@@ -0,0 +1,12 @@+.content {+ width: 100%;+}++.collapsed {+ height: 35px;+ overflow: hidden;+}++.badge-expander {+ //display: inline-block;+}\ No newline at end of filediff --git a/UI/Web/src/app/shared/badge-expander/badge-expander.component.ts b/UI/Web/src/app/shared/badge-expander/badge-expander.component.tsnew file mode 100644index 000000000..3f4ddbcb4--- /dev/null+++ b/UI/Web/src/app/shared/badge-expander/badge-expander.component.ts@@ -0,0 +1,32 @@+import { Component, ContentChild, Input, OnInit, TemplateRef } from '@angular/core';++@Component({+ selector: 'app-badge-expander',+ templateUrl: './badge-expander.component.html',+ styleUrls: ['./badge-expander.component.scss']+})+export class BadgeExpanderComponent implements OnInit {++ @Input() items: Array<any> = [];+ @ContentChild('badgeExpanderItem') itemTemplate!: TemplateRef<any>;+++ visibleItems: Array<any> = [];+ isCollapsed: boolean = false;++ get itemsLeft() {+ return Math.max(this.items.length - 4, 0);+ }+ constructor() { }++ ngOnInit(): void {+ this.visibleItems = this.items.slice(0, 4);+ }++ toggleVisible() {+ this.isCollapsed = !this.isCollapsed;++ this.visibleItems = this.items;+ }++}diff --git a/UI/Web/src/app/shared/person-badge/person-badge.component.html b/UI/Web/src/app/shared/person-badge/person-badge.component.htmlnew file mode 100644index 000000000..6506ef49a--- /dev/null+++ b/UI/Web/src/app/shared/person-badge/person-badge.component.html@@ -0,0 +1,9 @@+<div class="tagbadge cursor clickable" style="cursor: pointer;">+ <div class="media">+ <!-- <img src="..." class="align-self-center mr-3" alt="..."> -->+ <i class="fa fa-user-circle align-self-center mr-2" aria-hidden="true"></i>+ <div class="media-body">+ <span class="mt-0 mb-0">{{person.name}}</span>+ </div>+ </div>+</div>\ No newline at end of filediff --git a/UI/Web/src/app/person-badge/person-badge.component.scss b/UI/Web/src/app/shared/person-badge/person-badge.component.scsssimilarity index 76%rename from UI/Web/src/app/person-badge/person-badge.component.scssrename to UI/Web/src/app/shared/person-badge/person-badge.component.scssindex c3c50f725..a78488384 100644--- a/UI/Web/src/app/person-badge/person-badge.component.scss+++ b/UI/Web/src/app/shared/person-badge/person-badge.component.scss@@ -1,10 +1,10 @@-@import '../../theme/colors';+@use '../../../theme/colors';$bg-color: #c9c9c9;$bdr-color: #f2f2f2;-::ng-deep .badge {- background-color: $bg-color;+.badge {+ //background-color: $bg-color;transition: all .3s ease-out;margin: 3px 5px 3px 0px;padding: 2px 15px;@@ -14,11 +14,11 @@ $bdr-color: #f2f2f2;display: inline-block;i {- color: $primary-color;+ color: colors.$primary-color;font-size: 14px;font-weight: bold;margin-left: 10px;margin-right: 0px;cursor: pointer;}-}\ No newline at end of file+}diff --git a/UI/Web/src/app/person-badge/person-badge.component.ts b/UI/Web/src/app/shared/person-badge/person-badge.component.tssimilarity index 64%rename from UI/Web/src/app/person-badge/person-badge.component.tsrename to UI/Web/src/app/shared/person-badge/person-badge.component.tsindex a91c513b6..591b9e3a3 100644--- a/UI/Web/src/app/person-badge/person-badge.component.ts+++ b/UI/Web/src/app/shared/person-badge/person-badge.component.ts@@ -1,4 +1,5 @@-import { Component, OnInit } from '@angular/core';+import { Component, Input, OnInit } from '@angular/core';+import { Person } from '../../_models/person';@Component({selector: 'app-person-badge',@@ -7,6 +8,9 @@ import { Component, OnInit } from '@angular/core';})export class PersonBadgeComponent implements OnInit {+ @Input() person!: Person;++constructor() { }ngOnInit(): void {diff --git a/UI/Web/src/app/shared/shared.module.ts b/UI/Web/src/app/shared/shared.module.tsindex efd0dc009..6ae54f582 100644--- a/UI/Web/src/app/shared/shared.module.ts+++ b/UI/Web/src/app/shared/shared.module.ts@@ -1,7 +1,7 @@import { NgModule } from '@angular/core';import { CommonModule } from '@angular/common';import { ReactiveFormsModule } from '@angular/forms';-import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap';+import { NgbCollapseModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';import { ConfirmDialogComponent } from './confirm-dialog/confirm-dialog.component';import { SafeHtmlPipe } from './safe-html.pipe';import { RegisterMemberComponent } from '../register-member/register-member.component';@@ -16,6 +16,8 @@ import { UpdateNotificationModalComponent } from './update-notification/update-nimport { CircularLoaderComponent } from './circular-loader/circular-loader.component';import { NgCircleProgressModule } from 'ng-circle-progress';import { SentenceCasePipe } from './sentence-case.pipe';+import { PersonBadgeComponent } from './person-badge/person-badge.component';+import { BadgeExpanderComponent } from './badge-expander/badge-expander.component';@NgModule({declarations: [@@ -31,12 +33,15 @@ import { SentenceCasePipe } from './sentence-case.pipe';UpdateNotificationModalComponent,CircularLoaderComponent,SentenceCasePipe,+ PersonBadgeComponent,+ BadgeExpanderComponent],imports: [CommonModule,RouterModule,ReactiveFormsModule,NgbCollapseModule,+ NgbTooltipModule, // RegisterMemberComponentNgCircleProgressModule.forRoot(),],exports: [@@ -52,6 +57,8 @@ import { SentenceCasePipe } from './sentence-case.pipe';SeriesFormatComponent,TagBadgeComponent,CircularLoaderComponent,+ PersonBadgeComponent,+ BadgeExpanderComponent],})export class SharedModule { }diff --git a/UI/Web/src/app/typeahead/typeahead.component.html b/UI/Web/src/app/typeahead/typeahead.component.htmlindex 41b06ec5d..e14019981 100644--- a/UI/Web/src/app/typeahead/typeahead.component.html+++ b/UI/Web/src/app/typeahead/typeahead.component.html@@ -1,7 +1,5 @@<form [formGroup]="typeaheadForm"><ng-container *ngIf="settings.multiple" >--<div class="typeahead-input" (click)="onInputFocus($event)"><div><app-tag-badge *ngFor="let option of optionSelection.selected(); let i = index">@@ -13,6 +11,7 @@<div class="spinner-border spinner-border-sm" role="status" *ngIf="isLoadingOptions"><span class="sr-only">Loading...</span></div>+ <!-- TODO: Add a clear all button --></div></div><div class="dropdown" *ngIf="hasFocus">diff --git a/UI/Web/src/app/typeahead/typeahead.component.scss b/UI/Web/src/app/typeahead/typeahead.component.scssindex 5372c19ef..40b9b8132 100644--- a/UI/Web/src/app/typeahead/typeahead.component.scss+++ b/UI/Web/src/app/typeahead/typeahead.component.scss@@ -1,4 +1,4 @@-@import "../../theme/colors";+@use "../../theme/colors";input {width: 15px;@@ -35,16 +35,19 @@ input {line-height: inherit !important;box-shadow: none !important;}+ input:empty {+ padding-top: 6px !important;+ }}::ng-deep .bg-dark .typeahead-input {color: #efefef;- background-color: $dark-bg-color;+ background-color: colors.$dark-bg-color;}// Causes bleedover::ng-deep .bg-dark .dropdown .list-group-item.active {- background-color: $dark-hover-color;+ background-color: colors.$dark-hover-color;}.dropdown {@@ -62,7 +65,7 @@ input {overflow-x: hidden;.list-group-item {- padding: 5px 5px;+ padding: 5px 10px;}diff --git a/UI/Web/src/app/typeahead/typeahead.component.ts b/UI/Web/src/app/typeahead/typeahead.component.tsindex c2db8ef7d..d26912044 100644--- a/UI/Web/src/app/typeahead/typeahead.component.ts+++ b/UI/Web/src/app/typeahead/typeahead.component.ts@@ -1,6 +1,6 @@import { Component, ContentChild, ElementRef, EventEmitter, HostListener, Input, OnDestroy, OnInit, Output, Renderer2, RendererStyleFlags2, TemplateRef, ViewChild } from '@angular/core';import { FormControl, FormGroup } from '@angular/forms';-import { Observable, of, Subject } from 'rxjs';+import { Observable, of, ReplaySubject, Subject } from 'rxjs';import { debounceTime, filter, map, shareReplay, switchMap, take, takeUntil, tap } from 'rxjs/operators';import { KEY_CODES } from '../shared/_services/utility.service';import { TypeaheadSettings } from './typeahead-settings';@@ -143,6 +143,10 @@ export class TypeaheadComponent implements OnInit, OnDestroy {@Input() settings!: TypeaheadSettings<any>;+ /**+ * When true, component will re-init and set back to false.+ */+ @Input() reset: Subject<boolean> = new ReplaySubject(1);@Output() selectedData = new EventEmitter<any[] | any>();@Output() newItemAdded = new EventEmitter<any[] | any>();@@ -167,6 +171,14 @@ export class TypeaheadComponent implements OnInit, OnDestroy {ngOnInit() {+ this.reset.pipe(takeUntil(this.onDestroy)).subscribe((reset: boolean) => {+ this.init();+ });++ this.init();+ }++ init() {if (this.settings.compareFn === undefined && this.settings.multiple) {console.error('A compare function must be defined');return;@@ -242,7 +254,7 @@ export class TypeaheadComponent implements OnInit, OnDestroy {@HostListener('window:click', ['$event'])- handleDocumentClick() {+ handleDocumentClick(event: any) {this.hasFocus = false;}@@ -358,6 +370,8 @@ export class TypeaheadComponent implements OnInit, OnDestroy {}if (this.inputElem) {+ // hack: To prevent multiple typeaheads from being open at once, click document then trigger the focus+ document.querySelector('body')?.click();this.inputElem.nativeElement.focus();this.hasFocus = true;}diff --git a/UI/Web/src/app/user-settings/user-preferences/user-preferences.component.html b/UI/Web/src/app/user-settings/user-preferences/user-preferences.component.htmlindex 2da355765..b336ae534 100644--- a/UI/Web/src/app/user-settings/user-preferences/user-preferences.component.html+++ b/UI/Web/src/app/user-settings/user-preferences/user-preferences.component.html@@ -2,7 +2,7 @@<h2>User Dashboard</h2><ul ngbNav #nav="ngbNav" [(activeId)]="active" class="nav-tabs nav-pills"><li *ngFor="let tab of tabs" [ngbNavItem]="tab">- <a ngbNavLink routerLink="." [fragment]="tab.fragment">{{ tab.title | titlecase }}</a>+ <a ngbNavLink routerLink="." [fragment]="tab.fragment">{{ tab.title | sentenceCase }}</a><ng-template ngbNavContent><ng-container *ngIf="tab.fragment === ''"><p>@@ -48,40 +48,48 @@</ng-template><ng-template ngbPanelContent><form [formGroup]="settingsForm" *ngIf="user !== undefined">- <h3 id="manga-header">Manga</h3>- <div class="form-group">- <label for="settings-reading-direction">Reading Direction</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="readingDirectionTooltip" role="button" tabindex="0"></i>- <ng-template #readingDirectionTooltip>Direction to click to move to next page. Right to Left means you click on left side of screen to move to next page.</ng-template>- <span class="sr-only" id="settings-reading-direction-help">Direction to click to move to next page. Right to Left means you click on left side of screen to move to next page.</span>- <select class="form-control" aria-describedby="manga-header" formControlName="readingDirection" id="settings-reading-direction">- <option *ngFor="let opt of readingDirections" [value]="opt.value">{{opt.text | titlecase}}</option>- </select>+ <h3 id="manga-header">Image Reader</h3>++ <div class="row no-gutters">+ <div class="form-group col-md-6 col-sm-12 pr-2">+ <label for="settings-reading-direction">Reading Direction</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="readingDirectionTooltip" role="button" tabindex="0"></i>+ <ng-template #readingDirectionTooltip>Direction to click to move to next page. Right to Left means you click on left side of screen to move to next page.</ng-template>+ <span class="sr-only" id="settings-reading-direction-help">Direction to click to move to next page. Right to Left means you click on left side of screen to move to next page.</span>+ <select class="form-control" aria-describedby="manga-header" formControlName="readingDirection" id="settings-reading-direction">+ <option *ngFor="let opt of readingDirections" [value]="opt.value">{{opt.text | titlecase}}</option>+ </select>+ </div>++ <div class="form-group col-md-6 col-sm-12">+ <label for="settings-scaling-option">Scaling Options</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="taskBackupTooltip" role="button" tabindex="0"></i>+ <ng-template #taskBackupTooltip>How to scale the image to your screen.</ng-template>+ <span class="sr-only" id="settings-scaling-option-help">How to scale the image to your screen.</span>+ <select class="form-control" aria-describedby="manga-header" formControlName="scalingOption" id="settings-scaling-option">+ <option *ngFor="let opt of scalingOptions" [value]="opt.value">{{opt.text | titlecase}}</option>+ </select>+ </div></div>-- <div class="form-group">- <label for="settings-scaling-option">Scaling Options</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="taskBackupTooltip" role="button" tabindex="0"></i>- <ng-template #taskBackupTooltip>How to scale the image to your screen.</ng-template>- <span class="sr-only" id="settings-scaling-option-help">How to scale the image to your screen.</span>- <select class="form-control" aria-describedby="manga-header" formControlName="scalingOption" id="settings-scaling-option">- <option *ngFor="let opt of scalingOptions" [value]="opt.value">{{opt.text | titlecase}}</option>- </select>++ <div class="row no-gutters">+ <div class="form-group col-md-6 col-sm-12 pr-2">+ <label for="settings-pagesplit-option">Page Splitting</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="pageSplitOptionTooltip" role="button" tabindex="0"></i>+ <ng-template #pageSplitOptionTooltip>How to split a full width image (ie both left and right images are combined)</ng-template>+ <span class="sr-only" id="settings-pagesplit-option-help">How to split a full width image (ie both left and right images are combined)</span>+ <select class="form-control" aria-describedby="manga-header" formControlName="pageSplitOption" id="settings-pagesplit-option">+ <option *ngFor="let opt of pageSplitOptions" [value]="opt.value">{{opt.text | titlecase}}</option>+ </select>+ </div>+ <div class="form-group col-md-6 col-sm-12">+ <label for="settings-readingmode-option">Reading Mode</label>+ <select class="form-control" aria-describedby="manga-header" formControlName="readerMode" id="settings-readingmode-option">+ <option *ngFor="let opt of readingModes" [value]="opt.value">{{opt.text | titlecase}}</option>+ </select>+ </div></div>+<div class="form-group">- <label for="settings-pagesplit-option">Page Splitting</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="pageSplitOptionTooltip" role="button" tabindex="0"></i>- <ng-template #pageSplitOptionTooltip>How to split a full width image (ie both left and right images are combined)</ng-template>- <span class="sr-only" id="settings-pagesplit-option-help">How to split a full width image (ie both left and right images are combined)</span>- <select class="form-control" aria-describedby="manga-header" formControlName="pageSplitOption" id="settings-pagesplit-option">- <option *ngFor="let opt of pageSplitOptions" [value]="opt.value">{{opt.text | titlecase}}</option>- </select>- </div>- <div class="form-group">- <label for="settings-readingmode-option">Reading Mode</label>- <select class="form-control" aria-describedby="manga-header" formControlName="readerMode" id="settings-readingmode-option">- <option *ngFor="let opt of readingModes" [value]="opt.value">{{opt.text | titlecase}}</option>- </select>- </div>- <div class="form-group">+ <!-- TODO: Turn this into a checkbox --><label id="auto-close-label">Auto Close Menu</label><div class="form-group"><div class="custom-control custom-radio custom-control-inline">@@ -95,68 +103,83 @@</div></div><hr>- <h3>Books</h3>- <div class="form-group">- <label id="dark-mode-label">Dark Mode</label>- <div class="form-group">- <div class="custom-control custom-radio custom-control-inline">- <input type="radio" id="dark-mode" formControlName="bookReaderDarkMode" class="custom-control-input" [value]="true" aria-labelledby="dark-mode-label">- <label class="custom-control-label" for="dark-mode">True</label>- </div>- <div class="custom-control custom-radio custom-control-inline">- <input type="radio" id="not-dark-mode" formControlName="bookReaderDarkMode" class="custom-control-input" [value]="false" aria-labelledby="dark-mode-label">- <label class="custom-control-label" for="not-dark-mode">False</label>+ <h3>Book Reader</h3>+ <div class="row no-gutters">+ <div class="form-group col-md-6 col-sm-12 pr-2">+ <label id="dark-mode-label">Dark Mode</label>+ <div class="form-group">+ <div class="custom-control custom-radio custom-control-inline">+ <input type="radio" id="dark-mode" formControlName="bookReaderDarkMode" class="custom-control-input" [value]="true" aria-labelledby="dark-mode-label">+ <label class="custom-control-label" for="dark-mode">True</label>+ </div>+ <div class="custom-control custom-radio custom-control-inline">+ <input type="radio" id="not-dark-mode" formControlName="bookReaderDarkMode" class="custom-control-input" [value]="false" aria-labelledby="dark-mode-label">+ <label class="custom-control-label" for="not-dark-mode">False</label>+ </div></div></div>- </div>- <div class="form-group">- <label for="settings-book-reading-direction">Book Reading Direction</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="bookReadingDirectionTooltip" role="button" tabindex="0"></i>- <ng-template #bookReadingDirectionTooltip>Direction to click to move to next page. Right to Left means you click on left side of screen to move to next page.</ng-template>- <span class="sr-only" id="settings-reading-direction-help">Direction to click to move to next page. Right to Left means you click on left side of screen to move to next page.</span>- <select class="form-control" aria-describedby="settings-reading-direction-help" formControlName="bookReaderReadingDirection">- <option *ngFor="let opt of readingDirections" [value]="opt.value">{{opt.text | titlecase}}</option>- </select>- </div>- <div class="form-group">- <label id="taptopaginate-label">Tap to Paginate</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="tapToPaginateOptionTooltip" role="button" tabindex="0"></i>- <ng-template #tapToPaginateOptionTooltip>Should the sides of the book reader screen allow tapping on it to move to prev/next page</ng-template>- <span class="sr-only" id="settings-taptopaginate-option-help">Should the sides of the book reader screen allow tapping on it to move to prev/next page</span>- <div class="form-group">- <div class="custom-control custom-radio custom-control-inline">- <input type="radio" id="taptopaginate" formControlName="bookReaderTapToPaginate" class="custom-control-input" [value]="true" aria-labelledby="taptopaginate-label">- <label class="custom-control-label" for="taptopaginate">True</label>- </div>- <div class="custom-control custom-radio custom-control-inline">- <input type="radio" id="not-taptopaginate" formControlName="bookReaderTapToPaginate" class="custom-control-input" [value]="false" aria-labelledby="taptopaginate-label">- <label class="custom-control-label" for="not-taptopaginate">False</label>++ <div class="form-group col-md-6 col-sm-12">+ <label id="taptopaginate-label">Tap to Paginate</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="tapToPaginateOptionTooltip" role="button" tabindex="0"></i>+ <ng-template #tapToPaginateOptionTooltip>Should the sides of the book reader screen allow tapping on it to move to prev/next page</ng-template>+ <span class="sr-only" id="settings-taptopaginate-option-help">Should the sides of the book reader screen allow tapping on it to move to prev/next page</span>+ <div class="form-group">+ <div class="custom-control custom-radio custom-control-inline">+ <input type="radio" id="taptopaginate" formControlName="bookReaderTapToPaginate" class="custom-control-input" [value]="true" aria-labelledby="taptopaginate-label">+ <label class="custom-control-label" for="taptopaginate">True</label>+ </div>+ <div class="custom-control custom-radio custom-control-inline">+ <input type="radio" id="not-taptopaginate" formControlName="bookReaderTapToPaginate" class="custom-control-input" [value]="false" aria-labelledby="taptopaginate-label">+ <label class="custom-control-label" for="not-taptopaginate">False</label>+ </div></div></div></div>- <div class="form-group">- <label for="settings-fontfamily-option">Font Family</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="fontFamilyOptionTooltip" role="button" tabindex="0"></i>- <ng-template #fontFamilyOptionTooltip>Font familty to load up. Default will load the book's default font</ng-template>- <span class="sr-only" id="settings-fontfamily-option-help">Font familty to load up. Default will load the book's default font</span>- <select class="form-control" aria-describedby="settings-fontfamily-option-help" formControlName="bookReaderFontFamily">- <option *ngFor="let opt of fontFamilies" [value]="opt">{{opt | titlecase}}</option>- </select>- </div>- <div class="form-group">- <label id="font-size">Font Size</label>- <div class="custom-slider"><ngx-slider [options]="bookReaderFontSizeOptions" formControlName="bookReaderFontSize" aria-labelledby="font-size"></ngx-slider></div>- </div>- <div class="form-group">- <label>Line Height</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="bookLineHeightOptionTooltip" role="button" tabindex="0"></i>- <ng-template #bookLineHeightOptionTooltip>How much spacing between the lines of the book</ng-template>- <span class="sr-only" id="settings-booklineheight-option-help">How much spacing between the lines of the book</span>- <div class="custom-slider"><ngx-slider [options]="bookReaderLineSpacingOptions" formControlName="bookReaderLineSpacing" aria-describedby="settings-booklineheight-option-help"></ngx-slider></div>++ <div class="row no-gutters">+ <div class="form-group col-md-6 col-sm-12 pr-2">+ <label for="settings-book-reading-direction">Book Reading Direction</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="bookReadingDirectionTooltip" role="button" tabindex="0"></i>+ <ng-template #bookReadingDirectionTooltip>Direction to click to move to next page. Right to Left means you click on left side of screen to move to next page.</ng-template>+ <span class="sr-only" id="settings-reading-direction-help">Direction to click to move to next page. Right to Left means you click on left side of screen to move to next page.</span>+ <select class="form-control" aria-describedby="settings-reading-direction-help" formControlName="bookReaderReadingDirection">+ <option *ngFor="let opt of readingDirections" [value]="opt.value">{{opt.text | titlecase}}</option>+ </select>+ </div>+++ <div class="form-group col-md-6 col-sm-12">+ <label for="settings-fontfamily-option">Font Family</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="fontFamilyOptionTooltip" role="button" tabindex="0"></i>+ <ng-template #fontFamilyOptionTooltip>Font familty to load up. Default will load the book's default font</ng-template>+ <span class="sr-only" id="settings-fontfamily-option-help">Font familty to load up. Default will load the book's default font</span>+ <select class="form-control" aria-describedby="settings-fontfamily-option-help" formControlName="bookReaderFontFamily">+ <option *ngFor="let opt of fontFamilies" [value]="opt">{{opt | titlecase}}</option>+ </select>+ </div></div>-- <div class="form-group">- <label>Margin</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="bookReaderMarginOptionTooltip" role="button" tabindex="0"></i>- <ng-template #bookReaderMarginOptionTooltip>How much spacing on each side of the screen. This will override to 0 on mobile devices regardless of this setting.</ng-template>- <span class="sr-only" id="settings-bookmargin-option-help">How much spacing on each side of the screen. This will override to 0 on mobile devices regardless of this setting.</span>- <div class="custom-slider"><ngx-slider [options]="bookReaderMarginOptions" formControlName="bookReaderMargin" aria-describedby="bookmargin"></ngx-slider></div>++++ <div class="row no-gutters">+ <div class="form-group col-md-4 col-sm-12 pr-2">+ <label id="font-size">Font Size</label>+ <div class="custom-slider"><ngx-slider [options]="bookReaderFontSizeOptions" formControlName="bookReaderFontSize" aria-labelledby="font-size"></ngx-slider></div>+ </div>+ <div class="form-group col-md-4 col-sm-12 pr-2">+ <label>Line Height</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="bookLineHeightOptionTooltip" role="button" tabindex="0"></i>+ <ng-template #bookLineHeightOptionTooltip>How much spacing between the lines of the book</ng-template>+ <span class="sr-only" id="settings-booklineheight-option-help">How much spacing between the lines of the book</span>+ <div class="custom-slider"><ngx-slider [options]="bookReaderLineSpacingOptions" formControlName="bookReaderLineSpacing" aria-describedby="settings-booklineheight-option-help"></ngx-slider></div>+ </div>++ <div class="form-group col-md-4 col-sm-12">+ <label>Margin</label> <i class="fa fa-info-circle" aria-hidden="true" placement="right" [ngbTooltip]="bookReaderMarginOptionTooltip" role="button" tabindex="0"></i>+ <ng-template #bookReaderMarginOptionTooltip>How much spacing on each side of the screen. This will override to 0 on mobile devices regardless of this setting.</ng-template>+ <span class="sr-only" id="settings-bookmargin-option-help">How much spacing on each side of the screen. This will override to 0 on mobile devices regardless of this setting.</span>+ <div class="custom-slider"><ngx-slider [options]="bookReaderMarginOptions" formControlName="bookReaderMargin" aria-describedby="bookmargin"></ngx-slider></div>+ </div></div>++<div class="float-right mb-3"><button type="button" class="btn btn-secondary mr-2" (click)="resetForm()" aria-describedby="reading-panel">Reset</button>@@ -165,76 +188,55 @@</form></ng-template></ngb-panel>--- <ngb-panel id="password-panel" title="Password">- <ng-template ngbPanelHeader>- <div class="d-flex align-items-center justify-content-between">- <button ngbPanelToggle class="btn container-fluid text-left pl-0 accordion-header">Password</button>- <span class="pull-right"><i class="fa fa-angle-{{acc.isExpanded('password-panel') ? 'down' : 'up'}}" aria-hidden="true"></i></span>- </div>- </ng-template>- <ng-template ngbPanelContent>- <ng-container *ngIf="isAuthenticationEnabled || isAdmin; else authDisabled">- <p>Change your Password</p>- <div class="alert alert-danger" role="alert" *ngIf="resetPasswordErrors.length > 0">- <div *ngFor="let error of resetPasswordErrors">{{error}}</div>- </div>- <form [formGroup]="passwordChangeForm">- <div class="form-group">- <label for="new-password">New Password</label>- <input class="form-control" type="password" id="new-password" formControlName="password" required>- <div id="password-validations" class="invalid-feedback" *ngIf="passwordChangeForm.dirty || passwordChangeForm.touched">- <div *ngIf="password?.errors?.required">- This field is required- </div>- </div>- </div>- <div class="form-group">- <label for="confirm-password">Confirm Password</label>- <input class="form-control" type="password" id="confirm-password" formControlName="confirmPassword" aria-describedby="password-validations" required>- <div id="password-validations" class="invalid-feedback" *ngIf="passwordChangeForm.dirty || passwordChangeForm.touched">- <div *ngIf="!passwordsMatch">- Passwords must match- </div>- <div *ngIf="confirmPassword?.errors?.required">- This field is required- </div>- </div>- </div>- <div class="float-right mb-3">- <button type="button" class="btn btn-secondary mr-2" aria-describedby="password-panel" (click)="resetPasswordForm()">Reset</button>- <button type="submit" class="btn btn-primary" aria-describedby="password-panel" (click)="savePasswordForm()" [disabled]="!passwordChangeForm.valid || !(passwordChangeForm.dirty || passwordChangeForm.touched)">Save</button>- </div>- </form>- </ng-container>- <ng-template #authDisabled>- <p class="text-warning">Authentication is disabled on this server. A password is not required to authenticate.</p>- </ng-template>- </ng-template>- </ngb-panel>- <ngb-panel id="api-panel" title="OPDS">- <ng-template ngbPanelHeader>- <div class="d-flex align-items-center justify-content-between">- <button ngbPanelToggle class="btn container-fluid text-left pl-0 accordion-header">OPDS</button>- <span class="pull-right"><i class="fa fa-angle-{{acc.isExpanded('api-panel') ? 'down' : 'up'}}" aria-hidden="true"></i></span>- </div>- </ng-template>- <ng-template ngbPanelContent>- <p class="alert alert-danger" role="alert" *ngIf="!opdsEnabled">- OPDS is not enabled on this server!- </p>- <ng-container *ngIf="opdsEnabled">- <app-api-key tooltipText="The API key is like a password. Keep it secret, Keep it safe."></app-api-key>- <app-api-key title="OPDS URL" [showRefresh]="false" [transform]="makeUrl"></app-api-key>- </ng-container>- </ng-template>- </ngb-panel></ngb-accordion></ng-container><ng-container *ngIf="tab.fragment === 'bookmarks'"><app-series-bookmarks></app-series-bookmarks></ng-container>+ <ng-container *ngIf="tab.fragment === 'password'">+ <ng-container *ngIf="isAuthenticationEnabled || isAdmin; else authDisabled">+ <p>Change your Password</p>+ <div class="alert alert-danger" role="alert" *ngIf="resetPasswordErrors.length > 0">+ <div *ngFor="let error of resetPasswordErrors">{{error}}</div>+ </div>+ <form [formGroup]="passwordChangeForm">+ <div class="form-group">+ <label for="new-password">New Password</label>+ <input class="form-control" type="password" id="new-password" formControlName="password" required>+ <div id="password-validations" class="invalid-feedback" *ngIf="passwordChangeForm.dirty || passwordChangeForm.touched">+ <div *ngIf="password?.errors?.required">+ This field is required+ </div>+ </div>+ </div>+ <div class="form-group">+ <label for="confirm-password">Confirm Password</label>+ <input class="form-control" type="password" id="confirm-password" formControlName="confirmPassword" aria-describedby="password-validations" required>+ <div id="password-validations" class="invalid-feedback" *ngIf="passwordChangeForm.dirty || passwordChangeForm.touched">+ <div *ngIf="!passwordsMatch">+ Passwords must match+ </div>+ <div *ngIf="confirmPassword?.errors?.required">+ This field is required+ </div>+ </div>+ </div>+ <div class="float-right mb-3">+ <button type="button" class="btn btn-secondary mr-2" aria-describedby="password-panel" (click)="resetPasswordForm()">Reset</button>+ <button type="submit" class="btn btn-primary" aria-describedby="password-panel" (click)="savePasswordForm()" [disabled]="!passwordChangeForm.valid || !(passwordChangeForm.dirty || passwordChangeForm.touched)">Save</button>+ </div>+ </form>+ </ng-container>+ <ng-template #authDisabled>+ <p class="text-warning">Authentication is disabled on this server. A password is not required to authenticate.</p>+ </ng-template>+ </ng-container>+ <ng-container *ngIf="tab.fragment === 'clients'">+ <p>All 3rd Party clients will either use the API key or the Connection Url below. These are like passwords, keep it private.</p>+ <p class="alert alert-warning" role="alert" *ngIf="!opdsEnabled">OPDS is not enabled on this server.</p>+ <app-api-key tooltipText="The API key is like a password. Keep it secret, Keep it safe."></app-api-key>+ <app-api-key title="OPDS URL" [showRefresh]="false" [transform]="makeUrl"></app-api-key>+ </ng-container></ng-template></li></ul>diff --git a/UI/Web/src/app/user-settings/user-preferences/user-preferences.component.ts b/UI/Web/src/app/user-settings/user-preferences/user-preferences.component.tsindex ba4c17865..e7947886b 100644--- a/UI/Web/src/app/user-settings/user-preferences/user-preferences.component.ts+++ b/UI/Web/src/app/user-settings/user-preferences/user-preferences.component.ts@@ -55,6 +55,8 @@ export class UserPreferencesComponent implements OnInit, OnDestroy {tabs: Array<{title: string, fragment: string}> = [{title: 'Preferences', fragment: ''},{title: 'Bookmarks', fragment: 'bookmarks'},+ {title: 'Password', fragment: 'password'},+ {title: '3rd Party Clients', fragment: 'clients'},];active = this.tabs[0];opdsEnabled: boolean = false;diff --git a/UI/Web/src/app/user-settings/user-settings.module.ts b/UI/Web/src/app/user-settings/user-settings.module.tsindex 5be4cfab8..5b837aba0 100644--- a/UI/Web/src/app/user-settings/user-settings.module.ts+++ b/UI/Web/src/app/user-settings/user-settings.module.ts@@ -7,6 +7,7 @@ import { ReactiveFormsModule } from '@angular/forms';import { NgxSliderModule } from '@angular-slider/ngx-slider';import { UserSettingsRoutingModule } from './user-settings-routing.module';import { ApiKeyComponent } from './api-key/api-key.component';+import { SharedModule } from '../shared/shared.module';@@ -24,6 +25,7 @@ import { ApiKeyComponent } from './api-key/api-key.component';NgbTooltipModule,NgxSliderModule,UserSettingsRoutingModule,+ SharedModule // SentenceCase pipe]})export class UserSettingsModule { }diff --git a/UI/Web/src/assets/themes/dark.scss b/UI/Web/src/assets/themes/dark.scssindex 54353d9d9..dfeea5dac 100644--- a/UI/Web/src/assets/themes/dark.scss+++ b/UI/Web/src/assets/themes/dark.scss@@ -16,6 +16,10 @@}}+ hr {+ background-color: colors.$dark-form-border;+ }+a.btn {color: white;}diff --git a/UI/Web/src/styles.scss b/UI/Web/src/styles.scssindex 330e84ee5..03861b498 100644--- a/UI/Web/src/styles.scss+++ b/UI/Web/src/styles.scss@@ -8,13 +8,6 @@@import '~swiper/swiper.scss';--@keyframes fadein {- from { opacity: 0; }- to { opacity: 1; }-}--@import './assets/themes/dark.scss';// Global Styles@@ -30,6 +23,14 @@ label, select, .clickable {color: white;}+:root {+ color-scheme: light;+}++// :root .bg-dark {+// color-scheme: dark;+// }+@font-face {font-family: "EBGarmond";src: url("assets/fonts/EBGarmond/EBGaramond-VariableFont_wght.ttf") format("truetype");@@ -51,6 +52,10 @@ body {cursor: pointer;}+app-root {+ background-color: inherit;+}+// Utiliities@include media-breakpoint-down(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) {@@ -65,6 +70,11 @@ body {}}+@keyframes fadein {+ from { opacity: 0; }+ to { opacity: 1; }+}+// Debug styles.redlines * {outline: 1px solid red;diff --git a/UI/Web/src/theme/_colors.scss b/UI/Web/src/theme/_colors.scssindex 216f62210..303d1d4f7 100644--- a/UI/Web/src/theme/_colors.scss+++ b/UI/Web/src/theme/_colors.scss@@ -14,6 +14,20 @@ $dark-form-border: rgba(239, 239, 239, 0.125);$dark-form-readonly: #434648;$dark-item-accent-bg: #292d32;++//=========================+// Ratings+//=========================+$rating-filled: $primary-color;+$rating-empty: #b0c4de;++//=========================+// Drawers+//=========================+// :root {+// --drawer-background-color: #FFF;+// }+$theme-colors: ("primary": $primary-color,"danger": $error-colordiff --git a/build.sh b/build.shindex 066b22dee..c49835c1d 100755--- a/build.sh+++ b/build.sh@@ -130,21 +130,21 @@ dir=$PWDif [[ -z "$RID" ]];then- Package "net5.0" "win-x64"+ Package "net6.0" "win-x64"cd "$dir"- Package "net5.0" "win-x86"+ Package "net6.0" "win-x86"cd "$dir"- Package "net5.0" "linux-x64"+ Package "net6.0" "linux-x64"cd "$dir"- Package "net5.0" "linux-arm"+ Package "net6.0" "linux-arm"cd "$dir"- Package "net5.0" "linux-arm64"+ Package "net6.0" "linux-arm64"cd "$dir"- Package "net5.0" "linux-musl-x64"+ Package "net6.0" "linux-musl-x64"cd "$dir"- Package "net5.0" "osx-x64"+ Package "net6.0" "osx-x64"cd "$dir"else- Package "net5.0" "$RID"+ Package "net6.0" "$RID"cd "$dir"fidiff --git a/docker-build.sh b/docker-build.shindex a0adc4bbf..79f72c1cf 100755--- a/docker-build.sh+++ b/docker-build.sh@@ -25,7 +25,7 @@ Build()dotnet clean $slnFile -c Releasedotnet msbuild -restore $slnFile -p:Configuration=Release -p:Platform="Any CPU" -p:RuntimeIdentifiers=$RID-+ProgressEnd 'Build for $RID'}@@ -37,7 +37,7 @@ BuildUI()npm run prodcd ../Kavita/ || exitProgressEnd 'Building UI'-+ProgressStart 'Building UI'echo 'Removing old wwwroot'rm -rf API/wwwroot/*@@ -68,18 +68,18 @@ Package()echo "Copying Install information"cp ../INSTALL.txt "$lOutputFolder"/README.txt-+echo "Copying LICENSE"cp ../LICENSE "$lOutputFolder"/LICENSE.txt-+echo "Renaming API -> Kavita"mv "$lOutputFolder"/API "$lOutputFolder"/Kavitaecho "Creating tar"cd ../$outputFolder/"$runtime"/tar -czvf ../kavita-$runtime.tar.gz Kavita-- ProgressEnd "Creating $runtime Package for $framework"++ ProgressEnd "Creating $runtime Package for $framework"}@@ -94,18 +94,18 @@ BuildUI#Build for x64Build "linux-x64"-Package "net5.0" "linux-x64"+Package "net6.0" "linux-x64"cd "$dir"#Build for armBuild "linux-arm"-Package "net5.0" "linux-arm"+Package "net6.0" "linux-arm"cd "$dir"#Build for arm64Build "linux-arm64"-Package "net5.0" "linux-arm64"+Package "net6.0" "linux-arm64"cd "$dir"#Builds Docker images-docker buildx build -t kizaing/kavita:nightly --platform linux/amd64,linux/arm/v7,linux/arm64 . --push\ No newline at end of file+docker buildx build -t kizaing/kavita:nightly --platform linux/amd64,linux/arm/v7,linux/arm64 . --pushdiff --git a/global.json b/global.jsonnew file mode 100644index 000000000..97dd87392--- /dev/null+++ b/global.json@@ -0,0 +1,7 @@+{+ "sdk": {+ "version": "6.0",+ "rollForward": "latestMajor",+ "allowPrerelease": false+ }+}\ No newline at end of filediff --git a/monorepo-build.sh b/monorepo-build.shindex c77b09350..d4c4b9b7d 100755--- a/monorepo-build.sh+++ b/monorepo-build.sh@@ -77,15 +77,15 @@ fi#Build for x64Build "linux-x64"-Package "net5.0" "linux-x64"+Package "net6.0" "linux-x64"cd "$dir"#Build for armBuild "linux-arm"-Package "net5.0" "linux-arm"+Package "net6.0" "linux-arm"cd "$dir"#Build for arm64Build "linux-arm64"-Package "net5.0" "linux-arm64"+Package "net6.0" "linux-arm64"cd "$dir"