Lots of Bugfixes (#2977)
This commit is contained in:
parent
8c629695ef
commit
616ed7a75d
26 changed files with 427 additions and 244 deletions
|
@ -22,6 +22,7 @@ using API.Extensions;
|
|||
using API.Helpers;
|
||||
using API.Services;
|
||||
using API.Services.Tasks.Scanner.Parser;
|
||||
using AutoMapper;
|
||||
using Kavita.Common;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -42,6 +43,7 @@ public class OpdsController : BaseApiController
|
|||
private readonly ISeriesService _seriesService;
|
||||
private readonly IAccountService _accountService;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
|
||||
private readonly XmlSerializer _xmlSerializer;
|
||||
|
@ -78,7 +80,8 @@ public class OpdsController : BaseApiController
|
|||
public OpdsController(IUnitOfWork unitOfWork, IDownloadService downloadService,
|
||||
IDirectoryService directoryService, ICacheService cacheService,
|
||||
IReaderService readerService, ISeriesService seriesService,
|
||||
IAccountService accountService, ILocalizationService localizationService)
|
||||
IAccountService accountService, ILocalizationService localizationService,
|
||||
IMapper mapper)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_downloadService = downloadService;
|
||||
|
@ -88,6 +91,7 @@ public class OpdsController : BaseApiController
|
|||
_seriesService = seriesService;
|
||||
_accountService = accountService;
|
||||
_localizationService = localizationService;
|
||||
_mapper = mapper;
|
||||
|
||||
_xmlSerializer = new XmlSerializer(typeof(Feed));
|
||||
_xmlOpenSearchSerializer = new XmlSerializer(typeof(OpenSearchDescription));
|
||||
|
@ -289,7 +293,7 @@ public class OpdsController : BaseApiController
|
|||
{
|
||||
var baseUrl = (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BaseUrl)).Value;
|
||||
var prefix = "/api/opds/";
|
||||
if (!Configuration.DefaultBaseUrl.Equals(baseUrl))
|
||||
if (!Configuration.DefaultBaseUrl.Equals(baseUrl, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
// We need to update the Prefix to account for baseUrl
|
||||
prefix = baseUrl + "api/opds/";
|
||||
|
@ -849,16 +853,15 @@ public class OpdsController : BaseApiController
|
|||
var seriesDetail = await _seriesService.GetSeriesDetail(seriesId, userId);
|
||||
foreach (var volume in seriesDetail.Volumes)
|
||||
{
|
||||
var chapters = (await _unitOfWork.ChapterRepository.GetChaptersAsync(volume.Id))
|
||||
.OrderBy(x => x.MinNumber, _chapterSortComparerDefaultLast);
|
||||
var chapters = await _unitOfWork.ChapterRepository.GetChaptersAsync(volume.Id, ChapterIncludes.Files);
|
||||
|
||||
foreach (var chapterId in chapters.Select(c => c.Id))
|
||||
foreach (var chapter in chapters)
|
||||
{
|
||||
var files = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId);
|
||||
var chapterTest = await _unitOfWork.ChapterRepository.GetChapterDtoAsync(chapterId);
|
||||
foreach (var mangaFile in files)
|
||||
var chapterId = chapter.Id;
|
||||
var chapterDto = _mapper.Map<ChapterDto>(chapter);
|
||||
foreach (var mangaFile in chapter.Files)
|
||||
{
|
||||
feed.Entries.Add(await CreateChapterWithFile(userId, seriesId, volume.Id, chapterId, mangaFile, series, chapterTest, apiKey, prefix, baseUrl));
|
||||
feed.Entries.Add(await CreateChapterWithFile(userId, seriesId, volume.Id, chapterId, mangaFile, series, chapterDto, apiKey, prefix, baseUrl));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -867,20 +870,20 @@ public class OpdsController : BaseApiController
|
|||
foreach (var storylineChapter in seriesDetail.StorylineChapters.Where(c => !c.IsSpecial))
|
||||
{
|
||||
var files = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(storylineChapter.Id);
|
||||
var chapterTest = await _unitOfWork.ChapterRepository.GetChapterDtoAsync(storylineChapter.Id);
|
||||
var chapterDto = _mapper.Map<ChapterDto>(storylineChapter);
|
||||
foreach (var mangaFile in files)
|
||||
{
|
||||
feed.Entries.Add(await CreateChapterWithFile(userId, seriesId, storylineChapter.VolumeId, storylineChapter.Id, mangaFile, series, chapterTest, apiKey, prefix, baseUrl));
|
||||
feed.Entries.Add(await CreateChapterWithFile(userId, seriesId, storylineChapter.VolumeId, storylineChapter.Id, mangaFile, series, chapterDto, apiKey, prefix, baseUrl));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var special in seriesDetail.Specials)
|
||||
{
|
||||
var files = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(special.Id);
|
||||
var chapterTest = await _unitOfWork.ChapterRepository.GetChapterDtoAsync(special.Id);
|
||||
var chapterDto = _mapper.Map<ChapterDto>(special);
|
||||
foreach (var mangaFile in files)
|
||||
{
|
||||
feed.Entries.Add(await CreateChapterWithFile(userId, seriesId, special.VolumeId, special.Id, mangaFile, series, chapterTest, apiKey, prefix, baseUrl));
|
||||
feed.Entries.Add(await CreateChapterWithFile(userId, seriesId, special.VolumeId, special.Id, mangaFile, series, chapterDto, apiKey, prefix, baseUrl));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1127,14 +1130,15 @@ public class OpdsController : BaseApiController
|
|||
? string.Empty
|
||||
: $" Summary: {chapter.Summary}"),
|
||||
Format = mangaFile.Format.ToString(),
|
||||
Links = new List<FeedLink>()
|
||||
{
|
||||
CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"{baseUrl}api/image/chapter-cover?chapterId={chapterId}&apiKey={apiKey}"),
|
||||
CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image, $"{baseUrl}api/image/chapter-cover?chapterId={chapterId}&apiKey={apiKey}"),
|
||||
// We can't not include acc link in the feed, panels doesn't work with just page streaming option. We have to block download directly
|
||||
accLink,
|
||||
await CreatePageStreamLink(series.LibraryId, seriesId, volumeId, chapterId, mangaFile, apiKey, prefix)
|
||||
},
|
||||
Links =
|
||||
[
|
||||
CreateLink(FeedLinkRelation.Image, FeedLinkType.Image,
|
||||
$"{baseUrl}api/image/chapter-cover?chapterId={chapterId}&apiKey={apiKey}"),
|
||||
CreateLink(FeedLinkRelation.Thumbnail, FeedLinkType.Image,
|
||||
$"{baseUrl}api/image/chapter-cover?chapterId={chapterId}&apiKey={apiKey}"),
|
||||
// We MUST include acc link in the feed, panels doesn't work with just page streaming option. We have to block download directly
|
||||
accLink
|
||||
],
|
||||
Content = new FeedEntryContent()
|
||||
{
|
||||
Text = fileType,
|
||||
|
@ -1142,6 +1146,12 @@ public class OpdsController : BaseApiController
|
|||
}
|
||||
};
|
||||
|
||||
var canPageStream = mangaFile.Extension != ".epub";
|
||||
if (canPageStream)
|
||||
{
|
||||
entry.Links.Add(await CreatePageStreamLink(series.LibraryId, seriesId, volumeId, chapterId, mangaFile, apiKey, prefix));
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
@ -1162,7 +1172,7 @@ public class OpdsController : BaseApiController
|
|||
{
|
||||
var userId = await GetUser(apiKey);
|
||||
if (pageNumber < 0) return BadRequest(await _localizationService.Translate(userId, "greater-0", "Page"));
|
||||
var chapter = await _cacheService.Ensure(chapterId);
|
||||
var chapter = await _cacheService.Ensure(chapterId, true);
|
||||
if (chapter == null) return BadRequest(await _localizationService.Translate(userId, "cache-file-find"));
|
||||
|
||||
try
|
||||
|
@ -1188,10 +1198,9 @@ public class OpdsController : BaseApiController
|
|||
SeriesId = seriesId,
|
||||
VolumeId = volumeId,
|
||||
LibraryId =libraryId
|
||||
}, await GetUser(apiKey));
|
||||
}, userId);
|
||||
}
|
||||
|
||||
|
||||
return File(content, MimeTypeMap.GetMimeType(format));
|
||||
}
|
||||
catch (Exception)
|
||||
|
@ -1223,8 +1232,7 @@ public class OpdsController : BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey);
|
||||
return user;
|
||||
return await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -1242,12 +1250,14 @@ public class OpdsController : BaseApiController
|
|||
var link = CreateLink(FeedLinkRelation.Stream, "image/jpeg",
|
||||
$"{prefix}{apiKey}/image?libraryId={libraryId}&seriesId={seriesId}&volumeId={volumeId}&chapterId={chapterId}&pageNumber=" + "{pageNumber}");
|
||||
link.TotalPages = mangaFile.Pages;
|
||||
link.IsPageStream = true;
|
||||
|
||||
if (progress != null)
|
||||
{
|
||||
link.LastRead = progress.PageNum;
|
||||
link.LastReadDate = progress.LastModifiedUtc.ToString("s"); // Adhere to ISO 8601
|
||||
}
|
||||
link.IsPageStream = true;
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
|
@ -1272,20 +1282,22 @@ public class OpdsController : BaseApiController
|
|||
{
|
||||
Title = title,
|
||||
Icon = $"{prefix}{apiKey}/favicon",
|
||||
Links = new List<FeedLink>()
|
||||
{
|
||||
Links =
|
||||
[
|
||||
link,
|
||||
CreateLink(FeedLinkRelation.Start, FeedLinkType.AtomNavigation, $"{prefix}{apiKey}"),
|
||||
CreateLink(FeedLinkRelation.Search, FeedLinkType.AtomSearch, $"{prefix}{apiKey}/search")
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
private string SerializeXml(Feed? feed)
|
||||
{
|
||||
if (feed == null) return string.Empty;
|
||||
|
||||
using var sm = new StringWriter();
|
||||
_xmlSerializer.Serialize(sm, feed);
|
||||
|
||||
return sm.ToString().Replace("utf-16", "utf-8"); // Chunky cannot accept UTF-16 feeds
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,8 +50,14 @@ public class SearchController : BaseApiController
|
|||
return Ok(await _unitOfWork.SeriesRepository.GetSeriesForChapter(chapterId, User.GetUserId()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches against different entities in the system against a query string
|
||||
/// </summary>
|
||||
/// <param name="queryString"></param>
|
||||
/// <param name="includeChapterAndFiles">Include Chapter and Filenames in the entities. This can slow down the search on larger systems</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("search")]
|
||||
public async Task<ActionResult<SearchResultGroupDto>> Search(string queryString)
|
||||
public async Task<ActionResult<SearchResultGroupDto>> Search(string queryString, [FromQuery] bool includeChapterAndFiles = true)
|
||||
{
|
||||
queryString = Services.Tasks.Scanner.Parser.Parser.CleanQuery(queryString);
|
||||
|
||||
|
@ -63,7 +69,7 @@ public class SearchController : BaseApiController
|
|||
var isAdmin = await _unitOfWork.UserRepository.IsUserAdminAsync(user);
|
||||
|
||||
var series = await _unitOfWork.SeriesRepository.SearchSeries(user.Id, isAdmin,
|
||||
libraries, queryString);
|
||||
libraries, queryString, includeChapterAndFiles);
|
||||
|
||||
return Ok(series);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public interface IChapterRepository
|
|||
Task<ChapterDto?> GetChapterDtoAsync(int chapterId, ChapterIncludes includes = ChapterIncludes.Files);
|
||||
Task<ChapterMetadataDto?> GetChapterMetadataDtoAsync(int chapterId, ChapterIncludes includes = ChapterIncludes.Files);
|
||||
Task<IList<MangaFile>> GetFilesForChapterAsync(int chapterId);
|
||||
Task<IList<Chapter>> GetChaptersAsync(int volumeId);
|
||||
Task<IList<Chapter>> GetChaptersAsync(int volumeId, ChapterIncludes includes = ChapterIncludes.None);
|
||||
Task<IList<MangaFile>> GetFilesForChaptersAsync(IReadOnlyList<int> chapterIds);
|
||||
Task<string?> GetChapterCoverImageAsync(int chapterId);
|
||||
Task<IList<string>> GetAllCoverImagesAsync();
|
||||
|
@ -184,10 +184,11 @@ public class ChapterRepository : IChapterRepository
|
|||
/// </summary>
|
||||
/// <param name="volumeId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IList<Chapter>> GetChaptersAsync(int volumeId)
|
||||
public async Task<IList<Chapter>> GetChaptersAsync(int volumeId, ChapterIncludes includes = ChapterIncludes.None)
|
||||
{
|
||||
return await _context.Chapter
|
||||
.Where(c => c.VolumeId == volumeId)
|
||||
.Includes(includes)
|
||||
.OrderBy(c => c.SortOrder)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
|
|
@ -91,8 +91,9 @@ public interface ISeriesRepository
|
|||
/// <param name="isAdmin"></param>
|
||||
/// <param name="libraryIds"></param>
|
||||
/// <param name="searchQuery"></param>
|
||||
/// <param name="includeChapterAndFiles">Includes Files in the Search</param>
|
||||
/// <returns></returns>
|
||||
Task<SearchResultGroupDto> SearchSeries(int userId, bool isAdmin, IList<int> libraryIds, string searchQuery);
|
||||
Task<SearchResultGroupDto> SearchSeries(int userId, bool isAdmin, IList<int> libraryIds, string searchQuery, bool includeChapterAndFiles = true);
|
||||
Task<IEnumerable<Series>> GetSeriesForLibraryIdAsync(int libraryId, SeriesIncludes includes = SeriesIncludes.None);
|
||||
Task<SeriesDto?> GetSeriesDtoByIdAsync(int seriesId, int userId);
|
||||
Task<Series?> GetSeriesByIdAsync(int seriesId, SeriesIncludes includes = SeriesIncludes.Volumes | SeriesIncludes.Metadata);
|
||||
|
@ -353,7 +354,7 @@ public class SeriesRepository : ISeriesRepository
|
|||
return [libraryId];
|
||||
}
|
||||
|
||||
public async Task<SearchResultGroupDto> SearchSeries(int userId, bool isAdmin, IList<int> libraryIds, string searchQuery)
|
||||
public async Task<SearchResultGroupDto> SearchSeries(int userId, bool isAdmin, IList<int> libraryIds, string searchQuery, bool includeChapterAndFiles = true)
|
||||
{
|
||||
const int maxRecords = 15;
|
||||
var result = new SearchResultGroupDto();
|
||||
|
@ -452,42 +453,45 @@ public class SeriesRepository : ISeriesRepository
|
|||
.ProjectTo<TagDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
|
||||
var fileIds = _context.Series
|
||||
.Where(s => seriesIds.Contains(s.Id))
|
||||
.AsSplitQuery()
|
||||
.SelectMany(s => s.Volumes)
|
||||
.SelectMany(v => v.Chapters)
|
||||
.SelectMany(c => c.Files.Select(f => f.Id));
|
||||
result.Files = new List<MangaFileDto>();
|
||||
result.Chapters = new List<ChapterDto>();
|
||||
|
||||
// Need to check if an admin
|
||||
var user = await _context.AppUser.FirstAsync(u => u.Id == userId);
|
||||
if (await _userManager.IsInRoleAsync(user, PolicyConstants.AdminRole))
|
||||
|
||||
if (includeChapterAndFiles)
|
||||
{
|
||||
result.Files = await _context.MangaFile
|
||||
.Where(m => EF.Functions.Like(m.FilePath, $"%{searchQuery}%") && fileIds.Contains(m.Id))
|
||||
var fileIds = _context.Series
|
||||
.Where(s => seriesIds.Contains(s.Id))
|
||||
.AsSplitQuery()
|
||||
.OrderBy(f => f.FilePath)
|
||||
.SelectMany(s => s.Volumes)
|
||||
.SelectMany(v => v.Chapters)
|
||||
.SelectMany(c => c.Files.Select(f => f.Id));
|
||||
|
||||
// Need to check if an admin
|
||||
var user = await _context.AppUser.FirstAsync(u => u.Id == userId);
|
||||
if (await _userManager.IsInRoleAsync(user, PolicyConstants.AdminRole))
|
||||
{
|
||||
result.Files = await _context.MangaFile
|
||||
.Where(m => EF.Functions.Like(m.FilePath, $"%{searchQuery}%") && fileIds.Contains(m.Id))
|
||||
.AsSplitQuery()
|
||||
.OrderBy(f => f.FilePath)
|
||||
.Take(maxRecords)
|
||||
.ProjectTo<MangaFileDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
result.Chapters = await _context.Chapter
|
||||
.Include(c => c.Files)
|
||||
.Where(c => EF.Functions.Like(c.TitleName, $"%{searchQuery}%")
|
||||
|| EF.Functions.Like(c.ISBN, $"%{searchQuery}%")
|
||||
|| EF.Functions.Like(c.Range, $"%{searchQuery}%")
|
||||
)
|
||||
.Where(c => c.Files.All(f => fileIds.Contains(f.Id)))
|
||||
.AsSplitQuery()
|
||||
.OrderBy(c => c.TitleName)
|
||||
.Take(maxRecords)
|
||||
.ProjectTo<MangaFileDto>(_mapper.ConfigurationProvider)
|
||||
.ProjectTo<ChapterDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Files = new List<MangaFileDto>();
|
||||
}
|
||||
|
||||
result.Chapters = await _context.Chapter
|
||||
.Include(c => c.Files)
|
||||
.Where(c => EF.Functions.Like(c.TitleName, $"%{searchQuery}%")
|
||||
|| EF.Functions.Like(c.ISBN, $"%{searchQuery}%")
|
||||
|| EF.Functions.Like(c.Range, $"%{searchQuery}%")
|
||||
)
|
||||
.Where(c => c.Files.All(f => fileIds.Contains(f.Id)))
|
||||
.AsSplitQuery()
|
||||
.OrderBy(c => c.TitleName)
|
||||
.Take(maxRecords)
|
||||
.ProjectTo<ChapterDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -2094,6 +2098,7 @@ public class SeriesRepository : ISeriesRepository
|
|||
LastScanned = s.LastFolderScanned,
|
||||
SeriesName = s.Name,
|
||||
FolderPath = s.FolderPath,
|
||||
LowestFolderPath = s.LowestFolderPath,
|
||||
Format = s.Format,
|
||||
LibraryRoots = s.Library.Folders.Select(f => f.Path)
|
||||
}).ToListAsync();
|
||||
|
@ -2101,7 +2106,7 @@ public class SeriesRepository : ISeriesRepository
|
|||
var map = new Dictionary<string, IList<SeriesModified>>();
|
||||
foreach (var series in info)
|
||||
{
|
||||
if (series.FolderPath == null) continue;
|
||||
if (string.IsNullOrEmpty(series.FolderPath)) continue;
|
||||
if (!map.TryGetValue(series.FolderPath, out var value))
|
||||
{
|
||||
map.Add(series.FolderPath, new List<SeriesModified>()
|
||||
|
@ -2113,6 +2118,20 @@ public class SeriesRepository : ISeriesRepository
|
|||
{
|
||||
value.Add(series);
|
||||
}
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(series.LowestFolderPath)) continue;
|
||||
if (!map.TryGetValue(series.LowestFolderPath, out var value2))
|
||||
{
|
||||
map.Add(series.LowestFolderPath, new List<SeriesModified>()
|
||||
{
|
||||
series
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
value2.Add(series);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
|
|
|
@ -7,17 +7,23 @@ namespace API.Extensions;
|
|||
|
||||
public static class ClaimsPrincipalExtensions
|
||||
{
|
||||
private const string NotAuthenticatedMessage = "User is not authenticated";
|
||||
/// <summary>
|
||||
/// Get's the authenticated user's username
|
||||
/// </summary>
|
||||
/// <remarks>Warning! Username's can contain .. and /, do not use folders or filenames explicitly with the Username</remarks>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="KavitaException"></exception>
|
||||
public static string GetUsername(this ClaimsPrincipal user)
|
||||
{
|
||||
var userClaim = user.FindFirst(JwtRegisteredClaimNames.Name);
|
||||
if (userClaim == null) throw new KavitaException("User is not authenticated");
|
||||
var userClaim = user.FindFirst(JwtRegisteredClaimNames.Name) ?? throw new KavitaException(NotAuthenticatedMessage);
|
||||
return userClaim.Value;
|
||||
}
|
||||
|
||||
public static int GetUserId(this ClaimsPrincipal user)
|
||||
{
|
||||
var userClaim = user.FindFirst(ClaimTypes.NameIdentifier);
|
||||
if (userClaim == null) throw new KavitaException("User is not authenticated");
|
||||
var userClaim = user.FindFirst(ClaimTypes.NameIdentifier) ?? throw new KavitaException(NotAuthenticatedMessage);
|
||||
return int.Parse(userClaim.Value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -847,7 +847,7 @@ public class BookService : IBookService
|
|||
Filename = Path.GetFileName(filePath),
|
||||
Title = specialName?.Trim() ?? string.Empty,
|
||||
FullFilePath = Parser.NormalizePath(filePath),
|
||||
IsSpecial = false,
|
||||
IsSpecial = Parser.HasSpecialMarker(filePath),
|
||||
Series = series.Trim(),
|
||||
SeriesSort = series.Trim(),
|
||||
Volumes = seriesIndex
|
||||
|
@ -869,7 +869,7 @@ public class BookService : IBookService
|
|||
Filename = Path.GetFileName(filePath),
|
||||
Title = epubBook.Title.Trim(),
|
||||
FullFilePath = Parser.NormalizePath(filePath),
|
||||
IsSpecial = false,
|
||||
IsSpecial = Parser.HasSpecialMarker(filePath),
|
||||
Series = epubBook.Title.Trim(),
|
||||
Volumes = Parser.LooseLeafVolume,
|
||||
};
|
||||
|
|
|
@ -322,7 +322,7 @@ public class CacheService : ICacheService
|
|||
var path = GetCachePath(chapterId);
|
||||
// NOTE: We can optimize this by extracting and renaming, so we don't need to scan for the files and can do a direct access
|
||||
var files = _directoryService.GetFilesWithExtension(path, Tasks.Scanner.Parser.Parser.ImageFileExtensions)
|
||||
.OrderByNatural(Path.GetFileNameWithoutExtension)
|
||||
//.OrderByNatural(Path.GetFileNameWithoutExtension) // This is already done in GetPageFromFiles
|
||||
.ToArray();
|
||||
|
||||
return GetPageFromFiles(files, page);
|
||||
|
|
|
@ -228,7 +228,7 @@ public class ScrobblingService : IScrobblingService
|
|||
LibraryId = series.LibraryId,
|
||||
ScrobbleEventType = ScrobbleEventType.Review,
|
||||
AniListId = ExtractId<int?>(series.Metadata.WebLinks, AniListWeblinkWebsite),
|
||||
MalId = ExtractId<long?>(series.Metadata.WebLinks, MalWeblinkWebsite),
|
||||
MalId = GetMalId(series),
|
||||
AppUserId = userId,
|
||||
Format = LibraryTypeHelper.GetFormat(series.Library.Type),
|
||||
ReviewBody = reviewBody,
|
||||
|
@ -250,7 +250,7 @@ public class ScrobblingService : IScrobblingService
|
|||
{
|
||||
if (!await _licenseService.HasActiveLicense()) return;
|
||||
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId, SeriesIncludes.Metadata | SeriesIncludes.Library);
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId, SeriesIncludes.Metadata | SeriesIncludes.Library | SeriesIncludes.ExternalMetadata);
|
||||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling rating event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
|
@ -274,22 +274,34 @@ public class ScrobblingService : IScrobblingService
|
|||
SeriesId = series.Id,
|
||||
LibraryId = series.LibraryId,
|
||||
ScrobbleEventType = ScrobbleEventType.ScoreUpdated,
|
||||
AniListId = ExtractId<int?>(series.Metadata.WebLinks, AniListWeblinkWebsite), // TODO: We can get this also from ExternalSeriesMetadata
|
||||
MalId = ExtractId<long?>(series.Metadata.WebLinks, MalWeblinkWebsite),
|
||||
AniListId = GetAniListId(series),
|
||||
MalId = GetMalId(series),
|
||||
AppUserId = userId,
|
||||
Format = LibraryTypeHelper.GetFormat(series.Library.Type),
|
||||
Rating = rating
|
||||
};
|
||||
_unitOfWork.ScrobbleRepository.Attach(evt);
|
||||
await _unitOfWork.CommitAsync();
|
||||
_logger.LogDebug("Added Scrobbling Rating update on {SeriesName} with Userid {UserId} ", series.Name, userId);
|
||||
_logger.LogDebug("Added Scrobbling Rating update on {SeriesName} with Userid {UserId}", series.Name, userId);
|
||||
}
|
||||
|
||||
private static long? GetMalId(Series series)
|
||||
{
|
||||
var malId = ExtractId<long?>(series.Metadata.WebLinks, MalWeblinkWebsite);
|
||||
return malId ?? series.ExternalSeriesMetadata.MalId;
|
||||
}
|
||||
|
||||
private static int? GetAniListId(Series series)
|
||||
{
|
||||
var aniListId = ExtractId<int?>(series.Metadata.WebLinks, AniListWeblinkWebsite);
|
||||
return aniListId ?? series.ExternalSeriesMetadata.AniListId;
|
||||
}
|
||||
|
||||
public async Task ScrobbleReadingUpdate(int userId, int seriesId)
|
||||
{
|
||||
if (!await _licenseService.HasActiveLicense()) return;
|
||||
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId, SeriesIncludes.Metadata | SeriesIncludes.Library);
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId, SeriesIncludes.Metadata | SeriesIncludes.Library | SeriesIncludes.ExternalMetadata);
|
||||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling reading event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
|
@ -321,8 +333,8 @@ public class ScrobblingService : IScrobblingService
|
|||
SeriesId = series.Id,
|
||||
LibraryId = series.LibraryId,
|
||||
ScrobbleEventType = ScrobbleEventType.ChapterRead,
|
||||
AniListId = ExtractId<int?>(series.Metadata.WebLinks, AniListWeblinkWebsite),
|
||||
MalId = ExtractId<long?>(series.Metadata.WebLinks, MalWeblinkWebsite),
|
||||
AniListId = GetAniListId(series),
|
||||
MalId = GetMalId(series),
|
||||
AppUserId = userId,
|
||||
VolumeNumber =
|
||||
(int) await _unitOfWork.AppUserProgressRepository.GetHighestFullyReadVolumeForSeries(seriesId, userId),
|
||||
|
@ -345,7 +357,7 @@ public class ScrobblingService : IScrobblingService
|
|||
{
|
||||
if (!await _licenseService.HasActiveLicense()) return;
|
||||
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId, SeriesIncludes.Metadata | SeriesIncludes.Library);
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId, SeriesIncludes.Metadata | SeriesIncludes.Library | SeriesIncludes.ExternalMetadata);
|
||||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling want-to-read event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
|
@ -360,8 +372,8 @@ public class ScrobblingService : IScrobblingService
|
|||
SeriesId = series.Id,
|
||||
LibraryId = series.LibraryId,
|
||||
ScrobbleEventType = onWantToRead ? ScrobbleEventType.AddWantToRead : ScrobbleEventType.RemoveWantToRead,
|
||||
AniListId = ExtractId<int?>(series.Metadata.WebLinks, AniListWeblinkWebsite),
|
||||
MalId = ExtractId<long?>(series.Metadata.WebLinks, MalWeblinkWebsite),
|
||||
AniListId = GetAniListId(series),
|
||||
MalId = GetMalId(series),
|
||||
AppUserId = userId,
|
||||
Format = LibraryTypeHelper.GetFormat(series.Library.Type),
|
||||
};
|
||||
|
|
|
@ -394,7 +394,7 @@ public class ReadingListService : IReadingListService
|
|||
var existingChapterExists = readingList.Items.Select(rli => rli.ChapterId).ToHashSet();
|
||||
var chaptersForSeries = (await _unitOfWork.ChapterRepository.GetChaptersByIdsAsync(chapterIds, ChapterIncludes.Volumes))
|
||||
.OrderBy(c => c.Volume.MinNumber)
|
||||
.ThenBy(x => x.MinNumber, _chapterSortComparerForInChapterSorting)
|
||||
.ThenBy(x => x.SortOrder)
|
||||
.ToList();
|
||||
|
||||
var index = readingList.Items.Count == 0 ? 0 : lastOrder + 1;
|
||||
|
|
|
@ -79,6 +79,7 @@ public class ScannedSeriesResult
|
|||
public class SeriesModified
|
||||
{
|
||||
public required string? FolderPath { get; set; }
|
||||
public required string? LowestFolderPath { get; set; }
|
||||
public required string SeriesName { get; set; }
|
||||
public DateTime LastScanned { get; set; }
|
||||
public MangaFormat Format { get; set; }
|
||||
|
@ -151,16 +152,28 @@ public class ParseScannedFiles
|
|||
HasChanged = false
|
||||
});
|
||||
}
|
||||
else if (seriesPaths.TryGetValue(normalizedPath, out var series) && series.All(s => !string.IsNullOrEmpty(s.LowestFolderPath)))
|
||||
{
|
||||
// If there are multiple series inside this path, let's check each of them to see which was modified and only scan those
|
||||
// This is very helpful for ComicVine libraries by Publisher
|
||||
foreach (var seriesModified in series)
|
||||
{
|
||||
if (HasSeriesFolderNotChangedSinceLastScan(seriesModified, seriesModified.LowestFolderPath!))
|
||||
{
|
||||
result.Add(CreateScanResult(directory, folderPath, false, ArraySegment<string>.Empty));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(CreateScanResult(directory, folderPath, true,
|
||||
_directoryService.ScanFiles(seriesModified.LowestFolderPath!, fileExtensions, matcher)));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// For a scan, this is doing everything in the directory loop before the folder Action is called...which leads to no progress indication
|
||||
result.Add(new ScanResult()
|
||||
{
|
||||
Files = _directoryService.ScanFiles(directory, fileExtensions, matcher),
|
||||
Folder = directory,
|
||||
LibraryRoot = folderPath,
|
||||
HasChanged = true
|
||||
});
|
||||
result.Add(CreateScanResult(directory, folderPath, true,
|
||||
_directoryService.ScanFiles(directory, fileExtensions)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,26 +188,30 @@ public class ParseScannedFiles
|
|||
|
||||
if (HasSeriesFolderNotChangedSinceLastScan(seriesPaths, normalizedPath, forceCheck))
|
||||
{
|
||||
result.Add(new ScanResult()
|
||||
{
|
||||
Files = ArraySegment<string>.Empty,
|
||||
Folder = folderPath,
|
||||
LibraryRoot = libraryRoot,
|
||||
HasChanged = false
|
||||
});
|
||||
result.Add(CreateScanResult(folderPath, libraryRoot, false, ArraySegment<string>.Empty));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(CreateScanResult(folderPath, libraryRoot, true,
|
||||
_directoryService.ScanFiles(folderPath, fileExtensions)));
|
||||
}
|
||||
|
||||
result.Add(new ScanResult()
|
||||
{
|
||||
Files = _directoryService.ScanFiles(folderPath, fileExtensions),
|
||||
Folder = folderPath,
|
||||
LibraryRoot = libraryRoot,
|
||||
HasChanged = true
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ScanResult CreateScanResult(string folderPath, string libraryRoot, bool hasChanged,
|
||||
IList<string> files)
|
||||
{
|
||||
return new ScanResult()
|
||||
{
|
||||
Files = files,
|
||||
Folder = folderPath,
|
||||
LibraryRoot = libraryRoot,
|
||||
HasChanged = hasChanged
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to either add a new instance of a series mapping to the _scannedSeries bag or adds to an existing.
|
||||
|
@ -535,10 +552,29 @@ public class ParseScannedFiles
|
|||
{
|
||||
if (forceCheck) return false;
|
||||
|
||||
return seriesPaths.ContainsKey(normalizedFolder) && seriesPaths[normalizedFolder].All(f => f.LastScanned.Truncate(TimeSpan.TicksPerSecond) >=
|
||||
_directoryService.GetLastWriteTime(normalizedFolder).Truncate(TimeSpan.TicksPerSecond));
|
||||
if (seriesPaths.TryGetValue(normalizedFolder, out var v))
|
||||
{
|
||||
return HasAllSeriesFolderNotChangedSinceLastScan(v, normalizedFolder);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool HasAllSeriesFolderNotChangedSinceLastScan(IList<SeriesModified> seriesFolders,
|
||||
string normalizedFolder)
|
||||
{
|
||||
return seriesFolders.All(f => HasSeriesFolderNotChangedSinceLastScan(f, normalizedFolder));
|
||||
}
|
||||
|
||||
private bool HasSeriesFolderNotChangedSinceLastScan(SeriesModified seriesModified, string normalizedFolder)
|
||||
{
|
||||
return seriesModified.LastScanned.Truncate(TimeSpan.TicksPerSecond) >=
|
||||
_directoryService.GetLastWriteTime(normalizedFolder)
|
||||
.Truncate(TimeSpan.TicksPerSecond);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if there are any ParserInfos that have a Series that matches the LocalizedSeries field in any other info. If so,
|
||||
/// rewrites the infos with series name instead of the localized name, so they stack.
|
||||
|
|
|
@ -12,8 +12,14 @@ public class BookParser(IDirectoryService directoryService, IBookService bookSer
|
|||
|
||||
info.ComicInfo = comicInfo;
|
||||
|
||||
// We need a special piece of code to override the Series IF there is a special marker in the filename for epub files
|
||||
if (info.IsSpecial && info.Volumes == "0" && info.ComicInfo.Series != info.Series)
|
||||
{
|
||||
info.Series = info.ComicInfo.Series;
|
||||
}
|
||||
|
||||
// This catches when original library type is Manga/Comic and when parsing with non
|
||||
if (Parser.ParseVolume(info.Series, type) != Parser.LooseLeafVolume) // Shouldn't this be info.Volume != DefaultVolume?
|
||||
if (Parser.ParseVolume(info.Series, type) != Parser.LooseLeafVolume)
|
||||
{
|
||||
var hasVolumeInTitle = !Parser.ParseVolume(info.Title, type)
|
||||
.Equals(Parser.LooseLeafVolume);
|
||||
|
|
|
@ -103,7 +103,7 @@ public static class Parser
|
|||
private static readonly Regex CoverImageRegex = new Regex(@"(?<![[a-z]\d])(?:!?)(?<!back)(?<!back_)(?<!back-)(cover|folder)(?![\w\d])",
|
||||
MatchOptions, RegexTimeout);
|
||||
|
||||
private static readonly Regex NormalizeRegex = new Regex(@"[^\p{L}0-9\+!]",
|
||||
private static readonly Regex NormalizeRegex = new Regex(@"[^\p{L}0-9\+!\*]",
|
||||
MatchOptions, RegexTimeout);
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -710,6 +710,12 @@ public class ProcessSeries : IProcessSeries
|
|||
chapter.SortOrder = info.IssueOrder;
|
||||
}
|
||||
chapter.Range = chapter.GetNumberTitle();
|
||||
if (float.TryParse(chapter.Title, out var _))
|
||||
{
|
||||
// If we have float based chapters, first scan can have the chapter formatted as Chapter 0.2 - .2 as the title is wrong.
|
||||
chapter.Title = chapter.GetNumberTitle();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -358,7 +358,14 @@ public class Startup
|
|||
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
ContentTypeProvider = new FileExtensionContentTypeProvider(),
|
||||
// bcmap files needed for PDF reader localizations (https://github.com/Kareadita/Kavita/issues/2970)
|
||||
ContentTypeProvider = new FileExtensionContentTypeProvider
|
||||
{
|
||||
Mappings =
|
||||
{
|
||||
[".bcmap"] = "application/octet-stream"
|
||||
}
|
||||
},
|
||||
HttpsCompression = HttpsCompressionMode.Compress,
|
||||
OnPrepareResponse = ctx =>
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue