diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index cdd72de1c..805c3b61d 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -28,7 +28,7 @@ body:
label: Kavita Version Number - If you don't see your version number listed, please update Kavita and see if your issue still persists.
multiple: false
options:
- - 0.8.6.2 - Stable
+ - 0.8.7 - Stable
- Nightly Testing Branch
validations:
required: true
diff --git a/API.Benchmark/API.Benchmark.csproj b/API.Benchmark/API.Benchmark.csproj
index 38ec425fe..ec9c1884f 100644
--- a/API.Benchmark/API.Benchmark.csproj
+++ b/API.Benchmark/API.Benchmark.csproj
@@ -10,8 +10,8 @@
-
-
+
+
@@ -26,5 +26,10 @@
Always
+
+
+ PreserveNewest
+
+
diff --git a/API.Benchmark/Data/AesopsFables.epub b/API.Benchmark/Data/AesopsFables.epub
new file mode 100644
index 000000000..d2ab9a8b2
Binary files /dev/null and b/API.Benchmark/Data/AesopsFables.epub differ
diff --git a/API.Benchmark/KoreaderHashBenchmark.cs b/API.Benchmark/KoreaderHashBenchmark.cs
new file mode 100644
index 000000000..c0abfd2ad
--- /dev/null
+++ b/API.Benchmark/KoreaderHashBenchmark.cs
@@ -0,0 +1,41 @@
+using API.Helpers.Builders;
+using BenchmarkDotNet.Attributes;
+using BenchmarkDotNet.Order;
+using System;
+using API.Entities.Enums;
+
+namespace API.Benchmark
+{
+ [StopOnFirstError]
+ [MemoryDiagnoser]
+ [RankColumn]
+ [Orderer(SummaryOrderPolicy.FastestToSlowest)]
+ [SimpleJob(launchCount: 1, warmupCount: 5, invocationCount: 20)]
+ public class KoreaderHashBenchmark
+ {
+ private const string sourceEpub = "./Data/AesopsFables.epub";
+
+ [Benchmark(Baseline = true)]
+ public void TestBuildManga_baseline()
+ {
+ var file = new MangaFileBuilder(sourceEpub, MangaFormat.Epub)
+ .Build();
+ if (file == null)
+ {
+ throw new Exception("Failed to build manga file");
+ }
+ }
+
+ [Benchmark]
+ public void TestBuildManga_withHash()
+ {
+ var file = new MangaFileBuilder(sourceEpub, MangaFormat.Epub)
+ .WithHash()
+ .Build();
+ if (file == null)
+ {
+ throw new Exception("Failed to build manga file");
+ }
+ }
+ }
+}
diff --git a/API.Tests/API.Tests.csproj b/API.Tests/API.Tests.csproj
index 20e10e548..a571a6e72 100644
--- a/API.Tests/API.Tests.csproj
+++ b/API.Tests/API.Tests.csproj
@@ -6,13 +6,13 @@
-
-
+
+
-
-
+
+
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
@@ -36,4 +36,10 @@
+
+
+ PreserveNewest
+
+
+
diff --git a/API.Tests/Data/AesopsFables.epub b/API.Tests/Data/AesopsFables.epub
new file mode 100644
index 000000000..d2ab9a8b2
Binary files /dev/null and b/API.Tests/Data/AesopsFables.epub differ
diff --git a/API.Tests/Extensions/QueryableExtensionsTests.cs b/API.Tests/Extensions/QueryableExtensionsTests.cs
index 866e0202c..96d74b46d 100644
--- a/API.Tests/Extensions/QueryableExtensionsTests.cs
+++ b/API.Tests/Extensions/QueryableExtensionsTests.cs
@@ -67,7 +67,7 @@ public class QueryableExtensionsTests
[Theory]
[InlineData(true, 2)]
- [InlineData(false, 1)]
+ [InlineData(false, 2)]
public void RestrictAgainstAgeRestriction_Genre_ShouldRestrictEverythingAboveTeen(bool includeUnknowns, int expectedCount)
{
var items = new List()
@@ -94,7 +94,7 @@ public class QueryableExtensionsTests
[Theory]
[InlineData(true, 2)]
- [InlineData(false, 1)]
+ [InlineData(false, 2)]
public void RestrictAgainstAgeRestriction_Tag_ShouldRestrictEverythingAboveTeen(bool includeUnknowns, int expectedCount)
{
var items = new List()
diff --git a/API.Tests/Helpers/BookSortTitlePrefixHelperTests.cs b/API.Tests/Helpers/BookSortTitlePrefixHelperTests.cs
new file mode 100644
index 000000000..e1f585806
--- /dev/null
+++ b/API.Tests/Helpers/BookSortTitlePrefixHelperTests.cs
@@ -0,0 +1,178 @@
+using API.Helpers;
+using Xunit;
+
+namespace API.Tests.Helpers;
+
+public class BookSortTitlePrefixHelperTests
+{
+ [Theory]
+ [InlineData("The Avengers", "Avengers")]
+ [InlineData("A Game of Thrones", "Game of Thrones")]
+ [InlineData("An American Tragedy", "American Tragedy")]
+ public void TestEnglishPrefixes(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("El Quijote", "Quijote")]
+ [InlineData("La Casa de Papel", "Casa de Papel")]
+ [InlineData("Los Miserables", "Miserables")]
+ [InlineData("Las Vegas", "Vegas")]
+ [InlineData("Un Mundo Feliz", "Mundo Feliz")]
+ [InlineData("Una Historia", "Historia")]
+ public void TestSpanishPrefixes(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("Le Petit Prince", "Petit Prince")]
+ [InlineData("La Belle et la Bête", "Belle et la Bête")]
+ [InlineData("Les Misérables", "Misérables")]
+ [InlineData("Un Amour de Swann", "Amour de Swann")]
+ [InlineData("Une Vie", "Vie")]
+ [InlineData("Des Souris et des Hommes", "Souris et des Hommes")]
+ public void TestFrenchPrefixes(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("Der Herr der Ringe", "Herr der Ringe")]
+ [InlineData("Die Verwandlung", "Verwandlung")]
+ [InlineData("Das Kapital", "Kapital")]
+ [InlineData("Ein Sommernachtstraum", "Sommernachtstraum")]
+ [InlineData("Eine Geschichte", "Geschichte")]
+ public void TestGermanPrefixes(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("Il Nome della Rosa", "Nome della Rosa")]
+ [InlineData("La Divina Commedia", "Divina Commedia")]
+ [InlineData("Lo Hobbit", "Hobbit")]
+ [InlineData("Gli Ultimi", "Ultimi")]
+ [InlineData("Le Città Invisibili", "Città Invisibili")]
+ [InlineData("Un Giorno", "Giorno")]
+ [InlineData("Una Notte", "Notte")]
+ public void TestItalianPrefixes(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("O Alquimista", "Alquimista")]
+ [InlineData("A Moreninha", "Moreninha")]
+ [InlineData("Os Lusíadas", "Lusíadas")]
+ [InlineData("As Meninas", "Meninas")]
+ [InlineData("Um Defeito de Cor", "Defeito de Cor")]
+ [InlineData("Uma História", "História")]
+ public void TestPortuguesePrefixes(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("", "")] // Empty string returns empty
+ [InlineData("Book", "Book")] // Single word, no change
+ [InlineData("Avengers", "Avengers")] // No prefix, no change
+ public void TestNoPrefixCases(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("The", "The")] // Just a prefix word alone
+ [InlineData("A", "A")] // Just single letter prefix alone
+ [InlineData("Le", "Le")] // French prefix alone
+ public void TestPrefixWordAlone(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("THE AVENGERS", "AVENGERS")] // All caps
+ [InlineData("the avengers", "avengers")] // All lowercase
+ [InlineData("The AVENGERS", "AVENGERS")] // Mixed case
+ [InlineData("tHe AvEnGeRs", "AvEnGeRs")] // Random case
+ public void TestCaseInsensitivity(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("Then Came You", "Then Came You")] // "The" + "n" = not a prefix
+ [InlineData("And Then There Were None", "And Then There Were None")] // "An" + "d" = not a prefix
+ [InlineData("Elsewhere", "Elsewhere")] // "El" + "sewhere" = not a prefix (no space)
+ [InlineData("Lesson Plans", "Lesson Plans")] // "Les" + "son" = not a prefix (no space)
+ [InlineData("Theory of Everything", "Theory of Everything")] // "The" + "ory" = not a prefix
+ public void TestFalsePositivePrefixes(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("The ", "The ")] // Prefix with only space after - returns original
+ [InlineData("La ", "La ")] // Same for other languages
+ [InlineData("El ", "El ")] // Same for Spanish
+ public void TestPrefixWithOnlySpaceAfter(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("The Multiple Spaces", " Multiple Spaces")] // Doesn't trim extra spaces from remainder
+ [InlineData("Le Petit Prince", " Petit Prince")] // Leading space preserved in remainder
+ public void TestSpaceHandling(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("The The Matrix", "The Matrix")] // Removes first "The", leaves second
+ [InlineData("A A Clockwork Orange", "A Clockwork Orange")] // Removes first "A", leaves second
+ [InlineData("El El Cid", "El Cid")] // Spanish version
+ public void TestRepeatedPrefixes(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("L'Étranger", "L'Étranger")] // French contraction - no space, no change
+ [InlineData("D'Artagnan", "D'Artagnan")] // Contraction - no space, no change
+ [InlineData("The-Matrix", "The-Matrix")] // Hyphen instead of space - no change
+ [InlineData("The.Avengers", "The.Avengers")] // Period instead of space - no change
+ public void TestNonSpaceSeparators(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("三国演义", "三国演义")] // Chinese - no processing due to CJK detection
+ [InlineData("한국어", "한국어")] // Korean - not in CJK range, would be processed normally
+ public void TestCjkLanguages(string inputString, string expected)
+ {
+ // NOTE: These don't do anything, I am waiting for user input on if these are needed
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("नमस्ते दुनिया", "नमस्ते दुनिया")] // Hindi - not CJK, processed normally
+ [InlineData("مرحبا بالعالم", "مرحبا بالعالم")] // Arabic - not CJK, processed normally
+ [InlineData("שלום עולם", "שלום עולם")] // Hebrew - not CJK, processed normally
+ public void TestNonLatinNonCjkScripts(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+
+ [Theory]
+ [InlineData("в мире", "мире")] // Russian "в" (in) - should be removed
+ [InlineData("на столе", "столе")] // Russian "на" (on) - should be removed
+ [InlineData("с друзьями", "друзьями")] // Russian "с" (with) - should be removed
+ public void TestRussianPrefixes(string inputString, string expected)
+ {
+ Assert.Equal(expected, BookSortTitlePrefixHelper.GetSortTitle(inputString));
+ }
+}
diff --git a/API.Tests/Helpers/KoreaderHelperTests.cs b/API.Tests/Helpers/KoreaderHelperTests.cs
new file mode 100644
index 000000000..66d287a5d
--- /dev/null
+++ b/API.Tests/Helpers/KoreaderHelperTests.cs
@@ -0,0 +1,60 @@
+using API.DTOs.Koreader;
+using API.DTOs.Progress;
+using API.Helpers;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+namespace API.Tests.Helpers;
+
+
+public class KoreaderHelperTests
+{
+
+ [Theory]
+ [InlineData("/body/DocFragment[11]/body/div/a", 10, null)]
+ [InlineData("/body/DocFragment[1]/body/div/p[40]", 0, 40)]
+ [InlineData("/body/DocFragment[8]/body/div/p[28]/text().264", 7, 28)]
+ public void GetEpubPositionDto(string koreaderPosition, int page, int? pNumber)
+ {
+ var expected = EmptyProgressDto();
+ expected.BookScrollId = pNumber.HasValue ? $"//html[1]/BODY/APP-ROOT[1]/DIV[1]/DIV[1]/DIV[1]/APP-BOOK-READER[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/P[{pNumber}]" : null;
+ expected.PageNum = page;
+ var actual = EmptyProgressDto();
+
+ KoreaderHelper.UpdateProgressDto(actual, koreaderPosition);
+ Assert.Equal(expected.BookScrollId, actual.BookScrollId);
+ Assert.Equal(expected.PageNum, actual.PageNum);
+ }
+
+
+ [Theory]
+ [InlineData("//html[1]/BODY/APP-ROOT[1]/DIV[1]/DIV[1]/DIV[1]/APP-BOOK-READER[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/P[20]", 5, "/body/DocFragment[6]/body/div/p[20]")]
+ [InlineData(null, 10, "/body/DocFragment[11]/body/div/a")]
+ public void GetKoreaderPosition(string scrollId, int page, string koreaderPosition)
+ {
+ var given = EmptyProgressDto();
+ given.BookScrollId = scrollId;
+ given.PageNum = page;
+
+ Assert.Equal(koreaderPosition, KoreaderHelper.GetKoreaderPosition(given));
+ }
+
+ [Theory]
+ [InlineData("./Data/AesopsFables.epub", "8795ACA4BF264B57C1EEDF06A0CEE688")]
+ public void GetKoreaderHash(string filePath, string hash)
+ {
+ Assert.Equal(KoreaderHelper.HashContents(filePath), hash);
+ }
+
+ private ProgressDto EmptyProgressDto()
+ {
+ return new ProgressDto
+ {
+ ChapterId = 0,
+ PageNum = 0,
+ VolumeId = 0,
+ SeriesId = 0,
+ LibraryId = 0
+ };
+ }
+}
diff --git a/API.Tests/Helpers/PersonHelperTests.cs b/API.Tests/Helpers/PersonHelperTests.cs
index 66713e17c..47dab48da 100644
--- a/API.Tests/Helpers/PersonHelperTests.cs
+++ b/API.Tests/Helpers/PersonHelperTests.cs
@@ -1,5 +1,10 @@
-using System.Linq;
+using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
+using API.Entities.Enums;
+using API.Helpers;
+using API.Helpers.Builders;
+using Xunit;
namespace API.Tests.Helpers;
@@ -7,127 +12,215 @@ public class PersonHelperTests : AbstractDbTest
{
protected override async Task ResetDb()
{
+ Context.Series.RemoveRange(Context.Series.ToList());
+ Context.Person.RemoveRange(Context.Person.ToList());
+ Context.Library.RemoveRange(Context.Library.ToList());
Context.Series.RemoveRange(Context.Series.ToList());
await Context.SaveChangesAsync();
}
- //
- // // 1. Test adding new people and keeping existing ones
- // [Fact]
- // public async Task UpdateChapterPeopleAsync_AddNewPeople_ExistingPersonRetained()
- // {
- // var existingPerson = new PersonBuilder("Joe Shmo").Build();
- // var chapter = new ChapterBuilder("1").Build();
- //
- // // Create an existing person and assign them to the series with a role
- // var series = new SeriesBuilder("Test 1")
- // .WithFormat(MangaFormat.Archive)
- // .WithMetadata(new SeriesMetadataBuilder()
- // .WithPerson(existingPerson, PersonRole.Editor)
- // .Build())
- // .WithVolume(new VolumeBuilder("1").WithChapter(chapter).Build())
- // .Build();
- //
- // _unitOfWork.SeriesRepository.Add(series);
- // await _unitOfWork.CommitAsync();
- //
- // // Call UpdateChapterPeopleAsync with one existing and one new person
- // await PersonHelper.UpdateChapterPeopleAsync(chapter, new List { "Joe Shmo", "New Person" }, PersonRole.Editor, _unitOfWork);
- //
- // // Assert existing person retained and new person added
- // var people = await _unitOfWork.PersonRepository.GetAllPeople();
- // Assert.Contains(people, p => p.Name == "Joe Shmo");
- // Assert.Contains(people, p => p.Name == "New Person");
- //
- // var chapterPeople = chapter.People.Select(cp => cp.Person.Name).ToList();
- // Assert.Contains("Joe Shmo", chapterPeople);
- // Assert.Contains("New Person", chapterPeople);
- // }
- //
- // // 2. Test removing a person no longer in the list
- // [Fact]
- // public async Task UpdateChapterPeopleAsync_RemovePeople()
- // {
- // var existingPerson1 = new PersonBuilder("Joe Shmo").Build();
- // var existingPerson2 = new PersonBuilder("Jane Doe").Build();
- // var chapter = new ChapterBuilder("1").Build();
- //
- // var series = new SeriesBuilder("Test 1")
- // .WithVolume(new VolumeBuilder("1")
- // .WithChapter(new ChapterBuilder("1")
- // .WithPerson(existingPerson1, PersonRole.Editor)
- // .WithPerson(existingPerson2, PersonRole.Editor)
- // .Build())
- // .Build())
- // .Build();
- //
- // _unitOfWork.SeriesRepository.Add(series);
- // await _unitOfWork.CommitAsync();
- //
- // // Call UpdateChapterPeopleAsync with only one person
- // await PersonHelper.UpdateChapterPeopleAsync(chapter, new List { "Joe Shmo" }, PersonRole.Editor, _unitOfWork);
- //
- // var people = await _unitOfWork.PersonRepository.GetAllPeople();
- // Assert.DoesNotContain(people, p => p.Name == "Jane Doe");
- //
- // var chapterPeople = chapter.People.Select(cp => cp.Person.Name).ToList();
- // Assert.Contains("Joe Shmo", chapterPeople);
- // Assert.DoesNotContain("Jane Doe", chapterPeople);
- // }
- //
- // // 3. Test no changes when the list of people is the same
- // [Fact]
- // public async Task UpdateChapterPeopleAsync_NoChanges()
- // {
- // var existingPerson = new PersonBuilder("Joe Shmo").Build();
- // var chapter = new ChapterBuilder("1").Build();
- //
- // var series = new SeriesBuilder("Test 1")
- // .WithVolume(new VolumeBuilder("1")
- // .WithChapter(new ChapterBuilder("1")
- // .WithPerson(existingPerson, PersonRole.Editor)
- // .Build())
- // .Build())
- // .Build();
- //
- // _unitOfWork.SeriesRepository.Add(series);
- // await _unitOfWork.CommitAsync();
- //
- // // Call UpdateChapterPeopleAsync with the same list
- // await PersonHelper.UpdateChapterPeopleAsync(chapter, new List { "Joe Shmo" }, PersonRole.Editor, _unitOfWork);
- //
- // var people = await _unitOfWork.PersonRepository.GetAllPeople();
- // Assert.Contains(people, p => p.Name == "Joe Shmo");
- //
- // var chapterPeople = chapter.People.Select(cp => cp.Person.Name).ToList();
- // Assert.Contains("Joe Shmo", chapterPeople);
- // Assert.Single(chapter.People); // No duplicate entries
- // }
- //
- // // 4. Test multiple roles for a person
- // [Fact]
- // public async Task UpdateChapterPeopleAsync_MultipleRoles()
- // {
- // var person = new PersonBuilder("Joe Shmo").Build();
- // var chapter = new ChapterBuilder("1").Build();
- //
- // var series = new SeriesBuilder("Test 1")
- // .WithVolume(new VolumeBuilder("1")
- // .WithChapter(new ChapterBuilder("1")
- // .WithPerson(person, PersonRole.Writer) // Assign person as Writer
- // .Build())
- // .Build())
- // .Build();
- //
- // _unitOfWork.SeriesRepository.Add(series);
- // await _unitOfWork.CommitAsync();
- //
- // // Add same person as Editor
- // await PersonHelper.UpdateChapterPeopleAsync(chapter, new List { "Joe Shmo" }, PersonRole.Editor, _unitOfWork);
- //
- // // Ensure that the same person is assigned with two roles
- // var chapterPeople = chapter.People.Where(cp => cp.Person.Name == "Joe Shmo").ToList();
- // Assert.Equal(2, chapterPeople.Count); // One for each role
- // Assert.Contains(chapterPeople, cp => cp.Role == PersonRole.Writer);
- // Assert.Contains(chapterPeople, cp => cp.Role == PersonRole.Editor);
- // }
+
+ // 1. Test adding new people and keeping existing ones
+ [Fact]
+ public async Task UpdateChapterPeopleAsync_AddNewPeople_ExistingPersonRetained()
+ {
+ await ResetDb();
+
+ var library = new LibraryBuilder("My Library")
+ .Build();
+
+ UnitOfWork.LibraryRepository.Add(library);
+ await UnitOfWork.CommitAsync();
+
+ var existingPerson = new PersonBuilder("Joe Shmo").Build();
+ var chapter = new ChapterBuilder("1").Build();
+
+ // Create an existing person and assign them to the series with a role
+ var series = new SeriesBuilder("Test 1")
+ .WithLibraryId(library.Id)
+ .WithFormat(MangaFormat.Archive)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithPerson(existingPerson, PersonRole.Editor)
+ .Build())
+ .WithVolume(new VolumeBuilder("1").WithChapter(chapter).Build())
+ .Build();
+
+ UnitOfWork.SeriesRepository.Add(series);
+ await UnitOfWork.CommitAsync();
+
+ // Call UpdateChapterPeopleAsync with one existing and one new person
+ await PersonHelper.UpdateChapterPeopleAsync(chapter, new List { "Joe Shmo", "New Person" }, PersonRole.Editor, UnitOfWork);
+
+ // Assert existing person retained and new person added
+ var people = await UnitOfWork.PersonRepository.GetAllPeople();
+ Assert.Contains(people, p => p.Name == "Joe Shmo");
+ Assert.Contains(people, p => p.Name == "New Person");
+
+ var chapterPeople = chapter.People.Select(cp => cp.Person.Name).ToList();
+ Assert.Contains("Joe Shmo", chapterPeople);
+ Assert.Contains("New Person", chapterPeople);
+ }
+
+ // 2. Test removing a person no longer in the list
+ [Fact]
+ public async Task UpdateChapterPeopleAsync_RemovePeople()
+ {
+ await ResetDb();
+
+ var library = new LibraryBuilder("My Library")
+ .Build();
+
+ UnitOfWork.LibraryRepository.Add(library);
+ await UnitOfWork.CommitAsync();
+
+ var existingPerson1 = new PersonBuilder("Joe Shmo").Build();
+ var existingPerson2 = new PersonBuilder("Jane Doe").Build();
+ var chapter = new ChapterBuilder("1")
+ .WithPerson(existingPerson1, PersonRole.Editor)
+ .WithPerson(existingPerson2, PersonRole.Editor)
+ .Build();
+
+ var series = new SeriesBuilder("Test 1")
+ .WithLibraryId(library.Id)
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(chapter)
+ .Build())
+ .Build();
+
+ UnitOfWork.SeriesRepository.Add(series);
+ await UnitOfWork.CommitAsync();
+
+ // Call UpdateChapterPeopleAsync with only one person
+ await PersonHelper.UpdateChapterPeopleAsync(chapter, new List { "Joe Shmo" }, PersonRole.Editor, UnitOfWork);
+
+ // PersonHelper does not remove the Person from the global DbSet itself
+ await UnitOfWork.PersonRepository.RemoveAllPeopleNoLongerAssociated();
+
+ var people = await UnitOfWork.PersonRepository.GetAllPeople();
+ Assert.DoesNotContain(people, p => p.Name == "Jane Doe");
+
+ var chapterPeople = chapter.People.Select(cp => cp.Person.Name).ToList();
+ Assert.Contains("Joe Shmo", chapterPeople);
+ Assert.DoesNotContain("Jane Doe", chapterPeople);
+ }
+
+ // 3. Test no changes when the list of people is the same
+ [Fact]
+ public async Task UpdateChapterPeopleAsync_NoChanges()
+ {
+ await ResetDb();
+
+ var library = new LibraryBuilder("My Library")
+ .Build();
+
+ UnitOfWork.LibraryRepository.Add(library);
+ await UnitOfWork.CommitAsync();
+
+ var existingPerson = new PersonBuilder("Joe Shmo").Build();
+ var chapter = new ChapterBuilder("1").WithPerson(existingPerson, PersonRole.Editor).Build();
+
+ var series = new SeriesBuilder("Test 1")
+ .WithLibraryId(library.Id)
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(chapter)
+ .Build())
+ .Build();
+
+ UnitOfWork.SeriesRepository.Add(series);
+ await UnitOfWork.CommitAsync();
+
+ // Call UpdateChapterPeopleAsync with the same list
+ await PersonHelper.UpdateChapterPeopleAsync(chapter, new List { "Joe Shmo" }, PersonRole.Editor, UnitOfWork);
+
+ var people = await UnitOfWork.PersonRepository.GetAllPeople();
+ Assert.Contains(people, p => p.Name == "Joe Shmo");
+
+ var chapterPeople = chapter.People.Select(cp => cp.Person.Name).ToList();
+ Assert.Contains("Joe Shmo", chapterPeople);
+ Assert.Single(chapter.People); // No duplicate entries
+ }
+
+ // 4. Test multiple roles for a person
+ [Fact]
+ public async Task UpdateChapterPeopleAsync_MultipleRoles()
+ {
+ await ResetDb();
+
+ var library = new LibraryBuilder("My Library")
+ .Build();
+
+ UnitOfWork.LibraryRepository.Add(library);
+ await UnitOfWork.CommitAsync();
+
+ var person = new PersonBuilder("Joe Shmo").Build();
+ var chapter = new ChapterBuilder("1").WithPerson(person, PersonRole.Writer).Build();
+
+ var series = new SeriesBuilder("Test 1")
+ .WithLibraryId(library.Id)
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(chapter)
+ .Build())
+ .Build();
+
+ UnitOfWork.SeriesRepository.Add(series);
+ await UnitOfWork.CommitAsync();
+
+ // Add same person as Editor
+ await PersonHelper.UpdateChapterPeopleAsync(chapter, new List { "Joe Shmo" }, PersonRole.Editor, UnitOfWork);
+
+ // Ensure that the same person is assigned with two roles
+ var chapterPeople = chapter
+ .People
+ .Where(cp =>
+ cp.Person.Name == "Joe Shmo")
+ .ToList();
+ Assert.Equal(2, chapterPeople.Count); // One for each role
+ Assert.Contains(chapterPeople, cp => cp.Role == PersonRole.Writer);
+ Assert.Contains(chapterPeople, cp => cp.Role == PersonRole.Editor);
+ }
+
+ [Fact]
+ public async Task UpdateChapterPeopleAsync_MatchOnAlias_NoChanges()
+ {
+ await ResetDb();
+
+ var library = new LibraryBuilder("My Library")
+ .Build();
+
+ UnitOfWork.LibraryRepository.Add(library);
+ await UnitOfWork.CommitAsync();
+
+ var person = new PersonBuilder("Joe Doe")
+ .WithAlias("Jonny Doe")
+ .Build();
+
+ var chapter = new ChapterBuilder("1")
+ .WithPerson(person, PersonRole.Editor)
+ .Build();
+
+ var series = new SeriesBuilder("Test 1")
+ .WithLibraryId(library.Id)
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(chapter)
+ .Build())
+ .Build();
+
+ UnitOfWork.SeriesRepository.Add(series);
+ await UnitOfWork.CommitAsync();
+
+ // Add on Name
+ await PersonHelper.UpdateChapterPeopleAsync(chapter, new List { "Joe Doe" }, PersonRole.Editor, UnitOfWork);
+ await UnitOfWork.CommitAsync();
+
+ var allPeople = await UnitOfWork.PersonRepository.GetAllPeople();
+ Assert.Single(allPeople);
+
+ // Add on alias
+ await PersonHelper.UpdateChapterPeopleAsync(chapter, new List { "Jonny Doe" }, PersonRole.Editor, UnitOfWork);
+ await UnitOfWork.CommitAsync();
+
+ allPeople = await UnitOfWork.PersonRepository.GetAllPeople();
+ Assert.Single(allPeople);
+ }
+
+ // TODO: Unit tests for series
}
diff --git a/API.Tests/Helpers/RandfHelper.cs b/API.Tests/Helpers/RandfHelper.cs
new file mode 100644
index 000000000..d8c007df7
--- /dev/null
+++ b/API.Tests/Helpers/RandfHelper.cs
@@ -0,0 +1,124 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+
+namespace API.Tests.Helpers;
+
+public class RandfHelper
+{
+ private static readonly Random Random = new ();
+
+ ///
+ /// Returns true if all simple fields are equal
+ ///
+ ///
+ ///
+ /// fields to ignore, note that the names are very weird sometimes
+ ///
+ ///
+ ///
+ public static bool AreSimpleFieldsEqual(object obj1, object obj2, IList ignoreFields)
+ {
+ if (obj1 == null || obj2 == null)
+ throw new ArgumentNullException("Neither object can be null.");
+
+ Type type1 = obj1.GetType();
+ Type type2 = obj2.GetType();
+
+ if (type1 != type2)
+ throw new ArgumentException("Objects must be of the same type.");
+
+ FieldInfo[] fields = type1.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
+
+ foreach (var field in fields)
+ {
+ if (field.IsInitOnly) continue;
+ if (ignoreFields.Contains(field.Name)) continue;
+
+ Type fieldType = field.FieldType;
+
+ if (IsRelevantType(fieldType))
+ {
+ object value1 = field.GetValue(obj1);
+ object value2 = field.GetValue(obj2);
+
+ if (!Equals(value1, value2))
+ {
+ throw new ArgumentException("Fields must be of the same type: " + field.Name + " was " + value1 + " and " + value2);
+ }
+ }
+ }
+
+ return true;
+ }
+
+ private static bool IsRelevantType(Type type)
+ {
+ return type.IsPrimitive
+ || type == typeof(string)
+ || type.IsEnum;
+ }
+
+ ///
+ /// Sets all simple fields of the given object to a random value
+ ///
+ ///
+ /// Simple is, primitive, string, or enum
+ ///
+ public static void SetRandomValues(object obj)
+ {
+ if (obj == null) throw new ArgumentNullException(nameof(obj));
+
+ Type type = obj.GetType();
+ FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+
+ foreach (var field in fields)
+ {
+ if (field.IsInitOnly) continue; // Skip readonly fields
+
+ object value = GenerateRandomValue(field.FieldType);
+ if (value != null)
+ {
+ field.SetValue(obj, value);
+ }
+ }
+ }
+
+ private static object GenerateRandomValue(Type type)
+ {
+ if (type == typeof(int))
+ return Random.Next();
+ if (type == typeof(float))
+ return (float)Random.NextDouble() * 100;
+ if (type == typeof(double))
+ return Random.NextDouble() * 100;
+ if (type == typeof(bool))
+ return Random.Next(2) == 1;
+ if (type == typeof(char))
+ return (char)Random.Next('A', 'Z' + 1);
+ if (type == typeof(byte))
+ return (byte)Random.Next(0, 256);
+ if (type == typeof(short))
+ return (short)Random.Next(short.MinValue, short.MaxValue);
+ if (type == typeof(long))
+ return (long)(Random.NextDouble() * long.MaxValue);
+ if (type == typeof(string))
+ return GenerateRandomString(10);
+ if (type.IsEnum)
+ {
+ var values = Enum.GetValues(type);
+ return values.GetValue(Random.Next(values.Length));
+ }
+
+ // Unsupported type
+ return null;
+ }
+
+ private static string GenerateRandomString(int length)
+ {
+ const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ return new string(Enumerable.Repeat(chars, length)
+ .Select(s => s[Random.Next(s.Length)]).ToArray());
+ }
+}
diff --git a/API.Tests/Parsers/ComicVineParserTests.cs b/API.Tests/Parsers/ComicVineParserTests.cs
index f01e98afd..2f4fd568e 100644
--- a/API.Tests/Parsers/ComicVineParserTests.cs
+++ b/API.Tests/Parsers/ComicVineParserTests.cs
@@ -36,7 +36,7 @@ public class ComicVineParserTests
public void Parse_SeriesWithComicInfo()
{
var actual = _parser.Parse("C:/Comics/Birds of Prey (2002)/Birds of Prey 001 (2002).cbz", "C:/Comics/Birds of Prey (2002)/",
- RootDirectory, LibraryType.ComicVine, new ComicInfo()
+ RootDirectory, LibraryType.ComicVine, true, new ComicInfo()
{
Series = "Birds of Prey",
Volume = "2002"
@@ -54,7 +54,7 @@ public class ComicVineParserTests
public void Parse_SeriesWithDirectoryNameAsSeriesYear()
{
var actual = _parser.Parse("C:/Comics/Birds of Prey (2002)/Birds of Prey 001 (2002).cbz", "C:/Comics/Birds of Prey (2002)/",
- RootDirectory, LibraryType.ComicVine, null);
+ RootDirectory, LibraryType.ComicVine, true, null);
Assert.NotNull(actual);
Assert.Equal("Birds of Prey (2002)", actual.Series);
@@ -69,7 +69,7 @@ public class ComicVineParserTests
public void Parse_SeriesWithADirectoryNameAsSeriesYear()
{
var actual = _parser.Parse("C:/Comics/DC Comics/Birds of Prey (1999)/Birds of Prey 001 (1999).cbz", "C:/Comics/DC Comics/",
- RootDirectory, LibraryType.ComicVine, null);
+ RootDirectory, LibraryType.ComicVine, true, null);
Assert.NotNull(actual);
Assert.Equal("Birds of Prey (1999)", actual.Series);
@@ -84,7 +84,7 @@ public class ComicVineParserTests
public void Parse_FallbackToDirectoryNameOnly()
{
var actual = _parser.Parse("C:/Comics/DC Comics/Blood Syndicate/Blood Syndicate 001 (1999).cbz", "C:/Comics/DC Comics/",
- RootDirectory, LibraryType.ComicVine, null);
+ RootDirectory, LibraryType.ComicVine, true, null);
Assert.NotNull(actual);
Assert.Equal("Blood Syndicate", actual.Series);
diff --git a/API.Tests/Parsers/DefaultParserTests.cs b/API.Tests/Parsers/DefaultParserTests.cs
index 733b55d62..244c08b97 100644
--- a/API.Tests/Parsers/DefaultParserTests.cs
+++ b/API.Tests/Parsers/DefaultParserTests.cs
@@ -33,7 +33,7 @@ public class DefaultParserTests
[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, rootDir, LibraryType.Manga, null);
+ var actual = _defaultParser.Parse(inputPath, rootDir, rootDir, LibraryType.Manga, true, null);
if (actual == null)
{
Assert.NotNull(actual);
@@ -74,7 +74,7 @@ public class DefaultParserTests
fs.AddFile(inputFile, new MockFileData(""));
var ds = new DirectoryService(Substitute.For>(), fs);
var parser = new BasicParser(ds, new ImageParser(ds));
- var actual = parser.Parse(inputFile, rootDirectory, rootDirectory, LibraryType.Manga, null);
+ var actual = parser.Parse(inputFile, rootDirectory, rootDirectory, LibraryType.Manga, true, null);
_defaultParser.ParseFromFallbackFolders(inputFile, rootDirectory, LibraryType.Manga, ref actual);
Assert.Equal(expectedParseInfo, actual.Series);
}
@@ -90,7 +90,7 @@ public class DefaultParserTests
fs.AddFile(inputFile, new MockFileData(""));
var ds = new DirectoryService(Substitute.For>(), fs);
var parser = new BasicParser(ds, new ImageParser(ds));
- var actual = parser.Parse(inputFile, rootDirectory, rootDirectory, LibraryType.Manga, null);
+ var actual = parser.Parse(inputFile, rootDirectory, rootDirectory, LibraryType.Manga, true, null);
_defaultParser.ParseFromFallbackFolders(inputFile, rootDirectory, LibraryType.Manga, ref actual);
Assert.Equal(expectedParseInfo, actual.Series);
}
@@ -251,7 +251,7 @@ public class DefaultParserTests
foreach (var file in expected.Keys)
{
var expectedInfo = expected[file];
- var actual = _defaultParser.Parse(file, rootPath, rootPath, LibraryType.Manga, null);
+ var actual = _defaultParser.Parse(file, rootPath, rootPath, LibraryType.Manga, true, null);
if (expectedInfo == null)
{
Assert.Null(actual);
@@ -289,7 +289,7 @@ public class DefaultParserTests
Chapters = "8", Filename = "13.jpg", Format = MangaFormat.Image,
FullFilePath = filepath, IsSpecial = false
};
- var actual2 = _defaultParser.Parse(filepath, @"E:/Manga/Monster #8", "E:/Manga", LibraryType.Manga, null);
+ var actual2 = _defaultParser.Parse(filepath, @"E:/Manga/Monster #8", "E:/Manga", LibraryType.Manga, true, null);
Assert.NotNull(actual2);
_testOutputHelper.WriteLine($"Validating {filepath}");
Assert.Equal(expectedInfo2.Format, actual2.Format);
@@ -315,7 +315,7 @@ public class DefaultParserTests
FullFilePath = filepath, IsSpecial = false
};
- actual2 = _defaultParser.Parse(filepath, @"E:/Manga/Extra layer for no reason/", "E:/Manga",LibraryType.Manga, null);
+ actual2 = _defaultParser.Parse(filepath, @"E:/Manga/Extra layer for no reason/", "E:/Manga",LibraryType.Manga, true, null);
Assert.NotNull(actual2);
_testOutputHelper.WriteLine($"Validating {filepath}");
Assert.Equal(expectedInfo2.Format, actual2.Format);
@@ -341,7 +341,7 @@ public class DefaultParserTests
FullFilePath = filepath, IsSpecial = false
};
- actual2 = _defaultParser.Parse(filepath, @"E:/Manga/Extra layer for no reason/", "E:/Manga", LibraryType.Manga, null);
+ actual2 = _defaultParser.Parse(filepath, @"E:/Manga/Extra layer for no reason/", "E:/Manga", LibraryType.Manga, true, null);
Assert.NotNull(actual2);
_testOutputHelper.WriteLine($"Validating {filepath}");
Assert.Equal(expectedInfo2.Format, actual2.Format);
@@ -383,7 +383,7 @@ public class DefaultParserTests
FullFilePath = filepath
};
- var actual = parser.Parse(filepath, rootPath, rootPath, LibraryType.Manga, null);
+ var actual = parser.Parse(filepath, rootPath, rootPath, LibraryType.Manga, true, null);
Assert.NotNull(actual);
_testOutputHelper.WriteLine($"Validating {filepath}");
@@ -412,7 +412,7 @@ public class DefaultParserTests
FullFilePath = filepath
};
- actual = parser.Parse(filepath, rootPath, rootPath, LibraryType.Manga, null);
+ actual = parser.Parse(filepath, rootPath, rootPath, LibraryType.Manga, true, null);
Assert.NotNull(actual);
_testOutputHelper.WriteLine($"Validating {filepath}");
Assert.Equal(expected.Format, actual.Format);
@@ -475,7 +475,7 @@ public class DefaultParserTests
foreach (var file in expected.Keys)
{
var expectedInfo = expected[file];
- var actual = _defaultParser.Parse(file, rootPath, rootPath, LibraryType.Comic, null);
+ var actual = _defaultParser.Parse(file, rootPath, rootPath, LibraryType.Comic, true, null);
if (expectedInfo == null)
{
Assert.Null(actual);
diff --git a/API.Tests/Parsers/ImageParserTests.cs b/API.Tests/Parsers/ImageParserTests.cs
index f95c98ddf..63df1926e 100644
--- a/API.Tests/Parsers/ImageParserTests.cs
+++ b/API.Tests/Parsers/ImageParserTests.cs
@@ -34,7 +34,7 @@ public class ImageParserTests
public void Parse_SeriesWithDirectoryName()
{
var actual = _parser.Parse("C:/Comics/Birds of Prey/Chapter 01/01.jpg", "C:/Comics/Birds of Prey/",
- RootDirectory, LibraryType.Image, null);
+ RootDirectory, LibraryType.Image, true, null);
Assert.NotNull(actual);
Assert.Equal("Birds of Prey", actual.Series);
@@ -48,7 +48,7 @@ public class ImageParserTests
public void Parse_SeriesWithNoNestedChapter()
{
var actual = _parser.Parse("C:/Comics/Birds of Prey/Chapter 01 page 01.jpg", "C:/Comics/",
- RootDirectory, LibraryType.Image, null);
+ RootDirectory, LibraryType.Image, true, null);
Assert.NotNull(actual);
Assert.Equal("Birds of Prey", actual.Series);
@@ -62,7 +62,7 @@ public class ImageParserTests
public void Parse_SeriesWithLooseImages()
{
var actual = _parser.Parse("C:/Comics/Birds of Prey/page 01.jpg", "C:/Comics/",
- RootDirectory, LibraryType.Image, null);
+ RootDirectory, LibraryType.Image, true, null);
Assert.NotNull(actual);
Assert.Equal("Birds of Prey", actual.Series);
diff --git a/API.Tests/Parsers/PdfParserTests.cs b/API.Tests/Parsers/PdfParserTests.cs
index 72088526d..08bf9f25d 100644
--- a/API.Tests/Parsers/PdfParserTests.cs
+++ b/API.Tests/Parsers/PdfParserTests.cs
@@ -35,7 +35,7 @@ public class PdfParserTests
{
var actual = _parser.Parse("C:/Books/A Dictionary of Japanese Food - Ingredients and Culture/A Dictionary of Japanese Food - Ingredients and Culture.pdf",
"C:/Books/A Dictionary of Japanese Food - Ingredients and Culture/",
- RootDirectory, LibraryType.Book, null);
+ RootDirectory, LibraryType.Book, true, null);
Assert.NotNull(actual);
Assert.Equal("A Dictionary of Japanese Food - Ingredients and Culture", actual.Series);
diff --git a/API.Tests/Parsing/ImageParsingTests.cs b/API.Tests/Parsing/ImageParsingTests.cs
index 3d78d9372..362b4b08c 100644
--- a/API.Tests/Parsing/ImageParsingTests.cs
+++ b/API.Tests/Parsing/ImageParsingTests.cs
@@ -34,7 +34,7 @@ public class ImageParsingTests
Chapters = "8", Filename = "13.jpg", Format = MangaFormat.Image,
FullFilePath = filepath, IsSpecial = false
};
- var actual2 = _parser.Parse(filepath, @"E:\Manga\Monster #8", "E:/Manga", LibraryType.Image, null);
+ var actual2 = _parser.Parse(filepath, @"E:\Manga\Monster #8", "E:/Manga", LibraryType.Image, true, null);
Assert.NotNull(actual2);
_testOutputHelper.WriteLine($"Validating {filepath}");
Assert.Equal(expectedInfo2.Format, actual2.Format);
@@ -60,7 +60,7 @@ public class ImageParsingTests
FullFilePath = filepath, IsSpecial = false
};
- actual2 = _parser.Parse(filepath, @"E:\Manga\Extra layer for no reason\", "E:/Manga", LibraryType.Image, null);
+ actual2 = _parser.Parse(filepath, @"E:\Manga\Extra layer for no reason\", "E:/Manga", LibraryType.Image, true, null);
Assert.NotNull(actual2);
_testOutputHelper.WriteLine($"Validating {filepath}");
Assert.Equal(expectedInfo2.Format, actual2.Format);
@@ -86,7 +86,7 @@ public class ImageParsingTests
FullFilePath = filepath, IsSpecial = false
};
- actual2 = _parser.Parse(filepath, @"E:\Manga\Extra layer for no reason\", "E:/Manga", LibraryType.Image, null);
+ actual2 = _parser.Parse(filepath, @"E:\Manga\Extra layer for no reason\", "E:/Manga", LibraryType.Image, true, null);
Assert.NotNull(actual2);
_testOutputHelper.WriteLine($"Validating {filepath}");
Assert.Equal(expectedInfo2.Format, actual2.Format);
diff --git a/API.Tests/Parsing/MagazineParserTests.cs b/API.Tests/Parsing/MagazineParserTests.cs
deleted file mode 100644
index f6e71d9e0..000000000
--- a/API.Tests/Parsing/MagazineParserTests.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using Xunit;
-
-namespace API.Tests.Parser;
-
-public class MagazineParserTests
-{
- [Theory]
- [InlineData("3D World - 2018 UK", "3D World")]
- [InlineData("3D World - 2018", "3D World")]
- [InlineData("UK World - 022012 [Digital]", "UK World")]
- [InlineData("Computer Weekly - September 2023", "Computer Weekly")]
- public void ParseSeriesTest(string filename, string expected)
- {
- Assert.Equal(expected, API.Services.Tasks.Scanner.Parser.Parser.ParseMagazineSeries(filename));
- }
-
- [Theory]
- [InlineData("UK World - 022012 [Digital]", "2012")]
- [InlineData("Computer Weekly - September 2023", "2023")]
- [InlineData("Computer Weekly - September 2023 #2", "2023")]
- [InlineData("PC Games - 2001 #01", "2001")]
- public void ParseVolumeTest(string filename, string expected)
- {
- Assert.Equal(expected, API.Services.Tasks.Scanner.Parser.Parser.ParseMagazineVolume(filename));
- }
-
- [Theory]
- [InlineData("UK World - 022012 [Digital]", "0")]
- [InlineData("Computer Weekly - September 2023", "9")]
- [InlineData("Computer Weekly - September 2023 #2", "2")]
- [InlineData("PC Games - 2001 #01", "1")]
- public void ParseChapterTest(string filename, string expected)
- {
- Assert.Equal(expected, API.Services.Tasks.Scanner.Parser.Parser.ParseMagazineChapter(filename));
- }
-
- [Theory]
- [InlineData("AIR International Vol. 14 No. 3 (ISSN 1011-3250)", "1011-3250")]
- public void ParseGTINTest(string filename, string expected)
- {
- Assert.Equal(expected, API.Services.Tasks.Scanner.Parser.Parser.ParseGTIN(filename));
- }
-}
diff --git a/API.Tests/Parsing/MangaParsingTests.cs b/API.Tests/Parsing/MangaParsingTests.cs
index 8b93c5f90..53f2bc4c9 100644
--- a/API.Tests/Parsing/MangaParsingTests.cs
+++ b/API.Tests/Parsing/MangaParsingTests.cs
@@ -68,10 +68,8 @@ public class MangaParsingTests
[InlineData("Манга Тома 1-4", "1-4")]
[InlineData("Манга Том 1-4", "1-4")]
[InlineData("조선왕조실톡 106화", "106")]
- [InlineData("죽음 13회", "13")]
[InlineData("동의보감 13장", "13")]
[InlineData("몰?루 아카이브 7.5권", "7.5")]
- [InlineData("주술회전 1.5권", "1.5")]
[InlineData("63권#200", "63")]
[InlineData("시즌34삽화2", "34")]
[InlineData("Accel World Chapter 001 Volume 002", "2")]
diff --git a/API.Tests/Repository/GenreRepositoryTests.cs b/API.Tests/Repository/GenreRepositoryTests.cs
new file mode 100644
index 000000000..d197a91ba
--- /dev/null
+++ b/API.Tests/Repository/GenreRepositoryTests.cs
@@ -0,0 +1,280 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using API.DTOs.Metadata.Browse;
+using API.Entities;
+using API.Entities.Enums;
+using API.Entities.Metadata;
+using API.Helpers;
+using API.Helpers.Builders;
+using Xunit;
+
+namespace API.Tests.Repository;
+
+public class GenreRepositoryTests : AbstractDbTest
+{
+ private AppUser _fullAccess;
+ private AppUser _restrictedAccess;
+ private AppUser _restrictedAgeAccess;
+
+ protected override async Task ResetDb()
+ {
+ Context.Genre.RemoveRange(Context.Genre);
+ Context.Library.RemoveRange(Context.Library);
+ await Context.SaveChangesAsync();
+ }
+
+ private TestGenreSet CreateTestGenres()
+ {
+ return new TestGenreSet
+ {
+ SharedSeriesChaptersGenre = new GenreBuilder("Shared Series Chapter Genre").Build(),
+ SharedSeriesGenre = new GenreBuilder("Shared Series Genre").Build(),
+ SharedChaptersGenre = new GenreBuilder("Shared Chapters Genre").Build(),
+ Lib0SeriesChaptersGenre = new GenreBuilder("Lib0 Series Chapter Genre").Build(),
+ Lib0SeriesGenre = new GenreBuilder("Lib0 Series Genre").Build(),
+ Lib0ChaptersGenre = new GenreBuilder("Lib0 Chapters Genre").Build(),
+ Lib1SeriesChaptersGenre = new GenreBuilder("Lib1 Series Chapter Genre").Build(),
+ Lib1SeriesGenre = new GenreBuilder("Lib1 Series Genre").Build(),
+ Lib1ChaptersGenre = new GenreBuilder("Lib1 Chapters Genre").Build(),
+ Lib1ChapterAgeGenre = new GenreBuilder("Lib1 Chapter Age Genre").Build()
+ };
+ }
+
+ private async Task SeedDbWithGenres(TestGenreSet genres)
+ {
+ await CreateTestUsers();
+ await AddGenresToContext(genres);
+ await CreateLibrariesWithGenres(genres);
+ await AssignLibrariesToUsers();
+ }
+
+ private async Task CreateTestUsers()
+ {
+ _fullAccess = new AppUserBuilder("amelia", "amelia@example.com").Build();
+ _restrictedAccess = new AppUserBuilder("mila", "mila@example.com").Build();
+ _restrictedAgeAccess = new AppUserBuilder("eva", "eva@example.com").Build();
+ _restrictedAgeAccess.AgeRestriction = AgeRating.Teen;
+ _restrictedAgeAccess.AgeRestrictionIncludeUnknowns = true;
+
+ Context.Users.Add(_fullAccess);
+ Context.Users.Add(_restrictedAccess);
+ Context.Users.Add(_restrictedAgeAccess);
+ await Context.SaveChangesAsync();
+ }
+
+ private async Task AddGenresToContext(TestGenreSet genres)
+ {
+ var allGenres = genres.GetAllGenres();
+ Context.Genre.AddRange(allGenres);
+ await Context.SaveChangesAsync();
+ }
+
+ private async Task CreateLibrariesWithGenres(TestGenreSet genres)
+ {
+ var lib0 = new LibraryBuilder("lib0")
+ .WithSeries(new SeriesBuilder("lib0-s0")
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithGenres([genres.SharedSeriesChaptersGenre, genres.SharedSeriesGenre, genres.Lib0SeriesChaptersGenre, genres.Lib0SeriesGenre])
+ .Build())
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(new ChapterBuilder("1")
+ .WithGenres([genres.SharedSeriesChaptersGenre, genres.SharedChaptersGenre, genres.Lib0SeriesChaptersGenre, genres.Lib0ChaptersGenre])
+ .Build())
+ .WithChapter(new ChapterBuilder("2")
+ .WithGenres([genres.SharedSeriesChaptersGenre, genres.SharedChaptersGenre, genres.Lib1SeriesChaptersGenre, genres.Lib1ChaptersGenre])
+ .Build())
+ .Build())
+ .Build())
+ .Build();
+
+ var lib1 = new LibraryBuilder("lib1")
+ .WithSeries(new SeriesBuilder("lib1-s0")
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithGenres([genres.SharedSeriesChaptersGenre, genres.SharedSeriesGenre, genres.Lib1SeriesChaptersGenre, genres.Lib1SeriesGenre])
+ .WithAgeRating(AgeRating.Mature17Plus)
+ .Build())
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(new ChapterBuilder("1")
+ .WithGenres([genres.SharedSeriesChaptersGenre, genres.SharedChaptersGenre, genres.Lib1SeriesChaptersGenre, genres.Lib1ChaptersGenre])
+ .Build())
+ .WithChapter(new ChapterBuilder("2")
+ .WithGenres([genres.SharedSeriesChaptersGenre, genres.SharedChaptersGenre, genres.Lib1SeriesChaptersGenre, genres.Lib1ChaptersGenre, genres.Lib1ChapterAgeGenre])
+ .WithAgeRating(AgeRating.Mature17Plus)
+ .Build())
+ .Build())
+ .Build())
+ .WithSeries(new SeriesBuilder("lib1-s1")
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithGenres([genres.SharedSeriesChaptersGenre, genres.SharedSeriesGenre, genres.Lib1SeriesChaptersGenre, genres.Lib1SeriesGenre])
+ .Build())
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(new ChapterBuilder("1")
+ .WithGenres([genres.SharedSeriesChaptersGenre, genres.SharedChaptersGenre, genres.Lib1SeriesChaptersGenre, genres.Lib1ChaptersGenre])
+ .Build())
+ .WithChapter(new ChapterBuilder("2")
+ .WithGenres([genres.SharedSeriesChaptersGenre, genres.SharedChaptersGenre, genres.Lib1SeriesChaptersGenre, genres.Lib1ChaptersGenre])
+ .Build())
+ .Build())
+ .Build())
+ .Build();
+
+ Context.Library.Add(lib0);
+ Context.Library.Add(lib1);
+ await Context.SaveChangesAsync();
+ }
+
+ private async Task AssignLibrariesToUsers()
+ {
+ var lib0 = Context.Library.First(l => l.Name == "lib0");
+ var lib1 = Context.Library.First(l => l.Name == "lib1");
+
+ _fullAccess.Libraries.Add(lib0);
+ _fullAccess.Libraries.Add(lib1);
+ _restrictedAccess.Libraries.Add(lib1);
+ _restrictedAgeAccess.Libraries.Add(lib1);
+
+ await Context.SaveChangesAsync();
+ }
+
+ private static Predicate ContainsGenreCheck(Genre genre)
+ {
+ return g => g.Id == genre.Id;
+ }
+
+ private static void AssertGenrePresent(IEnumerable genres, Genre expectedGenre)
+ {
+ Assert.Contains(genres, ContainsGenreCheck(expectedGenre));
+ }
+
+ private static void AssertGenreNotPresent(IEnumerable genres, Genre expectedGenre)
+ {
+ Assert.DoesNotContain(genres, ContainsGenreCheck(expectedGenre));
+ }
+
+ private static BrowseGenreDto GetGenreDto(IEnumerable genres, Genre genre)
+ {
+ return genres.First(dto => dto.Id == genre.Id);
+ }
+
+ [Fact]
+ public async Task GetBrowseableGenre_FullAccess_ReturnsAllGenresWithCorrectCounts()
+ {
+ // Arrange
+ await ResetDb();
+ var genres = CreateTestGenres();
+ await SeedDbWithGenres(genres);
+
+ // Act
+ var fullAccessGenres = await UnitOfWork.GenreRepository.GetBrowseableGenre(_fullAccess.Id, new UserParams());
+
+ // Assert
+ Assert.Equal(genres.GetAllGenres().Count, fullAccessGenres.TotalCount);
+
+ foreach (var genre in genres.GetAllGenres())
+ {
+ AssertGenrePresent(fullAccessGenres, genre);
+ }
+
+ // Verify counts - 1 lib0 series, 2 lib1 series = 3 total series
+ Assert.Equal(3, GetGenreDto(fullAccessGenres, genres.SharedSeriesChaptersGenre).SeriesCount);
+ Assert.Equal(6, GetGenreDto(fullAccessGenres, genres.SharedSeriesChaptersGenre).ChapterCount);
+ Assert.Equal(1, GetGenreDto(fullAccessGenres, genres.Lib0SeriesGenre).SeriesCount);
+ }
+
+ [Fact]
+ public async Task GetBrowseableGenre_RestrictedAccess_ReturnsOnlyAccessibleGenres()
+ {
+ // Arrange
+ await ResetDb();
+ var genres = CreateTestGenres();
+ await SeedDbWithGenres(genres);
+
+ // Act
+ var restrictedAccessGenres = await UnitOfWork.GenreRepository.GetBrowseableGenre(_restrictedAccess.Id, new UserParams());
+
+ // Assert - Should see: 3 shared + 4 library 1 specific = 7 genres
+ Assert.Equal(7, restrictedAccessGenres.TotalCount);
+
+ // Verify shared and Library 1 genres are present
+ AssertGenrePresent(restrictedAccessGenres, genres.SharedSeriesChaptersGenre);
+ AssertGenrePresent(restrictedAccessGenres, genres.SharedSeriesGenre);
+ AssertGenrePresent(restrictedAccessGenres, genres.SharedChaptersGenre);
+ AssertGenrePresent(restrictedAccessGenres, genres.Lib1SeriesChaptersGenre);
+ AssertGenrePresent(restrictedAccessGenres, genres.Lib1SeriesGenre);
+ AssertGenrePresent(restrictedAccessGenres, genres.Lib1ChaptersGenre);
+ AssertGenrePresent(restrictedAccessGenres, genres.Lib1ChapterAgeGenre);
+
+ // Verify Library 0 specific genres are not present
+ AssertGenreNotPresent(restrictedAccessGenres, genres.Lib0SeriesChaptersGenre);
+ AssertGenreNotPresent(restrictedAccessGenres, genres.Lib0SeriesGenre);
+ AssertGenreNotPresent(restrictedAccessGenres, genres.Lib0ChaptersGenre);
+
+ // Verify counts - 2 lib1 series
+ Assert.Equal(2, GetGenreDto(restrictedAccessGenres, genres.SharedSeriesChaptersGenre).SeriesCount);
+ Assert.Equal(4, GetGenreDto(restrictedAccessGenres, genres.SharedSeriesChaptersGenre).ChapterCount);
+ Assert.Equal(2, GetGenreDto(restrictedAccessGenres, genres.Lib1SeriesGenre).SeriesCount);
+ Assert.Equal(4, GetGenreDto(restrictedAccessGenres, genres.Lib1ChaptersGenre).ChapterCount);
+ Assert.Equal(1, GetGenreDto(restrictedAccessGenres, genres.Lib1ChapterAgeGenre).ChapterCount);
+ }
+
+ [Fact]
+ public async Task GetBrowseableGenre_RestrictedAgeAccess_FiltersAgeRestrictedContent()
+ {
+ // Arrange
+ await ResetDb();
+ var genres = CreateTestGenres();
+ await SeedDbWithGenres(genres);
+
+ // Act
+ var restrictedAgeAccessGenres = await UnitOfWork.GenreRepository.GetBrowseableGenre(_restrictedAgeAccess.Id, new UserParams());
+
+ // Assert - Should see: 3 shared + 3 lib1 specific = 6 genres (age-restricted genre filtered out)
+ Assert.Equal(6, restrictedAgeAccessGenres.TotalCount);
+
+ // Verify accessible genres are present
+ AssertGenrePresent(restrictedAgeAccessGenres, genres.SharedSeriesChaptersGenre);
+ AssertGenrePresent(restrictedAgeAccessGenres, genres.SharedSeriesGenre);
+ AssertGenrePresent(restrictedAgeAccessGenres, genres.SharedChaptersGenre);
+ AssertGenrePresent(restrictedAgeAccessGenres, genres.Lib1SeriesChaptersGenre);
+ AssertGenrePresent(restrictedAgeAccessGenres, genres.Lib1SeriesGenre);
+ AssertGenrePresent(restrictedAgeAccessGenres, genres.Lib1ChaptersGenre);
+
+ // Verify age-restricted genre is filtered out
+ AssertGenreNotPresent(restrictedAgeAccessGenres, genres.Lib1ChapterAgeGenre);
+
+ // Verify counts - 1 series lib1 (age-restricted series filtered out)
+ Assert.Equal(1, GetGenreDto(restrictedAgeAccessGenres, genres.SharedSeriesChaptersGenre).SeriesCount);
+ Assert.Equal(1, GetGenreDto(restrictedAgeAccessGenres, genres.Lib1SeriesGenre).SeriesCount);
+
+ // These values represent a bug - chapters are not properly filtered when their series is age-restricted
+ // Should be 2, but currently returns 3 due to the filtering issue
+ Assert.Equal(3, GetGenreDto(restrictedAgeAccessGenres, genres.SharedSeriesChaptersGenre).ChapterCount);
+ Assert.Equal(3, GetGenreDto(restrictedAgeAccessGenres, genres.Lib1ChaptersGenre).ChapterCount);
+ }
+
+ private class TestGenreSet
+ {
+ public Genre SharedSeriesChaptersGenre { get; set; }
+ public Genre SharedSeriesGenre { get; set; }
+ public Genre SharedChaptersGenre { get; set; }
+ public Genre Lib0SeriesChaptersGenre { get; set; }
+ public Genre Lib0SeriesGenre { get; set; }
+ public Genre Lib0ChaptersGenre { get; set; }
+ public Genre Lib1SeriesChaptersGenre { get; set; }
+ public Genre Lib1SeriesGenre { get; set; }
+ public Genre Lib1ChaptersGenre { get; set; }
+ public Genre Lib1ChapterAgeGenre { get; set; }
+
+ public List GetAllGenres()
+ {
+ return
+ [
+ SharedSeriesChaptersGenre, SharedSeriesGenre, SharedChaptersGenre,
+ Lib0SeriesChaptersGenre, Lib0SeriesGenre, Lib0ChaptersGenre,
+ Lib1SeriesChaptersGenre, Lib1SeriesGenre, Lib1ChaptersGenre, Lib1ChapterAgeGenre
+ ];
+ }
+ }
+}
diff --git a/API.Tests/Repository/PersonRepositoryTests.cs b/API.Tests/Repository/PersonRepositoryTests.cs
new file mode 100644
index 000000000..a2b19cc0c
--- /dev/null
+++ b/API.Tests/Repository/PersonRepositoryTests.cs
@@ -0,0 +1,342 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using API.DTOs.Metadata.Browse;
+using API.DTOs.Metadata.Browse.Requests;
+using API.Entities;
+using API.Entities.Enums;
+using API.Entities.Person;
+using API.Helpers;
+using API.Helpers.Builders;
+using Xunit;
+
+namespace API.Tests.Repository;
+
+public class PersonRepositoryTests : AbstractDbTest
+{
+ private AppUser _fullAccess;
+ private AppUser _restrictedAccess;
+ private AppUser _restrictedAgeAccess;
+
+ protected override async Task ResetDb()
+ {
+ Context.Person.RemoveRange(Context.Person.ToList());
+ Context.Library.RemoveRange(Context.Library.ToList());
+ Context.AppUser.RemoveRange(Context.AppUser.ToList());
+ await UnitOfWork.CommitAsync();
+ }
+
+ private async Task SeedDb()
+ {
+ _fullAccess = new AppUserBuilder("amelia", "amelia@example.com").Build();
+ _restrictedAccess = new AppUserBuilder("mila", "mila@example.com").Build();
+ _restrictedAgeAccess = new AppUserBuilder("eva", "eva@example.com").Build();
+ _restrictedAgeAccess.AgeRestriction = AgeRating.Teen;
+ _restrictedAgeAccess.AgeRestrictionIncludeUnknowns = true;
+
+ Context.AppUser.Add(_fullAccess);
+ Context.AppUser.Add(_restrictedAccess);
+ Context.AppUser.Add(_restrictedAgeAccess);
+ await Context.SaveChangesAsync();
+
+ var people = CreateTestPeople();
+ Context.Person.AddRange(people);
+ await Context.SaveChangesAsync();
+
+ var libraries = CreateTestLibraries(people);
+ Context.Library.AddRange(libraries);
+ await Context.SaveChangesAsync();
+
+ _fullAccess.Libraries.Add(libraries[0]); // lib0
+ _fullAccess.Libraries.Add(libraries[1]); // lib1
+ _restrictedAccess.Libraries.Add(libraries[1]); // lib1 only
+ _restrictedAgeAccess.Libraries.Add(libraries[1]); // lib1 only
+
+ await Context.SaveChangesAsync();
+ }
+
+ private static List CreateTestPeople()
+ {
+ return new List
+ {
+ new PersonBuilder("Shared Series Chapter Person").Build(),
+ new PersonBuilder("Shared Series Person").Build(),
+ new PersonBuilder("Shared Chapters Person").Build(),
+ new PersonBuilder("Lib0 Series Chapter Person").Build(),
+ new PersonBuilder("Lib0 Series Person").Build(),
+ new PersonBuilder("Lib0 Chapters Person").Build(),
+ new PersonBuilder("Lib1 Series Chapter Person").Build(),
+ new PersonBuilder("Lib1 Series Person").Build(),
+ new PersonBuilder("Lib1 Chapters Person").Build(),
+ new PersonBuilder("Lib1 Chapter Age Person").Build()
+ };
+ }
+
+ private static List CreateTestLibraries(List people)
+ {
+ var lib0 = new LibraryBuilder("lib0")
+ .WithSeries(new SeriesBuilder("lib0-s0")
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithPerson(GetPersonByName(people, "Shared Series Chapter Person"), PersonRole.Writer)
+ .WithPerson(GetPersonByName(people, "Shared Series Person"), PersonRole.Writer)
+ .WithPerson(GetPersonByName(people, "Lib0 Series Chapter Person"), PersonRole.Writer)
+ .WithPerson(GetPersonByName(people, "Lib0 Series Person"), PersonRole.Writer)
+ .Build())
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(new ChapterBuilder("1")
+ .WithPerson(GetPersonByName(people, "Shared Series Chapter Person"), PersonRole.Colorist)
+ .WithPerson(GetPersonByName(people, "Shared Chapters Person"), PersonRole.Colorist)
+ .WithPerson(GetPersonByName(people, "Lib0 Series Chapter Person"), PersonRole.Colorist)
+ .WithPerson(GetPersonByName(people, "Lib0 Chapters Person"), PersonRole.Colorist)
+ .Build())
+ .WithChapter(new ChapterBuilder("2")
+ .WithPerson(GetPersonByName(people, "Shared Series Chapter Person"), PersonRole.Editor)
+ .WithPerson(GetPersonByName(people, "Shared Chapters Person"), PersonRole.Editor)
+ .WithPerson(GetPersonByName(people, "Lib0 Series Chapter Person"), PersonRole.Editor)
+ .WithPerson(GetPersonByName(people, "Lib0 Chapters Person"), PersonRole.Editor)
+ .Build())
+ .Build())
+ .Build())
+ .Build();
+
+ var lib1 = new LibraryBuilder("lib1")
+ .WithSeries(new SeriesBuilder("lib1-s0")
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithPerson(GetPersonByName(people, "Shared Series Chapter Person"), PersonRole.Letterer)
+ .WithPerson(GetPersonByName(people, "Shared Series Person"), PersonRole.Letterer)
+ .WithPerson(GetPersonByName(people, "Lib1 Series Chapter Person"), PersonRole.Letterer)
+ .WithPerson(GetPersonByName(people, "Lib1 Series Person"), PersonRole.Letterer)
+ .WithAgeRating(AgeRating.Mature17Plus)
+ .Build())
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(new ChapterBuilder("1")
+ .WithPerson(GetPersonByName(people, "Shared Series Chapter Person"), PersonRole.Imprint)
+ .WithPerson(GetPersonByName(people, "Shared Chapters Person"), PersonRole.Imprint)
+ .WithPerson(GetPersonByName(people, "Lib1 Series Chapter Person"), PersonRole.Imprint)
+ .WithPerson(GetPersonByName(people, "Lib1 Chapters Person"), PersonRole.Imprint)
+ .Build())
+ .WithChapter(new ChapterBuilder("2")
+ .WithPerson(GetPersonByName(people, "Shared Series Chapter Person"), PersonRole.CoverArtist)
+ .WithPerson(GetPersonByName(people, "Shared Chapters Person"), PersonRole.CoverArtist)
+ .WithPerson(GetPersonByName(people, "Lib1 Series Chapter Person"), PersonRole.CoverArtist)
+ .WithPerson(GetPersonByName(people, "Lib1 Chapters Person"), PersonRole.CoverArtist)
+ .WithPerson(GetPersonByName(people, "Lib1 Chapter Age Person"), PersonRole.CoverArtist)
+ .WithAgeRating(AgeRating.Mature17Plus)
+ .Build())
+ .Build())
+ .Build())
+ .WithSeries(new SeriesBuilder("lib1-s1")
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithPerson(GetPersonByName(people, "Shared Series Chapter Person"), PersonRole.Inker)
+ .WithPerson(GetPersonByName(people, "Shared Series Person"), PersonRole.Inker)
+ .WithPerson(GetPersonByName(people, "Lib1 Series Chapter Person"), PersonRole.Inker)
+ .WithPerson(GetPersonByName(people, "Lib1 Series Person"), PersonRole.Inker)
+ .Build())
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(new ChapterBuilder("1")
+ .WithPerson(GetPersonByName(people, "Shared Series Chapter Person"), PersonRole.Team)
+ .WithPerson(GetPersonByName(people, "Shared Chapters Person"), PersonRole.Team)
+ .WithPerson(GetPersonByName(people, "Lib1 Series Chapter Person"), PersonRole.Team)
+ .WithPerson(GetPersonByName(people, "Lib1 Chapters Person"), PersonRole.Team)
+ .Build())
+ .WithChapter(new ChapterBuilder("2")
+ .WithPerson(GetPersonByName(people, "Shared Series Chapter Person"), PersonRole.Translator)
+ .WithPerson(GetPersonByName(people, "Shared Chapters Person"), PersonRole.Translator)
+ .WithPerson(GetPersonByName(people, "Lib1 Series Chapter Person"), PersonRole.Translator)
+ .WithPerson(GetPersonByName(people, "Lib1 Chapters Person"), PersonRole.Translator)
+ .Build())
+ .Build())
+ .Build())
+ .Build();
+
+ return new List { lib0, lib1 };
+ }
+
+ private static Person GetPersonByName(List people, string name)
+ {
+ return people.First(p => p.Name == name);
+ }
+
+ private Person GetPersonByName(string name)
+ {
+ return Context.Person.First(p => p.Name == name);
+ }
+
+ private static Predicate ContainsPersonCheck(Person person)
+ {
+ return p => p.Id == person.Id;
+ }
+
+ [Fact]
+ public async Task GetBrowsePersonDtos()
+ {
+ await ResetDb();
+ await SeedDb();
+
+ // Get people from database for assertions
+ var sharedSeriesChaptersPerson = GetPersonByName("Shared Series Chapter Person");
+ var lib0SeriesPerson = GetPersonByName("Lib0 Series Person");
+ var lib1SeriesPerson = GetPersonByName("Lib1 Series Person");
+ var lib1ChapterAgePerson = GetPersonByName("Lib1 Chapter Age Person");
+ var allPeople = Context.Person.ToList();
+
+ var fullAccessPeople =
+ await UnitOfWork.PersonRepository.GetBrowsePersonDtos(_fullAccess.Id, new BrowsePersonFilterDto(),
+ new UserParams());
+ Assert.Equal(allPeople.Count, fullAccessPeople.TotalCount);
+
+ foreach (var person in allPeople)
+ Assert.Contains(fullAccessPeople, ContainsPersonCheck(person));
+
+ // 1 series in lib0, 2 series in lib1
+ Assert.Equal(3, fullAccessPeople.First(dto => dto.Id == sharedSeriesChaptersPerson.Id).SeriesCount);
+ // 3 series with each 2 chapters
+ Assert.Equal(6, fullAccessPeople.First(dto => dto.Id == sharedSeriesChaptersPerson.Id).ChapterCount);
+ // 1 series in lib0
+ Assert.Equal(1, fullAccessPeople.First(dto => dto.Id == lib0SeriesPerson.Id).SeriesCount);
+ // 2 series in lib1
+ Assert.Equal(2, fullAccessPeople.First(dto => dto.Id == lib1SeriesPerson.Id).SeriesCount);
+
+ var restrictedAccessPeople =
+ await UnitOfWork.PersonRepository.GetBrowsePersonDtos(_restrictedAccess.Id, new BrowsePersonFilterDto(),
+ new UserParams());
+
+ Assert.Equal(7, restrictedAccessPeople.TotalCount);
+
+ Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(GetPersonByName("Shared Series Chapter Person")));
+ Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(GetPersonByName("Shared Series Person")));
+ Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(GetPersonByName("Shared Chapters Person")));
+ Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(GetPersonByName("Lib1 Series Chapter Person")));
+ Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(GetPersonByName("Lib1 Series Person")));
+ Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(GetPersonByName("Lib1 Chapters Person")));
+ Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(GetPersonByName("Lib1 Chapter Age Person")));
+
+ // 2 series in lib1, no series in lib0
+ Assert.Equal(2, restrictedAccessPeople.First(dto => dto.Id == sharedSeriesChaptersPerson.Id).SeriesCount);
+ // 2 series with each 2 chapters
+ Assert.Equal(4, restrictedAccessPeople.First(dto => dto.Id == sharedSeriesChaptersPerson.Id).ChapterCount);
+ // 2 series in lib1
+ Assert.Equal(2, restrictedAccessPeople.First(dto => dto.Id == lib1SeriesPerson.Id).SeriesCount);
+
+ var restrictedAgeAccessPeople = await UnitOfWork.PersonRepository.GetBrowsePersonDtos(_restrictedAgeAccess.Id,
+ new BrowsePersonFilterDto(), new UserParams());
+
+ // Note: There is a potential bug here where a person in a different chapter of an age restricted series will show up
+ Assert.Equal(6, restrictedAgeAccessPeople.TotalCount);
+
+ // No access to the age restricted chapter
+ Assert.DoesNotContain(restrictedAgeAccessPeople, ContainsPersonCheck(lib1ChapterAgePerson));
+ }
+
+ [Fact]
+ public async Task GetRolesForPersonByName()
+ {
+ await ResetDb();
+ await SeedDb();
+
+ var sharedSeriesPerson = GetPersonByName("Shared Series Person");
+ var sharedChaptersPerson = GetPersonByName("Shared Chapters Person");
+ var lib1ChapterAgePerson = GetPersonByName("Lib1 Chapter Age Person");
+
+ var sharedSeriesRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(sharedSeriesPerson.Id, _fullAccess.Id);
+ var chapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(sharedChaptersPerson.Id, _fullAccess.Id);
+ var ageChapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(lib1ChapterAgePerson.Id, _fullAccess.Id);
+ Assert.Equal(3, sharedSeriesRoles.Count());
+ Assert.Equal(6, chapterRoles.Count());
+ Assert.Single(ageChapterRoles);
+
+ var restrictedRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(sharedSeriesPerson.Id, _restrictedAccess.Id);
+ var restrictedChapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(sharedChaptersPerson.Id, _restrictedAccess.Id);
+ var restrictedAgePersonChapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(lib1ChapterAgePerson.Id, _restrictedAccess.Id);
+ Assert.Equal(2, restrictedRoles.Count());
+ Assert.Equal(4, restrictedChapterRoles.Count());
+ Assert.Single(restrictedAgePersonChapterRoles);
+
+ var restrictedAgeRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(sharedSeriesPerson.Id, _restrictedAgeAccess.Id);
+ var restrictedAgeChapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(sharedChaptersPerson.Id, _restrictedAgeAccess.Id);
+ var restrictedAgeAgePersonChapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(lib1ChapterAgePerson.Id, _restrictedAgeAccess.Id);
+ Assert.Single(restrictedAgeRoles);
+ Assert.Equal(2, restrictedAgeChapterRoles.Count());
+ // Note: There is a potential bug here where a person in a different chapter of an age restricted series will show up
+ Assert.Empty(restrictedAgeAgePersonChapterRoles);
+ }
+
+ [Fact]
+ public async Task GetPersonDtoByName()
+ {
+ await ResetDb();
+ await SeedDb();
+
+ var allPeople = Context.Person.ToList();
+
+ foreach (var person in allPeople)
+ {
+ Assert.NotNull(await UnitOfWork.PersonRepository.GetPersonDtoByName(person.Name, _fullAccess.Id));
+ }
+
+ Assert.Null(await UnitOfWork.PersonRepository.GetPersonDtoByName("Lib0 Chapters Person", _restrictedAccess.Id));
+ Assert.NotNull(await UnitOfWork.PersonRepository.GetPersonDtoByName("Shared Series Person", _restrictedAccess.Id));
+ Assert.NotNull(await UnitOfWork.PersonRepository.GetPersonDtoByName("Lib1 Series Person", _restrictedAccess.Id));
+
+ Assert.Null(await UnitOfWork.PersonRepository.GetPersonDtoByName("Lib0 Chapters Person", _restrictedAgeAccess.Id));
+ Assert.NotNull(await UnitOfWork.PersonRepository.GetPersonDtoByName("Lib1 Series Person", _restrictedAgeAccess.Id));
+ // Note: There is a potential bug here where a person in a different chapter of an age restricted series will show up
+ Assert.Null(await UnitOfWork.PersonRepository.GetPersonDtoByName("Lib1 Chapter Age Person", _restrictedAgeAccess.Id));
+ }
+
+ [Fact]
+ public async Task GetSeriesKnownFor()
+ {
+ await ResetDb();
+ await SeedDb();
+
+ var sharedSeriesPerson = GetPersonByName("Shared Series Person");
+ var lib1SeriesPerson = GetPersonByName("Lib1 Series Person");
+
+ var series = await UnitOfWork.PersonRepository.GetSeriesKnownFor(sharedSeriesPerson.Id, _fullAccess.Id);
+ Assert.Equal(3, series.Count());
+
+ series = await UnitOfWork.PersonRepository.GetSeriesKnownFor(sharedSeriesPerson.Id, _restrictedAccess.Id);
+ Assert.Equal(2, series.Count());
+
+ series = await UnitOfWork.PersonRepository.GetSeriesKnownFor(sharedSeriesPerson.Id, _restrictedAgeAccess.Id);
+ Assert.Single(series);
+
+ series = await UnitOfWork.PersonRepository.GetSeriesKnownFor(lib1SeriesPerson.Id, _restrictedAgeAccess.Id);
+ Assert.Single(series);
+ }
+
+ [Fact]
+ public async Task GetChaptersForPersonByRole()
+ {
+ await ResetDb();
+ await SeedDb();
+
+ var sharedChaptersPerson = GetPersonByName("Shared Chapters Person");
+
+ // Lib0
+ var chapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(sharedChaptersPerson.Id, _fullAccess.Id, PersonRole.Colorist);
+ var restrictedChapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(sharedChaptersPerson.Id, _restrictedAccess.Id, PersonRole.Colorist);
+ var restrictedAgeChapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(sharedChaptersPerson.Id, _restrictedAgeAccess.Id, PersonRole.Colorist);
+ Assert.Single(chapters);
+ Assert.Empty(restrictedChapters);
+ Assert.Empty(restrictedAgeChapters);
+
+ // Lib1 - age restricted series
+ chapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(sharedChaptersPerson.Id, _fullAccess.Id, PersonRole.Imprint);
+ restrictedChapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(sharedChaptersPerson.Id, _restrictedAccess.Id, PersonRole.Imprint);
+ restrictedAgeChapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(sharedChaptersPerson.Id, _restrictedAgeAccess.Id, PersonRole.Imprint);
+ Assert.Single(chapters);
+ Assert.Single(restrictedChapters);
+ Assert.Empty(restrictedAgeChapters);
+
+ // Lib1 - not age restricted series
+ chapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(sharedChaptersPerson.Id, _fullAccess.Id, PersonRole.Team);
+ restrictedChapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(sharedChaptersPerson.Id, _restrictedAccess.Id, PersonRole.Team);
+ restrictedAgeChapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(sharedChaptersPerson.Id, _restrictedAgeAccess.Id, PersonRole.Team);
+ Assert.Single(chapters);
+ Assert.Single(restrictedChapters);
+ Assert.Single(restrictedAgeChapters);
+ }
+}
diff --git a/API.Tests/Repository/TagRepositoryTests.cs b/API.Tests/Repository/TagRepositoryTests.cs
new file mode 100644
index 000000000..229082eb6
--- /dev/null
+++ b/API.Tests/Repository/TagRepositoryTests.cs
@@ -0,0 +1,278 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using API.DTOs.Metadata.Browse;
+using API.Entities;
+using API.Entities.Enums;
+using API.Entities.Metadata;
+using API.Helpers;
+using API.Helpers.Builders;
+using Xunit;
+
+namespace API.Tests.Repository;
+
+public class TagRepositoryTests : AbstractDbTest
+{
+ private AppUser _fullAccess;
+ private AppUser _restrictedAccess;
+ private AppUser _restrictedAgeAccess;
+
+ protected override async Task ResetDb()
+ {
+ Context.Tag.RemoveRange(Context.Tag);
+ Context.Library.RemoveRange(Context.Library);
+ await Context.SaveChangesAsync();
+ }
+
+ private TestTagSet CreateTestTags()
+ {
+ return new TestTagSet
+ {
+ SharedSeriesChaptersTag = new TagBuilder("Shared Series Chapter Tag").Build(),
+ SharedSeriesTag = new TagBuilder("Shared Series Tag").Build(),
+ SharedChaptersTag = new TagBuilder("Shared Chapters Tag").Build(),
+ Lib0SeriesChaptersTag = new TagBuilder("Lib0 Series Chapter Tag").Build(),
+ Lib0SeriesTag = new TagBuilder("Lib0 Series Tag").Build(),
+ Lib0ChaptersTag = new TagBuilder("Lib0 Chapters Tag").Build(),
+ Lib1SeriesChaptersTag = new TagBuilder("Lib1 Series Chapter Tag").Build(),
+ Lib1SeriesTag = new TagBuilder("Lib1 Series Tag").Build(),
+ Lib1ChaptersTag = new TagBuilder("Lib1 Chapters Tag").Build(),
+ Lib1ChapterAgeTag = new TagBuilder("Lib1 Chapter Age Tag").Build()
+ };
+ }
+
+ private async Task SeedDbWithTags(TestTagSet tags)
+ {
+ await CreateTestUsers();
+ await AddTagsToContext(tags);
+ await CreateLibrariesWithTags(tags);
+ await AssignLibrariesToUsers();
+ }
+
+ private async Task CreateTestUsers()
+ {
+ _fullAccess = new AppUserBuilder("amelia", "amelia@example.com").Build();
+ _restrictedAccess = new AppUserBuilder("mila", "mila@example.com").Build();
+ _restrictedAgeAccess = new AppUserBuilder("eva", "eva@example.com").Build();
+ _restrictedAgeAccess.AgeRestriction = AgeRating.Teen;
+ _restrictedAgeAccess.AgeRestrictionIncludeUnknowns = true;
+
+ Context.Users.Add(_fullAccess);
+ Context.Users.Add(_restrictedAccess);
+ Context.Users.Add(_restrictedAgeAccess);
+ await Context.SaveChangesAsync();
+ }
+
+ private async Task AddTagsToContext(TestTagSet tags)
+ {
+ var allTags = tags.GetAllTags();
+ Context.Tag.AddRange(allTags);
+ await Context.SaveChangesAsync();
+ }
+
+ private async Task CreateLibrariesWithTags(TestTagSet tags)
+ {
+ var lib0 = new LibraryBuilder("lib0")
+ .WithSeries(new SeriesBuilder("lib0-s0")
+ .WithMetadata(new SeriesMetadata
+ {
+ Tags = [tags.SharedSeriesChaptersTag, tags.SharedSeriesTag, tags.Lib0SeriesChaptersTag, tags.Lib0SeriesTag]
+ })
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(new ChapterBuilder("1")
+ .WithTags([tags.SharedSeriesChaptersTag, tags.SharedChaptersTag, tags.Lib0SeriesChaptersTag, tags.Lib0ChaptersTag])
+ .Build())
+ .WithChapter(new ChapterBuilder("2")
+ .WithTags([tags.SharedSeriesChaptersTag, tags.SharedChaptersTag, tags.Lib1SeriesChaptersTag, tags.Lib1ChaptersTag])
+ .Build())
+ .Build())
+ .Build())
+ .Build();
+
+ var lib1 = new LibraryBuilder("lib1")
+ .WithSeries(new SeriesBuilder("lib1-s0")
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithTags([tags.SharedSeriesChaptersTag, tags.SharedSeriesTag, tags.Lib1SeriesChaptersTag, tags.Lib1SeriesTag])
+ .WithAgeRating(AgeRating.Mature17Plus)
+ .Build())
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(new ChapterBuilder("1")
+ .WithTags([tags.SharedSeriesChaptersTag, tags.SharedChaptersTag, tags.Lib1SeriesChaptersTag, tags.Lib1ChaptersTag])
+ .Build())
+ .WithChapter(new ChapterBuilder("2")
+ .WithTags([tags.SharedSeriesChaptersTag, tags.SharedChaptersTag, tags.Lib1SeriesChaptersTag, tags.Lib1ChaptersTag, tags.Lib1ChapterAgeTag])
+ .WithAgeRating(AgeRating.Mature17Plus)
+ .Build())
+ .Build())
+ .Build())
+ .WithSeries(new SeriesBuilder("lib1-s1")
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithTags([tags.SharedSeriesChaptersTag, tags.SharedSeriesTag, tags.Lib1SeriesChaptersTag, tags.Lib1SeriesTag])
+ .Build())
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(new ChapterBuilder("1")
+ .WithTags([tags.SharedSeriesChaptersTag, tags.SharedChaptersTag, tags.Lib1SeriesChaptersTag, tags.Lib1ChaptersTag])
+ .Build())
+ .WithChapter(new ChapterBuilder("2")
+ .WithTags([tags.SharedSeriesChaptersTag, tags.SharedChaptersTag, tags.Lib1SeriesChaptersTag, tags.Lib1ChaptersTag])
+ .WithAgeRating(AgeRating.Mature17Plus)
+ .Build())
+ .Build())
+ .Build())
+ .Build();
+
+ Context.Library.Add(lib0);
+ Context.Library.Add(lib1);
+ await Context.SaveChangesAsync();
+ }
+
+ private async Task AssignLibrariesToUsers()
+ {
+ var lib0 = Context.Library.First(l => l.Name == "lib0");
+ var lib1 = Context.Library.First(l => l.Name == "lib1");
+
+ _fullAccess.Libraries.Add(lib0);
+ _fullAccess.Libraries.Add(lib1);
+ _restrictedAccess.Libraries.Add(lib1);
+ _restrictedAgeAccess.Libraries.Add(lib1);
+
+ await Context.SaveChangesAsync();
+ }
+
+ private static Predicate ContainsTagCheck(Tag tag)
+ {
+ return t => t.Id == tag.Id;
+ }
+
+ private static void AssertTagPresent(IEnumerable tags, Tag expectedTag)
+ {
+ Assert.Contains(tags, ContainsTagCheck(expectedTag));
+ }
+
+ private static void AssertTagNotPresent(IEnumerable tags, Tag expectedTag)
+ {
+ Assert.DoesNotContain(tags, ContainsTagCheck(expectedTag));
+ }
+
+ private static BrowseTagDto GetTagDto(IEnumerable tags, Tag tag)
+ {
+ return tags.First(dto => dto.Id == tag.Id);
+ }
+
+ [Fact]
+ public async Task GetBrowseableTag_FullAccess_ReturnsAllTagsWithCorrectCounts()
+ {
+ // Arrange
+ await ResetDb();
+ var tags = CreateTestTags();
+ await SeedDbWithTags(tags);
+
+ // Act
+ var fullAccessTags = await UnitOfWork.TagRepository.GetBrowseableTag(_fullAccess.Id, new UserParams());
+
+ // Assert
+ Assert.Equal(tags.GetAllTags().Count, fullAccessTags.TotalCount);
+
+ foreach (var tag in tags.GetAllTags())
+ {
+ AssertTagPresent(fullAccessTags, tag);
+ }
+
+ // Verify counts - 1 series lib0, 2 series lib1 = 3 total series
+ Assert.Equal(3, GetTagDto(fullAccessTags, tags.SharedSeriesChaptersTag).SeriesCount);
+ Assert.Equal(6, GetTagDto(fullAccessTags, tags.SharedSeriesChaptersTag).ChapterCount);
+ Assert.Equal(1, GetTagDto(fullAccessTags, tags.Lib0SeriesTag).SeriesCount);
+ }
+
+ [Fact]
+ public async Task GetBrowseableTag_RestrictedAccess_ReturnsOnlyAccessibleTags()
+ {
+ // Arrange
+ await ResetDb();
+ var tags = CreateTestTags();
+ await SeedDbWithTags(tags);
+
+ // Act
+ var restrictedAccessTags = await UnitOfWork.TagRepository.GetBrowseableTag(_restrictedAccess.Id, new UserParams());
+
+ // Assert - Should see: 3 shared + 4 library 1 specific = 7 tags
+ Assert.Equal(7, restrictedAccessTags.TotalCount);
+
+ // Verify shared and Library 1 tags are present
+ AssertTagPresent(restrictedAccessTags, tags.SharedSeriesChaptersTag);
+ AssertTagPresent(restrictedAccessTags, tags.SharedSeriesTag);
+ AssertTagPresent(restrictedAccessTags, tags.SharedChaptersTag);
+ AssertTagPresent(restrictedAccessTags, tags.Lib1SeriesChaptersTag);
+ AssertTagPresent(restrictedAccessTags, tags.Lib1SeriesTag);
+ AssertTagPresent(restrictedAccessTags, tags.Lib1ChaptersTag);
+ AssertTagPresent(restrictedAccessTags, tags.Lib1ChapterAgeTag);
+
+ // Verify Library 0 specific tags are not present
+ AssertTagNotPresent(restrictedAccessTags, tags.Lib0SeriesChaptersTag);
+ AssertTagNotPresent(restrictedAccessTags, tags.Lib0SeriesTag);
+ AssertTagNotPresent(restrictedAccessTags, tags.Lib0ChaptersTag);
+
+ // Verify counts - 2 series lib1
+ Assert.Equal(2, GetTagDto(restrictedAccessTags, tags.SharedSeriesChaptersTag).SeriesCount);
+ Assert.Equal(4, GetTagDto(restrictedAccessTags, tags.SharedSeriesChaptersTag).ChapterCount);
+ Assert.Equal(2, GetTagDto(restrictedAccessTags, tags.Lib1SeriesTag).SeriesCount);
+ Assert.Equal(4, GetTagDto(restrictedAccessTags, tags.Lib1ChaptersTag).ChapterCount);
+ }
+
+ [Fact]
+ public async Task GetBrowseableTag_RestrictedAgeAccess_FiltersAgeRestrictedContent()
+ {
+ // Arrange
+ await ResetDb();
+ var tags = CreateTestTags();
+ await SeedDbWithTags(tags);
+
+ // Act
+ var restrictedAgeAccessTags = await UnitOfWork.TagRepository.GetBrowseableTag(_restrictedAgeAccess.Id, new UserParams());
+
+ // Assert - Should see: 3 shared + 3 lib1 specific = 6 tags (age-restricted tag filtered out)
+ Assert.Equal(6, restrictedAgeAccessTags.TotalCount);
+
+ // Verify accessible tags are present
+ AssertTagPresent(restrictedAgeAccessTags, tags.SharedSeriesChaptersTag);
+ AssertTagPresent(restrictedAgeAccessTags, tags.SharedSeriesTag);
+ AssertTagPresent(restrictedAgeAccessTags, tags.SharedChaptersTag);
+ AssertTagPresent(restrictedAgeAccessTags, tags.Lib1SeriesChaptersTag);
+ AssertTagPresent(restrictedAgeAccessTags, tags.Lib1SeriesTag);
+ AssertTagPresent(restrictedAgeAccessTags, tags.Lib1ChaptersTag);
+
+ // Verify age-restricted tag is filtered out
+ AssertTagNotPresent(restrictedAgeAccessTags, tags.Lib1ChapterAgeTag);
+
+ // Verify counts - 1 series lib1 (age-restricted series filtered out)
+ Assert.Equal(1, GetTagDto(restrictedAgeAccessTags, tags.SharedSeriesChaptersTag).SeriesCount);
+ Assert.Equal(2, GetTagDto(restrictedAgeAccessTags, tags.SharedSeriesChaptersTag).ChapterCount);
+ Assert.Equal(1, GetTagDto(restrictedAgeAccessTags, tags.Lib1SeriesTag).SeriesCount);
+ Assert.Equal(2, GetTagDto(restrictedAgeAccessTags, tags.Lib1ChaptersTag).ChapterCount);
+ }
+
+ private class TestTagSet
+ {
+ public Tag SharedSeriesChaptersTag { get; set; }
+ public Tag SharedSeriesTag { get; set; }
+ public Tag SharedChaptersTag { get; set; }
+ public Tag Lib0SeriesChaptersTag { get; set; }
+ public Tag Lib0SeriesTag { get; set; }
+ public Tag Lib0ChaptersTag { get; set; }
+ public Tag Lib1SeriesChaptersTag { get; set; }
+ public Tag Lib1SeriesTag { get; set; }
+ public Tag Lib1ChaptersTag { get; set; }
+ public Tag Lib1ChapterAgeTag { get; set; }
+
+ public List GetAllTags()
+ {
+ return
+ [
+ SharedSeriesChaptersTag, SharedSeriesTag, SharedChaptersTag,
+ Lib0SeriesChaptersTag, Lib0SeriesTag, Lib0ChaptersTag,
+ Lib1SeriesChaptersTag, Lib1SeriesTag, Lib1ChaptersTag, Lib1ChapterAgeTag
+ ];
+ }
+ }
+}
diff --git a/API.Tests/Services/BookServiceTests.cs b/API.Tests/Services/BookServiceTests.cs
index a80c1ca01..5848c74ba 100644
--- a/API.Tests/Services/BookServiceTests.cs
+++ b/API.Tests/Services/BookServiceTests.cs
@@ -137,7 +137,7 @@ public class BookServiceTests
var comicInfo = _bookService.GetComicInfo(filePath);
Assert.NotNull(comicInfo);
- var parserInfo = pdfParser.Parse(filePath, testDirectory, ds.GetParentDirectoryName(testDirectory), LibraryType.Book, comicInfo);
+ var parserInfo = pdfParser.Parse(filePath, testDirectory, ds.GetParentDirectoryName(testDirectory), LibraryType.Book, true, comicInfo);
Assert.NotNull(parserInfo);
Assert.Equal(parserInfo.Title, comicInfo.Title);
Assert.Equal(parserInfo.Series, comicInfo.Title);
diff --git a/API.Tests/Services/CacheServiceTests.cs b/API.Tests/Services/CacheServiceTests.cs
index 5c1752cd8..caf1ae393 100644
--- a/API.Tests/Services/CacheServiceTests.cs
+++ b/API.Tests/Services/CacheServiceTests.cs
@@ -50,12 +50,12 @@ internal class MockReadingItemServiceForCacheService : IReadingItemService
throw new System.NotImplementedException();
}
- public ParserInfo Parse(string path, string rootPath, string libraryRoot, LibraryType type)
+ public ParserInfo Parse(string path, string rootPath, string libraryRoot, LibraryType type, bool enableMetadata = true)
{
throw new System.NotImplementedException();
}
- public ParserInfo ParseFile(string path, string rootPath, string libraryRoot, LibraryType type)
+ public ParserInfo ParseFile(string path, string rootPath, string libraryRoot, LibraryType type, bool enableMetadata = true)
{
throw new System.NotImplementedException();
}
diff --git a/API.Tests/Services/ExternalMetadataServiceTests.cs b/API.Tests/Services/ExternalMetadataServiceTests.cs
index c2c226538..973b7c6df 100644
--- a/API.Tests/Services/ExternalMetadataServiceTests.cs
+++ b/API.Tests/Services/ExternalMetadataServiceTests.cs
@@ -15,6 +15,7 @@ using API.Entities.Person;
using API.Helpers.Builders;
using API.Services.Plus;
using API.Services.Tasks.Metadata;
+using API.Services.Tasks.Scanner.Parser;
using API.SignalR;
using Hangfire;
using Microsoft.EntityFrameworkCore;
@@ -42,7 +43,7 @@ public class ExternalMetadataServiceTests : AbstractDbTest
_externalMetadataService = new ExternalMetadataService(UnitOfWork, Substitute.For>(),
Mapper, Substitute.For(), Substitute.For(), Substitute.For(),
- Substitute.For());
+ Substitute.For(), Substitute.For());
}
#region Gloabl
@@ -881,6 +882,217 @@ public class ExternalMetadataServiceTests : AbstractDbTest
}
+ [Fact]
+ public void IsSeriesCompleted_ExactMatch()
+ {
+ const string seriesName = "Test - Exact Match";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithMaxCount(5)
+ .WithTotalCount(5)
+ .Build())
+ .Build();
+
+ var chapters = new List();
+ var externalMetadata = new ExternalSeriesDetailDto { Chapters = 5, Volumes = 0 };
+
+ var result = ExternalMetadataService.IsSeriesCompleted(series, chapters, externalMetadata, Parser.DefaultChapterNumber);
+
+ Assert.True(result);
+ }
+
+ [Fact]
+ public void IsSeriesCompleted_Volumes_DecimalVolumes()
+ {
+ const string seriesName = "Test - Volume Complete";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithMaxCount(2)
+ .WithTotalCount(3)
+ .Build())
+ .WithVolume(new VolumeBuilder("1").WithNumber(1).Build())
+ .WithVolume(new VolumeBuilder("2").WithNumber(2).Build())
+ .WithVolume(new VolumeBuilder("2.5").WithNumber(2.5f).Build())
+ .Build();
+
+ var chapters = new List();
+ // External metadata includes decimal volume 2.5
+ var externalMetadata = new ExternalSeriesDetailDto { Chapters = 0, Volumes = 3 };
+
+ var result = ExternalMetadataService.IsSeriesCompleted(series, chapters, externalMetadata, 2);
+
+ Assert.True(result);
+ Assert.Equal(3, series.Metadata.MaxCount);
+ Assert.Equal(3, series.Metadata.TotalCount);
+ }
+
+ ///
+ /// This is validating that we get a completed even though we have a special chapter and AL doesn't count it
+ ///
+ [Fact]
+ public void IsSeriesCompleted_Volumes_HasSpecialAndDecimal_ExternalNoSpecial()
+ {
+ const string seriesName = "Test - Volume Complete";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithMaxCount(2)
+ .WithTotalCount(3)
+ .Build())
+ .WithVolume(new VolumeBuilder("1").WithNumber(1).Build())
+ .WithVolume(new VolumeBuilder("1.5").WithNumber(1.5f).Build())
+ .WithVolume(new VolumeBuilder("2").WithNumber(2).Build())
+ .WithVolume(new VolumeBuilder(Parser.SpecialVolume).Build())
+ .Build();
+
+ var chapters = new List();
+ // External metadata includes volume 1.5, but not the special
+ var externalMetadata = new ExternalSeriesDetailDto { Chapters = 0, Volumes = 3 };
+
+ var result = ExternalMetadataService.IsSeriesCompleted(series, chapters, externalMetadata, 2);
+
+ Assert.True(result);
+ Assert.Equal(3, series.Metadata.MaxCount);
+ Assert.Equal(3, series.Metadata.TotalCount);
+ }
+
+ ///
+ /// This unit test also illustrates the bug where you may get a false positive if you had Volumes 1,2, and 2.1. While
+ /// missing volume 3. With the external metadata expecting non-decimal volumes.
+ /// i.e. it would fail if we only had one decimal volume
+ ///
+ [Fact]
+ public void IsSeriesCompleted_Volumes_TooManyDecimalVolumes()
+ {
+ const string seriesName = "Test - Volume Complete";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithMaxCount(2)
+ .WithTotalCount(3)
+ .Build())
+ .WithVolume(new VolumeBuilder("1").WithNumber(1).Build())
+ .WithVolume(new VolumeBuilder("2").WithNumber(2).Build())
+ .WithVolume(new VolumeBuilder("2.1").WithNumber(2.1f).Build())
+ .WithVolume(new VolumeBuilder("2.2").WithNumber(2.2f).Build())
+ .Build();
+
+ var chapters = new List();
+ // External metadata includes no special or decimals. There are 3 volumes. And we're missing volume 3
+ var externalMetadata = new ExternalSeriesDetailDto { Chapters = 0, Volumes = 3 };
+
+ var result = ExternalMetadataService.IsSeriesCompleted(series, chapters, externalMetadata, 2);
+
+ Assert.False(result);
+ }
+
+ [Fact]
+ public void IsSeriesCompleted_NoVolumes_GEQChapterCheck()
+ {
+ // We own 11 chapters, the external metadata expects 10
+ const string seriesName = "Test - Chapter MaxCount, no volumes";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithMaxCount(11)
+ .WithTotalCount(10)
+ .Build())
+ .Build();
+
+ var chapters = new List();
+ var externalMetadata = new ExternalSeriesDetailDto { Chapters = 10, Volumes = 0 };
+
+ var result = ExternalMetadataService.IsSeriesCompleted(series, chapters, externalMetadata, Parser.DefaultChapterNumber);
+
+ Assert.True(result);
+ Assert.Equal(11, series.Metadata.TotalCount);
+ Assert.Equal(11, series.Metadata.MaxCount);
+ }
+
+ [Fact]
+ public void IsSeriesCompleted_NoVolumes_IncludeAllChaptersCheck()
+ {
+ const string seriesName = "Test - Chapter Count";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithMaxCount(7)
+ .WithTotalCount(10)
+ .Build())
+ .Build();
+
+ var chapters = new List
+ {
+ new ChapterBuilder("0").Build(),
+ new ChapterBuilder("2").Build(),
+ new ChapterBuilder("3").Build(),
+ new ChapterBuilder("4").Build(),
+ new ChapterBuilder("5").Build(),
+ new ChapterBuilder("6").Build(),
+ new ChapterBuilder("7").Build(),
+ new ChapterBuilder("7.1").Build(),
+ new ChapterBuilder("7.2").Build(),
+ new ChapterBuilder("7.3").Build()
+ };
+ // External metadata includes prologues (0) and extra's (7.X)
+ var externalMetadata = new ExternalSeriesDetailDto { Chapters = 10, Volumes = 0 };
+
+ var result = ExternalMetadataService.IsSeriesCompleted(series, chapters, externalMetadata, Parser.DefaultChapterNumber);
+
+ Assert.True(result);
+ Assert.Equal(10, series.Metadata.TotalCount);
+ Assert.Equal(10, series.Metadata.MaxCount);
+ }
+
+ [Fact]
+ public void IsSeriesCompleted_NotEnoughVolumes()
+ {
+ const string seriesName = "Test - Incomplete Volume";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithMaxCount(2)
+ .WithTotalCount(5)
+ .Build())
+ .WithVolume(new VolumeBuilder("1").WithNumber(1).Build())
+ .WithVolume(new VolumeBuilder("2").WithNumber(2).Build())
+ .Build();
+
+ var chapters = new List();
+ var externalMetadata = new ExternalSeriesDetailDto { Chapters = 0, Volumes = 5 };
+
+ var result = ExternalMetadataService.IsSeriesCompleted(series, chapters, externalMetadata, 2);
+
+ Assert.False(result);
+ }
+
+ [Fact]
+ public void IsSeriesCompleted_NoVolumes_NotEnoughChapters()
+ {
+ const string seriesName = "Test - Incomplete Chapter";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithMaxCount(5)
+ .WithTotalCount(8)
+ .Build())
+ .Build();
+
+ var chapters = new List
+ {
+ new ChapterBuilder("1").Build(),
+ new ChapterBuilder("2").Build(),
+ new ChapterBuilder("3").Build()
+ };
+ var externalMetadata = new ExternalSeriesDetailDto { Chapters = 10, Volumes = 0 };
+
+ var result = ExternalMetadataService.IsSeriesCompleted(series, chapters, externalMetadata, Parser.DefaultChapterNumber);
+
+ Assert.False(result);
+ }
+
#endregion
@@ -1678,6 +1890,130 @@ public class ExternalMetadataServiceTests : AbstractDbTest
#endregion
+ #region People Alias
+
+ [Fact]
+ public async Task PeopleAliasing_AddAsAlias()
+ {
+ await ResetDb();
+
+ const string seriesName = "Test - People - Add as Alias";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .Build())
+ .Build();
+ Context.Series.Attach(series);
+ Context.Person.Add(new PersonBuilder("John Doe").Build());
+ await Context.SaveChangesAsync();
+
+ var metadataSettings = await UnitOfWork.SettingsRepository.GetMetadataSettings();
+ metadataSettings.Enabled = true;
+ metadataSettings.EnablePeople = true;
+ metadataSettings.FirstLastPeopleNaming = true;
+ metadataSettings.Overrides = [MetadataSettingField.People];
+ metadataSettings.PersonRoles = [PersonRole.Writer];
+ Context.MetadataSettings.Update(metadataSettings);
+ await Context.SaveChangesAsync();
+
+ await _externalMetadataService.WriteExternalMetadataToSeries(new ExternalSeriesDetailDto()
+ {
+ Name = seriesName,
+ Staff = [CreateStaff("Doe", "John", "Story")]
+ }, 1);
+
+ var postSeries = await UnitOfWork.SeriesRepository.GetSeriesByIdAsync(1, SeriesIncludes.Metadata);
+ Assert.NotNull(postSeries);
+
+ var allWriters = postSeries.Metadata.People.Where(p => p.Role == PersonRole.Writer).ToList();
+ Assert.Single(allWriters);
+
+ var johnDoe = allWriters[0].Person;
+
+ Assert.Contains("Doe John", johnDoe.Aliases.Select(pa => pa.Alias));
+ }
+
+ [Fact]
+ public async Task PeopleAliasing_AddOnAlias()
+ {
+ await ResetDb();
+
+ const string seriesName = "Test - People - Add as Alias";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .Build())
+ .Build();
+ Context.Series.Attach(series);
+
+ Context.Person.Add(new PersonBuilder("John Doe").WithAlias("Doe John").Build());
+
+ await Context.SaveChangesAsync();
+
+ var metadataSettings = await UnitOfWork.SettingsRepository.GetMetadataSettings();
+ metadataSettings.Enabled = true;
+ metadataSettings.EnablePeople = true;
+ metadataSettings.FirstLastPeopleNaming = true;
+ metadataSettings.Overrides = [MetadataSettingField.People];
+ metadataSettings.PersonRoles = [PersonRole.Writer];
+ Context.MetadataSettings.Update(metadataSettings);
+ await Context.SaveChangesAsync();
+
+ await _externalMetadataService.WriteExternalMetadataToSeries(new ExternalSeriesDetailDto()
+ {
+ Name = seriesName,
+ Staff = [CreateStaff("Doe", "John", "Story")]
+ }, 1);
+
+ var postSeries = await UnitOfWork.SeriesRepository.GetSeriesByIdAsync(1, SeriesIncludes.Metadata);
+ Assert.NotNull(postSeries);
+
+ var allWriters = postSeries.Metadata.People.Where(p => p.Role == PersonRole.Writer).ToList();
+ Assert.Single(allWriters);
+
+ var johnDoe = allWriters[0].Person;
+
+ Assert.Contains("Doe John", johnDoe.Aliases.Select(pa => pa.Alias));
+ }
+
+ [Fact]
+ public async Task PeopleAliasing_DontAddAsAlias_SameButNotSwitched()
+ {
+ await ResetDb();
+
+ const string seriesName = "Test - People - Add as Alias";
+ var series = new SeriesBuilder(seriesName)
+ .WithLibraryId(1)
+ .WithMetadata(new SeriesMetadataBuilder()
+ .Build())
+ .Build();
+ Context.Series.Attach(series);
+ await Context.SaveChangesAsync();
+
+ var metadataSettings = await UnitOfWork.SettingsRepository.GetMetadataSettings();
+ metadataSettings.Enabled = true;
+ metadataSettings.EnablePeople = true;
+ metadataSettings.FirstLastPeopleNaming = true;
+ metadataSettings.Overrides = [MetadataSettingField.People];
+ metadataSettings.PersonRoles = [PersonRole.Writer];
+ Context.MetadataSettings.Update(metadataSettings);
+ await Context.SaveChangesAsync();
+
+ await _externalMetadataService.WriteExternalMetadataToSeries(new ExternalSeriesDetailDto()
+ {
+ Name = seriesName,
+ Staff = [CreateStaff("John", "Doe Doe", "Story"), CreateStaff("Doe", "John Doe", "Story")]
+ }, 1);
+
+ var postSeries = await UnitOfWork.SeriesRepository.GetSeriesByIdAsync(1, SeriesIncludes.Metadata);
+ Assert.NotNull(postSeries);
+
+ var allWriters = postSeries.Metadata.People.Where(p => p.Role == PersonRole.Writer).ToList();
+ Assert.Equal(2, allWriters.Count);
+ }
+
+ #endregion
+
#region People - Characters
[Fact]
@@ -2811,6 +3147,8 @@ public class ExternalMetadataServiceTests : AbstractDbTest
metadataSettings.EnableTags = false;
metadataSettings.EnablePublicationStatus = false;
metadataSettings.EnableStartDate = false;
+ metadataSettings.FieldMappings = [];
+ metadataSettings.AgeRatingMappings = new Dictionary();
Context.MetadataSettings.Update(metadataSettings);
await Context.SaveChangesAsync();
diff --git a/API.Tests/Services/ImageServiceTests.cs b/API.Tests/Services/ImageServiceTests.cs
index a1073a55b..f2c87e1ad 100644
--- a/API.Tests/Services/ImageServiceTests.cs
+++ b/API.Tests/Services/ImageServiceTests.cs
@@ -161,10 +161,10 @@ public class ImageServiceTests
private static void GenerateColorImage(string hexColor, string outputPath)
{
- var color = ImageService.HexToRgb(hexColor);
- using var colorImage = Image.Black(200, 100);
- using var output = colorImage + new[] { color.R / 255.0, color.G / 255.0, color.B / 255.0 };
- output.WriteToFile(outputPath);
+ var (r, g, b) = ImageService.HexToRgb(hexColor);
+ using var blackImage = Image.Black(200, 100);
+ using var colorImage = blackImage.NewFromImage(r, g, b);
+ colorImage.WriteToFile(outputPath);
}
private void GenerateHtmlFileForColorScape()
diff --git a/API.Tests/Services/ParseScannedFilesTests.cs b/API.Tests/Services/ParseScannedFilesTests.cs
index f8714f69a..a732b2526 100644
--- a/API.Tests/Services/ParseScannedFilesTests.cs
+++ b/API.Tests/Services/ParseScannedFilesTests.cs
@@ -58,35 +58,35 @@ public class MockReadingItemService : IReadingItemService
throw new NotImplementedException();
}
- public ParserInfo Parse(string path, string rootPath, string libraryRoot, LibraryType type)
+ public ParserInfo Parse(string path, string rootPath, string libraryRoot, LibraryType type, bool enableMetadata)
{
if (_comicVineParser.IsApplicable(path, type))
{
- return _comicVineParser.Parse(path, rootPath, libraryRoot, type, GetComicInfo(path));
+ return _comicVineParser.Parse(path, rootPath, libraryRoot, type, enableMetadata, GetComicInfo(path));
}
if (_imageParser.IsApplicable(path, type))
{
- return _imageParser.Parse(path, rootPath, libraryRoot, type, GetComicInfo(path));
+ return _imageParser.Parse(path, rootPath, libraryRoot, type, enableMetadata, GetComicInfo(path));
}
if (_bookParser.IsApplicable(path, type))
{
- return _bookParser.Parse(path, rootPath, libraryRoot, type, GetComicInfo(path));
+ return _bookParser.Parse(path, rootPath, libraryRoot, type, enableMetadata, GetComicInfo(path));
}
if (_pdfParser.IsApplicable(path, type))
{
- return _pdfParser.Parse(path, rootPath, libraryRoot, type, GetComicInfo(path));
+ return _pdfParser.Parse(path, rootPath, libraryRoot, type, enableMetadata, GetComicInfo(path));
}
if (_basicParser.IsApplicable(path, type))
{
- return _basicParser.Parse(path, rootPath, libraryRoot, type, GetComicInfo(path));
+ return _basicParser.Parse(path, rootPath, libraryRoot, type, enableMetadata, GetComicInfo(path));
}
return null;
}
- public ParserInfo ParseFile(string path, string rootPath, string libraryRoot, LibraryType type)
+ public ParserInfo ParseFile(string path, string rootPath, string libraryRoot, LibraryType type, bool enableMetadata)
{
- return Parse(path, rootPath, libraryRoot, type);
+ return Parse(path, rootPath, libraryRoot, type, enableMetadata);
}
}
diff --git a/API.Tests/Services/PersonServiceTests.cs b/API.Tests/Services/PersonServiceTests.cs
new file mode 100644
index 000000000..5c1929b1c
--- /dev/null
+++ b/API.Tests/Services/PersonServiceTests.cs
@@ -0,0 +1,286 @@
+using System.Linq;
+using System.Threading.Tasks;
+using API.Data.Repositories;
+using API.Entities;
+using API.Entities.Enums;
+using API.Entities.Person;
+using API.Extensions;
+using API.Helpers.Builders;
+using API.Services;
+using Xunit;
+
+namespace API.Tests.Services;
+
+public class PersonServiceTests: AbstractDbTest
+{
+
+ [Fact]
+ public async Task PersonMerge_KeepNonEmptyMetadata()
+ {
+ var ps = new PersonService(UnitOfWork);
+
+ var person1 = new Person
+ {
+ Name = "Casey Delores",
+ NormalizedName = "Casey Delores".ToNormalized(),
+ HardcoverId = "ANonEmptyId",
+ MalId = 12,
+ };
+
+ var person2 = new Person
+ {
+ Name= "Delores Casey",
+ NormalizedName = "Delores Casey".ToNormalized(),
+ Description = "Hi, I'm Delores Casey!",
+ Aliases = [new PersonAliasBuilder("Casey, Delores").Build()],
+ AniListId = 27,
+ };
+
+ UnitOfWork.PersonRepository.Attach(person1);
+ UnitOfWork.PersonRepository.Attach(person2);
+ await UnitOfWork.CommitAsync();
+
+ await ps.MergePeopleAsync(person2, person1);
+
+ var allPeople = await UnitOfWork.PersonRepository.GetAllPeople();
+ Assert.Single(allPeople);
+
+ var person = allPeople[0];
+ Assert.Equal("Casey Delores", person.Name);
+ Assert.NotEmpty(person.Description);
+ Assert.Equal(27, person.AniListId);
+ Assert.NotNull(person.HardcoverId);
+ Assert.NotEmpty(person.HardcoverId);
+ Assert.Contains(person.Aliases, pa => pa.Alias == "Delores Casey");
+ Assert.Contains(person.Aliases, pa => pa.Alias == "Casey, Delores");
+ }
+
+ [Fact]
+ public async Task PersonMerge_MergedPersonDestruction()
+ {
+ var ps = new PersonService(UnitOfWork);
+
+ var person1 = new Person
+ {
+ Name = "Casey Delores",
+ NormalizedName = "Casey Delores".ToNormalized(),
+ };
+
+ var person2 = new Person
+ {
+ Name = "Delores Casey",
+ NormalizedName = "Delores Casey".ToNormalized(),
+ };
+
+ UnitOfWork.PersonRepository.Attach(person1);
+ UnitOfWork.PersonRepository.Attach(person2);
+ await UnitOfWork.CommitAsync();
+
+ await ps.MergePeopleAsync(person2, person1);
+ var allPeople = await UnitOfWork.PersonRepository.GetAllPeople();
+ Assert.Single(allPeople);
+ }
+
+ [Fact]
+ public async Task PersonMerge_RetentionChapters()
+ {
+ var ps = new PersonService(UnitOfWork);
+
+ var library = new LibraryBuilder("My Library").Build();
+ UnitOfWork.LibraryRepository.Add(library);
+ await UnitOfWork.CommitAsync();
+
+ var user = new AppUserBuilder("Amelia", "amelia@localhost")
+ .WithLibrary(library).Build();
+ UnitOfWork.UserRepository.Add(user);
+
+ var person = new PersonBuilder("Jillian Cowan").Build();
+
+ var person2 = new PersonBuilder("Cowan Jillian").Build();
+
+ var chapter = new ChapterBuilder("1")
+ .WithPerson(person, PersonRole.Editor)
+ .Build();
+
+ var chapter2 = new ChapterBuilder("2")
+ .WithPerson(person2, PersonRole.Editor)
+ .Build();
+
+ var series = new SeriesBuilder("Test 1")
+ .WithLibraryId(library.Id)
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(chapter)
+ .Build())
+ .Build();
+
+ var series2 = new SeriesBuilder("Test 2")
+ .WithLibraryId(library.Id)
+ .WithVolume(new VolumeBuilder("2")
+ .WithChapter(chapter2)
+ .Build())
+ .Build();
+
+ UnitOfWork.SeriesRepository.Add(series);
+ UnitOfWork.SeriesRepository.Add(series2);
+ await UnitOfWork.CommitAsync();
+
+ await ps.MergePeopleAsync(person2, person);
+
+ var allPeople = await UnitOfWork.PersonRepository.GetAllPeople();
+ Assert.Single(allPeople);
+ var mergedPerson = allPeople[0];
+
+ Assert.Equal("Jillian Cowan", mergedPerson.Name);
+
+ var chapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(1, 1, PersonRole.Editor);
+ Assert.Equal(2, chapters.Count());
+
+ chapter = await UnitOfWork.ChapterRepository.GetChapterAsync(1, ChapterIncludes.People);
+ Assert.NotNull(chapter);
+ Assert.Single(chapter.People);
+
+ chapter2 = await UnitOfWork.ChapterRepository.GetChapterAsync(2, ChapterIncludes.People);
+ Assert.NotNull(chapter2);
+ Assert.Single(chapter2.People);
+
+ Assert.Equal(chapter.People.First().PersonId, chapter2.People.First().PersonId);
+ }
+
+ [Fact]
+ public async Task PersonMerge_NoDuplicateChaptersOrSeries()
+ {
+ await ResetDb();
+
+ var ps = new PersonService(UnitOfWork);
+
+ var library = new LibraryBuilder("My Library").Build();
+ UnitOfWork.LibraryRepository.Add(library);
+ await UnitOfWork.CommitAsync();
+
+ var user = new AppUserBuilder("Amelia", "amelia@localhost")
+ .WithLibrary(library).Build();
+ UnitOfWork.UserRepository.Add(user);
+
+ var person = new PersonBuilder("Jillian Cowan").Build();
+
+ var person2 = new PersonBuilder("Cowan Jillian").Build();
+
+ var chapter = new ChapterBuilder("1")
+ .WithPerson(person, PersonRole.Editor)
+ .WithPerson(person2, PersonRole.Colorist)
+ .Build();
+
+ var chapter2 = new ChapterBuilder("2")
+ .WithPerson(person2, PersonRole.Editor)
+ .WithPerson(person, PersonRole.Editor)
+ .Build();
+
+ var series = new SeriesBuilder("Test 1")
+ .WithLibraryId(library.Id)
+ .WithVolume(new VolumeBuilder("1")
+ .WithChapter(chapter)
+ .Build())
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithPerson(person, PersonRole.Editor)
+ .WithPerson(person2, PersonRole.Editor)
+ .Build())
+ .Build();
+
+ var series2 = new SeriesBuilder("Test 2")
+ .WithLibraryId(library.Id)
+ .WithVolume(new VolumeBuilder("2")
+ .WithChapter(chapter2)
+ .Build())
+ .WithMetadata(new SeriesMetadataBuilder()
+ .WithPerson(person, PersonRole.Editor)
+ .WithPerson(person2, PersonRole.Colorist)
+ .Build())
+ .Build();
+
+ UnitOfWork.SeriesRepository.Add(series);
+ UnitOfWork.SeriesRepository.Add(series2);
+ await UnitOfWork.CommitAsync();
+
+ await ps.MergePeopleAsync(person2, person);
+ var allPeople = await UnitOfWork.PersonRepository.GetAllPeople();
+ Assert.Single(allPeople);
+
+ var mergedPerson = await UnitOfWork.PersonRepository.GetPersonById(person.Id, PersonIncludes.All);
+ Assert.NotNull(mergedPerson);
+ Assert.Equal(3, mergedPerson.ChapterPeople.Count);
+ Assert.Equal(3, mergedPerson.SeriesMetadataPeople.Count);
+
+ chapter = await UnitOfWork.ChapterRepository.GetChapterAsync(chapter.Id, ChapterIncludes.People);
+ Assert.NotNull(chapter);
+ Assert.Equal(2, chapter.People.Count);
+ Assert.Single(chapter.People.Select(p => p.Person.Id).Distinct());
+ Assert.Contains(chapter.People, p => p.Role == PersonRole.Editor);
+ Assert.Contains(chapter.People, p => p.Role == PersonRole.Colorist);
+
+ chapter2 = await UnitOfWork.ChapterRepository.GetChapterAsync(chapter2.Id, ChapterIncludes.People);
+ Assert.NotNull(chapter2);
+ Assert.Single(chapter2.People);
+ Assert.Contains(chapter2.People, p => p.Role == PersonRole.Editor);
+ Assert.DoesNotContain(chapter2.People, p => p.Role == PersonRole.Colorist);
+
+ series = await UnitOfWork.SeriesRepository.GetSeriesByIdAsync(series.Id, SeriesIncludes.Metadata);
+ Assert.NotNull(series);
+ Assert.Single(series.Metadata.People);
+ Assert.Contains(series.Metadata.People, p => p.Role == PersonRole.Editor);
+ Assert.DoesNotContain(series.Metadata.People, p => p.Role == PersonRole.Colorist);
+
+ series2 = await UnitOfWork.SeriesRepository.GetSeriesByIdAsync(series2.Id, SeriesIncludes.Metadata);
+ Assert.NotNull(series2);
+ Assert.Equal(2, series2.Metadata.People.Count);
+ Assert.Contains(series2.Metadata.People, p => p.Role == PersonRole.Editor);
+ Assert.Contains(series2.Metadata.People, p => p.Role == PersonRole.Colorist);
+
+
+ }
+
+ [Fact]
+ public async Task PersonAddAlias_NoOverlap()
+ {
+ await ResetDb();
+
+ UnitOfWork.PersonRepository.Attach(new PersonBuilder("Jillian Cowan").Build());
+ UnitOfWork.PersonRepository.Attach(new PersonBuilder("Jilly Cowan").WithAlias("Jolly Cowan").Build());
+ await UnitOfWork.CommitAsync();
+
+ var ps = new PersonService(UnitOfWork);
+
+ var person1 = await UnitOfWork.PersonRepository.GetPersonByNameOrAliasAsync("Jillian Cowan");
+ var person2 = await UnitOfWork.PersonRepository.GetPersonByNameOrAliasAsync("Jilly Cowan");
+ Assert.NotNull(person1);
+ Assert.NotNull(person2);
+
+ // Overlap on Name
+ var success = await ps.UpdatePersonAliasesAsync(person1, ["Jilly Cowan"]);
+ Assert.False(success);
+
+ // Overlap on alias
+ success = await ps.UpdatePersonAliasesAsync(person1, ["Jolly Cowan"]);
+ Assert.False(success);
+
+ // No overlap
+ success = await ps.UpdatePersonAliasesAsync(person2, ["Jilly Joy Cowan"]);
+ Assert.True(success);
+
+ // Some overlap
+ success = await ps.UpdatePersonAliasesAsync(person1, ["Jolly Cowan", "Jilly Joy Cowan"]);
+ Assert.False(success);
+
+ // Some overlap
+ success = await ps.UpdatePersonAliasesAsync(person1, ["Jolly Cowan", "Jilly Joy Cowan"]);
+ Assert.False(success);
+
+ Assert.Single(person2.Aliases);
+ }
+
+ protected override async Task ResetDb()
+ {
+ Context.Person.RemoveRange(Context.Person.ToList());
+
+ await Context.SaveChangesAsync();
+ }
+}
diff --git a/API.Tests/Services/ReadingProfileServiceTest.cs b/API.Tests/Services/ReadingProfileServiceTest.cs
new file mode 100644
index 000000000..b3d81e5ac
--- /dev/null
+++ b/API.Tests/Services/ReadingProfileServiceTest.cs
@@ -0,0 +1,561 @@
+using System.Linq;
+using System.Threading.Tasks;
+using API.Data.Repositories;
+using API.DTOs;
+using API.Entities;
+using API.Entities.Enums;
+using API.Helpers.Builders;
+using API.Services;
+using API.Tests.Helpers;
+using Kavita.Common;
+using Microsoft.EntityFrameworkCore;
+using NSubstitute;
+using Xunit;
+
+namespace API.Tests.Services;
+
+public class ReadingProfileServiceTest: AbstractDbTest
+{
+
+ ///
+ /// Does not add a default reading profile
+ ///
+ ///
+ public async Task<(ReadingProfileService, AppUser, Library, Series)> Setup()
+ {
+ var user = new AppUserBuilder("amelia", "amelia@localhost").Build();
+ Context.AppUser.Add(user);
+ await UnitOfWork.CommitAsync();
+
+ var series = new SeriesBuilder("Spice and Wolf").Build();
+
+ var library = new LibraryBuilder("Manga")
+ .WithSeries(series)
+ .Build();
+
+ user.Libraries.Add(library);
+ await UnitOfWork.CommitAsync();
+
+ var rps = new ReadingProfileService(UnitOfWork, Substitute.For(), Mapper);
+ user = await UnitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.UserPreferences);
+
+ return (rps, user, library, series);
+ }
+
+ [Fact]
+ public async Task ImplicitProfileFirst()
+ {
+ await ResetDb();
+ var (rps, user, library, series) = await Setup();
+
+ var profile = new AppUserReadingProfileBuilder(user.Id)
+ .WithKind(ReadingProfileKind.Implicit)
+ .WithSeries(series)
+ .WithName("Implicit Profile")
+ .Build();
+
+ var profile2 = new AppUserReadingProfileBuilder(user.Id)
+ .WithSeries(series)
+ .WithName("Non-implicit Profile")
+ .Build();
+
+ user.ReadingProfiles.Add(profile);
+ user.ReadingProfiles.Add(profile2);
+ await UnitOfWork.CommitAsync();
+
+ var seriesProfile = await rps.GetReadingProfileDtoForSeries(user.Id, series.Id);
+ Assert.NotNull(seriesProfile);
+ Assert.Equal("Implicit Profile", seriesProfile.Name);
+
+ // Find parent
+ seriesProfile = await rps.GetReadingProfileDtoForSeries(user.Id, series.Id, true);
+ Assert.NotNull(seriesProfile);
+ Assert.Equal("Non-implicit Profile", seriesProfile.Name);
+ }
+
+ [Fact]
+ public async Task CantDeleteDefaultReadingProfile()
+ {
+ await ResetDb();
+ var (rps, user, _, _) = await Setup();
+
+ var profile = new AppUserReadingProfileBuilder(user.Id)
+ .WithKind(ReadingProfileKind.Default)
+ .Build();
+ Context.AppUserReadingProfiles.Add(profile);
+ await UnitOfWork.CommitAsync();
+
+ await Assert.ThrowsAsync(async () =>
+ {
+ await rps.DeleteReadingProfile(user.Id, profile.Id);
+ });
+
+ var profile2 = new AppUserReadingProfileBuilder(user.Id).Build();
+ Context.AppUserReadingProfiles.Add(profile2);
+ await UnitOfWork.CommitAsync();
+
+ await rps.DeleteReadingProfile(user.Id, profile2.Id);
+ await UnitOfWork.CommitAsync();
+
+ var allProfiles = await Context.AppUserReadingProfiles.ToListAsync();
+ Assert.Single(allProfiles);
+ }
+
+ [Fact]
+ public async Task CreateImplicitSeriesReadingProfile()
+ {
+ await ResetDb();
+ var (rps, user, _, series) = await Setup();
+
+ var dto = new UserReadingProfileDto
+ {
+ ReaderMode = ReaderMode.Webtoon,
+ ScalingOption = ScalingOption.FitToHeight,
+ WidthOverride = 53,
+ };
+
+ await rps.UpdateImplicitReadingProfile(user.Id, series.Id, dto);
+
+ var profile = await rps.GetReadingProfileForSeries(user.Id, series.Id);
+ Assert.NotNull(profile);
+ Assert.Contains(profile.SeriesIds, s => s == series.Id);
+ Assert.Equal(ReadingProfileKind.Implicit, profile.Kind);
+ }
+
+ [Fact]
+ public async Task UpdateImplicitReadingProfile_DoesNotCreateNew()
+ {
+ await ResetDb();
+ var (rps, user, _, series) = await Setup();
+
+ var dto = new UserReadingProfileDto
+ {
+ ReaderMode = ReaderMode.Webtoon,
+ ScalingOption = ScalingOption.FitToHeight,
+ WidthOverride = 53,
+ };
+
+ await rps.UpdateImplicitReadingProfile(user.Id, series.Id, dto);
+
+ var profile = await rps.GetReadingProfileForSeries(user.Id, series.Id);
+ Assert.NotNull(profile);
+ Assert.Contains(profile.SeriesIds, s => s == series.Id);
+ Assert.Equal(ReadingProfileKind.Implicit, profile.Kind);
+
+ dto = new UserReadingProfileDto
+ {
+ ReaderMode = ReaderMode.LeftRight,
+ };
+
+ await rps.UpdateImplicitReadingProfile(user.Id, series.Id, dto);
+ profile = await rps.GetReadingProfileForSeries(user.Id, series.Id);
+ Assert.NotNull(profile);
+ Assert.Contains(profile.SeriesIds, s => s == series.Id);
+ Assert.Equal(ReadingProfileKind.Implicit, profile.Kind);
+ Assert.Equal(ReaderMode.LeftRight, profile.ReaderMode);
+
+ var implicitCount = await Context.AppUserReadingProfiles
+ .Where(p => p.Kind == ReadingProfileKind.Implicit)
+ .CountAsync();
+ Assert.Equal(1, implicitCount);
+ }
+
+ [Fact]
+ public async Task GetCorrectProfile()
+ {
+ await ResetDb();
+ var (rps, user, lib, series) = await Setup();
+
+ var profile = new AppUserReadingProfileBuilder(user.Id)
+ .WithSeries(series)
+ .WithName("Series Specific")
+ .Build();
+ var profile2 = new AppUserReadingProfileBuilder(user.Id)
+ .WithLibrary(lib)
+ .WithName("Library Specific")
+ .Build();
+ var profile3 = new AppUserReadingProfileBuilder(user.Id)
+ .WithKind(ReadingProfileKind.Default)
+ .WithName("Global")
+ .Build();
+ Context.AppUserReadingProfiles.Add(profile);
+ Context.AppUserReadingProfiles.Add(profile2);
+ Context.AppUserReadingProfiles.Add(profile3);
+
+ var series2 = new SeriesBuilder("Rainbows After Storms").Build();
+ lib.Series.Add(series2);
+
+ var lib2 = new LibraryBuilder("Manga2").Build();
+ var series3 = new SeriesBuilder("A Tropical Fish Yearns for Snow").Build();
+ lib2.Series.Add(series3);
+
+ user.Libraries.Add(lib2);
+ await UnitOfWork.CommitAsync();
+
+ var p = await rps.GetReadingProfileDtoForSeries(user.Id, series.Id);
+ Assert.NotNull(p);
+ Assert.Equal("Series Specific", p.Name);
+
+ p = await rps.GetReadingProfileDtoForSeries(user.Id, series2.Id);
+ Assert.NotNull(p);
+ Assert.Equal("Library Specific", p.Name);
+
+ p = await rps.GetReadingProfileDtoForSeries(user.Id, series3.Id);
+ Assert.NotNull(p);
+ Assert.Equal("Global", p.Name);
+ }
+
+ [Fact]
+ public async Task ReplaceReadingProfile()
+ {
+ await ResetDb();
+ var (rps, user, lib, series) = await Setup();
+
+ var profile1 = new AppUserReadingProfileBuilder(user.Id)
+ .WithSeries(series)
+ .WithName("Profile 1")
+ .Build();
+
+ var profile2 = new AppUserReadingProfileBuilder(user.Id)
+ .WithName("Profile 2")
+ .Build();
+
+ Context.AppUserReadingProfiles.Add(profile1);
+ Context.AppUserReadingProfiles.Add(profile2);
+ await UnitOfWork.CommitAsync();
+
+ var profile = await rps.GetReadingProfileDtoForSeries(user.Id, series.Id);
+ Assert.NotNull(profile);
+ Assert.Equal("Profile 1", profile.Name);
+
+ await rps.AddProfileToSeries(user.Id, profile2.Id, series.Id);
+ profile = await rps.GetReadingProfileDtoForSeries(user.Id, series.Id);
+ Assert.NotNull(profile);
+ Assert.Equal("Profile 2", profile.Name);
+ }
+
+ [Fact]
+ public async Task DeleteReadingProfile()
+ {
+ await ResetDb();
+ var (rps, user, lib, series) = await Setup();
+
+ var profile1 = new AppUserReadingProfileBuilder(user.Id)
+ .WithSeries(series)
+ .WithName("Profile 1")
+ .Build();
+
+ Context.AppUserReadingProfiles.Add(profile1);
+ await UnitOfWork.CommitAsync();
+
+ await rps.ClearSeriesProfile(user.Id, series.Id);
+ var profiles = await UnitOfWork.AppUserReadingProfileRepository.GetProfilesForUser(user.Id);
+ Assert.DoesNotContain(profiles, rp => rp.SeriesIds.Contains(series.Id));
+
+ }
+
+ [Fact]
+ public async Task BulkAddReadingProfiles()
+ {
+ await ResetDb();
+ var (rps, user, lib, series) = await Setup();
+
+ for (var i = 0; i < 10; i++)
+ {
+ var generatedSeries = new SeriesBuilder($"Generated Series #{i}").Build();
+ lib.Series.Add(generatedSeries);
+ }
+
+ var profile = new AppUserReadingProfileBuilder(user.Id)
+ .WithSeries(series)
+ .WithName("Profile")
+ .Build();
+ Context.AppUserReadingProfiles.Add(profile);
+
+ var profile2 = new AppUserReadingProfileBuilder(user.Id)
+ .WithSeries(series)
+ .WithName("Profile2")
+ .Build();
+ Context.AppUserReadingProfiles.Add(profile2);
+
+ await UnitOfWork.CommitAsync();
+
+ var someSeriesIds = lib.Series.Take(lib.Series.Count / 2).Select(s => s.Id).ToList();
+ await rps.BulkAddProfileToSeries(user.Id, profile.Id, someSeriesIds);
+
+ foreach (var id in someSeriesIds)
+ {
+ var foundProfile = await rps.GetReadingProfileDtoForSeries(user.Id, id);
+ Assert.NotNull(foundProfile);
+ Assert.Equal(profile.Id, foundProfile.Id);
+ }
+
+ var allIds = lib.Series.Select(s => s.Id).ToList();
+ await rps.BulkAddProfileToSeries(user.Id, profile2.Id, allIds);
+
+ foreach (var id in allIds)
+ {
+ var foundProfile = await rps.GetReadingProfileDtoForSeries(user.Id, id);
+ Assert.NotNull(foundProfile);
+ Assert.Equal(profile2.Id, foundProfile.Id);
+ }
+
+
+ }
+
+ [Fact]
+ public async Task BulkAssignDeletesImplicit()
+ {
+ await ResetDb();
+ var (rps, user, lib, series) = await Setup();
+
+ var implicitProfile = Mapper.Map(new AppUserReadingProfileBuilder(user.Id)
+ .Build());
+
+ var profile = new AppUserReadingProfileBuilder(user.Id)
+ .WithName("Profile 1")
+ .Build();
+ Context.AppUserReadingProfiles.Add(profile);
+
+ for (var i = 0; i < 10; i++)
+ {
+ var generatedSeries = new SeriesBuilder($"Generated Series #{i}").Build();
+ lib.Series.Add(generatedSeries);
+ }
+ await UnitOfWork.CommitAsync();
+
+ var ids = lib.Series.Select(s => s.Id).ToList();
+
+ foreach (var id in ids)
+ {
+ await rps.UpdateImplicitReadingProfile(user.Id, id, implicitProfile);
+ var seriesProfile = await rps.GetReadingProfileDtoForSeries(user.Id, id);
+ Assert.NotNull(seriesProfile);
+ Assert.Equal(ReadingProfileKind.Implicit, seriesProfile.Kind);
+ }
+
+ await rps.BulkAddProfileToSeries(user.Id, profile.Id, ids);
+
+ foreach (var id in ids)
+ {
+ var seriesProfile = await rps.GetReadingProfileDtoForSeries(user.Id, id);
+ Assert.NotNull(seriesProfile);
+ Assert.Equal(ReadingProfileKind.User, seriesProfile.Kind);
+ }
+
+ var implicitCount = await Context.AppUserReadingProfiles
+ .Where(p => p.Kind == ReadingProfileKind.Implicit)
+ .CountAsync();
+ Assert.Equal(0, implicitCount);
+ }
+
+ [Fact]
+ public async Task AddDeletesImplicit()
+ {
+ await ResetDb();
+ var (rps, user, lib, series) = await Setup();
+
+ var implicitProfile = Mapper.Map(new AppUserReadingProfileBuilder(user.Id)
+ .WithKind(ReadingProfileKind.Implicit)
+ .Build());
+
+ var profile = new AppUserReadingProfileBuilder(user.Id)
+ .WithName("Profile 1")
+ .Build();
+ Context.AppUserReadingProfiles.Add(profile);
+ await UnitOfWork.CommitAsync();
+
+ await rps.UpdateImplicitReadingProfile(user.Id, series.Id, implicitProfile);
+
+ var seriesProfile = await rps.GetReadingProfileDtoForSeries(user.Id, series.Id);
+ Assert.NotNull(seriesProfile);
+ Assert.Equal(ReadingProfileKind.Implicit, seriesProfile.Kind);
+
+ await rps.AddProfileToSeries(user.Id, profile.Id, series.Id);
+
+ seriesProfile = await rps.GetReadingProfileDtoForSeries(user.Id, series.Id);
+ Assert.NotNull(seriesProfile);
+ Assert.Equal(ReadingProfileKind.User, seriesProfile.Kind);
+
+ var implicitCount = await Context.AppUserReadingProfiles
+ .Where(p => p.Kind == ReadingProfileKind.Implicit)
+ .CountAsync();
+ Assert.Equal(0, implicitCount);
+ }
+
+ [Fact]
+ public async Task CreateReadingProfile()
+ {
+ await ResetDb();
+ var (rps, user, lib, series) = await Setup();
+
+ var dto = new UserReadingProfileDto
+ {
+ Name = "Profile 1",
+ ReaderMode = ReaderMode.LeftRight,
+ EmulateBook = false,
+ };
+
+ await rps.CreateReadingProfile(user.Id, dto);
+
+ var dto2 = new UserReadingProfileDto
+ {
+ Name = "Profile 2",
+ ReaderMode = ReaderMode.LeftRight,
+ EmulateBook = false,
+ };
+
+ await rps.CreateReadingProfile(user.Id, dto2);
+
+ var dto3 = new UserReadingProfileDto
+ {
+ Name = "Profile 1", // Not unique name
+ ReaderMode = ReaderMode.LeftRight,
+ EmulateBook = false,
+ };
+
+ await Assert.ThrowsAsync(async () =>
+ {
+ await rps.CreateReadingProfile(user.Id, dto3);
+ });
+
+ var allProfiles = Context.AppUserReadingProfiles.ToList();
+ Assert.Equal(2, allProfiles.Count);
+ }
+
+ [Fact]
+ public async Task ClearSeriesProfile_RemovesImplicitAndUnlinksExplicit()
+ {
+ await ResetDb();
+ var (rps, user, _, series) = await Setup();
+
+ var implicitProfile = new AppUserReadingProfileBuilder(user.Id)
+ .WithSeries(series)
+ .WithKind(ReadingProfileKind.Implicit)
+ .WithName("Implicit Profile")
+ .Build();
+
+ var explicitProfile = new AppUserReadingProfileBuilder(user.Id)
+ .WithSeries(series)
+ .WithName("Explicit Profile")
+ .Build();
+
+ Context.AppUserReadingProfiles.Add(implicitProfile);
+ Context.AppUserReadingProfiles.Add(explicitProfile);
+ await UnitOfWork.CommitAsync();
+
+ var allBefore = await UnitOfWork.AppUserReadingProfileRepository.GetProfilesForUser(user.Id);
+ Assert.Equal(2, allBefore.Count(rp => rp.SeriesIds.Contains(series.Id)));
+
+ await rps.ClearSeriesProfile(user.Id, series.Id);
+
+ var remainingProfiles = await Context.AppUserReadingProfiles.ToListAsync();
+ Assert.Single(remainingProfiles);
+ Assert.Equal("Explicit Profile", remainingProfiles[0].Name);
+ Assert.Empty(remainingProfiles[0].SeriesIds);
+
+ var profilesForSeries = await UnitOfWork.AppUserReadingProfileRepository.GetProfilesForUser(user.Id);
+ Assert.DoesNotContain(profilesForSeries, rp => rp.SeriesIds.Contains(series.Id));
+ }
+
+ [Fact]
+ public async Task AddProfileToLibrary_AddsAndOverridesExisting()
+ {
+ await ResetDb();
+ var (rps, user, lib, _) = await Setup();
+
+ var profile = new AppUserReadingProfileBuilder(user.Id)
+ .WithName("Library Profile")
+ .Build();
+ Context.AppUserReadingProfiles.Add(profile);
+ await UnitOfWork.CommitAsync();
+
+ await rps.AddProfileToLibrary(user.Id, profile.Id, lib.Id);
+ await UnitOfWork.CommitAsync();
+
+ var linkedProfile = (await UnitOfWork.AppUserReadingProfileRepository.GetProfilesForUser(user.Id))
+ .FirstOrDefault(rp => rp.LibraryIds.Contains(lib.Id));
+ Assert.NotNull(linkedProfile);
+ Assert.Equal(profile.Id, linkedProfile.Id);
+
+ var newProfile = new AppUserReadingProfileBuilder(user.Id)
+ .WithName("New Profile")
+ .Build();
+ Context.AppUserReadingProfiles.Add(newProfile);
+ await UnitOfWork.CommitAsync();
+
+ await rps.AddProfileToLibrary(user.Id, newProfile.Id, lib.Id);
+ await UnitOfWork.CommitAsync();
+
+ linkedProfile = (await UnitOfWork.AppUserReadingProfileRepository.GetProfilesForUser(user.Id))
+ .FirstOrDefault(rp => rp.LibraryIds.Contains(lib.Id));
+ Assert.NotNull(linkedProfile);
+ Assert.Equal(newProfile.Id, linkedProfile.Id);
+ }
+
+ [Fact]
+ public async Task ClearLibraryProfile_RemovesImplicitOrUnlinksExplicit()
+ {
+ await ResetDb();
+ var (rps, user, lib, _) = await Setup();
+
+ var implicitProfile = new AppUserReadingProfileBuilder(user.Id)
+ .WithKind(ReadingProfileKind.Implicit)
+ .WithLibrary(lib)
+ .Build();
+ Context.AppUserReadingProfiles.Add(implicitProfile);
+ await UnitOfWork.CommitAsync();
+
+ await rps.ClearLibraryProfile(user.Id, lib.Id);
+ var profile = (await UnitOfWork.AppUserReadingProfileRepository.GetProfilesForUser(user.Id))
+ .FirstOrDefault(rp => rp.LibraryIds.Contains(lib.Id));
+ Assert.Null(profile);
+
+ var explicitProfile = new AppUserReadingProfileBuilder(user.Id)
+ .WithLibrary(lib)
+ .Build();
+ Context.AppUserReadingProfiles.Add(explicitProfile);
+ await UnitOfWork.CommitAsync();
+
+ await rps.ClearLibraryProfile(user.Id, lib.Id);
+ profile = (await UnitOfWork.AppUserReadingProfileRepository.GetProfilesForUser(user.Id))
+ .FirstOrDefault(rp => rp.LibraryIds.Contains(lib.Id));
+ Assert.Null(profile);
+
+ var stillExists = await Context.AppUserReadingProfiles.FindAsync(explicitProfile.Id);
+ Assert.NotNull(stillExists);
+ }
+
+ ///
+ /// As response to #3793, I'm not sure if we want to keep this. It's not the most nice. But I think the idea of this test
+ /// is worth having.
+ ///
+ [Fact]
+ public void UpdateFields_UpdatesAll()
+ {
+ // Repeat to ensure booleans are flipped and actually tested
+ for (int i = 0; i < 10; i++)
+ {
+ var profile = new AppUserReadingProfile();
+ var dto = new UserReadingProfileDto();
+
+ RandfHelper.SetRandomValues(profile);
+ RandfHelper.SetRandomValues(dto);
+
+ ReadingProfileService.UpdateReaderProfileFields(profile, dto);
+
+ var newDto = Mapper.Map(profile);
+
+ Assert.True(RandfHelper.AreSimpleFieldsEqual(dto, newDto,
+ ["k__BackingField", "k__BackingField"]));
+ }
+ }
+
+
+
+ protected override async Task ResetDb()
+ {
+ Context.AppUserReadingProfiles.RemoveRange(Context.AppUserReadingProfiles);
+ await UnitOfWork.CommitAsync();
+ }
+}
diff --git a/API.Tests/Services/ScannerServiceTests.cs b/API.Tests/Services/ScannerServiceTests.cs
index 2e812647b..c337d2311 100644
--- a/API.Tests/Services/ScannerServiceTests.cs
+++ b/API.Tests/Services/ScannerServiceTests.cs
@@ -483,7 +483,7 @@ public class ScannerServiceTests : AbstractDbTest
var infos = new Dictionary();
var library = await _scannerHelper.GenerateScannerData(testcase, infos);
- library.LibraryExcludePatterns = [new LibraryExcludePattern() {Pattern = "**/Extra/*"}];
+ library.LibraryExcludePatterns = [new LibraryExcludePattern() { Pattern = "**/Extra/*" }];
UnitOfWork.LibraryRepository.Update(library);
await UnitOfWork.CommitAsync();
@@ -507,7 +507,7 @@ public class ScannerServiceTests : AbstractDbTest
var infos = new Dictionary();
var library = await _scannerHelper.GenerateScannerData(testcase, infos);
- library.LibraryExcludePatterns = [new LibraryExcludePattern() {Pattern = "**\\Extra\\*"}];
+ library.LibraryExcludePatterns = [new LibraryExcludePattern() { Pattern = "**\\Extra\\*" }];
UnitOfWork.LibraryRepository.Update(library);
await UnitOfWork.CommitAsync();
@@ -938,4 +938,61 @@ public class ScannerServiceTests : AbstractDbTest
Assert.True(sortedChapters[1].SortOrder.Is(4f));
Assert.True(sortedChapters[2].SortOrder.Is(5f));
}
+
+
+ [Fact]
+ public async Task ScanLibrary_MetadataDisabled_NoOverrides()
+ {
+ const string testcase = "Series with Localized No Metadata - Manga.json";
+
+ // Get the first file and generate a ComicInfo
+ var infos = new Dictionary();
+ infos.Add("Immoral Guild v01.cbz", new ComicInfo()
+ {
+ Series = "Immoral Guild",
+ LocalizedSeries = "Futoku no Guild" // Filename has a capital N and localizedSeries has lowercase
+ });
+
+ var library = await _scannerHelper.GenerateScannerData(testcase, infos);
+
+ // Disable metadata
+ library.EnableMetadata = false;
+ UnitOfWork.LibraryRepository.Update(library);
+ await UnitOfWork.CommitAsync();
+
+ var scanner = _scannerHelper.CreateServices();
+ await scanner.ScanLibrary(library.Id);
+
+ var postLib = await UnitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
+
+ // Validate that there are 2 series
+ Assert.NotNull(postLib);
+ Assert.Equal(2, postLib.Series.Count);
+
+ Assert.Contains(postLib.Series, x => x.Name == "Immoral Guild");
+ Assert.Contains(postLib.Series, x => x.Name == "Futoku No Guild");
+ }
+
+ [Fact]
+ public async Task ScanLibrary_SortName_NoPrefix()
+ {
+ const string testcase = "Series with Prefix - Book.json";
+
+ var library = await _scannerHelper.GenerateScannerData(testcase);
+
+ library.RemovePrefixForSortName = true;
+ UnitOfWork.LibraryRepository.Update(library);
+ await UnitOfWork.CommitAsync();
+
+ var scanner = _scannerHelper.CreateServices();
+ await scanner.ScanLibrary(library.Id);
+
+ var postLib = await UnitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
+
+ Assert.NotNull(postLib);
+ Assert.Equal(1, postLib.Series.Count);
+
+ Assert.Equal("The Avengers", postLib.Series.First().Name);
+ Assert.Equal("Avengers", postLib.Series.First().SortName);
+ }
}
diff --git a/API.Tests/Services/ScrobblingServiceTests.cs b/API.Tests/Services/ScrobblingServiceTests.cs
index 50398a146..9245c8ecd 100644
--- a/API.Tests/Services/ScrobblingServiceTests.cs
+++ b/API.Tests/Services/ScrobblingServiceTests.cs
@@ -1,11 +1,17 @@
-using System.Linq;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
+using API.Data.Repositories;
using API.DTOs.Scrobbling;
+using API.Entities;
using API.Entities.Enums;
+using API.Entities.Scrobble;
using API.Helpers.Builders;
using API.Services;
using API.Services.Plus;
using API.SignalR;
+using Kavita.Common;
using Microsoft.Extensions.Logging;
using NSubstitute;
using Xunit;
@@ -15,11 +21,33 @@ namespace API.Tests.Services;
public class ScrobblingServiceTests : AbstractDbTest
{
+ private const int ChapterPages = 100;
+
+ ///
+ /// {
+ /// "Issuer": "Issuer",
+ /// "Issued At": "2025-06-15T21:01:57.615Z",
+ /// "Expiration": "2200-06-15T21:01:57.615Z"
+ /// }
+ ///
+ /// Our UnitTests will fail in 2200 :(
+ private const string ValidJwtToken =
+ "eyJhbGciOiJIUzI1NiJ9.eyJJc3N1ZXIiOiJJc3N1ZXIiLCJleHAiOjcyNzI0NTAxMTcsImlhdCI6MTc1MDAyMTMxN30.zADmcGq_BfxbcV8vy4xw5Cbzn4COkmVINxgqpuL17Ng";
+
private readonly ScrobblingService _service;
private readonly ILicenseService _licenseService;
private readonly ILocalizationService _localizationService;
private readonly ILogger _logger;
private readonly IEmailService _emailService;
+ private readonly IKavitaPlusApiService _kavitaPlusApiService;
+ ///
+ /// IReaderService, without the ScrobblingService injected
+ ///
+ private readonly IReaderService _readerService;
+ ///
+ /// IReaderService, with the _service injected
+ ///
+ private readonly IReaderService _hookedUpReaderService;
public ScrobblingServiceTests()
{
@@ -27,8 +55,24 @@ public class ScrobblingServiceTests : AbstractDbTest
_localizationService = Substitute.For();
_logger = Substitute.For>();
_emailService = Substitute.For();
+ _kavitaPlusApiService = Substitute.For();
- _service = new ScrobblingService(UnitOfWork, Substitute.For(), _logger, _licenseService, _localizationService, _emailService);
+ _service = new ScrobblingService(UnitOfWork, Substitute.For(), _logger, _licenseService,
+ _localizationService, _emailService, _kavitaPlusApiService);
+
+ _readerService = new ReaderService(UnitOfWork,
+ Substitute.For>(),
+ Substitute.For(),
+ Substitute.For(),
+ Substitute.For(),
+ Substitute.For()); // Do not use the actual one
+
+ _hookedUpReaderService = new ReaderService(UnitOfWork,
+ Substitute.For>(),
+ Substitute.For(),
+ Substitute.For(),
+ Substitute.For(),
+ _service);
}
protected override async Task ResetDb()
@@ -46,6 +90,30 @@ public class ScrobblingServiceTests : AbstractDbTest
var series = new SeriesBuilder("Test Series")
.WithFormat(MangaFormat.Archive)
.WithMetadata(new SeriesMetadataBuilder().Build())
+ .WithVolume(new VolumeBuilder("Volume 1")
+ .WithChapters([
+ new ChapterBuilder("1")
+ .WithPages(ChapterPages)
+ .Build(),
+ new ChapterBuilder("2")
+ .WithPages(ChapterPages)
+ .Build(),
+ new ChapterBuilder("3")
+ .WithPages(ChapterPages)
+ .Build()])
+ .Build())
+ .WithVolume(new VolumeBuilder("Volume 2")
+ .WithChapters([
+ new ChapterBuilder("4")
+ .WithPages(ChapterPages)
+ .Build(),
+ new ChapterBuilder("5")
+ .WithPages(ChapterPages)
+ .Build(),
+ new ChapterBuilder("6")
+ .WithPages(ChapterPages)
+ .Build()])
+ .Build())
.Build();
var library = new LibraryBuilder("Test Library", LibraryType.Manga)
@@ -67,6 +135,296 @@ public class ScrobblingServiceTests : AbstractDbTest
await UnitOfWork.CommitAsync();
}
+ private async Task CreateScrobbleEvent(int? seriesId = null)
+ {
+ var evt = new ScrobbleEvent
+ {
+ ScrobbleEventType = ScrobbleEventType.ChapterRead,
+ Format = PlusMediaFormat.Manga,
+ SeriesId = seriesId ?? 0,
+ LibraryId = 0,
+ AppUserId = 0,
+ };
+
+ if (seriesId != null)
+ {
+ var series = await UnitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId.Value);
+ if (series != null) evt.Series = series;
+ }
+
+ return evt;
+ }
+
+
+ #region K+ API Request Tests
+
+ [Fact]
+ public async Task PostScrobbleUpdate_AuthErrors()
+ {
+ _kavitaPlusApiService.PostScrobbleUpdate(null!, "")
+ .ReturnsForAnyArgs(new ScrobbleResponseDto()
+ {
+ ErrorMessage = "Unauthorized"
+ });
+
+ var evt = await CreateScrobbleEvent();
+ await Assert.ThrowsAsync(async () =>
+ {
+ await _service.PostScrobbleUpdate(new ScrobbleDto(), "", evt);
+ });
+ Assert.True(evt.IsErrored);
+ Assert.Equal("Kavita+ subscription no longer active", evt.ErrorDetails);
+ }
+
+ [Fact]
+ public async Task PostScrobbleUpdate_UnknownSeriesLoggedAsError()
+ {
+ _kavitaPlusApiService.PostScrobbleUpdate(null!, "")
+ .ReturnsForAnyArgs(new ScrobbleResponseDto()
+ {
+ ErrorMessage = "Unknown Series"
+ });
+
+ await SeedData();
+ var evt = await CreateScrobbleEvent(1);
+
+ await _service.PostScrobbleUpdate(new ScrobbleDto(), "", evt);
+ await UnitOfWork.CommitAsync();
+ Assert.True(evt.IsErrored);
+
+ var series = await UnitOfWork.SeriesRepository.GetSeriesByIdAsync(1);
+ Assert.NotNull(series);
+ Assert.True(series.IsBlacklisted);
+
+ var errors = await UnitOfWork.ScrobbleRepository.GetAllScrobbleErrorsForSeries(1);
+ Assert.Single(errors);
+ Assert.Equal("Series cannot be matched for Scrobbling", errors.First().Comment);
+ Assert.Equal(series.Id, errors.First().SeriesId);
+ }
+
+ [Fact]
+ public async Task PostScrobbleUpdate_InvalidAccessToken()
+ {
+ _kavitaPlusApiService.PostScrobbleUpdate(null!, "")
+ .ReturnsForAnyArgs(new ScrobbleResponseDto()
+ {
+ ErrorMessage = "Access token is invalid"
+ });
+
+ var evt = await CreateScrobbleEvent();
+
+ await Assert.ThrowsAsync(async () =>
+ {
+ await _service.PostScrobbleUpdate(new ScrobbleDto(), "", evt);
+ });
+
+ Assert.True(evt.IsErrored);
+ Assert.Equal("Access Token needs to be rotated to continue scrobbling", evt.ErrorDetails);
+ }
+
+ #endregion
+
+ #region K+ API Request data tests
+
+ [Fact]
+ public async Task ProcessReadEvents_CreatesNoEventsWhenNoProgress()
+ {
+ await ResetDb();
+ await SeedData();
+
+ // Set Returns
+ _licenseService.HasActiveLicense().Returns(Task.FromResult(true));
+ _kavitaPlusApiService.GetRateLimit(Arg.Any(), Arg.Any())
+ .Returns(100);
+
+ var user = await UnitOfWork.UserRepository.GetUserByIdAsync(1);
+ Assert.NotNull(user);
+
+ // Ensure CanProcessScrobbleEvent returns true
+ user.AniListAccessToken = ValidJwtToken;
+ UnitOfWork.UserRepository.Update(user);
+ await UnitOfWork.CommitAsync();
+
+ var chapter = await UnitOfWork.ChapterRepository.GetChapterAsync(4);
+ Assert.NotNull(chapter);
+
+ var volume = await UnitOfWork.VolumeRepository.GetVolumeAsync(1, VolumeIncludes.Chapters);
+ Assert.NotNull(volume);
+
+ // Call Scrobble without having any progress
+ await _service.ScrobbleReadingUpdate(1, 1);
+ var events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Empty(events);
+ }
+
+ [Fact]
+ public async Task ProcessReadEvents_UpdateVolumeAndChapterData()
+ {
+ await ResetDb();
+ await SeedData();
+
+ // Set Returns
+ _licenseService.HasActiveLicense().Returns(Task.FromResult(true));
+ _kavitaPlusApiService.GetRateLimit(Arg.Any(), Arg.Any())
+ .Returns(100);
+
+ var user = await UnitOfWork.UserRepository.GetUserByIdAsync(1);
+ Assert.NotNull(user);
+
+ // Ensure CanProcessScrobbleEvent returns true
+ user.AniListAccessToken = ValidJwtToken;
+ UnitOfWork.UserRepository.Update(user);
+ await UnitOfWork.CommitAsync();
+
+ var chapter = await UnitOfWork.ChapterRepository.GetChapterAsync(4);
+ Assert.NotNull(chapter);
+
+ var volume = await UnitOfWork.VolumeRepository.GetVolumeAsync(1, VolumeIncludes.Chapters);
+ Assert.NotNull(volume);
+
+ // Mark something as read to trigger event creation
+ await _readerService.MarkChaptersAsRead(user, 1, new List() {volume.Chapters[0]});
+ await UnitOfWork.CommitAsync();
+
+ // Call Scrobble while having some progress
+ await _service.ScrobbleReadingUpdate(user.Id, 1);
+ var events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Single(events);
+
+ // Give it some (more) read progress
+ await _readerService.MarkChaptersAsRead(user, 1, volume.Chapters);
+ await _readerService.MarkChaptersAsRead(user, 1, [chapter]);
+ await UnitOfWork.CommitAsync();
+
+ await _service.ProcessUpdatesSinceLastSync();
+
+ await _kavitaPlusApiService.Received(1).PostScrobbleUpdate(
+ Arg.Is(data =>
+ data.ChapterNumber == (int)chapter.MaxNumber &&
+ data.VolumeNumber == (int)volume.MaxNumber
+ ),
+ Arg.Any());
+ }
+
+ #endregion
+
+ #region Scrobble Reading Update Tests
+
+ [Fact]
+ public async Task ScrobbleReadingUpdate_IgnoreNoLicense()
+ {
+ await ResetDb();
+ await SeedData();
+
+ _licenseService.HasActiveLicense().Returns(false);
+
+ await _service.ScrobbleReadingUpdate(1, 1);
+ var events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Empty(events);
+ }
+
+ [Fact]
+ public async Task ScrobbleReadingUpdate_RemoveWhenNoProgress()
+ {
+ await ResetDb();
+ await SeedData();
+
+ _licenseService.HasActiveLicense().Returns(true);
+
+ var user = await UnitOfWork.UserRepository.GetUserByIdAsync(1);
+ Assert.NotNull(user);
+
+ var volume = await UnitOfWork.VolumeRepository.GetVolumeAsync(1, VolumeIncludes.Chapters);
+ Assert.NotNull(volume);
+
+ await _readerService.MarkChaptersAsRead(user, 1, new List() {volume.Chapters[0]});
+ await UnitOfWork.CommitAsync();
+
+ await _service.ScrobbleReadingUpdate(1, 1);
+ var events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Single(events);
+
+ var readEvent = events.First();
+ Assert.False(readEvent.IsProcessed);
+
+ await _hookedUpReaderService.MarkSeriesAsUnread(user, 1);
+ await UnitOfWork.CommitAsync();
+
+ // Existing event is deleted
+ await _service.ScrobbleReadingUpdate(1, 1);
+ events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Empty(events);
+
+ await _hookedUpReaderService.MarkSeriesAsUnread(user, 1);
+ await UnitOfWork.CommitAsync();
+
+ // No new events are added
+ events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Empty(events);
+ }
+
+ [Fact]
+ public async Task ScrobbleReadingUpdate_UpdateExistingNotIsProcessed()
+ {
+ await ResetDb();
+ await SeedData();
+
+ var user = await UnitOfWork.UserRepository.GetUserByIdAsync(1);
+ Assert.NotNull(user);
+
+ var chapter1 = await UnitOfWork.ChapterRepository.GetChapterAsync(1);
+ var chapter2 = await UnitOfWork.ChapterRepository.GetChapterAsync(2);
+ var chapter3 = await UnitOfWork.ChapterRepository.GetChapterAsync(3);
+ Assert.NotNull(chapter1);
+ Assert.NotNull(chapter2);
+ Assert.NotNull(chapter3);
+
+ _licenseService.HasActiveLicense().Returns(true);
+
+ var events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Empty(events);
+
+
+ await _readerService.MarkChaptersAsRead(user, 1, [chapter1]);
+ await UnitOfWork.CommitAsync();
+
+ // Scrobble update
+ await _service.ScrobbleReadingUpdate(1, 1);
+ events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Single(events);
+
+ var readEvent = events[0];
+ Assert.False(readEvent.IsProcessed);
+ Assert.Equal(1, readEvent.ChapterNumber);
+
+ // Mark as processed
+ readEvent.IsProcessed = true;
+ await UnitOfWork.CommitAsync();
+
+ await _readerService.MarkChaptersAsRead(user, 1, [chapter2]);
+ await UnitOfWork.CommitAsync();
+
+ // Scrobble update
+ await _service.ScrobbleReadingUpdate(1, 1);
+ events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Equal(2, events.Count);
+ Assert.Single(events.Where(e => e.IsProcessed).ToList());
+ Assert.Single(events.Where(e => !e.IsProcessed).ToList());
+
+ // Should update the existing non processed event
+ await _readerService.MarkChaptersAsRead(user, 1, [chapter3]);
+ await UnitOfWork.CommitAsync();
+
+ // Scrobble update
+ await _service.ScrobbleReadingUpdate(1, 1);
+ events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Equal(2, events.Count);
+ Assert.Single(events.Where(e => e.IsProcessed).ToList());
+ Assert.Single(events.Where(e => !e.IsProcessed).ToList());
+ }
+
+ #endregion
+
#region ScrobbleWantToReadUpdate Tests
[Fact]
@@ -203,6 +561,59 @@ public class ScrobblingServiceTests : AbstractDbTest
#endregion
+ #region Scrobble Rating Update Test
+
+ [Fact]
+ public async Task ScrobbleRatingUpdate_IgnoreNoLicense()
+ {
+ await ResetDb();
+ await SeedData();
+
+ _licenseService.HasActiveLicense().Returns(false);
+
+ await _service.ScrobbleRatingUpdate(1, 1, 1);
+ var events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Empty(events);
+ }
+
+ [Fact]
+ public async Task ScrobbleRatingUpdate_UpdateExistingNotIsProcessed()
+ {
+ await ResetDb();
+ await SeedData();
+
+ _licenseService.HasActiveLicense().Returns(true);
+
+ var user = await UnitOfWork.UserRepository.GetUserByIdAsync(1);
+ Assert.NotNull(user);
+
+ var series = await UnitOfWork.SeriesRepository.GetSeriesByIdAsync(1);
+ Assert.NotNull(series);
+
+ await _service.ScrobbleRatingUpdate(user.Id, series.Id, 1);
+ var events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Single(events);
+ Assert.Equal(1, events.First().Rating);
+
+ // Mark as processed
+ events.First().IsProcessed = true;
+ await UnitOfWork.CommitAsync();
+
+ await _service.ScrobbleRatingUpdate(user.Id, series.Id, 5);
+ events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Equal(2, events.Count);
+ Assert.Single(events, evt => evt.IsProcessed);
+ Assert.Single(events, evt => !evt.IsProcessed);
+
+ await _service.ScrobbleRatingUpdate(user.Id, series.Id, 5);
+ events = await UnitOfWork.ScrobbleRepository.GetAllEventsForSeries(1);
+ Assert.Single(events, evt => !evt.IsProcessed);
+ Assert.Equal(5, events.First(evt => !evt.IsProcessed).Rating);
+
+ }
+
+ #endregion
+
[Theory]
[InlineData("https://anilist.co/manga/35851/Byeontaega-Doeja/", 35851)]
[InlineData("https://anilist.co/manga/30105", 30105)]
diff --git a/API.Tests/Services/SeriesServiceTests.cs b/API.Tests/Services/SeriesServiceTests.cs
index 4bf0e6782..55babf815 100644
--- a/API.Tests/Services/SeriesServiceTests.cs
+++ b/API.Tests/Services/SeriesServiceTests.cs
@@ -8,6 +8,7 @@ using API.Data;
using API.Data.Repositories;
using API.DTOs;
using API.DTOs.Metadata;
+using API.DTOs.Person;
using API.DTOs.SeriesDetail;
using API.Entities;
using API.Entities.Enums;
diff --git a/API.Tests/Services/Test Data/ScannerService/TestCases/Series with Localized No Metadata - Manga.json b/API.Tests/Services/Test Data/ScannerService/TestCases/Series with Localized No Metadata - Manga.json
new file mode 100644
index 000000000..d6e91183b
--- /dev/null
+++ b/API.Tests/Services/Test Data/ScannerService/TestCases/Series with Localized No Metadata - Manga.json
@@ -0,0 +1,5 @@
+[
+ "Immoral Guild/Immoral Guild v01.cbz",
+ "Immoral Guild/Immoral Guild v02.cbz",
+ "Immoral Guild/Futoku No Guild - Vol. 12 Ch. 67 - Take Responsibility.cbz"
+]
diff --git a/API.Tests/Services/Test Data/ScannerService/TestCases/Series with Prefix - Book.json b/API.Tests/Services/Test Data/ScannerService/TestCases/Series with Prefix - Book.json
new file mode 100644
index 000000000..fc2bee18c
--- /dev/null
+++ b/API.Tests/Services/Test Data/ScannerService/TestCases/Series with Prefix - Book.json
@@ -0,0 +1,3 @@
+[
+ "The Avengers/The Avengers vol 1.pdf"
+]
\ No newline at end of file
diff --git a/API/API.csproj b/API/API.csproj
index 1ddb37d7f..a7d1177dc 100644
--- a/API/API.csproj
+++ b/API/API.csproj
@@ -50,9 +50,9 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
@@ -62,45 +62,45 @@
-
+
-
+
-
+
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
-
+
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
-
+
+
+
+
+
+
@@ -111,17 +111,16 @@
-
-
-
-
-
+
+
+
+
@@ -139,6 +138,7 @@
+
@@ -188,7 +188,6 @@
-
Always
diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.cs
index c504e1ce7..d8b9164af 100644
--- a/API/Controllers/AccountController.cs
+++ b/API/Controllers/AccountController.cs
@@ -153,6 +153,9 @@ public class AccountController : BaseApiController
// Assign default streams
AddDefaultStreamsToUser(user);
+ // Assign default reading profile
+ await AddDefaultReadingProfileToUser(user);
+
var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
if (string.IsNullOrEmpty(token)) return BadRequest(await _localizationService.Get("en", "confirm-token-gen"));
if (!await ConfirmEmailToken(token, user)) return BadRequest(await _localizationService.Get("en", "validate-email", token));
@@ -609,7 +612,7 @@ public class AccountController : BaseApiController
}
///
- /// Requests the Invite Url for the UserId. Will return error if user is already validated.
+ /// Requests the Invite Url for the AppUserId. Will return error if user is already validated.
///
///
/// Include the "https://ip:port/" in the generated link
@@ -669,6 +672,9 @@ public class AccountController : BaseApiController
// Assign default streams
AddDefaultStreamsToUser(user);
+ // Assign default reading profile
+ await AddDefaultReadingProfileToUser(user);
+
// Assign Roles
var roles = dto.Roles;
var hasAdminRole = dto.Roles.Contains(PolicyConstants.AdminRole);
@@ -779,6 +785,16 @@ public class AccountController : BaseApiController
}
}
+ private async Task AddDefaultReadingProfileToUser(AppUser user)
+ {
+ var profile = new AppUserReadingProfileBuilder(user.Id)
+ .WithName("Default Profile")
+ .WithKind(ReadingProfileKind.Default)
+ .Build();
+ _unitOfWork.AppUserReadingProfileRepository.Add(profile);
+ await _unitOfWork.CommitAsync();
+ }
+
///
/// Last step in authentication flow, confirms the email token for email
///
diff --git a/API/Controllers/BookController.cs b/API/Controllers/BookController.cs
index 251811346..e1d7da9e8 100644
--- a/API/Controllers/BookController.cs
+++ b/API/Controllers/BookController.cs
@@ -82,7 +82,6 @@ public class BookController : BaseApiController
SeriesFormat = dto.SeriesFormat,
SeriesId = dto.SeriesId,
LibraryId = dto.LibraryId,
- LibraryType = dto.LibraryType,
IsSpecial = dto.IsSpecial,
Pages = dto.Pages,
});
diff --git a/API/Controllers/ChapterController.cs b/API/Controllers/ChapterController.cs
index 8de26cf97..94535d499 100644
--- a/API/Controllers/ChapterController.cs
+++ b/API/Controllers/ChapterController.cs
@@ -9,6 +9,7 @@ using API.DTOs;
using API.DTOs.SeriesDetail;
using API.Entities;
using API.Entities.Enums;
+using API.Entities.MetadataMatching;
using API.Entities.Person;
using API.Extensions;
using API.Helpers;
@@ -208,6 +209,7 @@ public class ChapterController : BaseApiController
if (chapter.AgeRating != dto.AgeRating)
{
chapter.AgeRating = dto.AgeRating;
+ chapter.KPlusOverrides.Remove(MetadataSettingField.AgeRating);
}
dto.Summary ??= string.Empty;
@@ -215,6 +217,7 @@ public class ChapterController : BaseApiController
if (chapter.Summary != dto.Summary.Trim())
{
chapter.Summary = dto.Summary.Trim();
+ chapter.KPlusOverrides.Remove(MetadataSettingField.ChapterSummary);
}
if (chapter.Language != dto.Language)
@@ -230,11 +233,13 @@ public class ChapterController : BaseApiController
if (chapter.TitleName != dto.TitleName)
{
chapter.TitleName = dto.TitleName;
+ chapter.KPlusOverrides.Remove(MetadataSettingField.ChapterTitle);
}
if (chapter.ReleaseDate != dto.ReleaseDate)
{
chapter.ReleaseDate = dto.ReleaseDate;
+ chapter.KPlusOverrides.Remove(MetadataSettingField.ChapterReleaseDate);
}
if (!string.IsNullOrEmpty(dto.ISBN) && ArticleNumberHelper.IsValidIsbn10(dto.ISBN) ||
@@ -333,6 +338,8 @@ public class ChapterController : BaseApiController
_unitOfWork
);
+ // TODO: Only remove field if changes were made
+ chapter.KPlusOverrides.Remove(MetadataSettingField.ChapterPublisher);
// Update publishers
await PersonHelper.UpdateChapterPeopleAsync(
chapter,
diff --git a/API/Controllers/KoreaderController.cs b/API/Controllers/KoreaderController.cs
new file mode 100644
index 000000000..8c4c41585
--- /dev/null
+++ b/API/Controllers/KoreaderController.cs
@@ -0,0 +1,119 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Threading.Tasks;
+using API.Data;
+using API.Data.Repositories;
+using API.DTOs.Koreader;
+using API.Entities;
+using API.Extensions;
+using API.Services;
+using Kavita.Common;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.Extensions.Logging;
+using static System.Net.WebRequestMethods;
+
+namespace API.Controllers;
+#nullable enable
+
+///
+/// The endpoint to interface with Koreader's Progress Sync plugin.
+///
+///
+/// Koreader uses a different form of authentication. It stores the username and password in headers.
+/// https://github.com/koreader/koreader/blob/master/plugins/kosync.koplugin/KOSyncClient.lua
+///
+[AllowAnonymous]
+public class KoreaderController : BaseApiController
+{
+
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly ILocalizationService _localizationService;
+ private readonly IKoreaderService _koreaderService;
+ private readonly ILogger _logger;
+
+ public KoreaderController(IUnitOfWork unitOfWork, ILocalizationService localizationService,
+ IKoreaderService koreaderService, ILogger logger)
+ {
+ _unitOfWork = unitOfWork;
+ _localizationService = localizationService;
+ _koreaderService = koreaderService;
+ _logger = logger;
+ }
+
+ // We won't allow users to be created from Koreader. Rather, they
+ // must already have an account.
+ /*
+ [HttpPost("/users/create")]
+ public IActionResult CreateUser(CreateUserRequest request)
+ {
+ }
+ */
+
+ [HttpGet("{apiKey}/users/auth")]
+ public async Task Authenticate(string apiKey)
+ {
+ var userId = await GetUserId(apiKey);
+ var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);
+ if (user == null) return Unauthorized();
+
+ return Ok(new { username = user.UserName });
+ }
+
+ ///
+ /// Syncs book progress with Kavita. Will attempt to save the underlying reader position if possible.
+ ///
+ ///
+ ///
+ ///
+ [HttpPut("{apiKey}/syncs/progress")]
+ public async Task> UpdateProgress(string apiKey, KoreaderBookDto request)
+ {
+ try
+ {
+ var userId = await GetUserId(apiKey);
+ await _koreaderService.SaveProgress(request, userId);
+
+ return Ok(new KoreaderProgressUpdateDto{ Document = request.Document, Timestamp = DateTime.UtcNow });
+ }
+ catch (KavitaException ex)
+ {
+ return BadRequest(ex.Message);
+ }
+ }
+
+ ///
+ /// Gets book progress from Kavita, if not found will return a 400
+ ///
+ ///
+ ///
+ ///
+ [HttpGet("{apiKey}/syncs/progress/{ebookHash}")]
+ public async Task> GetProgress(string apiKey, string ebookHash)
+ {
+ try
+ {
+ var userId = await GetUserId(apiKey);
+ var response = await _koreaderService.GetProgress(ebookHash, userId);
+ _logger.LogDebug("Koreader response progress for User ({UserId}): {Progress}", userId, response.Progress.Sanitize());
+
+ return Ok(response);
+ }
+ catch (KavitaException ex)
+ {
+ return BadRequest(ex.Message);
+ }
+ }
+
+ private async Task GetUserId(string apiKey)
+ {
+ try
+ {
+ return await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey);
+ }
+ catch
+ {
+ throw new KavitaException(await _localizationService.Get("en", "user-doesnt-exist"));
+ }
+ }
+}
diff --git a/API/Controllers/LibraryController.cs b/API/Controllers/LibraryController.cs
index dbd809cee..8f9b18317 100644
--- a/API/Controllers/LibraryController.cs
+++ b/API/Controllers/LibraryController.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -624,6 +623,9 @@ public class LibraryController : BaseApiController
library.ManageReadingLists = dto.ManageReadingLists;
library.AllowScrobbling = dto.AllowScrobbling;
library.AllowMetadataMatching = dto.AllowMetadataMatching;
+ library.EnableMetadata = dto.EnableMetadata;
+ library.RemovePrefixForSortName = dto.RemovePrefixForSortName;
+
library.LibraryFileTypes = dto.FileGroupTypes
.Select(t => new LibraryFileTypeGroup() {FileTypeGroup = t, LibraryId = library.Id})
.Distinct()
@@ -655,14 +657,4 @@ public class LibraryController : BaseApiController
{
return Ok(await _unitOfWork.LibraryRepository.GetLibraryTypeAsync(libraryId));
}
-
- ///
- /// Return pairs of all types
- ///
- ///
- [HttpGet("types")]
- public async Task>> GetLibraryTypes()
- {
- return Ok(await _unitOfWork.LibraryRepository.GetLibraryTypesAsync(User.GetUserId()));
- }
}
diff --git a/API/Controllers/MetadataController.cs b/API/Controllers/MetadataController.cs
index b08ac1f38..cab33692a 100644
--- a/API/Controllers/MetadataController.cs
+++ b/API/Controllers/MetadataController.cs
@@ -9,6 +9,8 @@ using API.Data.Repositories;
using API.DTOs;
using API.DTOs.Filtering;
using API.DTOs.Metadata;
+using API.DTOs.Metadata.Browse;
+using API.DTOs.Person;
using API.DTOs.Recommendation;
using API.DTOs.SeriesDetail;
using API.Entities.Enums;
@@ -46,6 +48,22 @@ public class MetadataController(IUnitOfWork unitOfWork, ILocalizationService loc
return Ok(await unitOfWork.GenreRepository.GetAllGenreDtosForLibrariesAsync(User.GetUserId(), ids, context));
}
+ ///
+ /// Returns a list of Genres with counts for counts when Genre is on Series/Chapter
+ ///
+ ///
+ [HttpPost("genres-with-counts")]
+ [ResponseCache(CacheProfileName = ResponseCacheProfiles.FiveMinute)]
+ public async Task>> GetBrowseGenres(UserParams? userParams = null)
+ {
+ userParams ??= UserParams.Default;
+
+ var list = await unitOfWork.GenreRepository.GetBrowseableGenre(User.GetUserId(), userParams);
+ Response.AddPaginationHeader(list.CurrentPage, list.PageSize, list.TotalCount, list.TotalPages);
+
+ return Ok(list);
+ }
+
///
/// Fetches people from the instance by role
///
@@ -74,6 +92,7 @@ public class MetadataController(IUnitOfWork unitOfWork, ILocalizationService loc
{
return Ok(await unitOfWork.PersonRepository.GetAllPeopleDtosForLibrariesAsync(User.GetUserId(), ids));
}
+
return Ok(await unitOfWork.PersonRepository.GetAllPeopleDtosForLibrariesAsync(User.GetUserId()));
}
@@ -94,6 +113,22 @@ public class MetadataController(IUnitOfWork unitOfWork, ILocalizationService loc
return Ok(await unitOfWork.TagRepository.GetAllTagDtosForLibrariesAsync(User.GetUserId()));
}
+ ///
+ /// Returns a list of Tags with counts for counts when Tag is on Series/Chapter
+ ///
+ ///
+ [HttpPost("tags-with-counts")]
+ [ResponseCache(CacheProfileName = ResponseCacheProfiles.FiveMinute)]
+ public async Task>> GetBrowseTags(UserParams? userParams = null)
+ {
+ userParams ??= UserParams.Default;
+
+ var list = await unitOfWork.TagRepository.GetBrowseableTag(User.GetUserId(), userParams);
+ Response.AddPaginationHeader(list.CurrentPage, list.PageSize, list.TotalCount, list.TotalPages);
+
+ return Ok(list);
+ }
+
///
/// Fetches all age ratings from the instance
///
diff --git a/API/Controllers/OPDSController.cs b/API/Controllers/OPDSController.cs
index fcc4ca58f..6e96c3063 100644
--- a/API/Controllers/OPDSController.cs
+++ b/API/Controllers/OPDSController.cs
@@ -15,6 +15,7 @@ using API.DTOs.CollectionTags;
using API.DTOs.Filtering;
using API.DTOs.Filtering.v2;
using API.DTOs.OPDS;
+using API.DTOs.Person;
using API.DTOs.Progress;
using API.DTOs.Search;
using API.Entities;
diff --git a/API/Controllers/PersonController.cs b/API/Controllers/PersonController.cs
index 1094a1137..7328ff954 100644
--- a/API/Controllers/PersonController.cs
+++ b/API/Controllers/PersonController.cs
@@ -1,7 +1,13 @@
using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
using API.Data;
+using API.Data.Repositories;
using API.DTOs;
+using API.DTOs.Filtering.v2;
+using API.DTOs.Metadata.Browse;
+using API.DTOs.Metadata.Browse.Requests;
+using API.DTOs.Person;
using API.Entities.Enums;
using API.Extensions;
using API.Helpers;
@@ -24,9 +30,10 @@ public class PersonController : BaseApiController
private readonly ICoverDbService _coverDbService;
private readonly IImageService _imageService;
private readonly IEventHub _eventHub;
+ private readonly IPersonService _personService;
public PersonController(IUnitOfWork unitOfWork, ILocalizationService localizationService, IMapper mapper,
- ICoverDbService coverDbService, IImageService imageService, IEventHub eventHub)
+ ICoverDbService coverDbService, IImageService imageService, IEventHub eventHub, IPersonService personService)
{
_unitOfWork = unitOfWork;
_localizationService = localizationService;
@@ -34,6 +41,7 @@ public class PersonController : BaseApiController
_coverDbService = coverDbService;
_imageService = imageService;
_eventHub = eventHub;
+ _personService = personService;
}
@@ -43,6 +51,17 @@ public class PersonController : BaseApiController
return Ok(await _unitOfWork.PersonRepository.GetPersonDtoByName(name, User.GetUserId()));
}
+ ///
+ /// Find a person by name or alias against a query string
+ ///
+ ///
+ ///
+ [HttpGet("search")]
+ public async Task>> SearchPeople([FromQuery] string queryString)
+ {
+ return Ok(await _unitOfWork.PersonRepository.SearchPeople(queryString));
+ }
+
///
/// Returns all roles for a Person
///
@@ -54,17 +73,20 @@ public class PersonController : BaseApiController
return Ok(await _unitOfWork.PersonRepository.GetRolesForPersonByName(personId, User.GetUserId()));
}
+
///
/// Returns a list of authors and artists for browsing
///
///
///
[HttpPost("all")]
- public async Task>> GetAuthorsForBrowse([FromQuery] UserParams? userParams)
+ public async Task>> GetPeopleForBrowse(BrowsePersonFilterDto filter, [FromQuery] UserParams? userParams)
{
userParams ??= UserParams.Default;
- var list = await _unitOfWork.PersonRepository.GetAllWritersAndSeriesCount(User.GetUserId(), userParams);
+
+ var list = await _unitOfWork.PersonRepository.GetBrowsePersonDtos(User.GetUserId(), filter, userParams);
Response.AddPaginationHeader(list.CurrentPage, list.PageSize, list.TotalCount, list.TotalPages);
+
return Ok(list);
}
@@ -78,7 +100,7 @@ public class PersonController : BaseApiController
public async Task> UpdatePerson(UpdatePersonDto dto)
{
// This needs to get all people and update them equally
- var person = await _unitOfWork.PersonRepository.GetPersonById(dto.Id);
+ var person = await _unitOfWork.PersonRepository.GetPersonById(dto.Id, PersonIncludes.Aliases);
if (person == null) return BadRequest(_localizationService.Translate(User.GetUserId(), "person-doesnt-exist"));
if (string.IsNullOrEmpty(dto.Name)) return BadRequest(await _localizationService.Translate(User.GetUserId(), "person-name-required"));
@@ -90,7 +112,12 @@ public class PersonController : BaseApiController
return BadRequest(await _localizationService.Translate(User.GetUserId(), "person-name-unique"));
}
+ var success = await _personService.UpdatePersonAliasesAsync(person, dto.Aliases);
+ if (!success) return BadRequest(await _localizationService.Translate(User.GetUserId(), "aliases-have-overlap"));
+
+
person.Name = dto.Name?.Trim();
+ person.NormalizedName = person.Name.ToNormalized();
person.Description = dto.Description ?? string.Empty;
person.CoverImageLocked = dto.CoverImageLocked;
@@ -158,7 +185,7 @@ public class PersonController : BaseApiController
[HttpGet("series-known-for")]
public async Task>> GetKnownSeries(int personId)
{
- return Ok(await _unitOfWork.PersonRepository.GetSeriesKnownFor(personId));
+ return Ok(await _unitOfWork.PersonRepository.GetSeriesKnownFor(personId, User.GetUserId()));
}
///
@@ -173,5 +200,42 @@ public class PersonController : BaseApiController
return Ok(await _unitOfWork.PersonRepository.GetChaptersForPersonByRole(personId, User.GetUserId(), role));
}
+ ///
+ /// Merges Persons into one, this action is irreversible
+ ///
+ ///
+ ///
+ [HttpPost("merge")]
+ [Authorize("RequireAdminRole")]
+ public async Task> MergePeople(PersonMergeDto dto)
+ {
+ var dst = await _unitOfWork.PersonRepository.GetPersonById(dto.DestId, PersonIncludes.All);
+ if (dst == null) return BadRequest();
+
+ var src = await _unitOfWork.PersonRepository.GetPersonById(dto.SrcId, PersonIncludes.All);
+ if (src == null) return BadRequest();
+
+ await _personService.MergePeopleAsync(src, dst);
+ await _eventHub.SendMessageAsync(MessageFactory.PersonMerged, MessageFactory.PersonMergedMessage(dst, src));
+
+ return Ok(_mapper.Map(dst));
+ }
+
+ ///
+ /// Ensure the alias is valid to be added. For example, the alias cannot be on another person or be the same as the current person name/alias.
+ ///
+ ///
+ ///
+ ///
+ [HttpGet("valid-alias")]
+ public async Task> IsValidAlias(int personId, string alias)
+ {
+ var person = await _unitOfWork.PersonRepository.GetPersonById(personId, PersonIncludes.Aliases);
+ if (person == null) return NotFound();
+
+ var existingAlias = await _unitOfWork.PersonRepository.AnyAliasExist(alias);
+ return Ok(!existingAlias && person.NormalizedName != alias.ToNormalized());
+ }
+
}
diff --git a/API/Controllers/PluginController.cs b/API/Controllers/PluginController.cs
index c7f48cf54..f39462bbf 100644
--- a/API/Controllers/PluginController.cs
+++ b/API/Controllers/PluginController.cs
@@ -45,7 +45,7 @@ public class PluginController(IUnitOfWork unitOfWork, ITokenService tokenService
throw new KavitaUnauthenticatedUserException();
}
var user = await unitOfWork.UserRepository.GetUserByIdAsync(userId);
- logger.LogInformation("Plugin {PluginName} has authenticated with {UserName} ({UserId})'s API Key", pluginName.Replace(Environment.NewLine, string.Empty), user!.UserName, userId);
+ logger.LogInformation("Plugin {PluginName} has authenticated with {UserName} ({AppUserId})'s API Key", pluginName.Replace(Environment.NewLine, string.Empty), user!.UserName, userId);
return new UserDto
{
diff --git a/API/Controllers/ReaderController.cs b/API/Controllers/ReaderController.cs
index 207dbabb5..38a5ad482 100644
--- a/API/Controllers/ReaderController.cs
+++ b/API/Controllers/ReaderController.cs
@@ -246,7 +246,6 @@ public class ReaderController : BaseApiController
SeriesFormat = dto.SeriesFormat,
SeriesId = dto.SeriesId,
LibraryId = dto.LibraryId,
- LibraryType = dto.LibraryType,
IsSpecial = dto.IsSpecial,
Pages = dto.Pages,
SeriesTotalPages = series.Pages,
@@ -288,7 +287,6 @@ public class ReaderController : BaseApiController
return Ok(info);
}
-
///
/// Returns various information about all bookmark files for a Series. Side effect: This will cache the bookmark images for reading.
///
diff --git a/API/Controllers/ReadingListController.cs b/API/Controllers/ReadingListController.cs
index 6c9be6c75..1187992bc 100644
--- a/API/Controllers/ReadingListController.cs
+++ b/API/Controllers/ReadingListController.cs
@@ -4,7 +4,7 @@ using System.Threading.Tasks;
using API.Constants;
using API.Data;
using API.Data.Repositories;
-using API.DTOs;
+using API.DTOs.Person;
using API.DTOs.ReadingLists;
using API.Entities.Enums;
using API.Extensions;
diff --git a/API/Controllers/ReadingProfileController.cs b/API/Controllers/ReadingProfileController.cs
new file mode 100644
index 000000000..bc1b4fa52
--- /dev/null
+++ b/API/Controllers/ReadingProfileController.cs
@@ -0,0 +1,198 @@
+#nullable enable
+using System;
+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.Services;
+using AutoMapper;
+using Kavita.Common;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Logging;
+
+namespace API.Controllers;
+
+[Route("api/reading-profile")]
+public class ReadingProfileController(ILogger logger, IUnitOfWork unitOfWork,
+ IReadingProfileService readingProfileService): BaseApiController
+{
+
+ ///
+ /// Gets all non-implicit reading profiles for a user
+ ///
+ ///
+ [HttpGet("all")]
+ public async Task>> GetAllReadingProfiles()
+ {
+ return Ok(await unitOfWork.AppUserReadingProfileRepository.GetProfilesDtoForUser(User.GetUserId(), true));
+ }
+
+ ///
+ /// Returns the ReadingProfile that should be applied to the given series, walks up the tree.
+ /// Series -> Library -> Default
+ ///
+ ///
+ ///
+ ///
+ [HttpGet("{seriesId:int}")]
+ public async Task> GetProfileForSeries(int seriesId, [FromQuery] bool skipImplicit)
+ {
+ return Ok(await readingProfileService.GetReadingProfileDtoForSeries(User.GetUserId(), seriesId, skipImplicit));
+ }
+
+ ///
+ /// Returns the (potential) Reading Profile bound to the library
+ ///
+ ///
+ ///
+ [HttpGet("library")]
+ public async Task> GetProfileForLibrary(int libraryId)
+ {
+ return Ok(await readingProfileService.GetReadingProfileDtoForLibrary(User.GetUserId(), libraryId));
+ }
+
+ ///
+ /// Creates a new reading profile for the current user
+ ///
+ ///
+ ///
+ [HttpPost("create")]
+ public async Task> CreateReadingProfile([FromBody] UserReadingProfileDto dto)
+ {
+ return Ok(await readingProfileService.CreateReadingProfile(User.GetUserId(), dto));
+ }
+
+ ///
+ /// Promotes the implicit profile to a user profile. Removes the series from other profiles
+ ///
+ ///
+ ///
+ [HttpPost("promote")]
+ public async Task> PromoteImplicitReadingProfile([FromQuery] int profileId)
+ {
+ return Ok(await readingProfileService.PromoteImplicitProfile(User.GetUserId(), profileId));
+ }
+
+ ///
+ /// Update the implicit reading profile for a series, creates one if none exists
+ ///
+ /// Any modification to the reader settings during reading will create an implicit profile. Use "update-parent" to save to the bound series profile.
+ ///
+ ///
+ ///
+ [HttpPost("series")]
+ public async Task> UpdateReadingProfileForSeries([FromBody] UserReadingProfileDto dto, [FromQuery] int seriesId)
+ {
+ var updatedProfile = await readingProfileService.UpdateImplicitReadingProfile(User.GetUserId(), seriesId, dto);
+ return Ok(updatedProfile);
+ }
+
+ ///
+ /// Updates the non-implicit reading profile for the given series, and removes implicit profiles
+ ///
+ ///
+ ///
+ ///
+ [HttpPost("update-parent")]
+ public async Task> UpdateParentProfileForSeries([FromBody] UserReadingProfileDto dto, [FromQuery] int seriesId)
+ {
+ var newParentProfile = await readingProfileService.UpdateParent(User.GetUserId(), seriesId, dto);
+ return Ok(newParentProfile);
+ }
+
+ ///
+ /// Updates the given reading profile, must belong to the current user
+ ///
+ ///
+ /// The updated reading profile
+ ///
+ /// This does not update connected series and libraries.
+ ///
+ [HttpPost]
+ public async Task> UpdateReadingProfile(UserReadingProfileDto dto)
+ {
+ return Ok(await readingProfileService.UpdateReadingProfile(User.GetUserId(), dto));
+ }
+
+ ///
+ /// Deletes the given profile, requires the profile to belong to the logged-in user
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpDelete]
+ public async Task DeleteReadingProfile([FromQuery] int profileId)
+ {
+ await readingProfileService.DeleteReadingProfile(User.GetUserId(), profileId);
+ return Ok();
+ }
+
+ ///
+ /// Sets the reading profile for a given series, removes the old one
+ ///
+ ///
+ ///
+ ///
+ [HttpPost("series/{seriesId:int}")]
+ public async Task AddProfileToSeries(int seriesId, [FromQuery] int profileId)
+ {
+ await readingProfileService.AddProfileToSeries(User.GetUserId(), profileId, seriesId);
+ return Ok();
+ }
+
+ ///
+ /// Clears the reading profile for the given series for the currently logged-in user
+ ///
+ ///
+ ///
+ [HttpDelete("series/{seriesId:int}")]
+ public async Task ClearSeriesProfile(int seriesId)
+ {
+ await readingProfileService.ClearSeriesProfile(User.GetUserId(), seriesId);
+ return Ok();
+ }
+
+ ///
+ /// Sets the reading profile for a given library, removes the old one
+ ///
+ ///
+ ///
+ ///
+ [HttpPost("library/{libraryId:int}")]
+ public async Task AddProfileToLibrary(int libraryId, [FromQuery] int profileId)
+ {
+ await readingProfileService.AddProfileToLibrary(User.GetUserId(), profileId, libraryId);
+ return Ok();
+ }
+
+ ///
+ /// Clears the reading profile for the given library for the currently logged-in user
+ ///
+ ///
+ ///
+ ///
+ [HttpDelete("library/{libraryId:int}")]
+ public async Task ClearLibraryProfile(int libraryId)
+ {
+ await readingProfileService.ClearLibraryProfile(User.GetUserId(), libraryId);
+ return Ok();
+ }
+
+ ///
+ /// Assigns the reading profile to all passes series, and deletes their implicit profiles
+ ///
+ ///
+ ///
+ ///
+ [HttpPost("bulk")]
+ public async Task BulkAddReadingProfile([FromQuery] int profileId, [FromBody] IList seriesIds)
+ {
+ await readingProfileService.BulkAddProfileToSeries(User.GetUserId(), profileId, seriesIds);
+ return Ok();
+ }
+
+}
diff --git a/API/Controllers/ScrobblingController.cs b/API/Controllers/ScrobblingController.cs
index 3904cb8e0..986f4f8e7 100644
--- a/API/Controllers/ScrobblingController.cs
+++ b/API/Controllers/ScrobblingController.cs
@@ -254,7 +254,7 @@ public class ScrobblingController : BaseApiController
}
///
- /// Adds a hold against the Series for user's scrobbling
+ /// Remove a hold against the Series for user's scrobbling
///
///
///
@@ -281,4 +281,18 @@ public class ScrobblingController : BaseApiController
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(User.GetUserId());
return Ok(user is {HasRunScrobbleEventGeneration: true});
}
+
+ ///
+ /// Delete the given scrobble events if they belong to that user
+ ///
+ ///
+ ///
+ [HttpPost("bulk-remove-events")]
+ public async Task BulkRemoveScrobbleEvents(IList eventIds)
+ {
+ var events = await _unitOfWork.ScrobbleRepository.GetUserEvents(User.GetUserId(), eventIds);
+ _unitOfWork.ScrobbleRepository.Remove(events);
+ await _unitOfWork.CommitAsync();
+ return Ok();
+ }
}
diff --git a/API/Controllers/SearchController.cs b/API/Controllers/SearchController.cs
index 5aa54d1db..cc89a124e 100644
--- a/API/Controllers/SearchController.cs
+++ b/API/Controllers/SearchController.cs
@@ -63,6 +63,7 @@ public class SearchController : BaseApiController
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
if (user == null) return Unauthorized();
+
var libraries = _unitOfWork.LibraryRepository.GetLibraryIdsForUserIdAsync(user.Id, QueryContext.Search).ToList();
if (libraries.Count == 0) return BadRequest(await _localizationService.Translate(User.GetUserId(), "libraries-restricted"));
diff --git a/API/Controllers/SeriesController.cs b/API/Controllers/SeriesController.cs
index 7cd897c32..389ff33a7 100644
--- a/API/Controllers/SeriesController.cs
+++ b/API/Controllers/SeriesController.cs
@@ -14,6 +14,7 @@ using API.DTOs.Recommendation;
using API.DTOs.SeriesDetail;
using API.Entities;
using API.Entities.Enums;
+using API.Entities.MetadataMatching;
using API.Extensions;
using API.Helpers;
using API.Services;
@@ -224,6 +225,7 @@ public class SeriesController : BaseApiController
needsRefreshMetadata = true;
series.CoverImage = null;
series.CoverImageLocked = false;
+ series.Metadata.KPlusOverrides.Remove(MetadataSettingField.Covers);
_logger.LogDebug("[SeriesCoverImageBug] Setting Series Cover Image to null: {SeriesId}", series.Id);
series.ResetColorScape();
@@ -310,7 +312,7 @@ public class SeriesController : BaseApiController
///
///
///
- ///
+ /// This is not in use
///
[HttpPost("all-v2")]
public async Task>> GetAllSeriesV2(FilterV2Dto filterDto, [FromQuery] UserParams userParams,
@@ -321,8 +323,6 @@ public class SeriesController : BaseApiController
await _unitOfWork.SeriesRepository.GetSeriesDtoForLibraryIdV2Async(userId, userParams, filterDto, context);
// Apply progress/rating information (I can't work out how to do this in initial query)
- if (series == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "no-series"));
-
await _unitOfWork.SeriesRepository.AddSeriesModifiers(userId, series);
Response.AddPaginationHeader(series.CurrentPage, series.PageSize, series.TotalCount, series.TotalPages);
diff --git a/API/Controllers/UploadController.cs b/API/Controllers/UploadController.cs
index 4b935a1bf..9652ba494 100644
--- a/API/Controllers/UploadController.cs
+++ b/API/Controllers/UploadController.cs
@@ -6,6 +6,7 @@ using API.Data;
using API.Data.Repositories;
using API.DTOs.Uploads;
using API.Entities.Enums;
+using API.Entities.MetadataMatching;
using API.Extensions;
using API.Services;
using API.Services.Tasks.Metadata;
@@ -112,8 +113,10 @@ public class UploadController : BaseApiController
series.CoverImage = filePath;
series.CoverImageLocked = lockState;
+ series.Metadata.KPlusOverrides.Remove(MetadataSettingField.Covers);
_imageService.UpdateColorScape(series);
_unitOfWork.SeriesRepository.Update(series);
+ _unitOfWork.SeriesRepository.Update(series.Metadata);
if (_unitOfWork.HasChanges())
{
@@ -277,6 +280,7 @@ public class UploadController : BaseApiController
chapter.CoverImage = filePath;
chapter.CoverImageLocked = lockState;
+ chapter.KPlusOverrides.Remove(MetadataSettingField.ChapterCovers);
_unitOfWork.ChapterRepository.Update(chapter);
var volume = await _unitOfWork.VolumeRepository.GetVolumeAsync(chapter.VolumeId);
if (volume != null)
diff --git a/API/Controllers/UsersController.cs b/API/Controllers/UsersController.cs
index 944ea987b..17ebc758e 100644
--- a/API/Controllers/UsersController.cs
+++ b/API/Controllers/UsersController.cs
@@ -103,38 +103,13 @@ public class UsersController : BaseApiController
var existingPreferences = user!.UserPreferences;
- existingPreferences.ReadingDirection = preferencesDto.ReadingDirection;
- existingPreferences.ScalingOption = preferencesDto.ScalingOption;
- existingPreferences.PageSplitOption = preferencesDto.PageSplitOption;
- existingPreferences.AutoCloseMenu = preferencesDto.AutoCloseMenu;
- existingPreferences.ShowScreenHints = preferencesDto.ShowScreenHints;
- existingPreferences.EmulateBook = preferencesDto.EmulateBook;
- existingPreferences.ReaderMode = preferencesDto.ReaderMode;
- existingPreferences.LayoutMode = preferencesDto.LayoutMode;
- existingPreferences.BackgroundColor = string.IsNullOrEmpty(preferencesDto.BackgroundColor) ? "#000000" : preferencesDto.BackgroundColor;
- existingPreferences.BookReaderMargin = preferencesDto.BookReaderMargin;
- existingPreferences.BookReaderLineSpacing = preferencesDto.BookReaderLineSpacing;
- existingPreferences.BookReaderFontFamily = preferencesDto.BookReaderFontFamily;
- existingPreferences.BookReaderFontSize = preferencesDto.BookReaderFontSize;
- existingPreferences.BookReaderTapToPaginate = preferencesDto.BookReaderTapToPaginate;
- existingPreferences.BookReaderReadingDirection = preferencesDto.BookReaderReadingDirection;
- existingPreferences.BookReaderWritingStyle = preferencesDto.BookReaderWritingStyle;
- existingPreferences.BookThemeName = preferencesDto.BookReaderThemeName;
- existingPreferences.BookReaderLayoutMode = preferencesDto.BookReaderLayoutMode;
- existingPreferences.BookReaderImmersiveMode = preferencesDto.BookReaderImmersiveMode;
existingPreferences.GlobalPageLayoutMode = preferencesDto.GlobalPageLayoutMode;
existingPreferences.BlurUnreadSummaries = preferencesDto.BlurUnreadSummaries;
- existingPreferences.LayoutMode = preferencesDto.LayoutMode;
existingPreferences.PromptForDownloadSize = preferencesDto.PromptForDownloadSize;
existingPreferences.NoTransitions = preferencesDto.NoTransitions;
- existingPreferences.SwipeToPaginate = preferencesDto.SwipeToPaginate;
existingPreferences.CollapseSeriesRelationships = preferencesDto.CollapseSeriesRelationships;
existingPreferences.ShareReviews = preferencesDto.ShareReviews;
- existingPreferences.PdfTheme = preferencesDto.PdfTheme;
- existingPreferences.PdfScrollMode = preferencesDto.PdfScrollMode;
- existingPreferences.PdfSpreadMode = preferencesDto.PdfSpreadMode;
-
if (await _licenseService.HasActiveLicense())
{
existingPreferences.AniListScrobblingEnabled = preferencesDto.AniListScrobblingEnabled;
diff --git a/API/DTOs/ChapterDto.cs b/API/DTOs/ChapterDto.cs
index 70fb12e85..85624b51c 100644
--- a/API/DTOs/ChapterDto.cs
+++ b/API/DTOs/ChapterDto.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using API.DTOs.Metadata;
+using API.DTOs.Person;
using API.Entities.Enums;
using API.Entities.Interfaces;
diff --git a/API/DTOs/Filtering/PersonSortField.cs b/API/DTOs/Filtering/PersonSortField.cs
new file mode 100644
index 000000000..5268a1bf9
--- /dev/null
+++ b/API/DTOs/Filtering/PersonSortField.cs
@@ -0,0 +1,8 @@
+namespace API.DTOs.Filtering;
+
+public enum PersonSortField
+{
+ Name = 1,
+ SeriesCount = 2,
+ ChapterCount = 3
+}
diff --git a/API/DTOs/Filtering/SortOptions.cs b/API/DTOs/Filtering/SortOptions.cs
index a08e2968e..18f2b17ea 100644
--- a/API/DTOs/Filtering/SortOptions.cs
+++ b/API/DTOs/Filtering/SortOptions.cs
@@ -8,3 +8,12 @@ public sealed record SortOptions
public SortField SortField { get; set; }
public bool IsAscending { get; set; } = true;
}
+
+///
+/// All Sorting Options for a query related to Person Entity
+///
+public sealed record PersonSortOptions
+{
+ public PersonSortField SortField { get; set; }
+ public bool IsAscending { get; set; } = true;
+}
diff --git a/API/DTOs/Filtering/v2/FilterField.cs b/API/DTOs/Filtering/v2/FilterField.cs
index 5323f2b48..246a92a90 100644
--- a/API/DTOs/Filtering/v2/FilterField.cs
+++ b/API/DTOs/Filtering/v2/FilterField.cs
@@ -56,5 +56,12 @@ public enum FilterField
/// Last time User Read
///
ReadLast = 32,
-
+}
+
+public enum PersonFilterField
+{
+ Role = 1,
+ Name = 2,
+ SeriesCount = 3,
+ ChapterCount = 4,
}
diff --git a/API/DTOs/Filtering/v2/FilterStatementDto.cs b/API/DTOs/Filtering/v2/FilterStatementDto.cs
index ebe6d16af..8c99bd24c 100644
--- a/API/DTOs/Filtering/v2/FilterStatementDto.cs
+++ b/API/DTOs/Filtering/v2/FilterStatementDto.cs
@@ -1,4 +1,6 @@
-namespace API.DTOs.Filtering.v2;
+using API.DTOs.Metadata.Browse.Requests;
+
+namespace API.DTOs.Filtering.v2;
public sealed record FilterStatementDto
{
@@ -6,3 +8,10 @@ public sealed record FilterStatementDto
public FilterField Field { get; set; }
public string Value { get; set; }
}
+
+public sealed record PersonFilterStatementDto
+{
+ public FilterComparison Comparison { get; set; }
+ public PersonFilterField Field { get; set; }
+ public string Value { get; set; }
+}
diff --git a/API/DTOs/Filtering/v2/FilterV2Dto.cs b/API/DTOs/Filtering/v2/FilterV2Dto.cs
index 11dc42a6b..a247a17a6 100644
--- a/API/DTOs/Filtering/v2/FilterV2Dto.cs
+++ b/API/DTOs/Filtering/v2/FilterV2Dto.cs
@@ -16,7 +16,7 @@ public sealed record FilterV2Dto
/// The name of the filter
///
public string? Name { get; set; }
- public ICollection Statements { get; set; } = new List();
+ public ICollection Statements { get; set; } = [];
public FilterCombination Combination { get; set; } = FilterCombination.And;
public SortOptions? SortOptions { get; set; }
diff --git a/API/DTOs/KavitaPlus/ExternalMetadata/ExternalMetadataIdsDto.cs b/API/DTOs/KavitaPlus/ExternalMetadata/ExternalMetadataIdsDto.cs
index 2b7dea8e6..c05ff0567 100644
--- a/API/DTOs/KavitaPlus/ExternalMetadata/ExternalMetadataIdsDto.cs
+++ b/API/DTOs/KavitaPlus/ExternalMetadata/ExternalMetadataIdsDto.cs
@@ -6,7 +6,7 @@ namespace API.DTOs.KavitaPlus.ExternalMetadata;
///
/// Used for matching and fetching metadata on a series
///
-internal sealed record ExternalMetadataIdsDto
+public sealed record ExternalMetadataIdsDto
{
public long? MalId { get; set; }
public int? AniListId { get; set; }
diff --git a/API/DTOs/KavitaPlus/ExternalMetadata/MatchSeriesRequestDto.cs b/API/DTOs/KavitaPlus/ExternalMetadata/MatchSeriesRequestDto.cs
index 6cd911700..a7359d69b 100644
--- a/API/DTOs/KavitaPlus/ExternalMetadata/MatchSeriesRequestDto.cs
+++ b/API/DTOs/KavitaPlus/ExternalMetadata/MatchSeriesRequestDto.cs
@@ -4,14 +4,18 @@ using API.DTOs.Scrobbling;
namespace API.DTOs.KavitaPlus.ExternalMetadata;
#nullable enable
-internal sealed record MatchSeriesRequestDto
+///
+/// Represents a request to match some series from Kavita to an external id which K+ uses.
+///
+public sealed record MatchSeriesRequestDto
{
- public string SeriesName { get; set; }
- public ICollection AlternativeNames { get; set; }
+ public required string SeriesName { get; set; }
+ public ICollection AlternativeNames { get; set; } = [];
public int Year { get; set; } = 0;
- public string Query { get; set; }
+ public string? Query { get; set; }
public int? AniListId { get; set; }
public long? MalId { get; set; }
public string? HardcoverId { get; set; }
+ public int? CbrId { get; set; }
public PlusMediaFormat Format { get; set; }
}
diff --git a/API/DTOs/KavitaPlus/ExternalMetadata/SeriesDetailPlusApiDto.cs b/API/DTOs/KavitaPlus/ExternalMetadata/SeriesDetailPlusApiDto.cs
index d0cbb7bd3..84e9bbf3e 100644
--- a/API/DTOs/KavitaPlus/ExternalMetadata/SeriesDetailPlusApiDto.cs
+++ b/API/DTOs/KavitaPlus/ExternalMetadata/SeriesDetailPlusApiDto.cs
@@ -6,7 +6,7 @@ using API.DTOs.SeriesDetail;
namespace API.DTOs.KavitaPlus.ExternalMetadata;
-internal sealed record SeriesDetailPlusApiDto
+public sealed record SeriesDetailPlusApiDto
{
public IEnumerable Recommendations { get; set; }
public IEnumerable Reviews { get; set; }
diff --git a/API/DTOs/KavitaPlus/Manage/ManageMatchFilterDto.cs b/API/DTOs/KavitaPlus/Manage/ManageMatchFilterDto.cs
index 8eb38c98a..c394cf8d4 100644
--- a/API/DTOs/KavitaPlus/Manage/ManageMatchFilterDto.cs
+++ b/API/DTOs/KavitaPlus/Manage/ManageMatchFilterDto.cs
@@ -15,5 +15,9 @@ public enum MatchStateOption
public sealed record ManageMatchFilterDto
{
public MatchStateOption MatchStateOption { get; set; } = MatchStateOption.All;
+ ///
+ /// Library Type in int form. -1 indicates to ignore the field.
+ ///
+ public int LibraryType { get; set; } = -1;
public string SearchTerm { get; set; } = string.Empty;
}
diff --git a/API/DTOs/KavitaPlus/Metadata/ExternalChapterDto.cs b/API/DTOs/KavitaPlus/Metadata/ExternalChapterDto.cs
index 1dcd8494c..add9ca723 100644
--- a/API/DTOs/KavitaPlus/Metadata/ExternalChapterDto.cs
+++ b/API/DTOs/KavitaPlus/Metadata/ExternalChapterDto.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using API.DTOs.SeriesDetail;
namespace API.DTOs.KavitaPlus.Metadata;
+#nullable enable
///
/// Information about an individual issue/chapter/book from Kavita+
diff --git a/API/DTOs/KavitaPlus/Metadata/ExternalSeriesDetailDto.cs b/API/DTOs/KavitaPlus/Metadata/ExternalSeriesDetailDto.cs
index a3cd378b2..6704bf697 100644
--- a/API/DTOs/KavitaPlus/Metadata/ExternalSeriesDetailDto.cs
+++ b/API/DTOs/KavitaPlus/Metadata/ExternalSeriesDetailDto.cs
@@ -29,7 +29,9 @@ public sealed record ExternalSeriesDetailDto
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public int AverageScore { get; set; }
+ /// AniList returns the total count of unique chapters, includes 1.1 for example
public int Chapters { get; set; }
+ /// AniList returns the total count of unique volumes, includes 1.1 for example
public int Volumes { get; set; }
public IList? Relations { get; set; } = [];
public IList? Characters { get; set; } = [];
diff --git a/API/DTOs/Koreader/KoreaderBookDto.cs b/API/DTOs/Koreader/KoreaderBookDto.cs
new file mode 100644
index 000000000..b66b7da3a
--- /dev/null
+++ b/API/DTOs/Koreader/KoreaderBookDto.cs
@@ -0,0 +1,33 @@
+using API.DTOs.Progress;
+
+namespace API.DTOs.Koreader;
+
+///
+/// This is the interface for receiving and sending updates to Koreader. The only fields
+/// that are actually used are the Document and Progress fields.
+///
+public class KoreaderBookDto
+{
+ ///
+ /// This is the Koreader hash of the book. It is used to identify the book.
+ ///
+ public string Document { get; set; }
+ ///
+ /// A randomly generated id from the koreader device. Only used to maintain the Koreader interface.
+ ///
+ public string Device_id { get; set; }
+ ///
+ /// The Koreader device name. Only used to maintain the Koreader interface.
+ ///
+ public string Device { get; set; }
+ ///
+ /// Percent progress of the book. Only used to maintain the Koreader interface.
+ ///
+ public float Percentage { get; set; }
+ ///
+ /// An XPath string read by Koreader to determine the location within the epub.
+ /// Essentially, it is Koreader's equivalent to ProgressDto.BookScrollId.
+ ///
+ ///
+ public string Progress { get; set; }
+}
diff --git a/API/DTOs/Koreader/KoreaderProgressUpdateDto.cs b/API/DTOs/Koreader/KoreaderProgressUpdateDto.cs
new file mode 100644
index 000000000..52a1d6cbd
--- /dev/null
+++ b/API/DTOs/Koreader/KoreaderProgressUpdateDto.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace API.DTOs.Koreader;
+
+public class KoreaderProgressUpdateDto
+{
+ ///
+ /// This is the Koreader hash of the book. It is used to identify the book.
+ ///
+ public string Document { get; set; }
+ ///
+ /// UTC Timestamp to return to KOReader
+ ///
+ public DateTime Timestamp { get; set; }
+}
diff --git a/API/DTOs/LibraryDto.cs b/API/DTOs/LibraryDto.cs
index 8ba687346..bd72ad2f0 100644
--- a/API/DTOs/LibraryDto.cs
+++ b/API/DTOs/LibraryDto.cs
@@ -66,4 +66,12 @@ public sealed record LibraryDto
/// This does not exclude the library from being linked to wrt Series Relationships
/// Requires a valid LicenseKey
public bool AllowMetadataMatching { get; set; } = true;
+ ///
+ /// Allow Kavita to read metadata (ComicInfo.xml, Epub, PDF)
+ ///
+ public bool EnableMetadata { get; set; } = true;
+ ///
+ /// Should Kavita remove sort articles "The" for the sort name
+ ///
+ public bool RemovePrefixForSortName { get; set; } = false;
}
diff --git a/API/DTOs/LibraryTypeDto.cs b/API/DTOs/LibraryTypeDto.cs
deleted file mode 100644
index 9f448e7b7..000000000
--- a/API/DTOs/LibraryTypeDto.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using API.Entities.Enums;
-
-namespace API.DTOs;
-
-///
-/// Simple pairing of LibraryId and LibraryType
-///
-public sealed record LibraryTypeDto
-{
- public int LibraryId { get; set; }
- public LibraryType LibraryType { get; set; }
-}
diff --git a/API/DTOs/Metadata/Browse/BrowseGenreDto.cs b/API/DTOs/Metadata/Browse/BrowseGenreDto.cs
new file mode 100644
index 000000000..8044c7914
--- /dev/null
+++ b/API/DTOs/Metadata/Browse/BrowseGenreDto.cs
@@ -0,0 +1,13 @@
+namespace API.DTOs.Metadata.Browse;
+
+public sealed record BrowseGenreDto : GenreTagDto
+{
+ ///
+ /// Number of Series this Entity is on
+ ///
+ public int SeriesCount { get; set; }
+ ///
+ /// Number of Chapters this Entity is on
+ ///
+ public int ChapterCount { get; set; }
+}
diff --git a/API/DTOs/Person/BrowsePersonDto.cs b/API/DTOs/Metadata/Browse/BrowsePersonDto.cs
similarity index 65%
rename from API/DTOs/Person/BrowsePersonDto.cs
rename to API/DTOs/Metadata/Browse/BrowsePersonDto.cs
index 8d6999973..20f84b783 100644
--- a/API/DTOs/Person/BrowsePersonDto.cs
+++ b/API/DTOs/Metadata/Browse/BrowsePersonDto.cs
@@ -1,4 +1,6 @@
-namespace API.DTOs;
+using API.DTOs.Person;
+
+namespace API.DTOs.Metadata.Browse;
///
/// Used to browse writers and click in to see their series
@@ -10,7 +12,7 @@ public class BrowsePersonDto : PersonDto
///
public int SeriesCount { get; set; }
///
- /// Number or Issues this Person is the Writer for
+ /// Number of Issues this Person is the Writer for
///
- public int IssueCount { get; set; }
+ public int ChapterCount { get; set; }
}
diff --git a/API/DTOs/Metadata/Browse/BrowseTagDto.cs b/API/DTOs/Metadata/Browse/BrowseTagDto.cs
new file mode 100644
index 000000000..9a71876e3
--- /dev/null
+++ b/API/DTOs/Metadata/Browse/BrowseTagDto.cs
@@ -0,0 +1,13 @@
+namespace API.DTOs.Metadata.Browse;
+
+public sealed record BrowseTagDto : TagDto
+{
+ ///
+ /// Number of Series this Entity is on
+ ///
+ public int SeriesCount { get; set; }
+ ///
+ /// Number of Chapters this Entity is on
+ ///
+ public int ChapterCount { get; set; }
+}
diff --git a/API/DTOs/Metadata/Browse/Requests/BrowsePersonFilterDto.cs b/API/DTOs/Metadata/Browse/Requests/BrowsePersonFilterDto.cs
new file mode 100644
index 000000000..d41cf37f3
--- /dev/null
+++ b/API/DTOs/Metadata/Browse/Requests/BrowsePersonFilterDto.cs
@@ -0,0 +1,27 @@
+using System.Collections.Generic;
+using API.DTOs.Filtering;
+using API.DTOs.Filtering.v2;
+using API.Entities.Enums;
+
+namespace API.DTOs.Metadata.Browse.Requests;
+#nullable enable
+
+public sealed record BrowsePersonFilterDto
+{
+ ///
+ /// Not used - For parity with Series Filter
+ ///
+ public int Id { get; set; }
+ ///
+ /// Not used - For parity with Series Filter
+ ///
+ public string? Name { get; set; }
+ public ICollection Statements { get; set; } = [];
+ public FilterCombination Combination { get; set; } = FilterCombination.And;
+ public PersonSortOptions? SortOptions { get; set; }
+
+ ///
+ /// Limit the number of rows returned. Defaults to not applying a limit (aka 0)
+ ///
+ public int LimitTo { get; set; } = 0;
+}
diff --git a/API/DTOs/Metadata/ChapterMetadataDto.cs b/API/DTOs/Metadata/ChapterMetadataDto.cs
index 1adc52cd1..c79436e24 100644
--- a/API/DTOs/Metadata/ChapterMetadataDto.cs
+++ b/API/DTOs/Metadata/ChapterMetadataDto.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using API.DTOs.Person;
using API.Entities.Enums;
namespace API.DTOs.Metadata;
diff --git a/API/DTOs/Metadata/GenreTagDto.cs b/API/DTOs/Metadata/GenreTagDto.cs
index 4846048d2..13a339d38 100644
--- a/API/DTOs/Metadata/GenreTagDto.cs
+++ b/API/DTOs/Metadata/GenreTagDto.cs
@@ -1,6 +1,6 @@
namespace API.DTOs.Metadata;
-public sealed record GenreTagDto
+public record GenreTagDto
{
public int Id { get; set; }
public required string Title { get; set; }
diff --git a/API/DTOs/Metadata/TagDto.cs b/API/DTOs/Metadata/TagDto.cs
index f8deb6913..f5c925e1f 100644
--- a/API/DTOs/Metadata/TagDto.cs
+++ b/API/DTOs/Metadata/TagDto.cs
@@ -1,6 +1,6 @@
namespace API.DTOs.Metadata;
-public sealed record TagDto
+public record TagDto
{
public int Id { get; set; }
public required string Title { get; set; }
diff --git a/API/DTOs/Person/PersonDto.cs b/API/DTOs/Person/PersonDto.cs
index 511317f2a..db152e3b1 100644
--- a/API/DTOs/Person/PersonDto.cs
+++ b/API/DTOs/Person/PersonDto.cs
@@ -1,6 +1,6 @@
-using System.Runtime.Serialization;
+using System.Collections.Generic;
-namespace API.DTOs;
+namespace API.DTOs.Person;
#nullable enable
public class PersonDto
@@ -13,6 +13,7 @@ public class PersonDto
public string? SecondaryColor { get; set; }
public string? CoverImage { get; set; }
+ public List Aliases { get; set; } = [];
public string? Description { get; set; }
///
diff --git a/API/DTOs/Person/PersonMergeDto.cs b/API/DTOs/Person/PersonMergeDto.cs
new file mode 100644
index 000000000..b5dc23375
--- /dev/null
+++ b/API/DTOs/Person/PersonMergeDto.cs
@@ -0,0 +1,17 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace API.DTOs;
+
+public sealed record PersonMergeDto
+{
+ ///
+ /// The id of the person being merged into
+ ///
+ [Required]
+ public int DestId { get; init; }
+ ///
+ /// The id of the person being merged. This person will be removed, and become an alias of
+ ///
+ [Required]
+ public int SrcId { get; init; }
+}
diff --git a/API/DTOs/Person/UpdatePersonDto.cs b/API/DTOs/Person/UpdatePersonDto.cs
index 29190151f..b43a45e88 100644
--- a/API/DTOs/Person/UpdatePersonDto.cs
+++ b/API/DTOs/Person/UpdatePersonDto.cs
@@ -1,4 +1,5 @@
-using System.ComponentModel.DataAnnotations;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
namespace API.DTOs;
#nullable enable
@@ -11,6 +12,7 @@ public sealed record UpdatePersonDto
public bool CoverImageLocked { get; set; }
[Required]
public string Name {get; set;}
+ public IList Aliases { get; set; } = [];
public string? Description { get; set; }
public int? AniListId { get; set; }
diff --git a/API/DTOs/Reader/BookInfoDto.cs b/API/DTOs/Reader/BookInfoDto.cs
index 5c4e530c6..2473cd5dc 100644
--- a/API/DTOs/Reader/BookInfoDto.cs
+++ b/API/DTOs/Reader/BookInfoDto.cs
@@ -15,5 +15,4 @@ public sealed record BookInfoDto : IChapterInfoDto
public int Pages { get; set; }
public bool IsSpecial { get; set; }
public string ChapterTitle { get; set; } = default! ;
- public LibraryType LibraryType { get; set; }
}
diff --git a/API/DTOs/Reader/IChapterInfoDto.cs b/API/DTOs/Reader/IChapterInfoDto.cs
index 568adf345..6a9a74a2c 100644
--- a/API/DTOs/Reader/IChapterInfoDto.cs
+++ b/API/DTOs/Reader/IChapterInfoDto.cs
@@ -14,6 +14,5 @@ public interface IChapterInfoDto
public int Pages { get; set; }
public bool IsSpecial { get; set; }
public string ChapterTitle { get; set; }
- public LibraryType LibraryType { get; set; }
}
diff --git a/API/DTOs/ReadingLists/ReadingListCast.cs b/API/DTOs/ReadingLists/ReadingListCast.cs
index 8f2587426..855bb12b7 100644
--- a/API/DTOs/ReadingLists/ReadingListCast.cs
+++ b/API/DTOs/ReadingLists/ReadingListCast.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using API.DTOs.Person;
namespace API.DTOs.ReadingLists;
diff --git a/API/DTOs/ReadingLists/ReadingListDto.cs b/API/DTOs/ReadingLists/ReadingListDto.cs
index cbc16275d..47a526411 100644
--- a/API/DTOs/ReadingLists/ReadingListDto.cs
+++ b/API/DTOs/ReadingLists/ReadingListDto.cs
@@ -49,6 +49,11 @@ public sealed record ReadingListDto : IHasCoverImage
///
public required AgeRating AgeRating { get; set; } = AgeRating.Unknown;
+ ///
+ /// Username of the User that owns (in the case of a promoted list)
+ ///
+ public string OwnerUserName { get; set; }
+
public void ResetColorScape()
{
PrimaryColor = string.Empty;
diff --git a/API/DTOs/Scrobbling/ScrobbleEventDto.cs b/API/DTOs/Scrobbling/ScrobbleEventDto.cs
index 7b1ccd75a..562d923ff 100644
--- a/API/DTOs/Scrobbling/ScrobbleEventDto.cs
+++ b/API/DTOs/Scrobbling/ScrobbleEventDto.cs
@@ -5,6 +5,7 @@ namespace API.DTOs.Scrobbling;
public sealed record ScrobbleEventDto
{
+ public long Id { get; init; }
public string SeriesName { get; set; }
public int SeriesId { get; set; }
public int LibraryId { get; set; }
diff --git a/API/DTOs/Scrobbling/ScrobbleResponseDto.cs b/API/DTOs/Scrobbling/ScrobbleResponseDto.cs
index 53d3a0cc9..ad66729d0 100644
--- a/API/DTOs/Scrobbling/ScrobbleResponseDto.cs
+++ b/API/DTOs/Scrobbling/ScrobbleResponseDto.cs
@@ -8,5 +8,6 @@ public sealed record ScrobbleResponseDto
{
public bool Successful { get; set; }
public string? ErrorMessage { get; set; }
+ public string? ExtraInformation {get; set;}
public int RateLeft { get; set; }
}
diff --git a/API/DTOs/Search/SearchResultGroupDto.cs b/API/DTOs/Search/SearchResultGroupDto.cs
index 20a53f853..11c4bdc08 100644
--- a/API/DTOs/Search/SearchResultGroupDto.cs
+++ b/API/DTOs/Search/SearchResultGroupDto.cs
@@ -2,6 +2,7 @@
using API.DTOs.Collection;
using API.DTOs.CollectionTags;
using API.DTOs.Metadata;
+using API.DTOs.Person;
using API.DTOs.Reader;
using API.DTOs.ReadingLists;
diff --git a/API/DTOs/SeriesMetadataDto.cs b/API/DTOs/SeriesMetadataDto.cs
index 701034d80..fa745148e 100644
--- a/API/DTOs/SeriesMetadataDto.cs
+++ b/API/DTOs/SeriesMetadataDto.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using API.DTOs.Metadata;
+using API.DTOs.Person;
using API.Entities.Enums;
namespace API.DTOs;
diff --git a/API/DTOs/UpdateChapterDto.cs b/API/DTOs/UpdateChapterDto.cs
index ec2f1cf62..9ead8adc8 100644
--- a/API/DTOs/UpdateChapterDto.cs
+++ b/API/DTOs/UpdateChapterDto.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using API.DTOs.Metadata;
+using API.DTOs.Person;
using API.Entities.Enums;
namespace API.DTOs;
diff --git a/API/DTOs/UpdateLibraryDto.cs b/API/DTOs/UpdateLibraryDto.cs
index 9bd47fd39..d7f314208 100644
--- a/API/DTOs/UpdateLibraryDto.cs
+++ b/API/DTOs/UpdateLibraryDto.cs
@@ -28,6 +28,10 @@ public sealed record UpdateLibraryDto
public bool AllowScrobbling { get; init; }
[Required]
public bool AllowMetadataMatching { get; init; }
+ [Required]
+ public bool EnableMetadata { get; init; }
+ [Required]
+ public bool RemovePrefixForSortName { get; init; }
///
/// What types of files to allow the scanner to pickup
///
diff --git a/API/DTOs/UserPreferencesDto.cs b/API/DTOs/UserPreferencesDto.cs
index 6645a8f39..46f42306e 100644
--- a/API/DTOs/UserPreferencesDto.cs
+++ b/API/DTOs/UserPreferencesDto.cs
@@ -9,61 +9,6 @@ namespace API.DTOs;
public sealed record UserPreferencesDto
{
- ///
- [Required]
- public ReadingDirection ReadingDirection { get; set; }
- ///
- [Required]
- public ScalingOption ScalingOption { get; set; }
- ///
- [Required]
- public PageSplitOption PageSplitOption { get; set; }
- ///
- [Required]
- public ReaderMode ReaderMode { get; set; }
- ///
- [Required]
- public LayoutMode LayoutMode { get; set; }
- ///
- [Required]
- public bool EmulateBook { get; set; }
- ///
- [Required]
- public string BackgroundColor { get; set; } = "#000000";
- ///
- [Required]
- public bool SwipeToPaginate { get; set; }
- ///
- [Required]
- public bool AutoCloseMenu { get; set; }
- ///
- [Required]
- public bool ShowScreenHints { get; set; } = true;
- ///
- [Required]
- public bool AllowAutomaticWebtoonReaderDetection { get; set; }
-
- ///
- [Required]
- public int BookReaderMargin { get; set; }
- ///
- [Required]
- public int BookReaderLineSpacing { get; set; }
- ///
- [Required]
- public int BookReaderFontSize { get; set; }
- ///
- [Required]
- public string BookReaderFontFamily { get; set; } = null!;
- ///
- [Required]
- public bool BookReaderTapToPaginate { get; set; }
- ///
- [Required]
- public ReadingDirection BookReaderReadingDirection { get; set; }
- ///
- [Required]
- public WritingStyle BookReaderWritingStyle { get; set; }
///
/// UI Site Global Setting: The UI theme the user should use.
@@ -72,15 +17,6 @@ public sealed record UserPreferencesDto
[Required]
public SiteThemeDto? Theme { get; set; }
- [Required] public string BookReaderThemeName { get; set; } = null!;
- ///
- [Required]
- public BookPageLayoutMode BookReaderLayoutMode { get; set; }
- ///
- [Required]
- public bool BookReaderImmersiveMode { get; set; } = false;
- ///
- [Required]
public PageLayoutMode GlobalPageLayoutMode { get; set; } = PageLayoutMode.Cards;
///
[Required]
@@ -101,16 +37,6 @@ public sealed record UserPreferencesDto
[Required]
public string Locale { get; set; }
- ///
- [Required]
- public PdfTheme PdfTheme { get; set; } = PdfTheme.Dark;
- ///
- [Required]
- public PdfScrollMode PdfScrollMode { get; set; } = PdfScrollMode.Vertical;
- ///
- [Required]
- public PdfSpreadMode PdfSpreadMode { get; set; } = PdfSpreadMode.None;
-
///
public bool AniListScrobblingEnabled { get; set; }
///
diff --git a/API/DTOs/UserReadingProfileDto.cs b/API/DTOs/UserReadingProfileDto.cs
new file mode 100644
index 000000000..24dbf1c34
--- /dev/null
+++ b/API/DTOs/UserReadingProfileDto.cs
@@ -0,0 +1,132 @@
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using API.Entities;
+using API.Entities.Enums;
+using API.Entities.Enums.UserPreferences;
+
+namespace API.DTOs;
+
+public sealed record UserReadingProfileDto
+{
+
+ public int Id { get; set; }
+ public int UserId { get; init; }
+
+ public string Name { get; init; }
+ public ReadingProfileKind Kind { get; init; }
+
+ #region MangaReader
+
+ ///
+ [Required]
+ public ReadingDirection ReadingDirection { get; set; }
+
+ ///
+ [Required]
+ public ScalingOption ScalingOption { get; set; }
+
+ ///
+ [Required]
+ public PageSplitOption PageSplitOption { get; set; }
+
+ ///
+ [Required]
+ public ReaderMode ReaderMode { get; set; }
+
+ ///
+ [Required]
+ public bool AutoCloseMenu { get; set; }
+
+ ///
+ [Required]
+ public bool ShowScreenHints { get; set; } = true;
+
+ ///
+ [Required]
+ public bool EmulateBook { get; set; }
+
+ ///
+ [Required]
+ public LayoutMode LayoutMode { get; set; }
+
+ ///
+ [Required]
+ public string BackgroundColor { get; set; } = "#000000";
+
+ ///
+ [Required]
+ public bool SwipeToPaginate { get; set; }
+
+ ///
+ [Required]
+ public bool AllowAutomaticWebtoonReaderDetection { get; set; }
+
+ ///
+ public int? WidthOverride { get; set; }
+
+ ///
+ public BreakPoint DisableWidthOverride { get; set; } = BreakPoint.Never;
+
+ #endregion
+
+ #region EpubReader
+
+ ///
+ [Required]
+ public int BookReaderMargin { get; set; }
+
+ ///
+ [Required]
+ public int BookReaderLineSpacing { get; set; }
+
+ ///
+ [Required]
+ public int BookReaderFontSize { get; set; }
+
+ ///
+ [Required]
+ public string BookReaderFontFamily { get; set; } = null!;
+
+ ///
+ [Required]
+ public bool BookReaderTapToPaginate { get; set; }
+
+ ///
+ [Required]
+ public ReadingDirection BookReaderReadingDirection { get; set; }
+
+ ///
+ [Required]
+ public WritingStyle BookReaderWritingStyle { get; set; }
+
+ ///
+ [Required]
+ public string BookReaderThemeName { get; set; } = null!;
+
+ ///
+ [Required]
+ public BookPageLayoutMode BookReaderLayoutMode { get; set; }
+
+ ///
+ [Required]
+ public bool BookReaderImmersiveMode { get; set; } = false;
+
+ #endregion
+
+ #region PdfReader
+
+ ///
+ [Required]
+ public PdfTheme PdfTheme { get; set; } = PdfTheme.Dark;
+
+ ///
+ [Required]
+ public PdfScrollMode PdfScrollMode { get; set; } = PdfScrollMode.Vertical;
+
+ ///
+ [Required]
+ public PdfSpreadMode PdfSpreadMode { get; set; } = PdfSpreadMode.None;
+
+ #endregion
+
+}
diff --git a/API/Data/DataContext.cs b/API/Data/DataContext.cs
index 714e29fdf..7d529b1da 100644
--- a/API/Data/DataContext.cs
+++ b/API/Data/DataContext.cs
@@ -4,7 +4,6 @@ using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
-using API.DTOs.KavitaPlus.Metadata;
using API.Entities;
using API.Entities.Enums;
using API.Entities.Enums.UserPreferences;
@@ -18,7 +17,6 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
-using Microsoft.EntityFrameworkCore.Diagnostics;
namespace API.Data;
@@ -43,12 +41,13 @@ public sealed class DataContext : IdentityDbContext ServerSetting { get; set; } = null!;
public DbSet AppUserPreferences { get; set; } = null!;
public DbSet SeriesMetadata { get; set; } = null!;
- [Obsolete]
+ [Obsolete("Use AppUserCollection")]
public DbSet CollectionTag { get; set; } = null!;
public DbSet AppUserBookmark { get; set; } = null!;
public DbSet ReadingList { get; set; } = null!;
public DbSet ReadingListItem { get; set; } = null!;
public DbSet Person { get; set; } = null!;
+ public DbSet PersonAlias { get; set; } = null!;
public DbSet Genre { get; set; } = null!;
public DbSet Tag { get; set; } = null!;
public DbSet SiteTheme { get; set; } = null!;
@@ -71,7 +70,7 @@ public sealed class DataContext : IdentityDbContext ExternalSeriesMetadata { get; set; } = null!;
public DbSet ExternalRecommendation { get; set; } = null!;
public DbSet ManualMigrationHistory { get; set; } = null!;
- [Obsolete]
+ [Obsolete("Use IsBlacklisted field on Series")]
public DbSet SeriesBlacklist { get; set; } = null!;
public DbSet AppUserCollection { get; set; } = null!;
public DbSet ChapterPeople { get; set; } = null!;
@@ -80,6 +79,7 @@ public sealed class DataContext : IdentityDbContext MetadataSettings { get; set; } = null!;
public DbSet MetadataFieldMapping { get; set; } = null!;
public DbSet AppUserChapterRating { get; set; } = null!;
+ public DbSet AppUserReadingProfiles { get; set; } = null!;
protected override void OnModelCreating(ModelBuilder builder)
{
@@ -145,6 +145,9 @@ public sealed class DataContext : IdentityDbContext()
.Property(b => b.AllowMetadataMatching)
.HasDefaultValue(true);
+ builder.Entity()
+ .Property(b => b.EnableMetadata)
+ .HasDefaultValue(true);
builder.Entity()
.Property(b => b.WebLinks)
@@ -255,6 +258,48 @@ public sealed class DataContext : IdentityDbContext()
.Property(b => b.EnableCoverImage)
.HasDefaultValue(true);
+
+ builder.Entity()
+ .Property(b => b.BookThemeName)
+ .HasDefaultValue("Dark");
+ builder.Entity()
+ .Property(b => b.BackgroundColor)
+ .HasDefaultValue("#000000");
+ builder.Entity()
+ .Property(b => b.BookReaderWritingStyle)
+ .HasDefaultValue(WritingStyle.Horizontal);
+ builder.Entity()
+ .Property(b => b.AllowAutomaticWebtoonReaderDetection)
+ .HasDefaultValue(true);
+
+ builder.Entity()
+ .Property(rp => rp.LibraryIds)
+ .HasConversion(
+ v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
+ v => JsonSerializer.Deserialize>(v, JsonSerializerOptions.Default) ?? new List())
+ .HasColumnType("TEXT");
+ builder.Entity()
+ .Property(rp => rp.SeriesIds)
+ .HasConversion(
+ v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
+ v => JsonSerializer.Deserialize>(v, JsonSerializerOptions.Default) ?? new List())
+ .HasColumnType("TEXT");
+
+ builder.Entity()
+ .Property(sm => sm.KPlusOverrides)
+ .HasConversion(
+ v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
+ v => JsonSerializer.Deserialize>(v, JsonSerializerOptions.Default) ??
+ new List())
+ .HasColumnType("TEXT")
+ .HasDefaultValue(new List());
+ builder.Entity()
+ .Property(sm => sm.KPlusOverrides)
+ .HasConversion(
+ v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
+ v => JsonSerializer.Deserialize>(v, JsonSerializerOptions.Default) ?? new List())
+ .HasColumnType("TEXT")
+ .HasDefaultValue(new List());
}
#nullable enable
diff --git a/API/Data/ManualMigrations/v0.8.7/ManualMigrateReadingProfiles.cs b/API/Data/ManualMigrations/v0.8.7/ManualMigrateReadingProfiles.cs
new file mode 100644
index 000000000..b2afde98a
--- /dev/null
+++ b/API/Data/ManualMigrations/v0.8.7/ManualMigrateReadingProfiles.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Threading.Tasks;
+using API.Entities;
+using API.Entities.Enums;
+using API.Entities.History;
+using API.Extensions;
+using API.Helpers.Builders;
+using Kavita.Common.EnvironmentInfo;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
+
+namespace API.Data.ManualMigrations;
+
+public static class ManualMigrateReadingProfiles
+{
+ public static async Task Migrate(DataContext context, ILogger logger)
+ {
+ if (await context.ManualMigrationHistory.AnyAsync(m => m.Name == "ManualMigrateReadingProfiles"))
+ {
+ return;
+ }
+
+ logger.LogCritical("Running ManualMigrateReadingProfiles migration - Please be patient, this may take some time. This is not an error");
+
+ var users = await context.AppUser
+ .Include(u => u.UserPreferences)
+ .Include(u => u.ReadingProfiles)
+ .ToListAsync();
+
+ foreach (var user in users)
+ {
+ var readingProfile = new AppUserReadingProfile
+ {
+ Name = "Default",
+ NormalizedName = "Default".ToNormalized(),
+ Kind = ReadingProfileKind.Default,
+ LibraryIds = [],
+ SeriesIds = [],
+ BackgroundColor = user.UserPreferences.BackgroundColor,
+ EmulateBook = user.UserPreferences.EmulateBook,
+ AppUser = user,
+ PdfTheme = user.UserPreferences.PdfTheme,
+ ReaderMode = user.UserPreferences.ReaderMode,
+ ReadingDirection = user.UserPreferences.ReadingDirection,
+ ScalingOption = user.UserPreferences.ScalingOption,
+ LayoutMode = user.UserPreferences.LayoutMode,
+ WidthOverride = null,
+ AppUserId = user.Id,
+ AutoCloseMenu = user.UserPreferences.AutoCloseMenu,
+ BookReaderMargin = user.UserPreferences.BookReaderMargin,
+ PageSplitOption = user.UserPreferences.PageSplitOption,
+ BookThemeName = user.UserPreferences.BookThemeName,
+ PdfSpreadMode = user.UserPreferences.PdfSpreadMode,
+ PdfScrollMode = user.UserPreferences.PdfScrollMode,
+ SwipeToPaginate = user.UserPreferences.SwipeToPaginate,
+ BookReaderFontFamily = user.UserPreferences.BookReaderFontFamily,
+ BookReaderFontSize = user.UserPreferences.BookReaderFontSize,
+ BookReaderImmersiveMode = user.UserPreferences.BookReaderImmersiveMode,
+ BookReaderLayoutMode = user.UserPreferences.BookReaderLayoutMode,
+ BookReaderLineSpacing = user.UserPreferences.BookReaderLineSpacing,
+ BookReaderReadingDirection = user.UserPreferences.BookReaderReadingDirection,
+ BookReaderWritingStyle = user.UserPreferences.BookReaderWritingStyle,
+ AllowAutomaticWebtoonReaderDetection = user.UserPreferences.AllowAutomaticWebtoonReaderDetection,
+ BookReaderTapToPaginate = user.UserPreferences.BookReaderTapToPaginate,
+ ShowScreenHints = user.UserPreferences.ShowScreenHints,
+ };
+ user.ReadingProfiles.Add(readingProfile);
+ }
+
+ await context.SaveChangesAsync();
+
+ context.ManualMigrationHistory.Add(new ManualMigrationHistory
+ {
+ Name = "ManualMigrateReadingProfiles",
+ ProductVersion = BuildInfo.Version.ToString(),
+ RanAt = DateTime.UtcNow,
+ });
+ await context.SaveChangesAsync();
+
+
+ logger.LogCritical("Running ManualMigrateReadingProfiles migration - Completed. This is not an error");
+
+ }
+}
diff --git a/API/Data/Migrations/20250507221026_PersonAliases.Designer.cs b/API/Data/Migrations/20250507221026_PersonAliases.Designer.cs
new file mode 100644
index 000000000..5d76571e1
--- /dev/null
+++ b/API/Data/Migrations/20250507221026_PersonAliases.Designer.cs
@@ -0,0 +1,3571 @@
+//
+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("20250507221026_PersonAliases")]
+ partial class PersonAliases
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "9.0.4");
+
+ modelBuilder.Entity("API.Entities.AppRole", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken()
+ .HasColumnType("TEXT");
+
+ b.Property("Name")
+ .HasMaxLength(256)
+ .HasColumnType("TEXT");
+
+ b.Property("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("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AccessFailedCount")
+ .HasColumnType("INTEGER");
+
+ b.Property("AgeRestriction")
+ .HasColumnType("INTEGER");
+
+ b.Property("AgeRestrictionIncludeUnknowns")
+ .HasColumnType("INTEGER");
+
+ b.Property("AniListAccessToken")
+ .HasColumnType("TEXT");
+
+ b.Property("ApiKey")
+ .HasColumnType("TEXT");
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken()
+ .HasColumnType("TEXT");
+
+ b.Property("ConfirmationToken")
+ .HasColumnType("TEXT");
+
+ b.Property("Created")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedUtc")
+ .HasColumnType("TEXT");
+
+ b.Property("Email")
+ .HasMaxLength(256)
+ .HasColumnType("TEXT");
+
+ b.Property("EmailConfirmed")
+ .HasColumnType("INTEGER");
+
+ b.Property("HasRunScrobbleEventGeneration")
+ .HasColumnType("INTEGER");
+
+ b.Property("LastActive")
+ .HasColumnType("TEXT");
+
+ b.Property("LastActiveUtc")
+ .HasColumnType("TEXT");
+
+ b.Property("LockoutEnabled")
+ .HasColumnType("INTEGER");
+
+ b.Property("LockoutEnd")
+ .HasColumnType("TEXT");
+
+ b.Property("MalAccessToken")
+ .HasColumnType("TEXT");
+
+ b.Property("MalUserName")
+ .HasColumnType("TEXT");
+
+ b.Property("NormalizedEmail")
+ .HasMaxLength(256)
+ .HasColumnType("TEXT");
+
+ b.Property("NormalizedUserName")
+ .HasMaxLength(256)
+ .HasColumnType("TEXT");
+
+ b.Property("PasswordHash")
+ .HasColumnType("TEXT");
+
+ b.Property("PhoneNumber")
+ .HasColumnType("TEXT");
+
+ b.Property("PhoneNumberConfirmed")
+ .HasColumnType("INTEGER");
+
+ b.Property("RowVersion")
+ .IsConcurrencyToken()
+ .HasColumnType("INTEGER");
+
+ b.Property("ScrobbleEventGenerationRan")
+ .HasColumnType("TEXT");
+
+ b.Property("SecurityStamp")
+ .HasColumnType("TEXT");
+
+ b.Property("TwoFactorEnabled")
+ .HasColumnType("INTEGER");
+
+ b.Property("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("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AppUserId")
+ .HasColumnType("INTEGER");
+
+ b.Property("ChapterId")
+ .HasColumnType("INTEGER");
+
+ b.Property("Created")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedUtc")
+ .HasColumnType("TEXT");
+
+ b.Property("FileName")
+ .HasColumnType("TEXT");
+
+ b.Property("LastModified")
+ .HasColumnType("TEXT");
+
+ b.Property("LastModifiedUtc")
+ .HasColumnType("TEXT");
+
+ b.Property("Page")
+ .HasColumnType("INTEGER");
+
+ b.Property("SeriesId")
+ .HasColumnType("INTEGER");
+
+ b.Property("VolumeId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AppUserId");
+
+ b.ToTable("AppUserBookmark");
+ });
+
+ modelBuilder.Entity("API.Entities.AppUserChapterRating", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AppUserId")
+ .HasColumnType("INTEGER");
+
+ b.Property("ChapterId")
+ .HasColumnType("INTEGER");
+
+ b.Property("HasBeenRated")
+ .HasColumnType("INTEGER");
+
+ b.Property("Rating")
+ .HasColumnType("REAL");
+
+ b.Property("Review")
+ .HasColumnType("TEXT");
+
+ b.Property("SeriesId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AppUserId");
+
+ b.HasIndex("ChapterId");
+
+ b.HasIndex("SeriesId");
+
+ b.ToTable("AppUserChapterRating");
+ });
+
+ modelBuilder.Entity("API.Entities.AppUserCollection", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AgeRating")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(0);
+
+ b.Property("AppUserId")
+ .HasColumnType("INTEGER");
+
+ b.Property("CoverImage")
+ .HasColumnType("TEXT");
+
+ b.Property("CoverImageLocked")
+ .HasColumnType("INTEGER");
+
+ b.Property("Created")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedUtc")
+ .HasColumnType("TEXT");
+
+ b.Property("LastModified")
+ .HasColumnType("TEXT");
+
+ b.Property("LastModifiedUtc")
+ .HasColumnType("TEXT");
+
+ b.Property("LastSyncUtc")
+ .HasColumnType("TEXT");
+
+ b.Property("MissingSeriesFromSource")
+ .HasColumnType("TEXT");
+
+ b.Property("NormalizedTitle")
+ .HasColumnType("TEXT");
+
+ b.Property("PrimaryColor")
+ .HasColumnType("TEXT");
+
+ b.Property("Promoted")
+ .HasColumnType("INTEGER");
+
+ b.Property("SecondaryColor")
+ .HasColumnType("TEXT");
+
+ b.Property("Source")
+ .HasColumnType("INTEGER");
+
+ b.Property("SourceUrl")
+ .HasColumnType("TEXT");
+
+ b.Property("Summary")
+ .HasColumnType("TEXT");
+
+ b.Property("Title")
+ .HasColumnType("TEXT");
+
+ b.Property("TotalSourceCount")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AppUserId");
+
+ b.ToTable("AppUserCollection");
+ });
+
+ modelBuilder.Entity("API.Entities.AppUserDashboardStream", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AppUserId")
+ .HasColumnType("INTEGER");
+
+ b.Property("IsProvided")
+ .HasColumnType("INTEGER");
+
+ b.Property("Name")
+ .HasColumnType("TEXT");
+
+ b.Property("Order")
+ .HasColumnType("INTEGER");
+
+ b.Property("SmartFilterId")
+ .HasColumnType("INTEGER");
+
+ b.Property("StreamType")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(4);
+
+ b.Property("Visible")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AppUserId");
+
+ b.HasIndex("SmartFilterId");
+
+ b.HasIndex("Visible");
+
+ b.ToTable("AppUserDashboardStream");
+ });
+
+ modelBuilder.Entity("API.Entities.AppUserExternalSource", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("ApiKey")
+ .HasColumnType("TEXT");
+
+ b.Property("AppUserId")
+ .HasColumnType("INTEGER");
+
+ b.Property("Host")
+ .HasColumnType("TEXT");
+
+ b.Property("Name")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AppUserId");
+
+ b.ToTable("AppUserExternalSource");
+ });
+
+ modelBuilder.Entity("API.Entities.AppUserOnDeckRemoval", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AppUserId")
+ .HasColumnType("INTEGER");
+
+ b.Property("SeriesId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AppUserId");
+
+ b.HasIndex("SeriesId");
+
+ b.ToTable("AppUserOnDeckRemoval");
+ });
+
+ modelBuilder.Entity("API.Entities.AppUserPreferences", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AllowAutomaticWebtoonReaderDetection")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(true);
+
+ b.Property("AniListScrobblingEnabled")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(true);
+
+ b.Property("AppUserId")
+ .HasColumnType("INTEGER");
+
+ b.Property("AutoCloseMenu")
+ .HasColumnType("INTEGER");
+
+ b.Property("BackgroundColor")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT")
+ .HasDefaultValue("#000000");
+
+ b.Property