Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
C# annotationscbzcomicinfocomicscomics-readercross-platformcsharpepubepub-readerfreelinuxmangamedia-servermetadataopdsopds-feedpdfself-hostedubooquitywindows
v0.6.1 - Security Patches + Hotfix (#1647)
Joe Milazzo1a0855a52612
diff --git a/API.Tests/Parser/ComicParserTests.cs b/API.Tests/Parser/ComicParserTests.csindex fa0448ff9..689327d98 100644--- a/API.Tests/Parser/ComicParserTests.cs+++ b/API.Tests/Parser/ComicParserTests.cs@@ -194,7 +194,7 @@ public class ComicParserTests[InlineData("Asterix - HS - Les 12 travaux d'Astérix", true)][InlineData("Sillage Hors Série - Le Collectionneur - Concordance-DKFR", true)][InlineData("laughs", false)]- [InlineData("Annual Days of Summer", false)]+ [InlineData("Annual Days of Summer", true)][InlineData("Adventure Time 2013 Annual #001 (2013)", true)][InlineData("Adventure Time 2013_Annual_#001 (2013)", true)][InlineData("Adventure Time 2013_-_Annual #001 (2013)", true)]@@ -202,6 +202,13 @@ public class ComicParserTests[InlineData("Mazebook 001", false)][InlineData("X-23 One Shot (2010)", true)][InlineData("Casus Belli v1 Hors-Série 21 - Mousquetaires et Sorcellerie", true)]+ [InlineData("Batman Beyond Annual", true)]+ [InlineData("Batman Beyond Bonus", true)]+ [InlineData("Batman Beyond OneShot", true)]+ [InlineData("Batman Beyond Specials", true)]+ [InlineData("Batman Beyond Omnibus (1999)", true)]+ [InlineData("Batman Beyond Omnibus", true)]+ [InlineData("01 Annual Batman Beyond", true)]public void IsComicSpecialTest(string input, bool expected){Assert.Equal(expected, API.Services.Tasks.Scanner.Parser.Parser.IsComicSpecial(input));diff --git a/API.Tests/Parser/DefaultParserTests.cs b/API.Tests/Parser/DefaultParserTests.csindex 2640aa6c2..7f843b552 100644--- a/API.Tests/Parser/DefaultParserTests.cs+++ b/API.Tests/Parser/DefaultParserTests.cs@@ -46,6 +46,7 @@ public class DefaultParserTests[InlineData("/manga/Btooom!/Vol.1/Chapter 1/1.cbz", "Btooom!~1~1")][InlineData("/manga/Btooom!/Vol.1 Chapter 2/1.cbz", "Btooom!~1~2")][InlineData("/manga/Monster/Ch. 001-016 [MangaPlus] [Digital] [amit34521]/Monster Ch. 001 [MangaPlus] [Digital] [amit34521]/13.jpg", "Monster~0~1")]+ [InlineData("/manga/Hajime no Ippo/Artbook/Hajime no Ippo - Artbook.cbz", "Hajime no Ippo~0~0")]public void ParseFromFallbackFolders_ShouldParseSeriesVolumeAndChapter(string inputFile, string expectedParseInfo){const string rootDirectory = "/manga/";@@ -80,6 +81,7 @@ public class DefaultParserTests[Theory][InlineData("/manga/Btooom!/Specials/Art Book.cbz", "Btooom!")]+ [InlineData("/manga/Hajime no Ippo/Artbook/Hajime no Ippo - Artbook.cbz", "Hajime no Ippo")]public void ParseFromFallbackFolders_ShouldUseExistingSeriesName_NewScanLoop(string inputFile, string expectedParseInfo){const string rootDirectory = "/manga/";diff --git a/API.Tests/Parser/MangaParserTests.cs b/API.Tests/Parser/MangaParserTests.csindex 89b1112f5..20c1a27ae 100644--- a/API.Tests/Parser/MangaParserTests.cs+++ b/API.Tests/Parser/MangaParserTests.cs@@ -195,6 +195,7 @@ public class MangaParserTests[InlineData("Манга Глава 2-2", "Манга")][InlineData("Манга Том 1 3-4 Глава", "Манга")][InlineData("Esquire 6권 2021년 10월호", "Esquire")]+ [InlineData("Accel World: Vol 1", "Accel World")]public void ParseSeriesTest(string filename, string expected){Assert.Equal(expected, API.Services.Tasks.Scanner.Parser.Parser.ParseSeries(filename));@@ -314,8 +315,8 @@ public class MangaParserTests[InlineData("Beastars SP01", false)][InlineData("The League of Extraordinary Gentlemen", false)][InlineData("The League of Extra-ordinary Gentlemen", false)]- [InlineData("Gifting The Wonderful World With Blessings! - 3 Side Stories [yuNS][Unknown].epub", true)]- [InlineData("Dr. Ramune - Mysterious Disease Specialist v01 (2020) (Digital) (danke-Empire).cbz", false)]+ [InlineData("Dr. Ramune - Mysterious Disease Specialist v01 (2020) (Digital) (danke-Empire)", false)]+ [InlineData("Hajime no Ippo - Artbook", false)]public void IsMangaSpecialTest(string input, bool expected){Assert.Equal(expected, API.Services.Tasks.Scanner.Parser.Parser.IsMangaSpecial(input));diff --git a/API.Tests/Services/ArchiveServiceTests.cs b/API.Tests/Services/ArchiveServiceTests.csindex f399cb790..b59ee097e 100644--- a/API.Tests/Services/ArchiveServiceTests.cs+++ b/API.Tests/Services/ArchiveServiceTests.cs@@ -281,6 +281,17 @@ public class ArchiveServiceTestsAssert.Equal("BTOOOM! - Duplicate", comicInfo.Series);}+ [Fact]+ public void ShouldHaveComicInfo_OutsideRoot_SharpCompress()+ {+ var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/ComicInfos");+ var archive = Path.Join(testDirectory, "ComicInfo_outside_root_SharpCompress.cb7");++ var comicInfo = _archiveService.GetComicInfo(archive);+ Assert.NotNull(comicInfo);+ Assert.Equal("Fire Punch", comicInfo.Series);+ }+#endregion#region CanParseComicInfodiff --git a/API.Tests/Services/BookServiceTests.cs b/API.Tests/Services/BookServiceTests.csindex 38a5da896..4665ab691 100644--- a/API.Tests/Services/BookServiceTests.cs+++ b/API.Tests/Services/BookServiceTests.cs@@ -54,4 +54,28 @@ public class BookServiceTestsAssert.Equal("Roger Starbuck,Junya Inoue", comicInfo.Writer);}+ [Fact]+ public void ShouldParseAsVolumeGroup_WithoutSeriesIndex()+ {+ var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BookService");+ var archive = Path.Join(testDirectory, "TitleWithVolume_NoSeriesOrSeriesIndex.epub");++ var comicInfo = _bookService.GetComicInfo(archive);+ Assert.NotNull(comicInfo);+ Assert.Equal("1", comicInfo.Volume);+ Assert.Equal("Accel World", comicInfo.Series);+ }++ [Fact]+ public void ShouldParseAsVolumeGroup_WithSeriesIndex()+ {+ var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BookService");+ var archive = Path.Join(testDirectory, "TitleWithVolume.epub");++ var comicInfo = _bookService.GetComicInfo(archive);+ Assert.NotNull(comicInfo);+ Assert.Equal("1.0", comicInfo.Volume);+ Assert.Equal("Accel World", comicInfo.Series);+ }+}diff --git a/API.Tests/Services/DirectoryServiceTests.cs b/API.Tests/Services/DirectoryServiceTests.csindex 254d851fa..134dc2361 100644--- a/API.Tests/Services/DirectoryServiceTests.cs+++ b/API.Tests/Services/DirectoryServiceTests.cs@@ -593,6 +593,23 @@ public class DirectoryServiceTests|| outputFiles.Contains(API.Services.Tasks.Scanner.Parser.Parser.NormalizePath("C:/manga/output/file (3).zip")));}+ [Fact]+ public void CopyFilesToDirectory_ShouldRenameFilesToPassedNames()+ {+ const string testDirectory = "/manga/";+ var fileSystem = new MockFileSystem();+ fileSystem.AddFile(MockUnixSupport.Path($"{testDirectory}file.zip"), new MockFileData(""));++ var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), fileSystem);+ ds.CopyFilesToDirectory(new []{MockUnixSupport.Path($"{testDirectory}file.zip")}, "/manga/output/", new [] {"01"});+ var outputFiles = ds.GetFiles("/manga/output/").Select(API.Services.Tasks.Scanner.Parser.Parser.NormalizePath).ToList();+ Assert.Single(outputFiles);+ // For some reason, this has C:/ on directory even though everything is emulated (System.IO.Abstractions issue, not changing)+ // https://github.com/TestableIO/System.IO.Abstractions/issues/831+ Assert.True(outputFiles.Contains(API.Services.Tasks.Scanner.Parser.Parser.NormalizePath("/manga/output/01.zip"))+ || outputFiles.Contains(API.Services.Tasks.Scanner.Parser.Parser.NormalizePath("C:/manga/output/01.zip")));+ }+#endregion#region ListDirectorydiff --git a/API.Tests/Services/Test Data/ArchiveService/ComicInfos/ComicInfo_outside_root_SharpCompress.cb7 b/API.Tests/Services/Test Data/ArchiveService/ComicInfos/ComicInfo_outside_root_SharpCompress.cb7new file mode 100644index 000000000..14944cbfeBinary files /dev/null and b/API.Tests/Services/Test Data/ArchiveService/ComicInfos/ComicInfo_outside_root_SharpCompress.cb7 differdiff --git a/API.Tests/Services/Test Data/BookService/TitleWithVolume.epub b/API.Tests/Services/Test Data/BookService/TitleWithVolume.epubnew file mode 100644index 000000000..2d8c25b26Binary files /dev/null and b/API.Tests/Services/Test Data/BookService/TitleWithVolume.epub differdiff --git a/API.Tests/Services/Test Data/BookService/TitleWithVolume_NoSeriesOrSeriesIndex.epub b/API.Tests/Services/Test Data/BookService/TitleWithVolume_NoSeriesOrSeriesIndex.epubnew file mode 100644index 000000000..56dc6f5a8Binary files /dev/null and b/API.Tests/Services/Test Data/BookService/TitleWithVolume_NoSeriesOrSeriesIndex.epub differdiff --git a/API/API.csproj b/API/API.csprojindex 4504e7804..ba8759d03 100644--- a/API/API.csproj+++ b/API/API.csproj@@ -54,6 +54,7 @@<PackageReference Include="Flurl.Http" Version="3.2.4" /><PackageReference Include="Hangfire" Version="1.7.31" /><PackageReference Include="Hangfire.AspNetCore" Version="1.7.31" />+ <PackageReference Include="Hangfire.InMemory" Version="0.3.4" /><PackageReference Include="Hangfire.MaximumConcurrentExecutions" Version="1.1.0" /><PackageReference Include="Hangfire.MemoryStorage.Core" Version="1.4.0" /><PackageReference Include="Hangfire.Storage.SQLite" Version="0.3.2" />diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.csindex b0d6c43ba..09e211d51 100644--- a/API/Controllers/AccountController.cs+++ b/API/Controllers/AccountController.cs@@ -186,7 +186,7 @@ public class AccountController : BaseApiController.Include(u => u.UserPreferences).SingleOrDefaultAsync(x => x.NormalizedUserName == loginDto.Username.ToUpper());- if (user == null) return Unauthorized("Invalid username");+ if (user == null) return Unauthorized("Your credentials are not correct");var result = await _signInManager.CheckPasswordSignInAsync(user, loginDto.Password, true);@@ -198,7 +198,7 @@ public class AccountController : BaseApiControllerif (!result.Succeeded){- return Unauthorized(result.IsNotAllowed ? "You must confirm your email first" : "Your credentials are not correct.");+ return Unauthorized(result.IsNotAllowed ? "You must confirm your email first" : "Your credentials are not correct");}// Update LastActive on account@@ -632,6 +632,11 @@ public class AccountController : BaseApiControllerreturn BadRequest("There was an error setting up your account. Please check the logs");}+ /// <summary>+ /// Last step in authentication flow, confirms the email token for email+ /// </summary>+ /// <param name="dto"></param>+ /// <returns></returns>[AllowAnonymous][HttpPost("confirm-email")]public async Task<ActionResult<UserDto>> ConfirmEmail(ConfirmEmailDto dto)@@ -640,7 +645,8 @@ public class AccountController : BaseApiControllerif (user == null){- return BadRequest("The email does not match the registered email");+ _logger.LogInformation("confirm-email failed from invalid registered email: {Email}", dto.Email);+ return BadRequest("Invalid email confirmation");}// Validate Password and Username@@ -654,7 +660,11 @@ public class AccountController : BaseApiController}- if (!await ConfirmEmailToken(dto.Token, user)) return BadRequest("Invalid Email Token");+ if (!await ConfirmEmailToken(dto.Token, user))+ {+ _logger.LogInformation("confirm-email failed from invalid token: {Token}", dto.Token);+ return BadRequest("Invalid email confirmation");+ }user.UserName = dto.Username;user.ConfirmationToken = null;@@ -694,11 +704,15 @@ public class AccountController : BaseApiControllervar user = await _unitOfWork.UserRepository.GetUserByConfirmationToken(dto.Token);if (user == null){- return BadRequest("Invalid Email Token");+ _logger.LogInformation("confirm-email failed from invalid registered email: {Email}", dto.Email);+ return BadRequest("Invalid email confirmation");}- if (!await ConfirmEmailToken(dto.Token, user)) return BadRequest("Invalid Email Token");-+ if (!await ConfirmEmailToken(dto.Token, user))+ {+ _logger.LogInformation("confirm-email failed from invalid token: {Token}", dto.Token);+ return BadRequest("Invalid email confirmation");+ }_logger.LogInformation("User is updating email from {OldEmail} to {NewEmail}", user.Email, dto.Email);var result = await _userManager.SetEmailAsync(user, dto.Email);@@ -728,12 +742,16 @@ public class AccountController : BaseApiControllervar user = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);if (user == null){- return BadRequest("Invalid Details");+ return BadRequest("Invalid credentials");}var result = await _userManager.VerifyUserTokenAsync(user, TokenOptions.DefaultProvider,"ResetPassword", dto.Token);- if (!result) return BadRequest("Unable to reset password, your email token is not correct.");+ if (!result)+ {+ _logger.LogInformation("Unable to reset password, your email token is not correct: {@Dto}", dto);+ return BadRequest("Invalid credentials");+ }var errors = await _accountService.ChangeUserPassword(user, dto.Password);return errors.Any() ? BadRequest(errors) : Ok("Password updated");@@ -801,9 +819,13 @@ public class AccountController : BaseApiControllerpublic async Task<ActionResult<UserDto>> ConfirmMigrationEmail(ConfirmMigrationEmailDto dto){var user = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);- if (user == null) return BadRequest("This email is not on system");+ if (user == null) return BadRequest("Invalid credentials");- if (!await ConfirmEmailToken(dto.Token, user)) return BadRequest("Invalid Email Token");+ if (!await ConfirmEmailToken(dto.Token, user))+ {+ _logger.LogInformation("confirm-migration-email email token is invalid");+ return BadRequest("Invalid credentials");+ }await _unitOfWork.CommitAsync();@@ -865,6 +887,10 @@ public class AccountController : BaseApiController[HttpPost("migrate-email")]public async Task<ActionResult<string>> MigrateEmail(MigrateUserEmailDto dto){+ // If there is an admin account already, return+ var users = await _unitOfWork.UserRepository.GetAdminUsersAsync();+ if (users.Any()) return BadRequest("Admin already exists");+// Check if there is an existing invitevar emailValidationErrors = await _accountService.ValidateEmail(dto.Email);if (emailValidationErrors.Any())diff --git a/API/Controllers/ReaderController.cs b/API/Controllers/ReaderController.csindex db5db71bb..73631e67c 100644--- a/API/Controllers/ReaderController.cs+++ b/API/Controllers/ReaderController.cs@@ -83,8 +83,9 @@ public class ReaderController : BaseApiController}/// <summary>- /// Returns an image for a given chapter. Side effect: This will cache the chapter images for reading.+ /// Returns an image for a given chapter. Will perform bounding checks/// </summary>+ /// <remarks>This will cache the chapter images for reading</remarks>/// <param name="chapterId"></param>/// <param name="page"></param>/// <returns></returns>@@ -99,6 +100,7 @@ public class ReaderController : BaseApiControllertry{+ // TODO: This code is very generic and repeated, see if we can refactor into a common methodvar path = _cacheService.GetCachedPagePath(chapter, page);if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No such image for page {page}. Try refreshing to allow re-cache.");var format = Path.GetExtension(path).Replace(".", "");@@ -128,7 +130,6 @@ public class ReaderController : BaseApiControllerif (page < 0) page = 0;var userId = await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey);- // NOTE: I'm not sure why I need this flow herevar totalPages = await _cacheService.CacheBookmarkForSeries(userId, seriesId);if (page > totalPages){@@ -139,7 +140,7 @@ public class ReaderController : BaseApiController{var path = _cacheService.GetCachedBookmarkPagePath(seriesId, page);if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No such image for page {page}");- var format = Path.GetExtension(path).Replace(".", "");+ var format = Path.GetExtension(path).Replace(".", string.Empty);return PhysicalFile(path, "image/" + format, Path.GetFileName(path));}diff --git a/API/Controllers/ReadingListController.cs b/API/Controllers/ReadingListController.csindex 1428e81f9..b6ee2724d 100644--- a/API/Controllers/ReadingListController.cs+++ b/API/Controllers/ReadingListController.cs@@ -1,4 +1,5 @@-using System.Collections.Generic;+using System;+using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using API.Comparators;diff --git a/API/DTOs/ReadingLists/UpdateReadingListDto.cs b/API/DTOs/ReadingLists/UpdateReadingListDto.csindex b61ab2a72..6be7b8f69 100644--- a/API/DTOs/ReadingLists/UpdateReadingListDto.cs+++ b/API/DTOs/ReadingLists/UpdateReadingListDto.cs@@ -1,10 +1,14 @@-namespace API.DTOs.ReadingLists;+using System;+using System.ComponentModel.DataAnnotations;++namespace API.DTOs.ReadingLists;public class UpdateReadingListDto{+ [Required]public int ReadingListId { get; set; }- public string Title { get; set; }- public string Summary { get; set; }+ public string Title { get; set; } = string.Empty;+ public string Summary { get; set; } = string.Empty;public bool Promoted { get; set; }public bool CoverImageLocked { get; set; }}diff --git a/API/Data/Repositories/UserRepository.cs b/API/Data/Repositories/UserRepository.csindex c7115081b..904cc64b1 100644--- a/API/Data/Repositories/UserRepository.cs+++ b/API/Data/Repositories/UserRepository.cs@@ -305,7 +305,7 @@ public class UserRepository : IUserRepository{return await _context.AppUserBookmark.Where(x => x.AppUserId == userId && x.SeriesId == seriesId)- .OrderBy(x => x.Page)+ .OrderBy(x => x.Created).AsNoTracking().ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider).ToListAsync();@@ -315,7 +315,7 @@ public class UserRepository : IUserRepository{return await _context.AppUserBookmark.Where(x => x.AppUserId == userId && x.VolumeId == volumeId)- .OrderBy(x => x.Page)+ .OrderBy(x => x.Created).AsNoTracking().ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider).ToListAsync();@@ -325,7 +325,7 @@ public class UserRepository : IUserRepository{return await _context.AppUserBookmark.Where(x => x.AppUserId == userId && x.ChapterId == chapterId)- .OrderBy(x => x.Page)+ .OrderBy(x => x.Created).AsNoTracking().ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider).ToListAsync();@@ -341,25 +341,27 @@ public class UserRepository : IUserRepository{var query = _context.AppUserBookmark.Where(x => x.AppUserId == userId)- .OrderBy(x => x.Page)+ .OrderBy(x => x.Created).AsNoTracking();- if (!string.IsNullOrEmpty(filter.SeriesNameQuery))- {- var seriesNameQueryNormalized = Services.Tasks.Scanner.Parser.Parser.Normalize(filter.SeriesNameQuery);- var filterSeriesQuery = query.Join(_context.Series, b => b.SeriesId, s => s.Id, (bookmark, series) => new- {- bookmark,- series- })- .Where(o => EF.Functions.Like(o.series.Name, $"%{filter.SeriesNameQuery}%")- || EF.Functions.Like(o.series.OriginalName, $"%{filter.SeriesNameQuery}%")- || EF.Functions.Like(o.series.LocalizedName, $"%{filter.SeriesNameQuery}%")- || EF.Functions.Like(o.series.NormalizedName, $"%{seriesNameQueryNormalized}%")- );-- query = filterSeriesQuery.Select(o => o.bookmark);- }+ if (string.IsNullOrEmpty(filter.SeriesNameQuery))+ return await query+ .ProjectTo<BookmarkDto>(_mapper.ConfigurationProvider)+ .ToListAsync();++ var seriesNameQueryNormalized = Services.Tasks.Scanner.Parser.Parser.Normalize(filter.SeriesNameQuery);+ var filterSeriesQuery = query.Join(_context.Series, b => b.SeriesId, s => s.Id, (bookmark, series) => new+ {+ bookmark,+ series+ })+ .Where(o => EF.Functions.Like(o.series.Name, $"%{filter.SeriesNameQuery}%")+ || EF.Functions.Like(o.series.OriginalName, $"%{filter.SeriesNameQuery}%")+ || EF.Functions.Like(o.series.LocalizedName, $"%{filter.SeriesNameQuery}%")+ || EF.Functions.Like(o.series.NormalizedName, $"%{seriesNameQueryNormalized}%")+ );++ query = filterSeriesQuery.Select(o => o.bookmark);return await querydiff --git a/API/Data/Seed.cs b/API/Data/Seed.csindex 15e68abeb..61f3b086d 100644--- a/API/Data/Seed.cs+++ b/API/Data/Seed.cs@@ -79,10 +79,7 @@ public static class Seed{new() {Key = ServerSettingKey.CacheDirectory, Value = directoryService.CacheDirectory},new() {Key = ServerSettingKey.TaskScan, Value = "daily"},- new()- {- Key = ServerSettingKey.LoggingLevel, Value = "Information"- }, // Not used from DB, but DB is sync with appSettings.json+ new() {Key = ServerSettingKey.LoggingLevel, Value = "Debug"},new() {Key = ServerSettingKey.TaskBackup, Value = "daily"},new(){diff --git a/API/Logging/LogLevelOptions.cs b/API/Logging/LogLevelOptions.csindex 34d7d353f..51ed86632 100644--- a/API/Logging/LogLevelOptions.cs+++ b/API/Logging/LogLevelOptions.cs@@ -71,7 +71,7 @@ public static class LogLevelOptionsAspNetCoreLogLevelSwitch.MinimumLevel = LogEventLevel.Warning;break;case "Information":- LogLevelSwitch.MinimumLevel = LogEventLevel.Error;+ LogLevelSwitch.MinimumLevel = LogEventLevel.Information;MicrosoftLogLevelSwitch.MinimumLevel = LogEventLevel.Error;MicrosoftHostingLifetimeLogLevelSwitch.MinimumLevel = LogEventLevel.Error;AspNetCoreLogLevelSwitch.MinimumLevel = LogEventLevel.Error;diff --git a/API/Services/ArchiveService.cs b/API/Services/ArchiveService.csindex b370f178d..211d85df7 100644--- a/API/Services/ArchiveService.cs+++ b/API/Services/ArchiveService.cs@@ -331,7 +331,7 @@ public class ArchiveService : IArchiveServiceprivate static bool IsComicInfoArchiveEntry(string fullName, string name){return !Tasks.Scanner.Parser.Parser.HasBlacklistedFolderInPath(fullName)- && name.Equals(ComicInfoFilename, StringComparison.OrdinalIgnoreCase)+ && name.EndsWith(ComicInfoFilename, StringComparison.OrdinalIgnoreCase)&& !name.StartsWith(Tasks.Scanner.Parser.Parser.MacOsMetadataFileStartsWith);}diff --git a/API/Services/BookService.cs b/API/Services/BookService.csindex 728b6f8ff..8156a56ff 100644--- a/API/Services/BookService.cs+++ b/API/Services/BookService.cs@@ -451,9 +451,22 @@ public class BookService : IBookServiceinfo.Series = metadataItem.Content;info.SeriesSort = metadataItem.Content;break;+ case "calibre:series_index":+ info.Volume = metadataItem.Content;+ break;}}+ var hasVolumeInSeries = !Tasks.Scanner.Parser.Parser.ParseVolume(info.Title)+ .Equals(Tasks.Scanner.Parser.Parser.DefaultVolume);++ if (string.IsNullOrEmpty(info.Volume) && hasVolumeInSeries && (!info.Series.Equals(info.Title) || string.IsNullOrEmpty(info.Series)))+ {+ // This is likely a light novel for which we can set series from parsed title+ info.Series = Tasks.Scanner.Parser.Parser.ParseSeries(info.Title);+ info.Volume = Tasks.Scanner.Parser.Parser.ParseVolume(info.Title);+ }+return info;}catch (Exception ex)diff --git a/API/Services/CacheService.cs b/API/Services/CacheService.csindex a150bde22..7cf00bf57 100644--- a/API/Services/CacheService.cs+++ b/API/Services/CacheService.cs@@ -1,4 +1,5 @@-using System.Collections.Generic;+using System;+using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading.Tasks;@@ -101,7 +102,7 @@ public class CacheService : ICacheServicevar extractPath = GetCachePath(chapterId);if (_directoryService.Exists(extractPath)) return chapter;- var files = chapter.Files.ToList();+ var files = chapter?.Files.ToList();ExtractChapterFiles(extractPath, files);return chapter;@@ -223,6 +224,8 @@ public class CacheService : ICacheServicereturn string.Empty;}+ if (page > files.Length) page = files.Length;+// Since array is 0 based, we need to keep that in account (only affects last image)return page == files.Length ? files.ElementAt(page - 1) : files.ElementAt(page);}@@ -234,8 +237,8 @@ public class CacheService : ICacheServicevar bookmarkDtos = await _unitOfWork.UserRepository.GetBookmarkDtosForSeries(userId, seriesId);var files = (await _bookmarkService.GetBookmarkFilesById(bookmarkDtos.Select(b => b.Id))).ToList();- _directoryService.CopyFilesToDirectory(files, destDirectory);- _directoryService.Flatten(destDirectory);+ _directoryService.CopyFilesToDirectory(files, destDirectory,+ Enumerable.Range(1, files.Count).Select(i => i + string.Empty).ToList());return files.Count;}diff --git a/API/Services/DirectoryService.cs b/API/Services/DirectoryService.csindex dbf7214cb..25119dbe0 100644--- a/API/Services/DirectoryService.cs+++ b/API/Services/DirectoryService.cs@@ -37,6 +37,7 @@ public interface IDirectoryServiceIEnumerable<DirectoryDto> ListDirectory(string rootPath);Task<byte[]> ReadFileAsync(string path);bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, string prepend = "");+ bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, IList<string> newFilenames);bool Exists(string directory);void CopyFileToDirectory(string fullFilePath, string targetDirectory);int TraverseTreeParallelForEach(string root, Action<string> action, string searchPattern, ILogger logger);@@ -424,6 +425,46 @@ public class DirectoryService : IDirectoryServicereturn true;}+ /// <summary>+ /// Copies files to a destination directory. If the destination directory doesn't exist, this will create it.+ /// </summary>+ /// <remarks>If a file already exists in dest, this will rename as (2). It does not support multiple iterations of this. Overwriting is not supported.</remarks>+ /// <param name="filePaths"></param>+ /// <param name="directoryPath"></param>+ /// <param name="newFilenames">A list that matches one to one with filePaths. Each filepath will be renamed to newFilenames</param>+ /// <returns></returns>+ public bool CopyFilesToDirectory(IEnumerable<string> filePaths, string directoryPath, IList<string> newFilenames)+ {+ ExistOrCreate(directoryPath);+ string currentFile = null;+ var index = 0;+ try+ {+ foreach (var file in filePaths)+ {+ currentFile = file;++ if (!FileSystem.File.Exists(file))+ {+ _logger.LogError("Unable to copy {File} to {DirectoryPath} as it doesn't exist", file, directoryPath);+ continue;+ }+ var fileInfo = FileSystem.FileInfo.FromFileName(file);+ var targetFile = FileSystem.FileInfo.FromFileName(RenameFileForCopy(newFilenames[index] + fileInfo.Extension, directoryPath));++ fileInfo.CopyTo(FileSystem.Path.Join(directoryPath, targetFile.Name));+ index++;+ }+ }+ catch (Exception ex)+ {+ _logger.LogError(ex, "Unable to copy {File} to {DirectoryPath}", currentFile, directoryPath);+ return false;+ }++ return true;+ }+/// <summary>/// Generates the combined filepath given a prepend (optional), output directory path, and a full input file path./// If the output file already exists, will append (1), (2), etc until it can be written out@@ -434,30 +475,32 @@ public class DirectoryService : IDirectoryService/// <returns></returns>private string RenameFileForCopy(string fileToCopy, string directoryPath, string prepend = ""){- var fileInfo = FileSystem.FileInfo.FromFileName(fileToCopy);- var filename = prepend + fileInfo.Name;-- var targetFile = FileSystem.FileInfo.FromFileName(FileSystem.Path.Join(directoryPath, filename));- if (!targetFile.Exists)+ while (true){- return targetFile.FullName;- }+ var fileInfo = FileSystem.FileInfo.FromFileName(fileToCopy);+ var filename = prepend + fileInfo.Name;- var noExtension = FileSystem.Path.GetFileNameWithoutExtension(fileInfo.Name);- if (FileCopyAppend.IsMatch(noExtension))- {- var match = FileCopyAppend.Match(noExtension).Value;- var matchNumber = match.Replace("(", string.Empty).Replace(")", string.Empty);- noExtension = noExtension.Replace(match, $"({int.Parse(matchNumber) + 1})");- }- else- {- noExtension += " (1)";- }+ var targetFile = FileSystem.FileInfo.FromFileName(FileSystem.Path.Join(directoryPath, filename));+ if (!targetFile.Exists)+ {+ return targetFile.FullName;+ }- var newFilename = prepend + noExtension +- FileSystem.Path.GetExtension(fileInfo.Name);- return RenameFileForCopy(FileSystem.Path.Join(directoryPath, newFilename), directoryPath, prepend);+ var noExtension = FileSystem.Path.GetFileNameWithoutExtension(fileInfo.Name);+ if (FileCopyAppend.IsMatch(noExtension))+ {+ var match = FileCopyAppend.Match(noExtension).Value;+ var matchNumber = match.Replace("(", string.Empty).Replace(")", string.Empty);+ noExtension = noExtension.Replace(match, $"({int.Parse(matchNumber) + 1})");+ }+ else+ {+ noExtension += " (1)";+ }++ var newFilename = prepend + noExtension + FileSystem.Path.GetExtension(fileInfo.Name);+ fileToCopy = FileSystem.Path.Join(directoryPath, newFilename);+ }}/// <summary>diff --git a/API/Services/ReadingItemService.cs b/API/Services/ReadingItemService.csindex 3f2122a08..551d1b668 100644--- a/API/Services/ReadingItemService.cs+++ b/API/Services/ReadingItemService.cs@@ -72,8 +72,23 @@ public class ReadingItemService : IReadingItemService// This catches when original library type is Manga/Comic and when parsing with nonif (Tasks.Scanner.Parser.Parser.IsEpub(path) && Tasks.Scanner.Parser.Parser.ParseVolume(info.Series) != Tasks.Scanner.Parser.Parser.DefaultVolume) // Shouldn't this be info.Volume != DefaultVolume?{- var info2 = _defaultParser.Parse(path, rootPath, LibraryType.Book);- info.Merge(info2);+ var hasVolumeInTitle = !Tasks.Scanner.Parser.Parser.ParseVolume(info.Title)+ .Equals(Tasks.Scanner.Parser.Parser.DefaultVolume);+ var hasVolumeInSeries = !Tasks.Scanner.Parser.Parser.ParseVolume(info.Series)+ .Equals(Tasks.Scanner.Parser.Parser.DefaultVolume);++ if (string.IsNullOrEmpty(info.ComicInfo?.Volume) && hasVolumeInTitle && (hasVolumeInSeries || string.IsNullOrEmpty(info.Series)))+ {+ // This is likely a light novel for which we can set series from parsed title+ info.Series = Tasks.Scanner.Parser.Parser.ParseSeries(info.Title);+ info.Volumes = Tasks.Scanner.Parser.Parser.ParseVolume(info.Title);+ }+ else+ {+ var info2 = _defaultParser.Parse(path, rootPath, LibraryType.Book);+ info.Merge(info2);+ }+}info.ComicInfo = GetComicInfo(path);diff --git a/API/Services/Tasks/Scanner/LibraryWatcher.cs b/API/Services/Tasks/Scanner/LibraryWatcher.csindex fea30b7fe..fee51f562 100644--- a/API/Services/Tasks/Scanner/LibraryWatcher.cs+++ b/API/Services/Tasks/Scanner/LibraryWatcher.cs@@ -192,6 +192,7 @@ public class LibraryWatcher : ILibraryWatcher/// <remarks>This is public only because Hangfire will invoke it. Do not call external to this class.</remarks>/// <param name="filePath">File or folder that changed</param>/// <param name="isDirectoryChange">If the change is on a directory and not a file</param>+ [DisableConcurrentExecution(60)]// ReSharper disable once MemberCanBePrivate.Globalpublic async Task ProcessChange(string filePath, bool isDirectoryChange = false){diff --git a/API/Services/Tasks/Scanner/ParseScannedFiles.cs b/API/Services/Tasks/Scanner/ParseScannedFiles.csindex dbd23d970..1a23af727 100644--- a/API/Services/Tasks/Scanner/ParseScannedFiles.cs+++ b/API/Services/Tasks/Scanner/ParseScannedFiles.cs@@ -38,7 +38,10 @@ public class SeriesModifiedpublic IEnumerable<string> LibraryRoots { get; set; }}-+/// <summary>+/// Responsible for taking parsed info from ReadingItemService and DirectoryService and combining them to emit DB work+/// on a series by series.+/// </summary>public class ParseScannedFiles{private readonly ILogger _logger;diff --git a/API/Services/Tasks/Scanner/Parser/DefaultParser.cs b/API/Services/Tasks/Scanner/Parser/DefaultParser.csindex 4bab428a3..072b1e44e 100644--- a/API/Services/Tasks/Scanner/Parser/DefaultParser.cs+++ b/API/Services/Tasks/Scanner/Parser/DefaultParser.cs@@ -34,6 +34,8 @@ public class DefaultParser : IDefaultParserpublic ParserInfo Parse(string filePath, string rootPath, LibraryType type = LibraryType.Manga){var fileName = _directoryService.FileSystem.Path.GetFileNameWithoutExtension(filePath);+ // TODO: Potential Bug: This will return null, but on Image libraries, if all images, we would want to include this.+ if (Parser.IsCoverImage(_directoryService.FileSystem.Path.GetFileName(filePath))) return null;ParserInfo ret;if (Parser.IsEpub(filePath))@@ -62,7 +64,6 @@ public class DefaultParser : IDefaultParser};}- if (Parser.IsCoverImage(_directoryService.FileSystem.Path.GetFileName(filePath))) return null;if (Parser.IsImage(filePath)){diff --git a/API/Services/Tasks/Scanner/Parser/Parser.cs b/API/Services/Tasks/Scanner/Parser/Parser.csindex 8a7e16933..13cce0feb 100644--- a/API/Services/Tasks/Scanner/Parser/Parser.cs+++ b/API/Services/Tasks/Scanner/Parser/Parser.cs@@ -200,11 +200,11 @@ public static class ParserMatchOptions, RegexTimeout),// [dmntsf.net] One Piece - Digital Colored Comics Vol. 20 Ch. 177 - 30 Million vs 81 Million.cbznew Regex(- @"(?<Series>.*) (\b|_|-)(vol)\.?(\s|-|_)?\d+",+ @"(?<Series>.+?):? (\b|_|-)(vol)\.?(\s|-|_)?\d+",MatchOptions, RegexTimeout),// [xPearse] Kyochuu Rettou Volume 1 [English] [Manga] [Volume Scans]new Regex(- @"(?<Series>.*) (\b|_|-)(vol)(ume)",+ @"(?<Series>.+?):? (\b|_|-)(vol)(ume)",MatchOptions,RegexTimeout),//Knights of Sidonia c000 (S2 LE BD Omake - BLAME!) [Habanero Scans]@@ -596,7 +596,7 @@ public static class Parserprivate static readonly Regex ComicSpecialRegex = new Regex(// All Keywords, does not account for checking if contains volume/chapter identification. Parser.Parse() will handle.- $@"\b(?:{CommonSpecial}|\d.+?\WAnnual|Annual\W\d.+?|Book \d.+?|Compendium \d.+?|Omnibus \d.+?|FCBD \d.+?|Absolute \d.+?|Preview \d.+?|Hors[ -]S[ée]rie|TPB|HS|THS)\b",+ $@"\b(?:{CommonSpecial}|\d.+?(\W|-|^)Annual|Annual(\W|-|$)|Book \d.+?|Compendium(\W|-|$|\s.+?)|Omnibus(\W|-|$|\s.+?)|FCBD \d.+?|Absolute(\W|-|$|\s.+?)|Preview(\W|-|$|\s.+?)|Hors[ -]S[ée]rie|TPB|HS|THS)\b",MatchOptions, RegexTimeout);diff --git a/API/Services/Tasks/ScannerService.cs b/API/Services/Tasks/ScannerService.csindex 18cb219e0..f934e6ba6 100644--- a/API/Services/Tasks/ScannerService.cs+++ b/API/Services/Tasks/ScannerService.cs@@ -160,6 +160,7 @@ public class ScannerService : IScannerServicevar sw = Stopwatch.StartNew();var files = await _unitOfWork.SeriesRepository.GetFilesForSeries(seriesId);var series = await _unitOfWork.SeriesRepository.GetFullSeriesForSeriesIdAsync(seriesId);+ if (series == null) return; // This can occur when UI deletes a series but doesn't update and user re-requests updatevar chapterIds = await _unitOfWork.SeriesRepository.GetChapterIdsForSeriesAsync(new[] {seriesId});var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(series.LibraryId, LibraryIncludes.Folders);var libraryPaths = library.Folders.Select(f => f.Path).ToList();diff --git a/API/Startup.cs b/API/Startup.csindex 00351a3fa..a9fef97b8 100644--- a/API/Startup.cs+++ b/API/Startup.cs@@ -177,7 +177,8 @@ public class Startupservices.AddHangfire(configuration => configuration.UseSimpleAssemblyNameTypeSerializer().UseRecommendedSerializerSettings()- .UseSQLiteStorage("config/Hangfire.db")); // UseSQLiteStorage - SQLite has some issues around resuming jobs when aborted+ .UseInMemoryStorage());+ //.UseSQLiteStorage("config/Hangfire.db")); // UseSQLiteStorage - SQLite has some issues around resuming jobs when aborted (and locking can cause high utilization)// Add the processing server as IHostedServiceservices.AddHangfireServer(options =>diff --git a/Kavita.Common/Kavita.Common.csproj b/Kavita.Common/Kavita.Common.csprojindex a46dfdf4b..657da79cb 100644--- a/Kavita.Common/Kavita.Common.csproj+++ b/Kavita.Common/Kavita.Common.csproj@@ -4,7 +4,7 @@<TargetFramework>net6.0</TargetFramework><Company>kavitareader.com</Company><Product>Kavita</Product>- <AssemblyVersion>0.6.0.0</AssemblyVersion>+ <AssemblyVersion>0.6.1.0</AssemblyVersion><NeutralLanguage>en</NeutralLanguage><TieredPGO>true</TieredPGO></PropertyGroup>diff --git a/UI/Web/package-lock.json b/UI/Web/package-lock.jsonindex 1e6b9b82b..aba7c9f7b 100644--- a/UI/Web/package-lock.json+++ b/UI/Web/package-lock.json@@ -12469,9 +12469,9 @@"integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A=="},"minimatch": {- "version": "3.0.4",- "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",- "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",+ "version": "3.1.2",+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",+ "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==","requires": {"brace-expansion": "^1.1.7"}@@ -15417,9 +15417,9 @@"dev": true},"swiper": {- "version": "8.0.6",- "resolved": "https://registry.npmjs.org/swiper/-/swiper-8.0.6.tgz",- "integrity": "sha512-Ssyu1+FeNATF/G8e84QG+ZUNtUOAZ5vngdgxzczh0oWZPhGUVgkdv+BoePUuaCXLAFXnwVpNjgLIcGnxMdmWPA==",+ "version": "8.4.4",+ "resolved": "https://registry.npmjs.org/swiper/-/swiper-8.4.4.tgz",+ "integrity": "sha512-jA/8BfOZwT8PqPSnMX0TENZYitXEhNa7ZSNj1Diqh5LZyUJoBQaZcqAiPQ/PIg1+IPaRn/V8ZYVb0nxHMh51yw==","requires": {"dom7": "^4.0.4","ssr-window": "^4.0.2"diff --git a/UI/Web/package.json b/UI/Web/package.jsonindex c78cdc29e..7df5cdf86 100644--- a/UI/Web/package.json+++ b/UI/Web/package.json@@ -44,7 +44,7 @@"ngx-toastr": "^14.2.1","requires": "^1.0.2","rxjs": "~7.5.4",- "swiper": "^8.0.6",+ "swiper": "^8.4.4","tslib": "^2.3.1","webpack-bundle-analyzer": "^4.5.0","zone.js": "~0.11.4"diff --git a/UI/Web/src/app/_services/action.service.ts b/UI/Web/src/app/_services/action.service.tsindex 489c5c30d..0fd52cd60 100644--- a/UI/Web/src/app/_services/action.service.ts+++ b/UI/Web/src/app/_services/action.service.ts@@ -264,7 +264,7 @@ export class ActionService implements OnDestroy {markChapterAsUnread(seriesId: number, chapter: Chapter, callback?: ChapterActionCallback) {this.readerService.saveProgress(seriesId, chapter.volumeId, chapter.id, 0).pipe(take(1)).subscribe(results => {chapter.pagesRead = 0;- this.toastr.success('Marked as unread');+ this.toastr.success('Marked as Unread');if (callback) {callback(chapter);}@@ -306,7 +306,7 @@ export class ActionService implements OnDestroy {volume.chapters?.forEach(c => c.pagesRead = 0);});chapters?.forEach(c => c.pagesRead = 0);- this.toastr.success('Marked as Read');+ this.toastr.success('Marked as Unread');if (callback) {callback();diff --git a/UI/Web/src/app/_services/jumpbar.service.ts b/UI/Web/src/app/_services/jumpbar.service.tsindex 43dc5ed3d..7c9bf8478 100644--- a/UI/Web/src/app/_services/jumpbar.service.ts+++ b/UI/Web/src/app/_services/jumpbar.service.ts@@ -36,15 +36,15 @@ export class JumpbarService {const removalTimes = Math.ceil(removeCount / 2);const midPoint = Math.floor(jumpBarKeys.length / 2);jumpBarKeysToRender.push(jumpBarKeys[0]);- this.removeFirstPartOfJumpBar(midPoint, removalTimes, jumpBarKeys, jumpBarKeysToRender);+ this._removeFirstPartOfJumpBar(midPoint, removalTimes, jumpBarKeys, jumpBarKeysToRender);jumpBarKeysToRender.push(jumpBarKeys[midPoint]);- this.removeSecondPartOfJumpBar(midPoint, removalTimes, jumpBarKeys, jumpBarKeysToRender);+ this._removeSecondPartOfJumpBar(midPoint, removalTimes, jumpBarKeys, jumpBarKeysToRender);jumpBarKeysToRender.push(jumpBarKeys[jumpBarKeys.length - 1]);return jumpBarKeysToRender;}- removeSecondPartOfJumpBar(midPoint: number, numberOfRemovals: number = 1, jumpBarKeys: Array<JumpKey>, jumpBarKeysToRender: Array<JumpKey>) {+ _removeSecondPartOfJumpBar(midPoint: number, numberOfRemovals: number = 1, jumpBarKeys: Array<JumpKey>, jumpBarKeysToRender: Array<JumpKey>) {const removedIndexes: Array<number> = [];for(let removal = 0; removal < numberOfRemovals; removal++) {let min = 100000000;@@ -62,7 +62,7 @@ export class JumpbarService {}}- removeFirstPartOfJumpBar(midPoint: number, numberOfRemovals: number = 1, jumpBarKeys: Array<JumpKey>, jumpBarKeysToRender: Array<JumpKey>) {+ _removeFirstPartOfJumpBar(midPoint: number, numberOfRemovals: number = 1, jumpBarKeys: Array<JumpKey>, jumpBarKeysToRender: Array<JumpKey>) {const removedIndexes: Array<number> = [];for(let removal = 0; removal < numberOfRemovals; removal++) {let min = 100000000;@@ -80,4 +80,35 @@ export class JumpbarService {if (!removedIndexes.includes(i)) jumpBarKeysToRender.push(jumpBarKeys[i]);}}++ /**+ *+ * @param data An array of objects+ * @param keySelector A method to fetch a string from the object, which is used to classify the JumpKey+ * @returns+ */+ getJumpKeys(data :Array<any>, keySelector: (data: any) => string) {+ const keys: {[key: string]: number} = {};+ data.forEach(obj => {+ let ch = keySelector(obj).charAt(0);+ if (/\d|\#|!|%|@|\(|\)|\^|\.|_|\*/g.test(ch)) {+ ch = '#';+ }+ if (!keys.hasOwnProperty(ch)) {+ keys[ch] = 0;+ }+ keys[ch] += 1;+ });+ return Object.keys(keys).map(k => {+ return {+ key: k,+ size: keys[k],+ title: k.toUpperCase()+ }+ }).sort((a, b) => {+ if (a.key < b.key) return -1;+ if (a.key > b.key) return 1;+ return 0;+ });+ }}diff --git a/UI/Web/src/app/admin/role-selector/role-selector.component.html b/UI/Web/src/app/admin/role-selector/role-selector.component.htmlindex 1eb806aab..5d97cdd0f 100644--- a/UI/Web/src/app/admin/role-selector/role-selector.component.html+++ b/UI/Web/src/app/admin/role-selector/role-selector.component.html@@ -3,7 +3,7 @@<li class="list-group-item" *ngFor="let role of selectedRoles; let i = index"><div class="form-check"><input id="role-{{i}}" type="checkbox" attr.aria-label="Role {{role.data}}" class="form-check-input"- [(ngModel)]="role.selected" name="role" (ngModelChange)="handleModelUpdate()">+ [(ngModel)]="role.selected" [disabled]="role.disabled" name="role" (ngModelChange)="handleModelUpdate()"><label attr.for="role-{{i}}" class="form-check-label">{{role.data}}</label></div></li>diff --git a/UI/Web/src/app/admin/role-selector/role-selector.component.ts b/UI/Web/src/app/admin/role-selector/role-selector.component.tsindex e21c2d67c..f748e3a70 100644--- a/UI/Web/src/app/admin/role-selector/role-selector.component.ts+++ b/UI/Web/src/app/admin/role-selector/role-selector.component.ts@@ -1,4 +1,4 @@-import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';import { Member } from 'src/app/_models/member';import { User } from 'src/app/_models/user';@@ -8,7 +8,8 @@ import { MemberService } from 'src/app/_services/member.service';@Component({selector: 'app-role-selector',templateUrl: './role-selector.component.html',- styleUrls: ['./role-selector.component.scss']+ styleUrls: ['./role-selector.component.scss'],+ changeDetection: ChangeDetectionStrategy.OnPush})export class RoleSelectorComponent implements OnInit {@@ -23,9 +24,9 @@ export class RoleSelectorComponent implements OnInit {@Output() selected: EventEmitter<string[]> = new EventEmitter<string[]>();allRoles: string[] = [];- selectedRoles: Array<{selected: boolean, data: string}> = [];+ selectedRoles: Array<{selected: boolean, disabled: boolean, data: string}> = [];- constructor(public modal: NgbActiveModal, private accountService: AccountService, private memberService: MemberService) { }+ constructor(public modal: NgbActiveModal, private accountService: AccountService, private readonly cdRef: ChangeDetectorRef) { }ngOnInit(): void {this.accountService.getRoles().subscribe(roles => {@@ -36,8 +37,9 @@ export class RoleSelectorComponent implements OnInit {roles = roles.filter(item => !bannedRoles.includes(item));this.allRoles = roles;this.selectedRoles = roles.map(item => {- return {selected: false, data: item};+ return {selected: false, disabled: false, data: item};});+ this.cdRef.markForCheck();this.preselect();this.selected.emit(this.selectedRoles.filter(item => item.selected).map(item => item.data));});@@ -51,11 +53,25 @@ export class RoleSelectorComponent implements OnInit {foundRole[0].selected = true;}});+ this.cdRef.markForCheck();}}handleModelUpdate() {- this.selected.emit(this.selectedRoles.filter(item => item.selected).map(item => item.data));+ const roles = this.selectedRoles.filter(item => item.selected).map(item => item.data);+ if (roles.filter(r => r === 'Admin').length > 0) {+ // Disable all other items as Admin is selected+ this.selectedRoles.filter(item => item.data !== 'Admin').forEach(e => {+ e.disabled = true;+ });+ } else {+ // Re-enable everything+ this.selectedRoles.forEach(e => {+ e.disabled = false;+ });+ }+ this.cdRef.markForCheck();+ this.selected.emit(roles);}}diff --git a/UI/Web/src/app/book-reader/_models/book-white-theme.ts b/UI/Web/src/app/book-reader/_models/book-white-theme.tsindex 27405b577..f25ab96a1 100644--- a/UI/Web/src/app/book-reader/_models/book-white-theme.ts+++ b/UI/Web/src/app/book-reader/_models/book-white-theme.ts@@ -20,7 +20,7 @@ export const BookWhiteTheme = `--drawer-text-color: black;--drawer-pagination-horizontal-rule: inset 0 -1px 0 rgb(255 255 255 / 20%);--drawer-pagination-border: 1px solid rgb(0 0 0 / 13%);-+/* Accordion */--accordion-header-text-color: rgba(74, 198, 148, 0.9);@@ -103,7 +103,7 @@ export const BookWhiteTheme = `.book-content *:not(input), .book-content *:not(select), .book-content *:not(code), .book-content *:not(:link), .book-content *:not(.ngx-toastr) {- color: #dcdcdc !important;+ color: black !important;}.book-content code {@@ -122,19 +122,19 @@ background-color: initial !important;.book-content *:not(code), .book-content *:not(a) {- background-color: black;+ background-color: white;box-shadow: none;text-shadow: none;border-radius: unset;color: #dcdcdc !important;}--.book-content :visited, .book-content :visited *, .book-content :visited *[class] {color: rgb(211, 138, 138) !important}-.book-content :link:not(cite), :link .book-content *:not(cite) {color: #8db2e5 !important}++.book-content :visited, .book-content :visited *, .book-content :visited *[class] {color: rgb(240, 50, 50) !important}+.book-content :link:not(cite), :link .book-content *:not(cite) {color: #00f !important}.btn-check:checked + .btn {color: white;background-color: var(--primary-color);}-`;\ No newline at end of file+`;diff --git a/UI/Web/src/app/bookmark/bookmarks/bookmarks.component.html b/UI/Web/src/app/bookmark/bookmarks/bookmarks.component.htmlindex a43e90936..78dbf6dc2 100644--- a/UI/Web/src/app/bookmark/bookmarks/bookmarks.component.html+++ b/UI/Web/src/app/bookmark/bookmarks/bookmarks.component.html@@ -11,6 +11,7 @@[filterSettings]="filterSettings"[trackByIdentity]="trackByIdentity"[refresh]="refresh"+ [jumpBarKeys]="jumpbarKeys"(applyFilter)="updateFilter($event)"><ng-template #cardItem let-item let-position="idx">diff --git a/UI/Web/src/app/bookmark/bookmarks/bookmarks.component.ts b/UI/Web/src/app/bookmark/bookmarks/bookmarks.component.tsindex 42c4cfaee..e37c96aea 100644--- a/UI/Web/src/app/bookmark/bookmarks/bookmarks.component.ts+++ b/UI/Web/src/app/bookmark/bookmarks/bookmarks.component.ts@@ -8,12 +8,14 @@ import { ConfirmService } from 'src/app/shared/confirm.service';import { DownloadService } from 'src/app/shared/_services/download.service';import { FilterUtilitiesService } from 'src/app/shared/_services/filter-utilities.service';import { KEY_CODES } from 'src/app/shared/_services/utility.service';+import { JumpKey } from 'src/app/_models/jumpbar/jump-key';import { PageBookmark } from 'src/app/_models/page-bookmark';import { Pagination } from 'src/app/_models/pagination';import { Series } from 'src/app/_models/series';import { FilterEvent, SeriesFilter } from 'src/app/_models/series-filter';import { Action, ActionFactoryService, ActionItem } from 'src/app/_services/action-factory.service';import { ImageService } from 'src/app/_services/image.service';+import { JumpbarService } from 'src/app/_services/jumpbar.service';import { ReaderService } from 'src/app/_services/reader.service';import { SeriesService } from 'src/app/_services/series.service';@@ -32,6 +34,7 @@ export class BookmarksComponent implements OnInit, OnDestroy {downloadingSeries: {[id: number]: boolean} = {};clearingSeries: {[id: number]: boolean} = {};actions: ActionItem<Series>[] = [];+ jumpbarKeys: Array<JumpKey> = [];pagination!: Pagination;filter: SeriesFilter | undefined = undefined;@@ -50,7 +53,8 @@ export class BookmarksComponent implements OnInit, OnDestroy {private confirmService: ConfirmService, public bulkSelectionService: BulkSelectionService,public imageService: ImageService, private actionFactoryService: ActionFactoryService,private router: Router, private readonly cdRef: ChangeDetectorRef,- private filterUtilityService: FilterUtilitiesService, private route: ActivatedRoute) {+ private filterUtilityService: FilterUtilitiesService, private route: ActivatedRoute,+ private jumpbarService: JumpbarService) {this.filterSettings.ageRatingDisabled = true;this.filterSettings.collectionDisabled = true;this.filterSettings.formatDisabled = true;@@ -158,6 +162,7 @@ export class BookmarksComponent implements OnInit, OnDestroy {const ids = Object.keys(this.seriesIds).map(k => parseInt(k, 10));this.seriesService.getAllSeriesByIds(ids).subscribe(series => {+ this.jumpbarKeys = this.jumpbarService.getJumpKeys(series, (t: Series) => t.name);this.series = series;this.loadingBookmarks = false;this.cdRef.markForCheck();diff --git a/UI/Web/src/app/collections/all-collections/all-collections.component.html b/UI/Web/src/app/collections/all-collections/all-collections.component.htmlindex b64402ea3..85937d6c8 100644--- a/UI/Web/src/app/collections/all-collections/all-collections.component.html+++ b/UI/Web/src/app/collections/all-collections/all-collections.component.html@@ -16,6 +16,7 @@</ng-template><ng-template #noData>- There are no collections. Try creating <a href="https://wiki.kavitareader.com/en/guides/get-started-using-your-library/collections" rel="noopener noreferrer" target="_blank">one <i class="fa fa-external-link-alt" aria-hidden="true"></i></a>.+ There are no collections.+ <ng-container *ngIf="isAdmin$ | async"> Try creating <a href="https://wiki.kavitareader.com/en/guides/get-started-using-your-library/collections" rel="noopener noreferrer" target="_blank">one <i class="fa fa-external-link-alt" aria-hidden="true"></i></a></ng-container></ng-template></app-card-detail-layout>\ No newline at end of filediff --git a/UI/Web/src/app/collections/all-collections/all-collections.component.ts b/UI/Web/src/app/collections/all-collections/all-collections.component.tsindex 02588d01a..0b61669af 100644--- a/UI/Web/src/app/collections/all-collections/all-collections.component.ts+++ b/UI/Web/src/app/collections/all-collections/all-collections.component.ts@@ -1,15 +1,18 @@-import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, OnInit } from '@angular/core';+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, OnDestroy, OnInit } from '@angular/core';import { Title } from '@angular/platform-browser';import { Router } from '@angular/router';import { NgbModal } from '@ng-bootstrap/ng-bootstrap';+import { map, of, Subject, takeUntil } from 'rxjs';+import { Observable } from 'rxjs/internal/Observable';import { EditCollectionTagsComponent } from 'src/app/cards/_modals/edit-collection-tags/edit-collection-tags.component';-import { UtilityService } from 'src/app/shared/_services/utility.service';import { CollectionTag } from 'src/app/_models/collection-tag';import { JumpKey } from 'src/app/_models/jumpbar/jump-key';import { Tag } from 'src/app/_models/tag';+import { AccountService } from 'src/app/_services/account.service';import { ActionItem, ActionFactoryService, Action } from 'src/app/_services/action-factory.service';import { CollectionTagService } from 'src/app/_services/collection-tag.service';import { ImageService } from 'src/app/_services/image.service';+import { JumpbarService } from 'src/app/_services/jumpbar.service';@Component({@@ -18,20 +21,23 @@ import { ImageService } from 'src/app/_services/image.service';styleUrls: ['./all-collections.component.scss'],changeDetection: ChangeDetectionStrategy.OnPush})-export class AllCollectionsComponent implements OnInit {+export class AllCollectionsComponent implements OnInit, OnDestroy {isLoading: boolean = true;collections: CollectionTag[] = [];collectionTagActions: ActionItem<CollectionTag>[] = [];jumpbarKeys: Array<JumpKey> = [];trackByIdentity = (index: number, item: CollectionTag) => `${item.id}_${item.title}`;+ isAdmin$: Observable<boolean> = of(false);+ private readonly onDestroy = new Subject<void>();filterOpen: EventEmitter<boolean> = new EventEmitter();constructor(private collectionService: CollectionTagService, private router: Router,private actionFactoryService: ActionFactoryService, private modalService: NgbModal,- private titleService: Title, private utilityService: UtilityService,- private readonly cdRef: ChangeDetectorRef, public imageSerivce: ImageService) {+ private titleService: Title, private jumpbarService: JumpbarService,+ private readonly cdRef: ChangeDetectorRef, public imageSerivce: ImageService,+ public accountService: AccountService) {this.router.routeReuseStrategy.shouldReuseRoute = () => false;this.titleService.setTitle('Kavita - Collections');}@@ -40,6 +46,15 @@ export class AllCollectionsComponent implements OnInit {this.loadPage();this.collectionTagActions = this.actionFactoryService.getCollectionTagActions(this.handleCollectionActionCallback.bind(this));this.cdRef.markForCheck();+ this.isAdmin$ = this.accountService.currentUser$.pipe(takeUntil(this.onDestroy), map(user => {+ if (!user) return false;+ return this.accountService.hasAdminRole(user);+ }));+ }++ ngOnDestroy(): void {+ this.onDestroy.next();+ this.onDestroy.complete();}@@ -54,7 +69,7 @@ export class AllCollectionsComponent implements OnInit {this.collectionService.allTags().subscribe(tags => {this.collections = tags;this.isLoading = false;- this.jumpbarKeys = this.utilityService.getJumpKeys(tags, (t: Tag) => t.title);+ this.jumpbarKeys = this.jumpbarService.getJumpKeys(tags, (t: Tag) => t.title);this.cdRef.markForCheck();});}diff --git a/UI/Web/src/app/collections/collection-detail/collection-detail.component.ts b/UI/Web/src/app/collections/collection-detail/collection-detail.component.tsindex b105f7007..6627c6d50 100644--- a/UI/Web/src/app/collections/collection-detail/collection-detail.component.ts+++ b/UI/Web/src/app/collections/collection-detail/collection-detail.component.ts@@ -21,6 +21,7 @@ import { Action, ActionFactoryService, ActionItem } from 'src/app/_services/actiimport { ActionService } from 'src/app/_services/action.service';import { CollectionTagService } from 'src/app/_services/collection-tag.service';import { ImageService } from 'src/app/_services/image.service';+import { JumpbarService } from 'src/app/_services/jumpbar.service';import { EVENTS, MessageHubService } from 'src/app/_services/message-hub.service';import { ScrollService } from 'src/app/_services/scroll.service';import { SeriesService } from 'src/app/_services/series.service';@@ -124,7 +125,7 @@ export class CollectionDetailComponent implements OnInit, OnDestroy, AfterContenconstructor(public imageService: ImageService, private collectionService: CollectionTagService, private router: Router, private route: ActivatedRoute,private seriesService: SeriesService, private toastr: ToastrService, private actionFactoryService: ActionFactoryService,- private modalService: NgbModal, private titleService: Title,+ private modalService: NgbModal, private titleService: Title, private jumpbarService: JumpbarService,public bulkSelectionService: BulkSelectionService, private actionService: ActionService, private messageHub: MessageHubService,private filterUtilityService: FilterUtilitiesService, private utilityService: UtilityService, @Inject(DOCUMENT) private document: Document,private readonly cdRef: ChangeDetectorRef, private scrollService: ScrollService) {@@ -210,7 +211,7 @@ export class CollectionDetailComponent implements OnInit, OnDestroy, AfterContenthis.seriesService.getAllSeries(undefined, undefined, this.filter).pipe(take(1)).subscribe(series => {this.series = series.result;this.seriesPagination = series.pagination;- this.jumpbarKeys = this.utilityService.getJumpKeys(this.series, (series: Series) => series.name);+ this.jumpbarKeys = this.jumpbarService.getJumpKeys(this.series, (series: Series) => series.name);this.isLoading = false;window.scrollTo(0, 0);this.cdRef.markForCheck();diff --git a/UI/Web/src/app/manga-reader/fullscreen-icon.pipe.ts b/UI/Web/src/app/manga-reader/_pipes/fullscreen-icon.pipe.tssimilarity index 100%rename from UI/Web/src/app/manga-reader/fullscreen-icon.pipe.tsrename to UI/Web/src/app/manga-reader/_pipes/fullscreen-icon.pipe.tsdiff --git a/UI/Web/src/app/manga-reader/_pipes/layout-mode-icon.pipe.ts b/UI/Web/src/app/manga-reader/_pipes/layout-mode-icon.pipe.tsnew file mode 100644index 000000000..26f43dfee--- /dev/null+++ b/UI/Web/src/app/manga-reader/_pipes/layout-mode-icon.pipe.ts@@ -0,0 +1,20 @@+import { Pipe, PipeTransform } from '@angular/core';+import { LayoutMode } from '../_models/layout-mode';++@Pipe({+ name: 'layoutModeIcon'+})+export class LayoutModeIconPipe implements PipeTransform {++ transform(layoutMode: LayoutMode): string {+ switch (layoutMode) {+ case LayoutMode.Single:+ return 'none';+ case LayoutMode.Double:+ return 'double';+ case LayoutMode.DoubleReversed:+ return 'double-reversed';+ }+ }++}diff --git a/UI/Web/src/app/manga-reader/_pipes/reader-mode-icon.pipe.ts b/UI/Web/src/app/manga-reader/_pipes/reader-mode-icon.pipe.tsnew file mode 100644index 000000000..5017ad755--- /dev/null+++ b/UI/Web/src/app/manga-reader/_pipes/reader-mode-icon.pipe.ts@@ -0,0 +1,22 @@+import { Pipe, PipeTransform } from '@angular/core';+import { ReaderMode } from 'src/app/_models/preferences/reader-mode';++@Pipe({+ name: 'readerModeIcon'+})+export class ReaderModeIconPipe implements PipeTransform {++ transform(readerMode: ReaderMode): string {+ switch(readerMode) {+ case ReaderMode.LeftRight:+ return 'fa-exchange-alt';+ case ReaderMode.UpDown:+ return 'fa-exchange-alt fa-rotate-90';+ case ReaderMode.Webtoon:+ return 'fa-arrows-alt-v';+ default:+ return '';+ }+ }++}diff --git a/UI/Web/src/app/manga-reader/manga-reader.component.html b/UI/Web/src/app/manga-reader/manga-reader.component.htmlindex 21c28f7fd..aca92651b 100644--- a/UI/Web/src/app/manga-reader/manga-reader.component.html+++ b/UI/Web/src/app/manga-reader/manga-reader.component.html@@ -121,7 +121,7 @@</div><div class="col"><button class="btn btn-icon" title="Reading Mode" (click)="toggleReaderMode();resetMenuCloseTimer();">- <i class="fa {{ReaderModeIcon}}" aria-hidden="true"></i>+ <i class="fa {{this.readerMode | readerModeIcon}}" aria-hidden="true"></i><span class="visually-hidden">Reading Mode</span></button></div>@@ -197,7 +197,6 @@</span></div></ng-container>- <!-- <div class="{{LayoutModeIconClass}}"></div> --></ng-container><select class="form-control" id="page-fitting" formControlName="layoutMode"><option [value]="opt.value" *ngFor="let opt of layoutModes">{{opt.text}}</option>diff --git a/UI/Web/src/app/manga-reader/manga-reader.component.ts b/UI/Web/src/app/manga-reader/manga-reader.component.tsindex 12d179ef1..b14bb958a 100644--- a/UI/Web/src/app/manga-reader/manga-reader.component.ts+++ b/UI/Web/src/app/manga-reader/manga-reader.component.ts@@ -1,4 +1,4 @@-import { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, HostListener, Inject, OnDestroy, OnInit, Renderer2, SimpleChanges, ViewChild } from '@angular/core';+import { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, HostListener, Inject, NgZone, OnDestroy, OnInit, Renderer2, SimpleChanges, ViewChild } from '@angular/core';import { DOCUMENT } from '@angular/common';import { ActivatedRoute, Router } from '@angular/router';import { debounceTime, take, takeUntil } from 'rxjs/operators';@@ -290,9 +290,9 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {bookmarkPageHandler = this.bookmarkPage.bind(this);- getPageUrl = (pageNum: number) => {+ getPageUrl = (pageNum: number, chapterId: number = this.chapterId) => {if (this.bookmarkMode) return this.readerService.getBookmarkPageUrl(this.seriesId, this.user.apiKey, pageNum);- return this.readerService.getPageUrl(this.chapterId, pageNum);+ return this.readerService.getPageUrl(chapterId, pageNum);}private readonly onDestroy = new Subject<void>();@@ -377,29 +377,6 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {return 'right-side';}- get LayoutModeIconClass() {- switch (this.layoutMode) {- case LayoutMode.Single:- return 'none';- case LayoutMode.Double:- return 'double';- case LayoutMode.DoubleReversed:- return 'double-reversed';- }- }-- get ReaderModeIcon() {- switch(this.readerMode) {- case ReaderMode.LeftRight:- return 'fa-exchange-alt';- case ReaderMode.UpDown:- return 'fa-exchange-alt fa-rotate-90';- case ReaderMode.Webtoon:- return 'fa-arrows-alt-v';- default:- return '';- }- }get ReaderMode() {return ReaderMode;@@ -433,7 +410,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {private toastr: ToastrService, private memberService: MemberService,public utilityService: UtilityService, private renderer: Renderer2,@Inject(DOCUMENT) private document: Document, private modalService: NgbModal,- private readonly cdRef: ChangeDetectorRef) {+ private readonly cdRef: ChangeDetectorRef, private readonly ngZone: NgZone) {this.navService.hideNavBar();this.navService.hideSideNav();this.cdRef.markForCheck();@@ -626,6 +603,23 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {}}+ /**+ * Gets a page from cache else gets a brand new Image+ * @param pageNum Page Number to load+ * @param forceNew Forces to fetch a new image+ * @param chapterId ChapterId to fetch page from. Defaults to current chapterId+ * @returns+ */+ getPage(pageNum: number, chapterId: number = this.chapterId, forceNew: boolean = false) {+ let img = this.cachedImages.find(img => this.readerService.imageUrlToPageNum(img.src) === pageNum);+ if (!img || forceNew) {+ img = new Image();+ img.src = this.getPageUrl(pageNum, chapterId);+ }++ return img;+ }+// if there is scroll room and on original, then don't paginatecheckIfPaginationAllowed() {// This is not used atm due to the complexity it adds with keyboard.@@ -748,6 +742,9 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {if (chapterId === CHAPTER_ID_DOESNT_EXIST || chapterId === this.chapterId) {this.nextChapterDisabled = true;this.cdRef.markForCheck();+ } else {+ // Fetch the first page of next chapter+ this.getPage(0, this.nextChapterId);}});this.readerService.getPrevChapter(this.seriesId, this.volumeId, this.chapterId, this.readingListId).pipe(take(1)).subscribe(chapterId => {@@ -755,6 +752,9 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {if (chapterId === CHAPTER_ID_DOESNT_EXIST || chapterId === this.chapterId) {this.prevChapterDisabled = true;this.cdRef.markForCheck();+ } else {+ // Fetch the last page of prev chapter+ this.getPage(1000000, this.nextChapterId);}});@@ -961,6 +961,10 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {}}+ onSwipeEvent(event: any) {+ console.log('Swipe event occured: ', event);+ }+handlePageChange(event: any, direction: string) {if (this.readerMode === ReaderMode.Webtoon) {if (direction === 'right') {@@ -1073,25 +1077,15 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {* Sets canvasImage's src to current page, but first attempts to use a pre-fetched image*/setCanvasImage() {- if (this.layoutMode === LayoutMode.Single) {- const img = this.cachedImages.find(img => this.readerService.imageUrlToPageNum(img.src) === this.pageNum);- if (img) {- this.canvasImage = img; // If we tried to use this for double, then the loadPage might not render correctly when switching layout mode- } else {- this.canvasImage.src = this.getPageUrl(this.pageNum);- }- } else {- this.canvasImage.src = this.getPageUrl(this.pageNum);- }--+ this.canvasImage = this.getPage(this.pageNum);this.canvasImage.onload = () => {- this.cdRef.markForCheck();+ this.renderPage();};this.cdRef.markForCheck();}+loadNextChapter() {if (this.nextPageDisabled || this.nextChapterDisabled || this.bookmarkMode) {this.toastr.info('No Next Chapter');@@ -1301,18 +1295,32 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {* and also maintains page info (wide image, etc) due to onload event.*/prefetch() {+ // NOTE: This doesn't allow for any directionality+ // NOTE: This doesn't maintain 1 image behind at all times+ // NOTE: I may want to provide a different prefetcher for double rendererfor(let i = 0; i <= PREFETCH_PAGES - 3; i++) {const numOffset = this.pageNum + i;if (numOffset > this.maxPages - 1) continue;const index = (numOffset % this.cachedImages.length + this.cachedImages.length) % this.cachedImages.length;if (this.readerService.imageUrlToPageNum(this.cachedImages[index].src) !== numOffset) {+ this.cachedImages[index] = new Image();this.cachedImages[index].src = this.getPageUrl(numOffset);- this.cachedImages[index].onload = () => this.cdRef.markForCheck();+ this.cachedImages[index].onload = () => {+ //console.log('Page ', numOffset, ' loaded');+ //this.cdRef.markForCheck();+ };}}- //console.log(this.pageNum, ' Prefetched pages: ', this.cachedImages.map(img => this.readerService.imageUrlToPageNum(img.src)));+ const pages = this.cachedImages.map(img => this.readerService.imageUrlToPageNum(img.src));+ const pagesBefore = pages.filter(p => p >= 0 && p < this.pageNum).length;+ const pagesAfter = pages.filter(p => p >= 0 && p > this.pageNum).length;+ console.log('Buffer Health: Before: ', pagesBefore, ' After: ', pagesAfter);+ console.log(this.pageNum, ' Prefetched pages: ', pages.map(p => {+ if (this.pageNum === p) return '[' + p + ']';+ return '' + p+ }));}@@ -1327,30 +1335,54 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {this.setCanvasImage();+ // ?! This logic is hella complex and confusing to read+ // ?! We need to refactor into separate methods and keep it clean+ // ?! In addition, we shouldn't update canvasImage outside of this code+if (this.layoutMode !== LayoutMode.Single) {- this.canvasImageNext.src = this.getPageUrl(this.pageNum + 1); // This needs to be capped at maxPages !this.isLastImage()- this.canvasImagePrev.src = this.getPageUrl(this.pageNum - 1);++ this.canvasImageNext = new Image();+++ // If prev page was a spread, then we don't do + 1+ console.log('Current canvas image page: ', this.readerService.imageUrlToPageNum(this.canvasImage.src));+ console.log('Prev canvas image page: ', this.readerService.imageUrlToPageNum(this.canvasImage2.src));+ // if (this.isWideImage(this.canvasImage2)) {+ // this.canvasImagePrev = this.getPage(this.pageNum); // this.getPageUrl(this.pageNum);+ // console.log('Setting Prev to ', this.pageNum);+ // } else {+ // this.canvasImagePrev = this.getPage(this.pageNum - 1); //this.getPageUrl(this.pageNum - 1);+ // console.log('Setting Prev to ', this.pageNum - 1);+ // }++ // TODO: Validate this statement: This needs to be capped at maxPages !this.isLastImage()+ this.canvasImageNext = this.getPage(this.pageNum + 1);+ console.log('Setting Next to ', this.pageNum + 1);++ this.canvasImagePrev = this.getPage(this.pageNum - 1);+ console.log('Setting Prev to ', this.pageNum - 1);if (this.pageNum + 2 < this.maxPages - 1) {- this.canvasImageAheadBy2.src = this.getPageUrl(this.pageNum + 2);+ this.canvasImageAheadBy2 = this.getPage(this.pageNum + 2);}if (this.pageNum - 2 >= 0) {- this.canvasImageBehindBy2.src = this.getPageUrl(this.pageNum - 2 || 0);+ this.canvasImageBehindBy2 = this.getPage(this.pageNum - 2 || 0);}if (this.ShouldRenderDoublePage || this.ShouldRenderReverseDouble) {+ console.log('Rendering Double Page');if (this.layoutMode === LayoutMode.Double) {- this.canvasImage2.src = this.canvasImageNext.src;+ this.canvasImage2 = this.canvasImageNext;} else {- this.canvasImage2.src = this.canvasImagePrev.src;+ this.canvasImage2 = this.canvasImagePrev;}}}- this.cdRef.markForCheck();++ this.cdRef.markForCheck();this.renderPage();this.prefetch();- this.isLoading = false;this.cdRef.markForCheck();}diff --git a/UI/Web/src/app/manga-reader/manga-reader.module.ts b/UI/Web/src/app/manga-reader/manga-reader.module.tsindex 03abe09e1..4712fb2ec 100644--- a/UI/Web/src/app/manga-reader/manga-reader.module.ts+++ b/UI/Web/src/app/manga-reader/manga-reader.module.ts@@ -8,14 +8,18 @@ import { SharedModule } from '../shared/shared.module';import { NgxSliderModule } from '@angular-slider/ngx-slider';import { InfiniteScrollerComponent } from './infinite-scroller/infinite-scroller.component';import { ReaderSharedModule } from '../reader-shared/reader-shared.module';-import { FullscreenIconPipe } from './fullscreen-icon.pipe';import { PipeModule } from '../pipe/pipe.module';+import { FullscreenIconPipe } from './_pipes/fullscreen-icon.pipe';+import { LayoutModeIconPipe } from './_pipes/layout-mode-icon.pipe';+import { ReaderModeIconPipe } from './_pipes/reader-mode-icon.pipe';@NgModule({declarations: [MangaReaderComponent,InfiniteScrollerComponent,- FullscreenIconPipe+ FullscreenIconPipe,+ ReaderModeIconPipe,+ LayoutModeIconPipe,],imports: [CommonModule,diff --git a/UI/Web/src/app/reading-list/_modals/edit-reading-list-modal/edit-reading-list-modal.component.ts b/UI/Web/src/app/reading-list/_modals/edit-reading-list-modal/edit-reading-list-modal.component.tsindex 13d6960a4..ed8c757d5 100644--- a/UI/Web/src/app/reading-list/_modals/edit-reading-list-modal/edit-reading-list-modal.component.ts+++ b/UI/Web/src/app/reading-list/_modals/edit-reading-list-modal/edit-reading-list-modal.component.ts@@ -56,9 +56,7 @@ export class EditReadingListModalComponent implements OnInit {save() {if (this.reviewGroup.value.title.trim() === '') return;-const model = {...this.reviewGroup.value, readingListId: this.readingList.id, promoted: this.readingList.promoted, coverImageLocked: this.coverImageLocked};-const apis = [this.readingListService.update(model)];if (this.selectedCover !== '') {@@ -77,7 +75,7 @@ export class EditReadingListModalComponent implements OnInit {togglePromotion() {const originalPromotion = this.readingList.promoted;this.readingList.promoted = !this.readingList.promoted;- const model = {readingListId: this.readingList.id, promoted: this.readingList.promoted};+ const model = {...this.reviewGroup.value, readingListId: this.readingList.id, promoted: this.readingList.promoted, coverImageLocked: this.coverImageLocked};this.readingListService.update(model).subscribe(res => {/* No Operation */}, err => {diff --git a/UI/Web/src/app/reading-list/reading-lists/reading-lists.component.ts b/UI/Web/src/app/reading-list/reading-lists/reading-lists.component.tsindex 758bd7aff..7a7120528 100644--- a/UI/Web/src/app/reading-list/reading-lists/reading-lists.component.ts+++ b/UI/Web/src/app/reading-list/reading-lists/reading-lists.component.ts@@ -2,7 +2,6 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@import { Router } from '@angular/router';import { ToastrService } from 'ngx-toastr';import { take } from 'rxjs/operators';-import { UtilityService } from 'src/app/shared/_services/utility.service';import { JumpKey } from 'src/app/_models/jumpbar/jump-key';import { PaginatedResult, Pagination } from 'src/app/_models/pagination';import { ReadingList } from 'src/app/_models/reading-list';@@ -10,6 +9,7 @@ import { AccountService } from 'src/app/_services/account.service';import { Action, ActionFactoryService, ActionItem } from 'src/app/_services/action-factory.service';import { ActionService } from 'src/app/_services/action.service';import { ImageService } from 'src/app/_services/image.service';+import { JumpbarService } from 'src/app/_services/jumpbar.service';import { ReadingListService } from 'src/app/_services/reading-list.service';@Component({@@ -28,7 +28,7 @@ export class ReadingListsComponent implements OnInit {constructor(private readingListService: ReadingListService, public imageService: ImageService, private actionFactoryService: ActionFactoryService,private accountService: AccountService, private toastr: ToastrService, private router: Router, private actionService: ActionService,- private utilityService: UtilityService, private readonly cdRef: ChangeDetectorRef) { }+ private jumpbarService: JumpbarService, private readonly cdRef: ChangeDetectorRef) { }ngOnInit(): void {this.accountService.currentUser$.pipe(take(1)).subscribe(user => {@@ -84,7 +84,7 @@ export class ReadingListsComponent implements OnInit {this.readingListService.getReadingLists(true).pipe(take(1)).subscribe((readingLists: PaginatedResult<ReadingList[]>) => {this.lists = readingLists.result;this.pagination = readingLists.pagination;- this.jumpbarKeys = this.utilityService.getJumpKeys(readingLists.result, (rl: ReadingList) => rl.title);+ this.jumpbarKeys = this.jumpbarService.getJumpKeys(readingLists.result, (rl: ReadingList) => rl.title);this.loadingLists = false;window.scrollTo(0, 0);this.cdRef.markForCheck();diff --git a/UI/Web/src/app/series-detail/series-detail.component.ts b/UI/Web/src/app/series-detail/series-detail.component.tsindex b342b519c..69230e135 100644--- a/UI/Web/src/app/series-detail/series-detail.component.ts+++ b/UI/Web/src/app/series-detail/series-detail.component.ts@@ -440,7 +440,7 @@ export class SeriesDetailComponent implements OnInit, OnDestroy, AfterContentCheasync deleteSeries(series: Series) {- this.actionService.deleteSeries(series, (result: boolean) => {+ await this.actionService.deleteSeries(series, (result: boolean) => {this.changeDetectionRef.markForCheck();if (result) {this.router.navigate(['library', this.libraryId]);diff --git a/UI/Web/src/app/shared/_services/utility.service.ts b/UI/Web/src/app/shared/_services/utility.service.tsindex ffe1143ad..a2660f141 100644--- a/UI/Web/src/app/shared/_services/utility.service.ts+++ b/UI/Web/src/app/shared/_services/utility.service.ts@@ -203,36 +203,4 @@ export class UtilityService {|| document.body.clientHeight;return [windowWidth, windowHeight];}-- /**- *- * @param data An array of objects- * @param keySelector A method to fetch a string from the object, which is used to classify the JumpKey- * @returns- */- getJumpKeys(data :Array<any>, keySelector: (data: any) => string) {- const keys: {[key: string]: number} = {};- data.forEach(obj => {- let ch = keySelector(obj).charAt(0);- if (/\d|\#|!|%|@|\(|\)|\^|\.|_|\*/g.test(ch)) {- ch = '#';- }- if (!keys.hasOwnProperty(ch)) {- keys[ch] = 0;- }- keys[ch] += 1;- });- return Object.keys(keys).map(k => {- return {- key: k,- size: keys[k],- title: k.toUpperCase()- }- }).sort((a, b) => {- if (a.key < b.key) return -1;- if (a.key > b.key) return 1;- return 0;- });- }-}diff --git a/UI/Web/src/app/want-to-read/want-to-read/want-to-read.component.ts b/UI/Web/src/app/want-to-read/want-to-read/want-to-read.component.tsindex 09a184755..ff2a906a5 100644--- a/UI/Web/src/app/want-to-read/want-to-read/want-to-read.component.ts+++ b/UI/Web/src/app/want-to-read/want-to-read/want-to-read.component.ts@@ -15,6 +15,7 @@ import { SeriesFilter, FilterEvent } from 'src/app/_models/series-filter';import { Action, ActionItem } from 'src/app/_services/action-factory.service';import { ActionService } from 'src/app/_services/action.service';import { ImageService } from 'src/app/_services/image.service';+import { JumpbarService } from 'src/app/_services/jumpbar.service';import { MessageHubService, EVENTS } from 'src/app/_services/message-hub.service';import { ScrollService } from 'src/app/_services/scroll.service';import { SeriesService } from 'src/app/_services/series.service';@@ -80,7 +81,8 @@ export class WantToReadComponent implements OnInit, OnDestroy {private seriesService: SeriesService, private titleService: Title,public bulkSelectionService: BulkSelectionService, private actionService: ActionService, private messageHub: MessageHubService,private filterUtilityService: FilterUtilitiesService, private utilityService: UtilityService, @Inject(DOCUMENT) private document: Document,- private readonly cdRef: ChangeDetectorRef, private scrollService: ScrollService, private hubService: MessageHubService) {+ private readonly cdRef: ChangeDetectorRef, private scrollService: ScrollService, private hubService: MessageHubService,+ private jumpbarService: JumpbarService) {this.router.routeReuseStrategy.shouldReuseRoute = () => false;this.titleService.setTitle('Want To Read');@@ -152,7 +154,7 @@ export class WantToReadComponent implements OnInit, OnDestroy {this.seriesService.getWantToRead(undefined, undefined, this.filter).pipe(take(1)).subscribe(paginatedList => {this.series = paginatedList.result;this.seriesPagination = paginatedList.pagination;- this.jumpbarKeys = this.utilityService.getJumpKeys(this.series, (series: Series) => series.name);+ this.jumpbarKeys = this.jumpbarService.getJumpKeys(this.series, (series: Series) => series.name);this.isLoading = false;window.scrollTo(0, 0);this.cdRef.markForCheck();