Merge branch 'develop' into feature/oidc
This commit is contained in:
commit
465723fedf
358 changed files with 34968 additions and 5203 deletions
|
@ -10,8 +10,8 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
|
||||
<PackageReference Include="BenchmarkDotNet.Annotations" Version="0.14.0" />
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.15.1" />
|
||||
<PackageReference Include="BenchmarkDotNet.Annotations" Version="0.15.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -26,5 +26,10 @@
|
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="Data\AesopsFables.epub">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
BIN
API.Benchmark/Data/AesopsFables.epub
Normal file
BIN
API.Benchmark/Data/AesopsFables.epub
Normal file
Binary file not shown.
41
API.Benchmark/KoreaderHashBenchmark.cs
Normal file
41
API.Benchmark/KoreaderHashBenchmark.cs
Normal file
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,13 +6,13 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="22.0.14" />
|
||||
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="22.0.14" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
@ -36,4 +36,10 @@
|
|||
<None Remove="Extensions\Test Data\modified on run.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Data\AesopsFables.epub">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
BIN
API.Tests/Data/AesopsFables.epub
Normal file
BIN
API.Tests/Data/AesopsFables.epub
Normal file
Binary file not shown.
|
@ -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<Genre>()
|
||||
|
@ -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<Tag>()
|
||||
|
|
60
API.Tests/Helpers/KoreaderHelperTests.cs
Normal file
60
API.Tests/Helpers/KoreaderHelperTests.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using API.DTOs.Koreader;
|
||||
using API.DTOs.Progress;
|
||||
using API.Helpers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Xunit;
|
||||
|
||||
namespace API.Tests.Helpers;
|
||||
|
||||
|
||||
public class KoreaderHelperTests
|
||||
{
|
||||
|
||||
[Theory]
|
||||
[InlineData("/body/DocFragment[11]/body/div/a", 10, null)]
|
||||
[InlineData("/body/DocFragment[1]/body/div/p[40]", 0, 40)]
|
||||
[InlineData("/body/DocFragment[8]/body/div/p[28]/text().264", 7, 28)]
|
||||
public void GetEpubPositionDto(string koreaderPosition, int page, int? pNumber)
|
||||
{
|
||||
var expected = EmptyProgressDto();
|
||||
expected.BookScrollId = pNumber.HasValue ? $"//html[1]/BODY/APP-ROOT[1]/DIV[1]/DIV[1]/DIV[1]/APP-BOOK-READER[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/P[{pNumber}]" : null;
|
||||
expected.PageNum = page;
|
||||
var actual = EmptyProgressDto();
|
||||
|
||||
KoreaderHelper.UpdateProgressDto(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
|
||||
};
|
||||
}
|
||||
}
|
124
API.Tests/Helpers/RandfHelper.cs
Normal file
124
API.Tests/Helpers/RandfHelper.cs
Normal file
|
@ -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 ();
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if all simple fields are equal
|
||||
/// </summary>
|
||||
/// <param name="obj1"></param>
|
||||
/// <param name="obj2"></param>
|
||||
/// <param name="ignoreFields">fields to ignore, note that the names are very weird sometimes</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public static bool AreSimpleFieldsEqual(object obj1, object obj2, IList<string> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets all simple fields of the given object to a random value
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <remarks>Simple is, primitive, string, or enum</remarks>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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<ILogger<DirectoryService>>(), 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<ILogger<DirectoryService>>(), 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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")]
|
||||
|
|
280
API.Tests/Repository/GenreRepositoryTests.cs
Normal file
280
API.Tests/Repository/GenreRepositoryTests.cs
Normal file
|
@ -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<BrowseGenreDto> ContainsGenreCheck(Genre genre)
|
||||
{
|
||||
return g => g.Id == genre.Id;
|
||||
}
|
||||
|
||||
private static void AssertGenrePresent(IEnumerable<BrowseGenreDto> genres, Genre expectedGenre)
|
||||
{
|
||||
Assert.Contains(genres, ContainsGenreCheck(expectedGenre));
|
||||
}
|
||||
|
||||
private static void AssertGenreNotPresent(IEnumerable<BrowseGenreDto> genres, Genre expectedGenre)
|
||||
{
|
||||
Assert.DoesNotContain(genres, ContainsGenreCheck(expectedGenre));
|
||||
}
|
||||
|
||||
private static BrowseGenreDto GetGenreDto(IEnumerable<BrowseGenreDto> 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<Genre> GetAllGenres()
|
||||
{
|
||||
return
|
||||
[
|
||||
SharedSeriesChaptersGenre, SharedSeriesGenre, SharedChaptersGenre,
|
||||
Lib0SeriesChaptersGenre, Lib0SeriesGenre, Lib0ChaptersGenre,
|
||||
Lib1SeriesChaptersGenre, Lib1SeriesGenre, Lib1ChaptersGenre, Lib1ChapterAgeGenre
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
342
API.Tests/Repository/PersonRepositoryTests.cs
Normal file
342
API.Tests/Repository/PersonRepositoryTests.cs
Normal file
|
@ -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<Person> CreateTestPeople()
|
||||
{
|
||||
return new List<Person>
|
||||
{
|
||||
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<Library> CreateTestLibraries(List<Person> 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<Library> { lib0, lib1 };
|
||||
}
|
||||
|
||||
private static Person GetPersonByName(List<Person> 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<BrowsePersonDto> 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);
|
||||
}
|
||||
}
|
278
API.Tests/Repository/TagRepositoryTests.cs
Normal file
278
API.Tests/Repository/TagRepositoryTests.cs
Normal file
|
@ -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<BrowseTagDto> ContainsTagCheck(Tag tag)
|
||||
{
|
||||
return t => t.Id == tag.Id;
|
||||
}
|
||||
|
||||
private static void AssertTagPresent(IEnumerable<BrowseTagDto> tags, Tag expectedTag)
|
||||
{
|
||||
Assert.Contains(tags, ContainsTagCheck(expectedTag));
|
||||
}
|
||||
|
||||
private static void AssertTagNotPresent(IEnumerable<BrowseTagDto> tags, Tag expectedTag)
|
||||
{
|
||||
Assert.DoesNotContain(tags, ContainsTagCheck(expectedTag));
|
||||
}
|
||||
|
||||
private static BrowseTagDto GetTagDto(IEnumerable<BrowseTagDto> 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<Tag> GetAllTags()
|
||||
{
|
||||
return
|
||||
[
|
||||
SharedSeriesChaptersTag, SharedSeriesTag, SharedChaptersTag,
|
||||
Lib0SeriesChaptersTag, Lib0SeriesTag, Lib0ChaptersTag,
|
||||
Lib1SeriesChaptersTag, Lib1SeriesTag, Lib1ChaptersTag, Lib1ChapterAgeTag
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<ILogger<ExternalMetadataService>>(),
|
||||
Mapper, Substitute.For<ILicenseService>(), Substitute.For<IScrobblingService>(), Substitute.For<IEventHub>(),
|
||||
Substitute.For<ICoverDbService>());
|
||||
Substitute.For<ICoverDbService>(), Substitute.For<IKavitaPlusApiService>());
|
||||
}
|
||||
|
||||
#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<Chapter>();
|
||||
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<Chapter>();
|
||||
// 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is validating that we get a completed even though we have a special chapter and AL doesn't count it
|
||||
/// </summary>
|
||||
[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<Chapter>();
|
||||
// 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);
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// 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
|
||||
/// </remarks>
|
||||
[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<Chapter>();
|
||||
// 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<Chapter>();
|
||||
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<Chapter>
|
||||
{
|
||||
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<Chapter>();
|
||||
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<Chapter>
|
||||
{
|
||||
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
|
||||
|
||||
|
@ -2935,6 +3147,8 @@ public class ExternalMetadataServiceTests : AbstractDbTest
|
|||
metadataSettings.EnableTags = false;
|
||||
metadataSettings.EnablePublicationStatus = false;
|
||||
metadataSettings.EnableStartDate = false;
|
||||
metadataSettings.FieldMappings = [];
|
||||
metadataSettings.AgeRatingMappings = new Dictionary<string, AgeRating>();
|
||||
Context.MetadataSettings.Update(metadataSettings);
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
561
API.Tests/Services/ReadingProfileServiceTest.cs
Normal file
561
API.Tests/Services/ReadingProfileServiceTest.cs
Normal file
|
@ -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
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Does not add a default reading profile
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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<ILocalizationService>(), 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<KavitaException>(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<UserReadingProfileDto>(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<UserReadingProfileDto>(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<KavitaException>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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<UserReadingProfileDto>(profile);
|
||||
|
||||
Assert.True(RandfHelper.AreSimpleFieldsEqual(dto, newDto,
|
||||
["<Id>k__BackingField", "<UserId>k__BackingField"]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override async Task ResetDb()
|
||||
{
|
||||
Context.AppUserReadingProfiles.RemoveRange(Context.AppUserReadingProfiles);
|
||||
await UnitOfWork.CommitAsync();
|
||||
}
|
||||
}
|
|
@ -483,7 +483,7 @@ public class ScannerServiceTests : AbstractDbTest
|
|||
var infos = new Dictionary<string, ComicInfo>();
|
||||
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<string, ComicInfo>();
|
||||
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,38 @@ 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<string, ComicInfo>();
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// {
|
||||
/// "Issuer": "Issuer",
|
||||
/// "Issued At": "2025-06-15T21:01:57.615Z",
|
||||
/// "Expiration": "2200-06-15T21:01:57.615Z"
|
||||
/// }
|
||||
/// </summary>
|
||||
/// <remarks>Our UnitTests will fail in 2200 :(</remarks>
|
||||
private const string ValidJwtToken =
|
||||
"eyJhbGciOiJIUzI1NiJ9.eyJJc3N1ZXIiOiJJc3N1ZXIiLCJleHAiOjcyNzI0NTAxMTcsImlhdCI6MTc1MDAyMTMxN30.zADmcGq_BfxbcV8vy4xw5Cbzn4COkmVINxgqpuL17Ng";
|
||||
|
||||
private readonly ScrobblingService _service;
|
||||
private readonly ILicenseService _licenseService;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly ILogger<ScrobblingService> _logger;
|
||||
private readonly IEmailService _emailService;
|
||||
private readonly IKavitaPlusApiService _kavitaPlusApiService;
|
||||
/// <summary>
|
||||
/// IReaderService, without the ScrobblingService injected
|
||||
/// </summary>
|
||||
private readonly IReaderService _readerService;
|
||||
/// <summary>
|
||||
/// IReaderService, with the _service injected
|
||||
/// </summary>
|
||||
private readonly IReaderService _hookedUpReaderService;
|
||||
|
||||
public ScrobblingServiceTests()
|
||||
{
|
||||
|
@ -27,8 +55,24 @@ public class ScrobblingServiceTests : AbstractDbTest
|
|||
_localizationService = Substitute.For<ILocalizationService>();
|
||||
_logger = Substitute.For<ILogger<ScrobblingService>>();
|
||||
_emailService = Substitute.For<IEmailService>();
|
||||
_kavitaPlusApiService = Substitute.For<IKavitaPlusApiService>();
|
||||
|
||||
_service = new ScrobblingService(UnitOfWork, Substitute.For<IEventHub>(), _logger, _licenseService, _localizationService, _emailService);
|
||||
_service = new ScrobblingService(UnitOfWork, Substitute.For<IEventHub>(), _logger, _licenseService,
|
||||
_localizationService, _emailService, _kavitaPlusApiService);
|
||||
|
||||
_readerService = new ReaderService(UnitOfWork,
|
||||
Substitute.For<ILogger<ReaderService>>(),
|
||||
Substitute.For<IEventHub>(),
|
||||
Substitute.For<IImageService>(),
|
||||
Substitute.For<IDirectoryService>(),
|
||||
Substitute.For<IScrobblingService>()); // Do not use the actual one
|
||||
|
||||
_hookedUpReaderService = new ReaderService(UnitOfWork,
|
||||
Substitute.For<ILogger<ReaderService>>(),
|
||||
Substitute.For<IEventHub>(),
|
||||
Substitute.For<IImageService>(),
|
||||
Substitute.For<IDirectoryService>(),
|
||||
_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<ScrobbleEvent> 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<KavitaException>(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<KavitaException>(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<string>(), Arg.Any<string>())
|
||||
.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<string>(), Arg.Any<string>())
|
||||
.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<Chapter>() {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<ScrobbleDto>(data =>
|
||||
data.ChapterNumber == (int)chapter.MaxNumber &&
|
||||
data.VolumeNumber == (int)volume.MaxNumber
|
||||
),
|
||||
Arg.Any<string>());
|
||||
}
|
||||
|
||||
#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<Chapter>() {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)]
|
||||
|
|
|
@ -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"
|
||||
]
|
|
@ -50,9 +50,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CsvHelper" Version="33.0.1" />
|
||||
<PackageReference Include="MailKit" Version="4.12.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4">
|
||||
<PackageReference Include="CsvHelper" Version="33.1.0" />
|
||||
<PackageReference Include="MailKit" Version="4.12.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.6">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
@ -62,25 +62,25 @@
|
|||
<PackageReference Include="ExCSS" Version="4.3.0" />
|
||||
<PackageReference Include="Flurl" Version="4.0.0" />
|
||||
<PackageReference Include="Flurl.Http" Version="4.0.2" />
|
||||
<PackageReference Include="Hangfire" Version="1.8.18" />
|
||||
<PackageReference Include="Hangfire" Version="1.8.20" />
|
||||
<PackageReference Include="Hangfire.InMemory" Version="1.0.0" />
|
||||
<PackageReference Include="Hangfire.MaximumConcurrentExecutions" Version="1.1.0" />
|
||||
<PackageReference Include="Hangfire.Storage.SQLite" Version="0.4.2" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.12.1" />
|
||||
<PackageReference Include="MarkdownDeep.NET.Core" Version="1.5.0.4" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.18" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.20" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
|
||||
<PackageReference Include="MimeTypeMapOfficial" Version="1.0.17" />
|
||||
<PackageReference Include="Nager.ArticleNumber" Version="1.0.7" />
|
||||
<PackageReference Include="NetVips" Version="3.0.1" />
|
||||
<PackageReference Include="NetVips.Native" Version="8.16.1" />
|
||||
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||
<PackageReference Include="NetVips" Version="3.1.0" />
|
||||
<PackageReference Include="NetVips.Native" Version="8.17.0.1" />
|
||||
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="9.0.0" />
|
||||
|
@ -89,17 +89,17 @@
|
|||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.SignalR.Core" Version="0.1.2" />
|
||||
<PackageReference Include="SharpCompress" Version="0.39.0" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.8" />
|
||||
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.9.0.115408">
|
||||
<PackageReference Include="SharpCompress" Version="0.40.0" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.10" />
|
||||
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.11.0.117924">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.3" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.9.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="9.0.6" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.0" />
|
||||
<PackageReference Include="System.IO.Abstractions" Version="22.0.14" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="9.0.4" />
|
||||
<PackageReference Include="VersOne.Epub" Version="3.3.4" />
|
||||
<PackageReference Include="YamlDotNet" Version="16.3.0" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -165,6 +165,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));
|
||||
|
@ -625,7 +628,7 @@ public class AccountController : BaseApiController
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="withBaseUrl">Include the "https://ip:port/" in the generated link</param>
|
||||
|
@ -685,6 +688,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);
|
||||
|
@ -795,6 +801,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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Last step in authentication flow, confirms the email token for email
|
||||
/// </summary>
|
||||
|
|
|
@ -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,
|
||||
|
|
119
API/Controllers/KoreaderController.cs
Normal file
119
API/Controllers/KoreaderController.cs
Normal file
|
@ -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
|
||||
|
||||
/// <summary>
|
||||
/// The endpoint to interface with Koreader's Progress Sync plugin.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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
|
||||
/// </remarks>
|
||||
[AllowAnonymous]
|
||||
public class KoreaderController : BaseApiController
|
||||
{
|
||||
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IKoreaderService _koreaderService;
|
||||
private readonly ILogger<KoreaderController> _logger;
|
||||
|
||||
public KoreaderController(IUnitOfWork unitOfWork, ILocalizationService localizationService,
|
||||
IKoreaderService koreaderService, ILogger<KoreaderController> logger)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_localizationService = localizationService;
|
||||
_koreaderService = koreaderService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// We won't allow users to be created from Koreader. Rather, they
|
||||
// must already have an account.
|
||||
/*
|
||||
[HttpPost("/users/create")]
|
||||
public IActionResult CreateUser(CreateUserRequest request)
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
[HttpGet("{apiKey}/users/auth")]
|
||||
public async Task<IActionResult> Authenticate(string apiKey)
|
||||
{
|
||||
var userId = await GetUserId(apiKey);
|
||||
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
return Ok(new { username = user.UserName });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Syncs book progress with Kavita. Will attempt to save the underlying reader position if possible.
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{apiKey}/syncs/progress")]
|
||||
public async Task<ActionResult<KoreaderProgressUpdateDto>> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets book progress from Kavita, if not found will return a 400
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="ebookHash"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{apiKey}/syncs/progress/{ebookHash}")]
|
||||
public async Task<ActionResult<KoreaderBookDto>> 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<int> GetUserId(string apiKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new KavitaException(await _localizationService.Get("en", "user-doesnt-exist"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -623,6 +623,7 @@ public class LibraryController : BaseApiController
|
|||
library.ManageReadingLists = dto.ManageReadingLists;
|
||||
library.AllowScrobbling = dto.AllowScrobbling;
|
||||
library.AllowMetadataMatching = dto.AllowMetadataMatching;
|
||||
library.EnableMetadata = dto.EnableMetadata;
|
||||
library.LibraryFileTypes = dto.FileGroupTypes
|
||||
.Select(t => new LibraryFileTypeGroup() {FileTypeGroup = t, LibraryId = library.Id})
|
||||
.Distinct()
|
||||
|
|
|
@ -6,8 +6,10 @@ using System.Threading.Tasks;
|
|||
using API.Constants;
|
||||
using API.Data;
|
||||
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;
|
||||
|
@ -46,6 +48,22 @@ public class MetadataController(IUnitOfWork unitOfWork, ILocalizationService loc
|
|||
return Ok(await unitOfWork.GenreRepository.GetAllGenreDtosForLibrariesAsync(User.GetUserId(), ids, context));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of Genres with counts for counts when Genre is on Series/Chapter
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("genres-with-counts")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.FiveMinute)]
|
||||
public async Task<ActionResult<PagedList<BrowseGenreDto>>> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches people from the instance by role
|
||||
/// </summary>
|
||||
|
@ -95,6 +113,22 @@ public class MetadataController(IUnitOfWork unitOfWork, ILocalizationService loc
|
|||
return Ok(await unitOfWork.TagRepository.GetAllTagDtosForLibrariesAsync(User.GetUserId()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of Tags with counts for counts when Tag is on Series/Chapter
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("tags-with-counts")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.FiveMinute)]
|
||||
public async Task<ActionResult<PagedList<BrowseTagDto>>> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches all age ratings from the instance
|
||||
/// </summary>
|
||||
|
|
|
@ -4,6 +4,9 @@ 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;
|
||||
|
@ -77,11 +80,13 @@ public class PersonController : BaseApiController
|
|||
/// <param name="userParams"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("all")]
|
||||
public async Task<ActionResult<PagedList<BrowsePersonDto>>> GetAuthorsForBrowse([FromQuery] UserParams? userParams)
|
||||
public async Task<ActionResult<PagedList<BrowsePersonDto>>> 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);
|
||||
}
|
||||
|
||||
|
@ -112,6 +117,7 @@ public class PersonController : BaseApiController
|
|||
|
||||
|
||||
person.Name = dto.Name?.Trim();
|
||||
person.NormalizedName = person.Name.ToNormalized();
|
||||
person.Description = dto.Description ?? string.Empty;
|
||||
person.CoverImageLocked = dto.CoverImageLocked;
|
||||
|
||||
|
@ -179,7 +185,7 @@ public class PersonController : BaseApiController
|
|||
[HttpGet("series-known-for")]
|
||||
public async Task<ActionResult<IEnumerable<SeriesDto>>> GetKnownSeries(int personId)
|
||||
{
|
||||
return Ok(await _unitOfWork.PersonRepository.GetSeriesKnownFor(personId));
|
||||
return Ok(await _unitOfWork.PersonRepository.GetSeriesKnownFor(personId, User.GetUserId()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -200,6 +206,7 @@ public class PersonController : BaseApiController
|
|||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("merge")]
|
||||
[Authorize("RequireAdminRole")]
|
||||
public async Task<ActionResult<PersonDto>> MergePeople(PersonMergeDto dto)
|
||||
{
|
||||
var dst = await _unitOfWork.PersonRepository.GetPersonById(dto.DestId, PersonIncludes.All);
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
198
API/Controllers/ReadingProfileController.cs
Normal file
198
API/Controllers/ReadingProfileController.cs
Normal file
|
@ -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<ReadingProfileController> logger, IUnitOfWork unitOfWork,
|
||||
IReadingProfileService readingProfileService): BaseApiController
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets all non-implicit reading profiles for a user
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("all")]
|
||||
public async Task<ActionResult<IList<UserReadingProfileDto>>> GetAllReadingProfiles()
|
||||
{
|
||||
return Ok(await unitOfWork.AppUserReadingProfileRepository.GetProfilesDtoForUser(User.GetUserId(), true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the ReadingProfile that should be applied to the given series, walks up the tree.
|
||||
/// Series -> Library -> Default
|
||||
/// </summary>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <param name="skipImplicit"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{seriesId:int}")]
|
||||
public async Task<ActionResult<UserReadingProfileDto>> GetProfileForSeries(int seriesId, [FromQuery] bool skipImplicit)
|
||||
{
|
||||
return Ok(await readingProfileService.GetReadingProfileDtoForSeries(User.GetUserId(), seriesId, skipImplicit));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the (potential) Reading Profile bound to the library
|
||||
/// </summary>
|
||||
/// <param name="libraryId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("library")]
|
||||
public async Task<ActionResult<UserReadingProfileDto?>> GetProfileForLibrary(int libraryId)
|
||||
{
|
||||
return Ok(await readingProfileService.GetReadingProfileDtoForLibrary(User.GetUserId(), libraryId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new reading profile for the current user
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("create")]
|
||||
public async Task<ActionResult<UserReadingProfileDto>> CreateReadingProfile([FromBody] UserReadingProfileDto dto)
|
||||
{
|
||||
return Ok(await readingProfileService.CreateReadingProfile(User.GetUserId(), dto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Promotes the implicit profile to a user profile. Removes the series from other profiles
|
||||
/// </summary>
|
||||
/// <param name="profileId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("promote")]
|
||||
public async Task<ActionResult<UserReadingProfileDto>> PromoteImplicitReadingProfile([FromQuery] int profileId)
|
||||
{
|
||||
return Ok(await readingProfileService.PromoteImplicitProfile(User.GetUserId(), profileId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the implicit reading profile for a series, creates one if none exists
|
||||
/// </summary>
|
||||
/// <remarks>Any modification to the reader settings during reading will create an implicit profile. Use "update-parent" to save to the bound series profile.</remarks>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("series")]
|
||||
public async Task<ActionResult<UserReadingProfileDto>> UpdateReadingProfileForSeries([FromBody] UserReadingProfileDto dto, [FromQuery] int seriesId)
|
||||
{
|
||||
var updatedProfile = await readingProfileService.UpdateImplicitReadingProfile(User.GetUserId(), seriesId, dto);
|
||||
return Ok(updatedProfile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the non-implicit reading profile for the given series, and removes implicit profiles
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("update-parent")]
|
||||
public async Task<ActionResult<UserReadingProfileDto>> UpdateParentProfileForSeries([FromBody] UserReadingProfileDto dto, [FromQuery] int seriesId)
|
||||
{
|
||||
var newParentProfile = await readingProfileService.UpdateParent(User.GetUserId(), seriesId, dto);
|
||||
return Ok(newParentProfile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the given reading profile, must belong to the current user
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns>The updated reading profile</returns>
|
||||
/// <remarks>
|
||||
/// This does not update connected series and libraries.
|
||||
/// </remarks>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<UserReadingProfileDto>> UpdateReadingProfile(UserReadingProfileDto dto)
|
||||
{
|
||||
return Ok(await readingProfileService.UpdateReadingProfile(User.GetUserId(), dto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the given profile, requires the profile to belong to the logged-in user
|
||||
/// </summary>
|
||||
/// <param name="profileId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="KavitaException"></exception>
|
||||
/// <exception cref="UnauthorizedAccessException"></exception>
|
||||
[HttpDelete]
|
||||
public async Task<IActionResult> DeleteReadingProfile([FromQuery] int profileId)
|
||||
{
|
||||
await readingProfileService.DeleteReadingProfile(User.GetUserId(), profileId);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the reading profile for a given series, removes the old one
|
||||
/// </summary>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <param name="profileId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("series/{seriesId:int}")]
|
||||
public async Task<IActionResult> AddProfileToSeries(int seriesId, [FromQuery] int profileId)
|
||||
{
|
||||
await readingProfileService.AddProfileToSeries(User.GetUserId(), profileId, seriesId);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the reading profile for the given series for the currently logged-in user
|
||||
/// </summary>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("series/{seriesId:int}")]
|
||||
public async Task<IActionResult> ClearSeriesProfile(int seriesId)
|
||||
{
|
||||
await readingProfileService.ClearSeriesProfile(User.GetUserId(), seriesId);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the reading profile for a given library, removes the old one
|
||||
/// </summary>
|
||||
/// <param name="libraryId"></param>
|
||||
/// <param name="profileId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("library/{libraryId:int}")]
|
||||
public async Task<IActionResult> AddProfileToLibrary(int libraryId, [FromQuery] int profileId)
|
||||
{
|
||||
await readingProfileService.AddProfileToLibrary(User.GetUserId(), profileId, libraryId);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the reading profile for the given library for the currently logged-in user
|
||||
/// </summary>
|
||||
/// <param name="libraryId"></param>
|
||||
/// <param name="profileId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("library/{libraryId:int}")]
|
||||
public async Task<IActionResult> ClearLibraryProfile(int libraryId)
|
||||
{
|
||||
await readingProfileService.ClearLibraryProfile(User.GetUserId(), libraryId);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assigns the reading profile to all passes series, and deletes their implicit profiles
|
||||
/// </summary>
|
||||
/// <param name="profileId"></param>
|
||||
/// <param name="seriesIds"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("bulk")]
|
||||
public async Task<IActionResult> BulkAddReadingProfile([FromQuery] int profileId, [FromBody] IList<int> seriesIds)
|
||||
{
|
||||
await readingProfileService.BulkAddProfileToSeries(User.GetUserId(), profileId, seriesIds);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
}
|
|
@ -254,7 +254,7 @@ public class ScrobblingController : BaseApiController
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a hold against the Series for user's scrobbling
|
||||
/// Remove a hold against the Series for user's scrobbling
|
||||
/// </summary>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <returns></returns>
|
||||
|
@ -281,4 +281,18 @@ public class ScrobblingController : BaseApiController
|
|||
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(User.GetUserId());
|
||||
return Ok(user is {HasRunScrobbleEventGeneration: true});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the given scrobble events if they belong to that user
|
||||
/// </summary>
|
||||
/// <param name="eventIds"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("bulk-remove-events")]
|
||||
public async Task<ActionResult> BulkRemoveScrobbleEvents(IList<long> eventIds)
|
||||
{
|
||||
var events = await _unitOfWork.ScrobbleRepository.GetUserEvents(User.GetUserId(), eventIds);
|
||||
_unitOfWork.ScrobbleRepository.Remove(events);
|
||||
await _unitOfWork.CommitAsync();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
|||
/// </summary>
|
||||
/// <param name="filterDto"></param>
|
||||
/// <param name="userParams"></param>
|
||||
/// <param name="libraryId"></param>
|
||||
/// <param name="libraryId">This is not in use</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("all-v2")]
|
||||
public async Task<ActionResult<IEnumerable<SeriesDto>>> 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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
8
API/DTOs/Filtering/PersonSortField.cs
Normal file
8
API/DTOs/Filtering/PersonSortField.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace API.DTOs.Filtering;
|
||||
|
||||
public enum PersonSortField
|
||||
{
|
||||
Name = 1,
|
||||
SeriesCount = 2,
|
||||
ChapterCount = 3
|
||||
}
|
|
@ -8,3 +8,12 @@ public sealed record SortOptions
|
|||
public SortField SortField { get; set; }
|
||||
public bool IsAscending { get; set; } = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All Sorting Options for a query related to Person Entity
|
||||
/// </summary>
|
||||
public sealed record PersonSortOptions
|
||||
{
|
||||
public PersonSortField SortField { get; set; }
|
||||
public bool IsAscending { get; set; } = true;
|
||||
}
|
||||
|
|
|
@ -56,5 +56,12 @@ public enum FilterField
|
|||
/// Last time User Read
|
||||
/// </summary>
|
||||
ReadLast = 32,
|
||||
|
||||
}
|
||||
|
||||
public enum PersonFilterField
|
||||
{
|
||||
Role = 1,
|
||||
Name = 2,
|
||||
SeriesCount = 3,
|
||||
ChapterCount = 4,
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public sealed record FilterV2Dto
|
|||
/// The name of the filter
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
public ICollection<FilterStatementDto> Statements { get; set; } = new List<FilterStatementDto>();
|
||||
public ICollection<FilterStatementDto> Statements { get; set; } = [];
|
||||
public FilterCombination Combination { get; set; } = FilterCombination.And;
|
||||
public SortOptions? SortOptions { get; set; }
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace API.DTOs.KavitaPlus.ExternalMetadata;
|
|||
/// <summary>
|
||||
/// Used for matching and fetching metadata on a series
|
||||
/// </summary>
|
||||
internal sealed record ExternalMetadataIdsDto
|
||||
public sealed record ExternalMetadataIdsDto
|
||||
{
|
||||
public long? MalId { get; set; }
|
||||
public int? AniListId { get; set; }
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace API.DTOs.KavitaPlus.ExternalMetadata;
|
|||
/// <summary>
|
||||
/// Represents a request to match some series from Kavita to an external id which K+ uses.
|
||||
/// </summary>
|
||||
internal sealed record MatchSeriesRequestDto
|
||||
public sealed record MatchSeriesRequestDto
|
||||
{
|
||||
public required string SeriesName { get; set; }
|
||||
public ICollection<string> AlternativeNames { get; set; } = [];
|
||||
|
|
|
@ -6,7 +6,7 @@ using API.DTOs.SeriesDetail;
|
|||
|
||||
namespace API.DTOs.KavitaPlus.ExternalMetadata;
|
||||
|
||||
internal sealed record SeriesDetailPlusApiDto
|
||||
public sealed record SeriesDetailPlusApiDto
|
||||
{
|
||||
public IEnumerable<MediaRecommendationDto> Recommendations { get; set; }
|
||||
public IEnumerable<UserReviewDto> Reviews { get; set; }
|
||||
|
|
|
@ -15,5 +15,9 @@ public enum MatchStateOption
|
|||
public sealed record ManageMatchFilterDto
|
||||
{
|
||||
public MatchStateOption MatchStateOption { get; set; } = MatchStateOption.All;
|
||||
/// <summary>
|
||||
/// Library Type in int form. -1 indicates to ignore the field.
|
||||
/// </summary>
|
||||
public int LibraryType { get; set; } = -1;
|
||||
public string SearchTerm { get; set; } = string.Empty;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using API.DTOs.SeriesDetail;
|
||||
|
||||
namespace API.DTOs.KavitaPlus.Metadata;
|
||||
#nullable enable
|
||||
|
||||
/// <summary>
|
||||
/// Information about an individual issue/chapter/book from Kavita+
|
||||
|
|
|
@ -29,7 +29,9 @@ public sealed record ExternalSeriesDetailDto
|
|||
public DateTime? StartDate { get; set; }
|
||||
public DateTime? EndDate { get; set; }
|
||||
public int AverageScore { get; set; }
|
||||
/// <remarks>AniList returns the total count of unique chapters, includes 1.1 for example</remarks>
|
||||
public int Chapters { get; set; }
|
||||
/// <remarks>AniList returns the total count of unique volumes, includes 1.1 for example</remarks>
|
||||
public int Volumes { get; set; }
|
||||
public IList<SeriesRelationship>? Relations { get; set; } = [];
|
||||
public IList<SeriesCharacter>? Characters { get; set; } = [];
|
||||
|
|
33
API/DTOs/Koreader/KoreaderBookDto.cs
Normal file
33
API/DTOs/Koreader/KoreaderBookDto.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using API.DTOs.Progress;
|
||||
|
||||
namespace API.DTOs.Koreader;
|
||||
|
||||
/// <summary>
|
||||
/// This is the interface for receiving and sending updates to Koreader. The only fields
|
||||
/// that are actually used are the Document and Progress fields.
|
||||
/// </summary>
|
||||
public class KoreaderBookDto
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the Koreader hash of the book. It is used to identify the book.
|
||||
/// </summary>
|
||||
public string Document { get; set; }
|
||||
/// <summary>
|
||||
/// A randomly generated id from the koreader device. Only used to maintain the Koreader interface.
|
||||
/// </summary>
|
||||
public string Device_id { get; set; }
|
||||
/// <summary>
|
||||
/// The Koreader device name. Only used to maintain the Koreader interface.
|
||||
/// </summary>
|
||||
public string Device { get; set; }
|
||||
/// <summary>
|
||||
/// Percent progress of the book. Only used to maintain the Koreader interface.
|
||||
/// </summary>
|
||||
public float Percentage { get; set; }
|
||||
/// <summary>
|
||||
/// An XPath string read by Koreader to determine the location within the epub.
|
||||
/// Essentially, it is Koreader's equivalent to ProgressDto.BookScrollId.
|
||||
/// </summary>
|
||||
/// <seealso cref="ProgressDto.BookScrollId"/>
|
||||
public string Progress { get; set; }
|
||||
}
|
15
API/DTOs/Koreader/KoreaderProgressUpdateDto.cs
Normal file
15
API/DTOs/Koreader/KoreaderProgressUpdateDto.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
|
||||
namespace API.DTOs.Koreader;
|
||||
|
||||
public class KoreaderProgressUpdateDto
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the Koreader hash of the book. It is used to identify the book.
|
||||
/// </summary>
|
||||
public string Document { get; set; }
|
||||
/// <summary>
|
||||
/// UTC Timestamp to return to KOReader
|
||||
/// </summary>
|
||||
public DateTime Timestamp { get; set; }
|
||||
}
|
|
@ -66,4 +66,8 @@ public sealed record LibraryDto
|
|||
/// <remarks>This does not exclude the library from being linked to wrt Series Relationships</remarks>
|
||||
/// <remarks>Requires a valid LicenseKey</remarks>
|
||||
public bool AllowMetadataMatching { get; set; } = true;
|
||||
/// <summary>
|
||||
/// Allow Kavita to read metadata (ComicInfo.xml, Epub, PDF)
|
||||
/// </summary>
|
||||
public bool EnableMetadata { get; set; } = true;
|
||||
}
|
||||
|
|
13
API/DTOs/Metadata/Browse/BrowseGenreDto.cs
Normal file
13
API/DTOs/Metadata/Browse/BrowseGenreDto.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace API.DTOs.Metadata.Browse;
|
||||
|
||||
public sealed record BrowseGenreDto : GenreTagDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of Series this Entity is on
|
||||
/// </summary>
|
||||
public int SeriesCount { get; set; }
|
||||
/// <summary>
|
||||
/// Number of Chapters this Entity is on
|
||||
/// </summary>
|
||||
public int ChapterCount { get; set; }
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
using API.DTOs.Person;
|
||||
|
||||
namespace API.DTOs;
|
||||
namespace API.DTOs.Metadata.Browse;
|
||||
|
||||
/// <summary>
|
||||
/// Used to browse writers and click in to see their series
|
||||
|
@ -12,7 +12,7 @@ public class BrowsePersonDto : PersonDto
|
|||
/// </summary>
|
||||
public int SeriesCount { get; set; }
|
||||
/// <summary>
|
||||
/// Number or Issues this Person is the Writer for
|
||||
/// Number of Issues this Person is the Writer for
|
||||
/// </summary>
|
||||
public int IssueCount { get; set; }
|
||||
public int ChapterCount { get; set; }
|
||||
}
|
13
API/DTOs/Metadata/Browse/BrowseTagDto.cs
Normal file
13
API/DTOs/Metadata/Browse/BrowseTagDto.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace API.DTOs.Metadata.Browse;
|
||||
|
||||
public sealed record BrowseTagDto : TagDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of Series this Entity is on
|
||||
/// </summary>
|
||||
public int SeriesCount { get; set; }
|
||||
/// <summary>
|
||||
/// Number of Chapters this Entity is on
|
||||
/// </summary>
|
||||
public int ChapterCount { get; set; }
|
||||
}
|
27
API/DTOs/Metadata/Browse/Requests/BrowsePersonFilterDto.cs
Normal file
27
API/DTOs/Metadata/Browse/Requests/BrowsePersonFilterDto.cs
Normal file
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Not used - For parity with Series Filter
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// Not used - For parity with Series Filter
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
public ICollection<PersonFilterStatementDto> Statements { get; set; } = [];
|
||||
public FilterCombination Combination { get; set; } = FilterCombination.And;
|
||||
public PersonSortOptions? SortOptions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Limit the number of rows returned. Defaults to not applying a limit (aka 0)
|
||||
/// </summary>
|
||||
public int LimitTo { get; set; } = 0;
|
||||
}
|
|
@ -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; }
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -49,6 +49,11 @@ public sealed record ReadingListDto : IHasCoverImage
|
|||
/// </summary>
|
||||
public required AgeRating AgeRating { get; set; } = AgeRating.Unknown;
|
||||
|
||||
/// <summary>
|
||||
/// Username of the User that owns (in the case of a promoted list)
|
||||
/// </summary>
|
||||
public string OwnerUserName { get; set; }
|
||||
|
||||
public void ResetColorScape()
|
||||
{
|
||||
PrimaryColor = string.Empty;
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ public sealed record UpdateLibraryDto
|
|||
public bool AllowScrobbling { get; init; }
|
||||
[Required]
|
||||
public bool AllowMetadataMatching { get; init; }
|
||||
[Required]
|
||||
public bool EnableMetadata { get; init; }
|
||||
/// <summary>
|
||||
/// What types of files to allow the scanner to pickup
|
||||
/// </summary>
|
||||
|
|
|
@ -9,61 +9,6 @@ namespace API.DTOs;
|
|||
|
||||
public sealed record UserPreferencesDto
|
||||
{
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.ReadingDirection"/>
|
||||
[Required]
|
||||
public ReadingDirection ReadingDirection { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.ScalingOption"/>
|
||||
[Required]
|
||||
public ScalingOption ScalingOption { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.PageSplitOption"/>
|
||||
[Required]
|
||||
public PageSplitOption PageSplitOption { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.ReaderMode"/>
|
||||
[Required]
|
||||
public ReaderMode ReaderMode { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.LayoutMode"/>
|
||||
[Required]
|
||||
public LayoutMode LayoutMode { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.EmulateBook"/>
|
||||
[Required]
|
||||
public bool EmulateBook { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BackgroundColor"/>
|
||||
[Required]
|
||||
public string BackgroundColor { get; set; } = "#000000";
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.SwipeToPaginate"/>
|
||||
[Required]
|
||||
public bool SwipeToPaginate { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.AutoCloseMenu"/>
|
||||
[Required]
|
||||
public bool AutoCloseMenu { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.ShowScreenHints"/>
|
||||
[Required]
|
||||
public bool ShowScreenHints { get; set; } = true;
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.AllowAutomaticWebtoonReaderDetection"/>
|
||||
[Required]
|
||||
public bool AllowAutomaticWebtoonReaderDetection { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BookReaderMargin"/>
|
||||
[Required]
|
||||
public int BookReaderMargin { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BookReaderLineSpacing"/>
|
||||
[Required]
|
||||
public int BookReaderLineSpacing { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BookReaderFontSize"/>
|
||||
[Required]
|
||||
public int BookReaderFontSize { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BookReaderFontFamily"/>
|
||||
[Required]
|
||||
public string BookReaderFontFamily { get; set; } = null!;
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BookReaderTapToPaginate"/>
|
||||
[Required]
|
||||
public bool BookReaderTapToPaginate { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BookReaderReadingDirection"/>
|
||||
[Required]
|
||||
public ReadingDirection BookReaderReadingDirection { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BookReaderWritingStyle"/>
|
||||
[Required]
|
||||
public WritingStyle BookReaderWritingStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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!;
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BookReaderLayoutMode"/>
|
||||
[Required]
|
||||
public BookPageLayoutMode BookReaderLayoutMode { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BookReaderImmersiveMode"/>
|
||||
[Required]
|
||||
public bool BookReaderImmersiveMode { get; set; } = false;
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.GlobalPageLayoutMode"/>
|
||||
[Required]
|
||||
public PageLayoutMode GlobalPageLayoutMode { get; set; } = PageLayoutMode.Cards;
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.BlurUnreadSummaries"/>
|
||||
[Required]
|
||||
|
@ -101,16 +37,6 @@ public sealed record UserPreferencesDto
|
|||
[Required]
|
||||
public string Locale { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.PdfTheme"/>
|
||||
[Required]
|
||||
public PdfTheme PdfTheme { get; set; } = PdfTheme.Dark;
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.PdfScrollMode"/>
|
||||
[Required]
|
||||
public PdfScrollMode PdfScrollMode { get; set; } = PdfScrollMode.Vertical;
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.PdfSpreadMode"/>
|
||||
[Required]
|
||||
public PdfSpreadMode PdfSpreadMode { get; set; } = PdfSpreadMode.None;
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.AniListScrobblingEnabled"/>
|
||||
public bool AniListScrobblingEnabled { get; set; }
|
||||
/// <inheritdoc cref="API.Entities.AppUserPreferences.WantToReadSync"/>
|
||||
|
|
132
API/DTOs/UserReadingProfileDto.cs
Normal file
132
API/DTOs/UserReadingProfileDto.cs
Normal file
|
@ -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
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.ReadingDirection"/>
|
||||
[Required]
|
||||
public ReadingDirection ReadingDirection { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.ScalingOption"/>
|
||||
[Required]
|
||||
public ScalingOption ScalingOption { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.PageSplitOption"/>
|
||||
[Required]
|
||||
public PageSplitOption PageSplitOption { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.ReaderMode"/>
|
||||
[Required]
|
||||
public ReaderMode ReaderMode { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.AutoCloseMenu"/>
|
||||
[Required]
|
||||
public bool AutoCloseMenu { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.ShowScreenHints"/>
|
||||
[Required]
|
||||
public bool ShowScreenHints { get; set; } = true;
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.EmulateBook"/>
|
||||
[Required]
|
||||
public bool EmulateBook { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.LayoutMode"/>
|
||||
[Required]
|
||||
public LayoutMode LayoutMode { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.BackgroundColor"/>
|
||||
[Required]
|
||||
public string BackgroundColor { get; set; } = "#000000";
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.SwipeToPaginate"/>
|
||||
[Required]
|
||||
public bool SwipeToPaginate { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.AllowAutomaticWebtoonReaderDetection"/>
|
||||
[Required]
|
||||
public bool AllowAutomaticWebtoonReaderDetection { get; set; }
|
||||
|
||||
/// <inheritdoc cref="AppUserReadingProfile.WidthOverride"/>
|
||||
public int? WidthOverride { get; set; }
|
||||
|
||||
/// <inheritdoc cref="AppUserReadingProfile.DisableWidthOverride"/>
|
||||
public BreakPoint DisableWidthOverride { get; set; } = BreakPoint.Never;
|
||||
|
||||
#endregion
|
||||
|
||||
#region EpubReader
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.BookReaderMargin"/>
|
||||
[Required]
|
||||
public int BookReaderMargin { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.BookReaderLineSpacing"/>
|
||||
[Required]
|
||||
public int BookReaderLineSpacing { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.BookReaderFontSize"/>
|
||||
[Required]
|
||||
public int BookReaderFontSize { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.BookReaderFontFamily"/>
|
||||
[Required]
|
||||
public string BookReaderFontFamily { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.BookReaderTapToPaginate"/>
|
||||
[Required]
|
||||
public bool BookReaderTapToPaginate { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.BookReaderReadingDirection"/>
|
||||
[Required]
|
||||
public ReadingDirection BookReaderReadingDirection { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.BookReaderWritingStyle"/>
|
||||
[Required]
|
||||
public WritingStyle BookReaderWritingStyle { get; set; }
|
||||
|
||||
/// <inheritdoc cref="AppUserReadingProfile.BookThemeName"/>
|
||||
[Required]
|
||||
public string BookReaderThemeName { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.BookReaderLayoutMode"/>
|
||||
[Required]
|
||||
public BookPageLayoutMode BookReaderLayoutMode { get; set; }
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.BookReaderImmersiveMode"/>
|
||||
[Required]
|
||||
public bool BookReaderImmersiveMode { get; set; } = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PdfReader
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.PdfTheme"/>
|
||||
[Required]
|
||||
public PdfTheme PdfTheme { get; set; } = PdfTheme.Dark;
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.PdfScrollMode"/>
|
||||
[Required]
|
||||
public PdfScrollMode PdfScrollMode { get; set; } = PdfScrollMode.Vertical;
|
||||
|
||||
/// <inheritdoc cref="API.Entities.AppUserReadingProfile.PdfSpreadMode"/>
|
||||
[Required]
|
||||
public PdfSpreadMode PdfSpreadMode { get; set; } = PdfSpreadMode.None;
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
|
@ -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,7 +41,7 @@ public sealed class DataContext : IdentityDbContext<AppUser, AppRole, int,
|
|||
public DbSet<ServerSetting> ServerSetting { get; set; } = null!;
|
||||
public DbSet<AppUserPreferences> AppUserPreferences { get; set; } = null!;
|
||||
public DbSet<SeriesMetadata> SeriesMetadata { get; set; } = null!;
|
||||
[Obsolete]
|
||||
[Obsolete("Use AppUserCollection")]
|
||||
public DbSet<CollectionTag> CollectionTag { get; set; } = null!;
|
||||
public DbSet<AppUserBookmark> AppUserBookmark { get; set; } = null!;
|
||||
public DbSet<ReadingList> ReadingList { get; set; } = null!;
|
||||
|
@ -72,7 +70,7 @@ public sealed class DataContext : IdentityDbContext<AppUser, AppRole, int,
|
|||
public DbSet<ExternalSeriesMetadata> ExternalSeriesMetadata { get; set; } = null!;
|
||||
public DbSet<ExternalRecommendation> ExternalRecommendation { get; set; } = null!;
|
||||
public DbSet<ManualMigrationHistory> ManualMigrationHistory { get; set; } = null!;
|
||||
[Obsolete]
|
||||
[Obsolete("Use IsBlacklisted field on Series")]
|
||||
public DbSet<SeriesBlacklist> SeriesBlacklist { get; set; } = null!;
|
||||
public DbSet<AppUserCollection> AppUserCollection { get; set; } = null!;
|
||||
public DbSet<ChapterPeople> ChapterPeople { get; set; } = null!;
|
||||
|
@ -81,6 +79,7 @@ public sealed class DataContext : IdentityDbContext<AppUser, AppRole, int,
|
|||
public DbSet<MetadataSettings> MetadataSettings { get; set; } = null!;
|
||||
public DbSet<MetadataFieldMapping> MetadataFieldMapping { get; set; } = null!;
|
||||
public DbSet<AppUserChapterRating> AppUserChapterRating { get; set; } = null!;
|
||||
public DbSet<AppUserReadingProfile> AppUserReadingProfiles { get; set; } = null!;
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
|
@ -146,6 +145,9 @@ public sealed class DataContext : IdentityDbContext<AppUser, AppRole, int,
|
|||
builder.Entity<Library>()
|
||||
.Property(b => b.AllowMetadataMatching)
|
||||
.HasDefaultValue(true);
|
||||
builder.Entity<Library>()
|
||||
.Property(b => b.EnableMetadata)
|
||||
.HasDefaultValue(true);
|
||||
|
||||
builder.Entity<Chapter>()
|
||||
.Property(b => b.WebLinks)
|
||||
|
@ -256,6 +258,48 @@ public sealed class DataContext : IdentityDbContext<AppUser, AppRole, int,
|
|||
builder.Entity<MetadataSettings>()
|
||||
.Property(b => b.EnableCoverImage)
|
||||
.HasDefaultValue(true);
|
||||
|
||||
builder.Entity<AppUserReadingProfile>()
|
||||
.Property(b => b.BookThemeName)
|
||||
.HasDefaultValue("Dark");
|
||||
builder.Entity<AppUserReadingProfile>()
|
||||
.Property(b => b.BackgroundColor)
|
||||
.HasDefaultValue("#000000");
|
||||
builder.Entity<AppUserReadingProfile>()
|
||||
.Property(b => b.BookReaderWritingStyle)
|
||||
.HasDefaultValue(WritingStyle.Horizontal);
|
||||
builder.Entity<AppUserReadingProfile>()
|
||||
.Property(b => b.AllowAutomaticWebtoonReaderDetection)
|
||||
.HasDefaultValue(true);
|
||||
|
||||
builder.Entity<AppUserReadingProfile>()
|
||||
.Property(rp => rp.LibraryIds)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
|
||||
v => JsonSerializer.Deserialize<List<int>>(v, JsonSerializerOptions.Default) ?? new List<int>())
|
||||
.HasColumnType("TEXT");
|
||||
builder.Entity<AppUserReadingProfile>()
|
||||
.Property(rp => rp.SeriesIds)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
|
||||
v => JsonSerializer.Deserialize<List<int>>(v, JsonSerializerOptions.Default) ?? new List<int>())
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
builder.Entity<SeriesMetadata>()
|
||||
.Property(sm => sm.KPlusOverrides)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
|
||||
v => JsonSerializer.Deserialize<IList<MetadataSettingField>>(v, JsonSerializerOptions.Default) ??
|
||||
new List<MetadataSettingField>())
|
||||
.HasColumnType("TEXT")
|
||||
.HasDefaultValue(new List<MetadataSettingField>());
|
||||
builder.Entity<Chapter>()
|
||||
.Property(sm => sm.KPlusOverrides)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
|
||||
v => JsonSerializer.Deserialize<IList<MetadataSettingField>>(v, JsonSerializerOptions.Default) ?? new List<MetadataSettingField>())
|
||||
.HasColumnType("TEXT")
|
||||
.HasDefaultValue(new List<MetadataSettingField>());
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
|
|
|
@ -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<Program> 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");
|
||||
|
||||
}
|
||||
}
|
3574
API/Data/Migrations/20250519151126_KoreaderHash.Designer.cs
generated
Normal file
3574
API/Data/Migrations/20250519151126_KoreaderHash.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
28
API/Data/Migrations/20250519151126_KoreaderHash.cs
Normal file
28
API/Data/Migrations/20250519151126_KoreaderHash.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class KoreaderHash : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "KoreaderHash",
|
||||
table: "MangaFile",
|
||||
type: "TEXT",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "KoreaderHash",
|
||||
table: "MangaFile");
|
||||
}
|
||||
}
|
||||
}
|
3698
API/Data/Migrations/20250601200056_ReadingProfiles.Designer.cs
generated
Normal file
3698
API/Data/Migrations/20250601200056_ReadingProfiles.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
75
API/Data/Migrations/20250601200056_ReadingProfiles.cs
Normal file
75
API/Data/Migrations/20250601200056_ReadingProfiles.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ReadingProfiles : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AppUserReadingProfiles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Name = table.Column<string>(type: "TEXT", nullable: true),
|
||||
NormalizedName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
AppUserId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Kind = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
LibraryIds = table.Column<string>(type: "TEXT", nullable: true),
|
||||
SeriesIds = table.Column<string>(type: "TEXT", nullable: true),
|
||||
ReadingDirection = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ScalingOption = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PageSplitOption = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ReaderMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
AutoCloseMenu = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
ShowScreenHints = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
EmulateBook = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
LayoutMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BackgroundColor = table.Column<string>(type: "TEXT", nullable: true, defaultValue: "#000000"),
|
||||
SwipeToPaginate = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
AllowAutomaticWebtoonReaderDetection = table.Column<bool>(type: "INTEGER", nullable: false, defaultValue: true),
|
||||
WidthOverride = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
BookReaderMargin = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderLineSpacing = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderFontSize = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderFontFamily = table.Column<string>(type: "TEXT", nullable: true),
|
||||
BookReaderTapToPaginate = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
BookReaderReadingDirection = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderWritingStyle = table.Column<int>(type: "INTEGER", nullable: false, defaultValue: 0),
|
||||
BookThemeName = table.Column<string>(type: "TEXT", nullable: true, defaultValue: "Dark"),
|
||||
BookReaderLayoutMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderImmersiveMode = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
PdfTheme = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PdfScrollMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PdfSpreadMode = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AppUserReadingProfiles", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AppUserReadingProfiles_AspNetUsers_AppUserId",
|
||||
column: x => x.AppUserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AppUserReadingProfiles_AppUserId",
|
||||
table: "AppUserReadingProfiles",
|
||||
column: "AppUserId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AppUserReadingProfiles");
|
||||
}
|
||||
}
|
||||
}
|
3701
API/Data/Migrations/20250610210618_AppUserReadingProfileDisableWidthOverrideBreakPoint.Designer.cs
generated
Normal file
3701
API/Data/Migrations/20250610210618_AppUserReadingProfileDisableWidthOverrideBreakPoint.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,29 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AppUserReadingProfileDisableWidthOverrideBreakPoint : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "DisableWidthOverride",
|
||||
table: "AppUserReadingProfiles",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DisableWidthOverride",
|
||||
table: "AppUserReadingProfiles");
|
||||
}
|
||||
}
|
||||
}
|
3709
API/Data/Migrations/20250620215058_EnableMetadataLibrary.Designer.cs
generated
Normal file
3709
API/Data/Migrations/20250620215058_EnableMetadataLibrary.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
29
API/Data/Migrations/20250620215058_EnableMetadataLibrary.cs
Normal file
29
API/Data/Migrations/20250620215058_EnableMetadataLibrary.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class EnableMetadataLibrary : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "EnableMetadata",
|
||||
table: "Library",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "EnableMetadata",
|
||||
table: "Library");
|
||||
}
|
||||
}
|
||||
}
|
3721
API/Data/Migrations/20250626162548_TrackKavitaPlusMetadata.Designer.cs
generated
Normal file
3721
API/Data/Migrations/20250626162548_TrackKavitaPlusMetadata.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,40 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class TrackKavitaPlusMetadata : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "KPlusOverrides",
|
||||
table: "SeriesMetadata",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
defaultValue: "[]");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "KPlusOverrides",
|
||||
table: "Chapter",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
defaultValue: "[]");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "KPlusOverrides",
|
||||
table: "SeriesMetadata");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "KPlusOverrides",
|
||||
table: "Chapter");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
// <auto-generated />
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using API.Data;
|
||||
using API.Entities.MetadataMatching;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
@ -15,7 +17,7 @@ namespace API.Data.Migrations
|
|||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.4");
|
||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.6");
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppRole", b =>
|
||||
{
|
||||
|
@ -612,6 +614,123 @@ namespace API.Data.Migrations
|
|||
b.ToTable("AppUserRating");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserReadingProfile", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("AllowAutomaticWebtoonReaderDetection")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
.HasDefaultValue(true);
|
||||
|
||||
b.Property<int>("AppUserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("AutoCloseMenu")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("BackgroundColor")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasDefaultValue("#000000");
|
||||
|
||||
b.Property<string>("BookReaderFontFamily")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("BookReaderFontSize")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("BookReaderImmersiveMode")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("BookReaderLayoutMode")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("BookReaderLineSpacing")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("BookReaderMargin")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("BookReaderReadingDirection")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("BookReaderTapToPaginate")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("BookReaderWritingStyle")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
.HasDefaultValue(0);
|
||||
|
||||
b.Property<string>("BookThemeName")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasDefaultValue("Dark");
|
||||
|
||||
b.Property<int>("DisableWidthOverride")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("EmulateBook")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Kind")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("LayoutMode")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("LibraryIds")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NormalizedName")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("PageSplitOption")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("PdfScrollMode")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("PdfSpreadMode")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("PdfTheme")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ReaderMode")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ReadingDirection")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ScalingOption")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("SeriesIds")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("ShowScreenHints")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("SwipeToPaginate")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("WidthOverride")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AppUserId");
|
||||
|
||||
b.ToTable("AppUserReadingProfiles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserRole", b =>
|
||||
{
|
||||
b.Property<int>("UserId")
|
||||
|
@ -843,6 +962,11 @@ namespace API.Data.Migrations
|
|||
b.Property<bool>("IsSpecial")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("KPlusOverrides")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasDefaultValue("[]");
|
||||
|
||||
b.Property<string>("Language")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
|
@ -1182,6 +1306,11 @@ namespace API.Data.Migrations
|
|||
b.Property<DateTime>("CreatedUtc")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("EnableMetadata")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
.HasDefaultValue(true);
|
||||
|
||||
b.Property<bool>("FolderWatching")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
|
@ -1294,6 +1423,9 @@ namespace API.Data.Migrations
|
|||
b.Property<int>("Format")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("KoreaderHash")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastFileAnalysis")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
|
@ -1561,6 +1693,11 @@ namespace API.Data.Migrations
|
|||
b.Property<bool>("InkerLocked")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("KPlusOverrides")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasDefaultValue("[]");
|
||||
|
||||
b.Property<string>("Language")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
|
@ -2841,6 +2978,17 @@ namespace API.Data.Migrations
|
|||
b.Navigation("Series");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserReadingProfile", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.AppUser", "AppUser")
|
||||
.WithMany("ReadingProfiles")
|
||||
.HasForeignKey("AppUserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AppUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserRole", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.AppRole", "Role")
|
||||
|
@ -3479,6 +3627,8 @@ namespace API.Data.Migrations
|
|||
|
||||
b.Navigation("ReadingLists");
|
||||
|
||||
b.Navigation("ReadingProfiles");
|
||||
|
||||
b.Navigation("ScrobbleHolds");
|
||||
|
||||
b.Navigation("SideNavStreams");
|
||||
|
|
112
API/Data/Repositories/AppUserReadingProfileRepository.cs
Normal file
112
API/Data/Repositories/AppUserReadingProfileRepository.cs
Normal file
|
@ -0,0 +1,112 @@
|
|||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Extensions;
|
||||
using API.Extensions.QueryExtensions;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Data.Repositories;
|
||||
|
||||
|
||||
public interface IAppUserReadingProfileRepository
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Return the given profile if it belongs the user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="profileId"></param>
|
||||
/// <returns></returns>
|
||||
Task<AppUserReadingProfile?> GetUserProfile(int userId, int profileId);
|
||||
/// <summary>
|
||||
/// Returns all reading profiles for the user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<IList<AppUserReadingProfile>> GetProfilesForUser(int userId, bool skipImplicit = false);
|
||||
/// <summary>
|
||||
/// Returns all reading profiles for the user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<IList<UserReadingProfileDto>> GetProfilesDtoForUser(int userId, bool skipImplicit = false);
|
||||
/// <summary>
|
||||
/// Is there a user reading profile with this name (normalized)
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> IsProfileNameInUse(int userId, string name);
|
||||
|
||||
void Add(AppUserReadingProfile readingProfile);
|
||||
void Update(AppUserReadingProfile readingProfile);
|
||||
void Remove(AppUserReadingProfile readingProfile);
|
||||
void RemoveRange(IEnumerable<AppUserReadingProfile> readingProfiles);
|
||||
}
|
||||
|
||||
public class AppUserReadingProfileRepository(DataContext context, IMapper mapper): IAppUserReadingProfileRepository
|
||||
{
|
||||
public async Task<AppUserReadingProfile?> GetUserProfile(int userId, int profileId)
|
||||
{
|
||||
return await context.AppUserReadingProfiles
|
||||
.Where(rp => rp.AppUserId == userId && rp.Id == profileId)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<IList<AppUserReadingProfile>> GetProfilesForUser(int userId, bool skipImplicit = false)
|
||||
{
|
||||
return await context.AppUserReadingProfiles
|
||||
.Where(rp => rp.AppUserId == userId)
|
||||
.WhereIf(skipImplicit, rp => rp.Kind != ReadingProfileKind.Implicit)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all Reading Profiles for the User
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IList<UserReadingProfileDto>> GetProfilesDtoForUser(int userId, bool skipImplicit = false)
|
||||
{
|
||||
return await context.AppUserReadingProfiles
|
||||
.Where(rp => rp.AppUserId == userId)
|
||||
.WhereIf(skipImplicit, rp => rp.Kind != ReadingProfileKind.Implicit)
|
||||
.ProjectTo<UserReadingProfileDto>(mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> IsProfileNameInUse(int userId, string name)
|
||||
{
|
||||
var normalizedName = name.ToNormalized();
|
||||
|
||||
return await context.AppUserReadingProfiles
|
||||
.Where(rp => rp.NormalizedName == normalizedName && rp.AppUserId == userId)
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
public void Add(AppUserReadingProfile readingProfile)
|
||||
{
|
||||
context.AppUserReadingProfiles.Add(readingProfile);
|
||||
}
|
||||
|
||||
public void Update(AppUserReadingProfile readingProfile)
|
||||
{
|
||||
context.AppUserReadingProfiles.Update(readingProfile).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
public void Remove(AppUserReadingProfile readingProfile)
|
||||
{
|
||||
context.AppUserReadingProfiles.Remove(readingProfile);
|
||||
}
|
||||
|
||||
public void RemoveRange(IEnumerable<AppUserReadingProfile> readingProfiles)
|
||||
{
|
||||
context.AppUserReadingProfiles.RemoveRange(readingProfiles);
|
||||
}
|
||||
}
|
|
@ -108,14 +108,17 @@ public class ExternalSeriesMetadataRepository : IExternalSeriesMetadataRepositor
|
|||
|
||||
public async Task<bool> NeedsDataRefresh(int seriesId)
|
||||
{
|
||||
// TODO: Add unit test
|
||||
var row = await _context.ExternalSeriesMetadata
|
||||
.Where(s => s.SeriesId == seriesId)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return row == null || row.ValidUntilUtc <= DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public async Task<SeriesDetailPlusDto?> GetSeriesDetailPlusDto(int seriesId)
|
||||
{
|
||||
// TODO: Add unit test
|
||||
var seriesDetailDto = await _context.ExternalSeriesMetadata
|
||||
.Where(m => m.SeriesId == seriesId)
|
||||
.Include(m => m.ExternalRatings)
|
||||
|
@ -144,7 +147,7 @@ public class ExternalSeriesMetadataRepository : IExternalSeriesMetadataRepositor
|
|||
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
|
||||
IEnumerable<UserReviewDto> reviews = new List<UserReviewDto>();
|
||||
IEnumerable<UserReviewDto> reviews = [];
|
||||
if (seriesDetailDto.ExternalReviews != null && seriesDetailDto.ExternalReviews.Any())
|
||||
{
|
||||
reviews = seriesDetailDto.ExternalReviews
|
||||
|
@ -231,6 +234,7 @@ public class ExternalSeriesMetadataRepository : IExternalSeriesMetadataRepositor
|
|||
.Include(s => s.ExternalSeriesMetadata)
|
||||
.Where(s => !ExternalMetadataService.NonEligibleLibraryTypes.Contains(s.Library.Type))
|
||||
.Where(s => s.Library.AllowMetadataMatching)
|
||||
.WhereIf(filter.LibraryType >= 0, s => s.Library.Type == (LibraryType) filter.LibraryType)
|
||||
.FilterMatchState(filter.MatchStateOption)
|
||||
.OrderBy(s => s.NormalizedName)
|
||||
.ProjectTo<ManageMatchSeriesDto>(_mapper.ConfigurationProvider)
|
||||
|
|
|
@ -3,9 +3,11 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs.Metadata;
|
||||
using API.DTOs.Metadata.Browse;
|
||||
using API.Entities;
|
||||
using API.Extensions;
|
||||
using API.Extensions.QueryExtensions;
|
||||
using API.Helpers;
|
||||
using API.Services.Tasks.Scanner.Parser;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
|
@ -27,6 +29,7 @@ public interface IGenreRepository
|
|||
Task<GenreTagDto> GetRandomGenre();
|
||||
Task<GenreTagDto> GetGenreById(int id);
|
||||
Task<List<string>> GetAllGenresNotInListAsync(ICollection<string> genreNames);
|
||||
Task<PagedList<BrowseGenreDto>> GetBrowseableGenre(int userId, UserParams userParams);
|
||||
}
|
||||
|
||||
public class GenreRepository : IGenreRepository
|
||||
|
@ -111,7 +114,7 @@ public class GenreRepository : IGenreRepository
|
|||
|
||||
/// <summary>
|
||||
/// Returns a set of Genre tags for a set of library Ids.
|
||||
/// UserId will restrict returned Genres based on user's age restriction and library access.
|
||||
/// AppUserId will restrict returned Genres based on user's age restriction and library access.
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="libraryIds"></param>
|
||||
|
@ -165,4 +168,38 @@ public class GenreRepository : IGenreRepository
|
|||
// Return the original non-normalized genres for the missing ones
|
||||
return missingGenres.Select(normalizedName => normalizedToOriginalMap[normalizedName]).ToList();
|
||||
}
|
||||
|
||||
public async Task<PagedList<BrowseGenreDto>> GetBrowseableGenre(int userId, UserParams userParams)
|
||||
{
|
||||
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
|
||||
|
||||
var allLibrariesCount = await _context.Library.CountAsync();
|
||||
var userLibs = await _context.Library.GetUserLibraries(userId).ToListAsync();
|
||||
|
||||
var seriesIds = await _context.Series.Where(s => userLibs.Contains(s.LibraryId)).Select(s => s.Id).ToListAsync();
|
||||
|
||||
var query = _context.Genre
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.WhereIf(allLibrariesCount != userLibs.Count,
|
||||
genre => genre.Chapters.Any(cp => seriesIds.Contains(cp.Volume.SeriesId)) ||
|
||||
genre.SeriesMetadatas.Any(sm => seriesIds.Contains(sm.SeriesId)))
|
||||
.Select(g => new BrowseGenreDto
|
||||
{
|
||||
Id = g.Id,
|
||||
Title = g.Title,
|
||||
SeriesCount = g.SeriesMetadatas
|
||||
.Where(sm => allLibrariesCount == userLibs.Count || seriesIds.Contains(sm.SeriesId))
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.Distinct()
|
||||
.Count(),
|
||||
ChapterCount = g.Chapters
|
||||
.Where(cp => allLibrariesCount == userLibs.Count || seriesIds.Contains(cp.Volume.SeriesId))
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.Distinct()
|
||||
.Count(),
|
||||
})
|
||||
.OrderBy(g => g.Title);
|
||||
|
||||
return await PagedList<BrowseGenreDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,13 @@ using API.Entities;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Data.Repositories;
|
||||
#nullable enable
|
||||
|
||||
public interface IMangaFileRepository
|
||||
{
|
||||
void Update(MangaFile file);
|
||||
Task<IList<MangaFile>> GetAllWithMissingExtension();
|
||||
Task<MangaFile?> GetByKoreaderHash(string hash);
|
||||
}
|
||||
|
||||
public class MangaFileRepository : IMangaFileRepository
|
||||
|
@ -32,4 +34,13 @@ public class MangaFileRepository : IMangaFileRepository
|
|||
.Where(f => string.IsNullOrEmpty(f.Extension))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<MangaFile?> GetByKoreaderHash(string hash)
|
||||
{
|
||||
if (string.IsNullOrEmpty(hash)) return null;
|
||||
|
||||
return await _context.MangaFile
|
||||
.FirstOrDefaultAsync(f => f.KoreaderHash != null &&
|
||||
f.KoreaderHash.Equals(hash.ToUpper()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,19 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Data.Misc;
|
||||
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.Entities.Person;
|
||||
using API.Extensions;
|
||||
using API.Extensions.QueryExtensions;
|
||||
using API.Extensions.QueryExtensions.Filtering;
|
||||
using API.Helpers;
|
||||
using API.Helpers.Converters;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
@ -45,7 +51,7 @@ public interface IPersonRepository
|
|||
Task<string?> GetCoverImageAsync(int personId);
|
||||
Task<string?> GetCoverImageByNameAsync(string name);
|
||||
Task<IEnumerable<PersonRole>> GetRolesForPersonByName(int personId, int userId);
|
||||
Task<PagedList<BrowsePersonDto>> GetAllWritersAndSeriesCount(int userId, UserParams userParams);
|
||||
Task<PagedList<BrowsePersonDto>> GetBrowsePersonDtos(int userId, BrowsePersonFilterDto filter, UserParams userParams);
|
||||
Task<Person?> GetPersonById(int personId, PersonIncludes includes = PersonIncludes.None);
|
||||
Task<PersonDto?> GetPersonDtoByName(string name, int userId, PersonIncludes includes = PersonIncludes.Aliases);
|
||||
/// <summary>
|
||||
|
@ -57,7 +63,7 @@ public interface IPersonRepository
|
|||
Task<Person?> GetPersonByNameOrAliasAsync(string name, PersonIncludes includes = PersonIncludes.Aliases);
|
||||
Task<bool> IsNameUnique(string name);
|
||||
|
||||
Task<IEnumerable<SeriesDto>> GetSeriesKnownFor(int personId);
|
||||
Task<IEnumerable<SeriesDto>> GetSeriesKnownFor(int personId, int userId);
|
||||
Task<IEnumerable<StandaloneChapterDto>> GetChaptersForPersonByRole(int personId, int userId, PersonRole role);
|
||||
/// <summary>
|
||||
/// Returns all people with a matching name, or alias
|
||||
|
@ -173,20 +179,25 @@ public class PersonRepository : IPersonRepository
|
|||
public async Task<IEnumerable<PersonRole>> GetRolesForPersonByName(int personId, int userId)
|
||||
{
|
||||
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
|
||||
var userLibs = _context.Library.GetUserLibraries(userId);
|
||||
|
||||
// Query roles from ChapterPeople
|
||||
var chapterRoles = await _context.Person
|
||||
.Where(p => p.Id == personId)
|
||||
.SelectMany(p => p.ChapterPeople)
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.SelectMany(p => p.ChapterPeople.Select(cp => cp.Role))
|
||||
.RestrictByLibrary(userLibs)
|
||||
.Select(cp => cp.Role)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
// Query roles from SeriesMetadataPeople
|
||||
var seriesRoles = await _context.Person
|
||||
.Where(p => p.Id == personId)
|
||||
.SelectMany(p => p.SeriesMetadataPeople)
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.SelectMany(p => p.SeriesMetadataPeople.Select(smp => smp.Role))
|
||||
.RestrictByLibrary(userLibs)
|
||||
.Select(smp => smp.Role)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
|
@ -194,34 +205,89 @@ public class PersonRepository : IPersonRepository
|
|||
return chapterRoles.Union(seriesRoles).Distinct();
|
||||
}
|
||||
|
||||
public async Task<PagedList<BrowsePersonDto>> GetAllWritersAndSeriesCount(int userId, UserParams userParams)
|
||||
public async Task<PagedList<BrowsePersonDto>> GetBrowsePersonDtos(int userId, BrowsePersonFilterDto filter, UserParams userParams)
|
||||
{
|
||||
List<PersonRole> roles = [PersonRole.Writer, PersonRole.CoverArtist];
|
||||
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
|
||||
|
||||
var query = _context.Person
|
||||
.Where(p => p.SeriesMetadataPeople.Any(smp => roles.Contains(smp.Role)) || p.ChapterPeople.Any(cmp => roles.Contains(cmp.Role)))
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.Select(p => new BrowsePersonDto
|
||||
var query = await CreateFilteredPersonQueryable(userId, filter, ageRating);
|
||||
|
||||
return await PagedList<BrowsePersonDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);
|
||||
}
|
||||
|
||||
private async Task<IQueryable<BrowsePersonDto>> CreateFilteredPersonQueryable(int userId, BrowsePersonFilterDto filter, AgeRestriction ageRating)
|
||||
{
|
||||
var allLibrariesCount = await _context.Library.CountAsync();
|
||||
var userLibs = await _context.Library.GetUserLibraries(userId).ToListAsync();
|
||||
|
||||
var seriesIds = await _context.Series.Where(s => userLibs.Contains(s.LibraryId)).Select(s => s.Id).ToListAsync();
|
||||
|
||||
var query = _context.Person.AsNoTracking();
|
||||
|
||||
// Apply filtering based on statements
|
||||
query = BuildPersonFilterQuery(userId, filter, query);
|
||||
|
||||
// Apply restrictions
|
||||
query = query.RestrictAgainstAgeRestriction(ageRating)
|
||||
.WhereIf(allLibrariesCount != userLibs.Count,
|
||||
person => person.ChapterPeople.Any(cp => seriesIds.Contains(cp.Chapter.Volume.SeriesId)) ||
|
||||
person.SeriesMetadataPeople.Any(smp => seriesIds.Contains(smp.SeriesMetadata.SeriesId)));
|
||||
|
||||
// Apply sorting and limiting
|
||||
var sortedQuery = query.SortBy(filter.SortOptions);
|
||||
|
||||
var limitedQuery = ApplyPersonLimit(sortedQuery, filter.LimitTo);
|
||||
|
||||
return limitedQuery.Select(p => new BrowsePersonDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Name,
|
||||
Description = p.Description,
|
||||
CoverImage = p.CoverImage,
|
||||
SeriesCount = p.SeriesMetadataPeople
|
||||
.Where(smp => roles.Contains(smp.Role))
|
||||
.Select(smp => smp.SeriesMetadata.SeriesId)
|
||||
.Select(smp => smp.SeriesMetadata)
|
||||
.Where(sm => allLibrariesCount == userLibs.Count || seriesIds.Contains(sm.SeriesId))
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.Distinct()
|
||||
.Count(),
|
||||
IssueCount = p.ChapterPeople
|
||||
.Where(cp => roles.Contains(cp.Role))
|
||||
.Select(cp => cp.Chapter.Id)
|
||||
ChapterCount = p.ChapterPeople
|
||||
.Select(chp => chp.Chapter)
|
||||
.Where(ch => allLibrariesCount == userLibs.Count || seriesIds.Contains(ch.Volume.SeriesId))
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.Distinct()
|
||||
.Count()
|
||||
})
|
||||
.OrderBy(p => p.Name);
|
||||
.Count(),
|
||||
});
|
||||
}
|
||||
|
||||
return await PagedList<BrowsePersonDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);
|
||||
private static IQueryable<Person> BuildPersonFilterQuery(int userId, BrowsePersonFilterDto filterDto, IQueryable<Person> query)
|
||||
{
|
||||
if (filterDto.Statements == null || filterDto.Statements.Count == 0) return query;
|
||||
|
||||
var queries = filterDto.Statements
|
||||
.Select(statement => BuildPersonFilterGroup(userId, statement, query))
|
||||
.ToList();
|
||||
|
||||
return filterDto.Combination == FilterCombination.And
|
||||
? queries.Aggregate((q1, q2) => q1.Intersect(q2))
|
||||
: queries.Aggregate((q1, q2) => q1.Union(q2));
|
||||
}
|
||||
|
||||
private static IQueryable<Person> BuildPersonFilterGroup(int userId, PersonFilterStatementDto statement, IQueryable<Person> query)
|
||||
{
|
||||
var value = PersonFilterFieldValueConverter.ConvertValue(statement.Field, statement.Value);
|
||||
|
||||
return statement.Field switch
|
||||
{
|
||||
PersonFilterField.Name => query.HasPersonName(true, statement.Comparison, (string)value),
|
||||
PersonFilterField.Role => query.HasPersonRole(true, statement.Comparison, (IList<PersonRole>)value),
|
||||
PersonFilterField.SeriesCount => query.HasPersonSeriesCount(true, statement.Comparison, (int)value),
|
||||
PersonFilterField.ChapterCount => query.HasPersonChapterCount(true, statement.Comparison, (int)value),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(statement.Field), $"Unexpected value for field: {statement.Field}")
|
||||
};
|
||||
}
|
||||
|
||||
private static IQueryable<Person> ApplyPersonLimit(IQueryable<Person> query, int limit)
|
||||
{
|
||||
return limit <= 0 ? query : query.Take(limit);
|
||||
}
|
||||
|
||||
public async Task<Person?> GetPersonById(int personId, PersonIncludes includes = PersonIncludes.None)
|
||||
|
@ -235,11 +301,13 @@ public class PersonRepository : IPersonRepository
|
|||
{
|
||||
var normalized = name.ToNormalized();
|
||||
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
|
||||
var userLibs = _context.Library.GetUserLibraries(userId);
|
||||
|
||||
return await _context.Person
|
||||
.Where(p => p.NormalizedName == normalized)
|
||||
.Includes(includes)
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.RestrictByLibrary(userLibs)
|
||||
.ProjectTo<PersonDto>(_mapper.ConfigurationProvider)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
@ -261,14 +329,18 @@ public class PersonRepository : IPersonRepository
|
|||
.AnyAsync(p => p.Name == name || p.Aliases.Any(pa => pa.Alias == name)));
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SeriesDto>> GetSeriesKnownFor(int personId)
|
||||
public async Task<IEnumerable<SeriesDto>> GetSeriesKnownFor(int personId, int userId)
|
||||
{
|
||||
List<PersonRole> notValidRoles = [PersonRole.Location, PersonRole.Team, PersonRole.Other, PersonRole.Publisher, PersonRole.Translator];
|
||||
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
|
||||
var userLibs = await _context.Library.GetUserLibraries(userId).ToListAsync();
|
||||
|
||||
return await _context.Person
|
||||
.Where(p => p.Id == personId)
|
||||
.SelectMany(p => p.SeriesMetadataPeople.Where(smp => !notValidRoles.Contains(smp.Role)))
|
||||
.SelectMany(p => p.SeriesMetadataPeople)
|
||||
.Select(smp => smp.SeriesMetadata)
|
||||
.Select(sm => sm.Series)
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.Where(s => userLibs.Contains(s.LibraryId))
|
||||
.Distinct()
|
||||
.OrderByDescending(s => s.ExternalSeriesMetadata.AverageExternalRating)
|
||||
.Take(20)
|
||||
|
@ -279,11 +351,13 @@ public class PersonRepository : IPersonRepository
|
|||
public async Task<IEnumerable<StandaloneChapterDto>> GetChaptersForPersonByRole(int personId, int userId, PersonRole role)
|
||||
{
|
||||
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
|
||||
var userLibs = _context.Library.GetUserLibraries(userId);
|
||||
|
||||
return await _context.ChapterPeople
|
||||
.Where(cp => cp.PersonId == personId && cp.Role == role)
|
||||
.Select(cp => cp.Chapter)
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.RestrictByLibrary(userLibs)
|
||||
.OrderBy(ch => ch.SortOrder)
|
||||
.Take(20)
|
||||
.ProjectTo<StandaloneChapterDto>(_mapper.ConfigurationProvider)
|
||||
|
@ -313,8 +387,8 @@ public class PersonRepository : IPersonRepository
|
|||
|
||||
return await _context.Person
|
||||
.Includes(includes)
|
||||
.Where(p => EF.Functions.Like(p.Name, $"%{searchQuery}%")
|
||||
|| p.Aliases.Any(pa => EF.Functions.Like(pa.Alias, $"%{searchQuery}%")))
|
||||
.Where(p => EF.Functions.Like(p.NormalizedName, $"%{searchQuery}%")
|
||||
|| p.Aliases.Any(pa => EF.Functions.Like(pa.NormalizedAlias, $"%{searchQuery}%")))
|
||||
.ProjectTo<PersonDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
@ -334,27 +408,31 @@ public class PersonRepository : IPersonRepository
|
|||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IList<PersonDto>> GetAllPersonDtosAsync(int userId, PersonIncludes includes = PersonIncludes.Aliases)
|
||||
public async Task<IList<PersonDto>> GetAllPersonDtosAsync(int userId, PersonIncludes includes = PersonIncludes.None)
|
||||
{
|
||||
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
|
||||
var userLibs = _context.Library.GetUserLibraries(userId);
|
||||
|
||||
return await _context.Person
|
||||
.Includes(includes)
|
||||
.OrderBy(p => p.Name)
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.RestrictByLibrary(userLibs)
|
||||
.OrderBy(p => p.Name)
|
||||
.ProjectTo<PersonDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IList<PersonDto>> GetAllPersonDtosByRoleAsync(int userId, PersonRole role, PersonIncludes includes = PersonIncludes.Aliases)
|
||||
public async Task<IList<PersonDto>> GetAllPersonDtosByRoleAsync(int userId, PersonRole role, PersonIncludes includes = PersonIncludes.None)
|
||||
{
|
||||
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
|
||||
var userLibs = _context.Library.GetUserLibraries(userId);
|
||||
|
||||
return await _context.Person
|
||||
.Where(p => p.SeriesMetadataPeople.Any(smp => smp.Role == role) || p.ChapterPeople.Any(cp => cp.Role == role)) // Filter by role in both series and chapters
|
||||
.Includes(includes)
|
||||
.OrderBy(p => p.Name)
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.RestrictByLibrary(userLibs)
|
||||
.OrderBy(p => p.Name)
|
||||
.ProjectTo<PersonDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
|
|
@ -29,8 +29,23 @@ public interface IScrobbleRepository
|
|||
Task<IList<ScrobbleError>> GetAllScrobbleErrorsForSeries(int seriesId);
|
||||
Task ClearScrobbleErrors();
|
||||
Task<bool> HasErrorForSeries(int seriesId);
|
||||
Task<ScrobbleEvent?> GetEvent(int userId, int seriesId, ScrobbleEventType eventType);
|
||||
/// <summary>
|
||||
/// Get all events for a specific user and type
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <param name="eventType"></param>
|
||||
/// <param name="isNotProcessed">If true, only returned not processed events</param>
|
||||
/// <returns></returns>
|
||||
Task<ScrobbleEvent?> GetEvent(int userId, int seriesId, ScrobbleEventType eventType, bool isNotProcessed = false);
|
||||
Task<IEnumerable<ScrobbleEvent>> GetUserEventsForSeries(int userId, int seriesId);
|
||||
/// <summary>
|
||||
/// Return the events with given ids, when belonging to the passed user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="scrobbleEventIds"></param>
|
||||
/// <returns></returns>
|
||||
Task<IList<ScrobbleEvent>> GetUserEvents(int userId, IList<long> scrobbleEventIds);
|
||||
Task<PagedList<ScrobbleEventDto>> GetUserEvents(int userId, ScrobbleEventFilter filter, UserParams pagination);
|
||||
Task<IList<ScrobbleEvent>> GetAllEventsForSeries(int seriesId);
|
||||
Task<IList<ScrobbleEvent>> GetAllEventsWithSeriesIds(IEnumerable<int> seriesIds);
|
||||
|
@ -146,22 +161,32 @@ public class ScrobbleRepository : IScrobbleRepository
|
|||
return await _context.ScrobbleError.AnyAsync(n => n.SeriesId == seriesId);
|
||||
}
|
||||
|
||||
public async Task<ScrobbleEvent?> GetEvent(int userId, int seriesId, ScrobbleEventType eventType)
|
||||
public async Task<ScrobbleEvent?> GetEvent(int userId, int seriesId, ScrobbleEventType eventType, bool isNotProcessed = false)
|
||||
{
|
||||
return await _context.ScrobbleEvent.FirstOrDefaultAsync(e =>
|
||||
e.AppUserId == userId && e.SeriesId == seriesId && e.ScrobbleEventType == eventType);
|
||||
return await _context.ScrobbleEvent
|
||||
.Where(e => e.AppUserId == userId && e.SeriesId == seriesId && e.ScrobbleEventType == eventType)
|
||||
.WhereIf(isNotProcessed, e => !e.IsProcessed)
|
||||
.OrderBy(e => e.LastModifiedUtc)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ScrobbleEvent>> GetUserEventsForSeries(int userId, int seriesId)
|
||||
{
|
||||
return await _context.ScrobbleEvent
|
||||
.Where(e => e.AppUserId == userId && !e.IsProcessed)
|
||||
.Where(e => e.AppUserId == userId && !e.IsProcessed && e.SeriesId == seriesId)
|
||||
.Include(e => e.Series)
|
||||
.OrderBy(e => e.LastModifiedUtc)
|
||||
.AsSplitQuery()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IList<ScrobbleEvent>> GetUserEvents(int userId, IList<long> scrobbleEventIds)
|
||||
{
|
||||
return await _context.ScrobbleEvent
|
||||
.Where(e => e.AppUserId == userId && scrobbleEventIds.Contains(e.Id))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<PagedList<ScrobbleEventDto>> GetUserEvents(int userId, ScrobbleEventFilter filter, UserParams pagination)
|
||||
{
|
||||
var query = _context.ScrobbleEvent
|
||||
|
|
|
@ -82,6 +82,7 @@ public interface ISeriesRepository
|
|||
void Attach(Series series);
|
||||
void Attach(SeriesRelation relation);
|
||||
void Update(Series series);
|
||||
void Update(SeriesMetadata seriesMetadata);
|
||||
void Remove(Series series);
|
||||
void Remove(IEnumerable<Series> series);
|
||||
void Detach(Series series);
|
||||
|
@ -219,6 +220,11 @@ public class SeriesRepository : ISeriesRepository
|
|||
_context.Entry(series).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
public void Update(SeriesMetadata seriesMetadata)
|
||||
{
|
||||
_context.Entry(seriesMetadata).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
public void Remove(Series series)
|
||||
{
|
||||
_context.Series.Remove(series);
|
||||
|
@ -735,6 +741,7 @@ public class SeriesRepository : ISeriesRepository
|
|||
{
|
||||
return await _context.Series
|
||||
.Where(s => s.Id == seriesId)
|
||||
.Include(s => s.ExternalSeriesMetadata)
|
||||
.Select(series => new PlusSeriesRequestDto()
|
||||
{
|
||||
MediaFormat = series.Library.Type.ConvertToPlusMediaFormat(series.Format),
|
||||
|
@ -744,6 +751,7 @@ public class SeriesRepository : ISeriesRepository
|
|||
ScrobblingService.AniListWeblinkWebsite),
|
||||
MalId = ScrobblingService.ExtractId<long?>(series.Metadata.WebLinks,
|
||||
ScrobblingService.MalWeblinkWebsite),
|
||||
CbrId = series.ExternalSeriesMetadata.CbrId,
|
||||
GoogleBooksId = ScrobblingService.ExtractId<string?>(series.Metadata.WebLinks,
|
||||
ScrobblingService.GoogleBooksWeblinkWebsite),
|
||||
MangaDexId = ScrobblingService.ExtractId<string?>(series.Metadata.WebLinks,
|
||||
|
@ -1088,8 +1096,6 @@ public class SeriesRepository : ISeriesRepository
|
|||
return query.Where(s => false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// First setup any FilterField.Libraries in the statements, as these don't have any traditional query statements applied here
|
||||
query = ApplyLibraryFilter(filter, query);
|
||||
|
||||
|
@ -1290,7 +1296,7 @@ public class SeriesRepository : ISeriesRepository
|
|||
FilterField.ReadingDate => query.HasReadingDate(true, statement.Comparison, (DateTime) value, userId),
|
||||
FilterField.ReadLast => query.HasReadLast(true, statement.Comparison, (int) value, userId),
|
||||
FilterField.AverageRating => query.HasAverageRating(true, statement.Comparison, (float) value),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(statement.Field), $"Unexpected value for field: {statement.Field}")
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs.Metadata;
|
||||
using API.DTOs.Metadata.Browse;
|
||||
using API.Entities;
|
||||
using API.Extensions;
|
||||
using API.Extensions.QueryExtensions;
|
||||
using API.Helpers;
|
||||
using API.Services.Tasks.Scanner.Parser;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
|
@ -23,6 +25,7 @@ public interface ITagRepository
|
|||
Task RemoveAllTagNoLongerAssociated();
|
||||
Task<IList<TagDto>> GetAllTagDtosForLibrariesAsync(int userId, IList<int>? libraryIds = null);
|
||||
Task<List<string>> GetAllTagsNotInListAsync(ICollection<string> tags);
|
||||
Task<PagedList<BrowseTagDto>> GetBrowseableTag(int userId, UserParams userParams);
|
||||
}
|
||||
|
||||
public class TagRepository : ITagRepository
|
||||
|
@ -104,6 +107,40 @@ public class TagRepository : ITagRepository
|
|||
return missingTags.Select(normalizedName => normalizedToOriginalMap[normalizedName]).ToList();
|
||||
}
|
||||
|
||||
public async Task<PagedList<BrowseTagDto>> GetBrowseableTag(int userId, UserParams userParams)
|
||||
{
|
||||
var ageRating = await _context.AppUser.GetUserAgeRestriction(userId);
|
||||
|
||||
var allLibrariesCount = await _context.Library.CountAsync();
|
||||
var userLibs = await _context.Library.GetUserLibraries(userId).ToListAsync();
|
||||
|
||||
var seriesIds = _context.Series.Where(s => userLibs.Contains(s.LibraryId)).Select(s => s.Id);
|
||||
|
||||
var query = _context.Tag
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.WhereIf(userLibs.Count != allLibrariesCount,
|
||||
tag => tag.Chapters.Any(cp => seriesIds.Contains(cp.Volume.SeriesId)) ||
|
||||
tag.SeriesMetadatas.Any(sm => seriesIds.Contains(sm.SeriesId)))
|
||||
.Select(g => new BrowseTagDto
|
||||
{
|
||||
Id = g.Id,
|
||||
Title = g.Title,
|
||||
SeriesCount = g.SeriesMetadatas
|
||||
.Where(sm => allLibrariesCount == userLibs.Count || seriesIds.Contains(sm.SeriesId))
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.Distinct()
|
||||
.Count(),
|
||||
ChapterCount = g.Chapters
|
||||
.Where(ch => allLibrariesCount == userLibs.Count || seriesIds.Contains(ch.Volume.SeriesId))
|
||||
.RestrictAgainstAgeRestriction(ageRating)
|
||||
.Distinct()
|
||||
.Count()
|
||||
})
|
||||
.OrderBy(g => g.Title);
|
||||
|
||||
return await PagedList<BrowseTagDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);
|
||||
}
|
||||
|
||||
public async Task<IList<Tag>> GetAllTagsAsync()
|
||||
{
|
||||
return await _context.Tag.ToListAsync();
|
||||
|
|
|
@ -768,7 +768,7 @@ public class UserRepository : IUserRepository
|
|||
|
||||
|
||||
/// <summary>
|
||||
/// Fetches the UserId by API Key. This does not include any extra information
|
||||
/// Fetches the AppUserId by API Key. This does not include any extra information
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <returns></returns>
|
||||
|
|
|
@ -120,7 +120,7 @@ public static class Seed
|
|||
new AppUserSideNavStream()
|
||||
{
|
||||
Name = "browse-authors",
|
||||
StreamType = SideNavStreamType.BrowseAuthors,
|
||||
StreamType = SideNavStreamType.BrowsePeople,
|
||||
Order = 6,
|
||||
IsProvided = true,
|
||||
Visible = true
|
||||
|
|
|
@ -33,6 +33,7 @@ public interface IUnitOfWork
|
|||
IAppUserExternalSourceRepository AppUserExternalSourceRepository { get; }
|
||||
IExternalSeriesMetadataRepository ExternalSeriesMetadataRepository { get; }
|
||||
IEmailHistoryRepository EmailHistoryRepository { get; }
|
||||
IAppUserReadingProfileRepository AppUserReadingProfileRepository { get; }
|
||||
bool Commit();
|
||||
Task<bool> CommitAsync();
|
||||
bool HasChanges();
|
||||
|
@ -74,6 +75,7 @@ public class UnitOfWork : IUnitOfWork
|
|||
AppUserExternalSourceRepository = new AppUserExternalSourceRepository(_context, _mapper);
|
||||
ExternalSeriesMetadataRepository = new ExternalSeriesMetadataRepository(_context, _mapper);
|
||||
EmailHistoryRepository = new EmailHistoryRepository(_context, _mapper);
|
||||
AppUserReadingProfileRepository = new AppUserReadingProfileRepository(_context, _mapper);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -103,6 +105,7 @@ public class UnitOfWork : IUnitOfWork
|
|||
public IAppUserExternalSourceRepository AppUserExternalSourceRepository { get; }
|
||||
public IExternalSeriesMetadataRepository ExternalSeriesMetadataRepository { get; }
|
||||
public IEmailHistoryRepository EmailHistoryRepository { get; }
|
||||
public IAppUserReadingProfileRepository AppUserReadingProfileRepository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Commits changes to the DB. Completes the open transaction.
|
||||
|
|
|
@ -21,6 +21,7 @@ public class AppUser : IdentityUser<int>, IHasConcurrencyToken
|
|||
public ICollection<AppUserRating> Ratings { get; set; } = null!;
|
||||
public ICollection<AppUserChapterRating> ChapterRatings { get; set; } = null!;
|
||||
public AppUserPreferences UserPreferences { get; set; } = null!;
|
||||
public ICollection<AppUserReadingProfile> ReadingProfiles { get; set; } = null!;
|
||||
/// <summary>
|
||||
/// Bookmarks associated with this User
|
||||
/// </summary>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using API.Data;
|
||||
using System.Collections.Generic;
|
||||
using API.Data;
|
||||
using API.Entities.Enums;
|
||||
using API.Entities.Enums.UserPreferences;
|
||||
|
||||
|
|
160
API/Entities/AppUserReadingProfile.cs
Normal file
160
API/Entities/AppUserReadingProfile.cs
Normal file
|
@ -0,0 +1,160 @@
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using API.Entities.Enums;
|
||||
using API.Entities.Enums.UserPreferences;
|
||||
|
||||
namespace API.Entities;
|
||||
|
||||
public enum BreakPoint
|
||||
{
|
||||
[Description("Never")]
|
||||
Never = 0,
|
||||
[Description("Mobile")]
|
||||
Mobile = 1,
|
||||
[Description("Tablet")]
|
||||
Tablet = 2,
|
||||
[Description("Desktop")]
|
||||
Desktop = 3,
|
||||
}
|
||||
|
||||
public class AppUserReadingProfile
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public string NormalizedName { get; set; }
|
||||
|
||||
public int AppUserId { get; set; }
|
||||
public AppUser AppUser { get; set; }
|
||||
|
||||
public ReadingProfileKind Kind { get; set; }
|
||||
public List<int> LibraryIds { get; set; }
|
||||
public List<int> SeriesIds { get; set; }
|
||||
|
||||
#region MangaReader
|
||||
|
||||
/// <summary>
|
||||
/// Manga Reader Option: What direction should the next/prev page buttons go
|
||||
/// </summary>
|
||||
public ReadingDirection ReadingDirection { get; set; } = ReadingDirection.LeftToRight;
|
||||
/// <summary>
|
||||
/// Manga Reader Option: How should the image be scaled to screen
|
||||
/// </summary>
|
||||
public ScalingOption ScalingOption { get; set; } = ScalingOption.Automatic;
|
||||
/// <summary>
|
||||
/// Manga Reader Option: Which side of a split image should we show first
|
||||
/// </summary>
|
||||
public PageSplitOption PageSplitOption { get; set; } = PageSplitOption.FitSplit;
|
||||
/// <summary>
|
||||
/// Manga Reader Option: How the manga reader should perform paging or reading of the file
|
||||
/// <example>
|
||||
/// Webtoon uses scrolling to page, MANGA_LR uses paging by clicking left/right side of reader, MANGA_UD uses paging
|
||||
/// by clicking top/bottom sides of reader.
|
||||
/// </example>
|
||||
/// </summary>
|
||||
public ReaderMode ReaderMode { get; set; }
|
||||
/// <summary>
|
||||
/// Manga Reader Option: Allow the menu to close after 6 seconds without interaction
|
||||
/// </summary>
|
||||
public bool AutoCloseMenu { get; set; } = true;
|
||||
/// <summary>
|
||||
/// Manga Reader Option: Show screen hints to the user on some actions, ie) pagination direction change
|
||||
/// </summary>
|
||||
public bool ShowScreenHints { get; set; } = true;
|
||||
/// <summary>
|
||||
/// Manga Reader Option: Emulate a book by applying a shadow effect on the pages
|
||||
/// </summary>
|
||||
public bool EmulateBook { get; set; } = false;
|
||||
/// <summary>
|
||||
/// Manga Reader Option: How many pages to display in the reader at once
|
||||
/// </summary>
|
||||
public LayoutMode LayoutMode { get; set; } = LayoutMode.Single;
|
||||
/// <summary>
|
||||
/// Manga Reader Option: Background color of the reader
|
||||
/// </summary>
|
||||
public string BackgroundColor { get; set; } = "#000000";
|
||||
/// <summary>
|
||||
/// Manga Reader Option: Should swiping trigger pagination
|
||||
/// </summary>
|
||||
public bool SwipeToPaginate { get; set; }
|
||||
/// <summary>
|
||||
/// Manga Reader Option: Allow Automatic Webtoon detection
|
||||
/// </summary>
|
||||
public bool AllowAutomaticWebtoonReaderDetection { get; set; }
|
||||
/// <summary>
|
||||
/// Manga Reader Option: Optional fixed width override
|
||||
/// </summary>
|
||||
public int? WidthOverride { get; set; } = null;
|
||||
/// <summary>
|
||||
/// Manga Reader Option: Disable the width override if the screen is past the breakpoint
|
||||
/// </summary>
|
||||
public BreakPoint DisableWidthOverride { get; set; } = BreakPoint.Never;
|
||||
|
||||
#endregion
|
||||
|
||||
#region EpubReader
|
||||
|
||||
/// <summary>
|
||||
/// Book Reader Option: Override extra Margin
|
||||
/// </summary>
|
||||
public int BookReaderMargin { get; set; } = 15;
|
||||
/// <summary>
|
||||
/// Book Reader Option: Override line-height
|
||||
/// </summary>
|
||||
public int BookReaderLineSpacing { get; set; } = 100;
|
||||
/// <summary>
|
||||
/// Book Reader Option: Override font size
|
||||
/// </summary>
|
||||
public int BookReaderFontSize { get; set; } = 100;
|
||||
/// <summary>
|
||||
/// Book Reader Option: Maps to the default Kavita font-family (inherit) or an override
|
||||
/// </summary>
|
||||
public string BookReaderFontFamily { get; set; } = "default";
|
||||
/// <summary>
|
||||
/// Book Reader Option: Allows tapping on side of screens to paginate
|
||||
/// </summary>
|
||||
public bool BookReaderTapToPaginate { get; set; } = false;
|
||||
/// <summary>
|
||||
/// Book Reader Option: What direction should the next/prev page buttons go
|
||||
/// </summary>
|
||||
public ReadingDirection BookReaderReadingDirection { get; set; } = ReadingDirection.LeftToRight;
|
||||
/// <summary>
|
||||
/// Book Reader Option: Defines the writing styles vertical/horizontal
|
||||
/// </summary>
|
||||
public WritingStyle BookReaderWritingStyle { get; set; } = WritingStyle.Horizontal;
|
||||
/// <summary>
|
||||
/// Book Reader Option: The color theme to decorate the book contents
|
||||
/// </summary>
|
||||
/// <remarks>Should default to Dark</remarks>
|
||||
public string BookThemeName { get; set; } = "Dark";
|
||||
/// <summary>
|
||||
/// Book Reader Option: The way a page from a book is rendered. Default is as book dictates, 1 column is fit to height,
|
||||
/// 2 column is fit to height, 2 columns
|
||||
/// </summary>
|
||||
/// <remarks>Defaults to Default</remarks>
|
||||
public BookPageLayoutMode BookReaderLayoutMode { get; set; } = BookPageLayoutMode.Default;
|
||||
/// <summary>
|
||||
/// Book Reader Option: A flag that hides the menu-ing system behind a click on the screen. This should be used with tap to paginate, but the app doesn't enforce this.
|
||||
/// </summary>
|
||||
/// <remarks>Defaults to false</remarks>
|
||||
public bool BookReaderImmersiveMode { get; set; } = false;
|
||||
#endregion
|
||||
|
||||
#region PdfReader
|
||||
|
||||
/// <summary>
|
||||
/// PDF Reader: Theme of the Reader
|
||||
/// </summary>
|
||||
public PdfTheme PdfTheme { get; set; } = PdfTheme.Dark;
|
||||
/// <summary>
|
||||
/// PDF Reader: Scroll mode of the reader
|
||||
/// </summary>
|
||||
public PdfScrollMode PdfScrollMode { get; set; } = PdfScrollMode.Vertical;
|
||||
/// <summary>
|
||||
/// PDF Reader: Spread Mode of the reader
|
||||
/// </summary>
|
||||
public PdfSpreadMode PdfSpreadMode { get; set; } = PdfSpreadMode.None;
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -4,13 +4,14 @@ using System.Globalization;
|
|||
using API.Entities.Enums;
|
||||
using API.Entities.Interfaces;
|
||||
using API.Entities.Metadata;
|
||||
using API.Entities.MetadataMatching;
|
||||
using API.Entities.Person;
|
||||
using API.Extensions;
|
||||
using API.Services.Tasks.Scanner.Parser;
|
||||
|
||||
namespace API.Entities;
|
||||
|
||||
public class Chapter : IEntityDate, IHasReadTimeEstimate, IHasCoverImage
|
||||
public class Chapter : IEntityDate, IHasReadTimeEstimate, IHasCoverImage, IHasKPlusMetadata
|
||||
{
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
|
@ -126,6 +127,11 @@ public class Chapter : IEntityDate, IHasReadTimeEstimate, IHasCoverImage
|
|||
public string WebLinks { get; set; } = string.Empty;
|
||||
public string ISBN { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Tracks which metadata has been set by K+
|
||||
/// </summary>
|
||||
public IList<MetadataSettingField> KPlusOverrides { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// (Kavita+) Average rating from Kavita+ metadata
|
||||
/// </summary>
|
||||
|
|
17
API/Entities/Enums/ReadingProfileKind.cs
Normal file
17
API/Entities/Enums/ReadingProfileKind.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
namespace API.Entities.Enums;
|
||||
|
||||
public enum ReadingProfileKind
|
||||
{
|
||||
/// <summary>
|
||||
/// Generate by Kavita when registering a user, this is your default profile
|
||||
/// </summary>
|
||||
Default,
|
||||
/// <summary>
|
||||
/// Created by the user in the UI or via the API
|
||||
/// </summary>
|
||||
User,
|
||||
/// <summary>
|
||||
/// Automatically generated by Kavita to track changes made in the readers. Can be converted to a User Reading Profile.
|
||||
/// </summary>
|
||||
Implicit
|
||||
}
|
12
API/Entities/Interfaces/IHasKPlusMetadata.cs
Normal file
12
API/Entities/Interfaces/IHasKPlusMetadata.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using API.Entities.MetadataMatching;
|
||||
|
||||
namespace API.Entities.Interfaces;
|
||||
|
||||
public interface IHasKPlusMetadata
|
||||
{
|
||||
/// <summary>
|
||||
/// Tracks which metadata has been set by K+
|
||||
/// </summary>
|
||||
public IList<MetadataSettingField> KPlusOverrides { get; set; }
|
||||
}
|
|
@ -48,6 +48,10 @@ public class Library : IEntityDate, IHasCoverImage
|
|||
/// <remarks>This does not exclude the library from being linked to wrt Series Relationships</remarks>
|
||||
/// <remarks>Requires a valid LicenseKey</remarks>
|
||||
public bool AllowMetadataMatching { get; set; } = true;
|
||||
/// <summary>
|
||||
/// Should Kavita read metadata files from the library
|
||||
/// </summary>
|
||||
public bool EnableMetadata { get; set; } = true;
|
||||
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
|
|
|
@ -21,6 +21,11 @@ public class MangaFile : IEntityDate
|
|||
/// </summary>
|
||||
public required string FilePath { get; set; }
|
||||
/// <summary>
|
||||
/// A hash of the document using Koreader's unique hashing algorithm
|
||||
/// </summary>
|
||||
/// <remark> KoreaderHash is only available for epub types </remark>
|
||||
public string? KoreaderHash { get; set; }
|
||||
/// <summary>
|
||||
/// Number of pages for the given file
|
||||
/// </summary>
|
||||
public int Pages { get; set; }
|
||||
|
|
|
@ -4,13 +4,14 @@ using System.ComponentModel.DataAnnotations;
|
|||
using System.Linq;
|
||||
using API.Entities.Enums;
|
||||
using API.Entities.Interfaces;
|
||||
using API.Entities.MetadataMatching;
|
||||
using API.Entities.Person;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Entities.Metadata;
|
||||
|
||||
[Index(nameof(Id), nameof(SeriesId), IsUnique = true)]
|
||||
public class SeriesMetadata : IHasConcurrencyToken
|
||||
public class SeriesMetadata : IHasConcurrencyToken, IHasKPlusMetadata
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
@ -42,6 +43,10 @@ public class SeriesMetadata : IHasConcurrencyToken
|
|||
/// </summary>
|
||||
/// <remarks>This is not populated from Chapters of the Series</remarks>
|
||||
public string WebLinks { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// Tracks which metadata has been set by K+
|
||||
/// </summary>
|
||||
public IList<MetadataSettingField> KPlusOverrides { get; set; } = [];
|
||||
|
||||
#region Locks
|
||||
|
||||
|
|
|
@ -68,4 +68,14 @@ public class ScrobbleEvent : IEntityDate
|
|||
public DateTime LastModified { get; set; }
|
||||
public DateTime CreatedUtc { get; set; }
|
||||
public DateTime LastModifiedUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the ErrorDetail and marks the event as <see cref="IsErrored"/>
|
||||
/// </summary>
|
||||
/// <param name="errorMessage"></param>
|
||||
public void SetErrorMessage(string errorMessage)
|
||||
{
|
||||
ErrorDetails = errorMessage;
|
||||
IsErrored = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,5 +10,5 @@ public enum SideNavStreamType
|
|||
ExternalSource = 6,
|
||||
AllSeries = 7,
|
||||
WantToRead = 8,
|
||||
BrowseAuthors = 9
|
||||
BrowsePeople = 9
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue