diff --git a/API/Controllers/ReaderController.cs b/API/Controllers/ReaderController.cs index e6021aa61..b17afa814 100644 --- a/API/Controllers/ReaderController.cs +++ b/API/Controllers/ReaderController.cs @@ -21,7 +21,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using Microsoft.IdentityModel.Tokens; using MimeTypes; namespace API.Controllers; @@ -141,7 +140,7 @@ public async Task GetImage(int chapterId, int page, string apiKey, /// /// [HttpGet("thumbnail")] - [ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = new []{"chapterId", "pageNum", "apiKey"})] + [ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = ["chapterId", "pageNum", "apiKey"])] [AllowAnonymous] public async Task GetThumbnail(int chapterId, int pageNum, string apiKey) { @@ -165,14 +164,14 @@ public async Task GetThumbnail(int chapterId, int pageNum, string /// We must use api key as bookmarks could be leaked to other users via the API /// [HttpGet("bookmark-image")] - [ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = new []{"seriesId", "page", "apiKey"})] + [ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = ["seriesId", "page", "apiKey"])] [AllowAnonymous] public async Task GetBookmarkImage(int seriesId, string apiKey, int page) { - if (page < 0) page = 0; var userId = await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey); if (userId == 0) return Unauthorized(); + if (page < 0) page = 0; var totalPages = await _cacheService.CacheBookmarkForSeries(userId, seriesId); if (page > totalPages) { @@ -189,7 +188,7 @@ public async Task GetBookmarkImage(int seriesId, string apiKey, in } catch (Exception) { - _cacheService.CleanupBookmarks(new []{ seriesId }); + _cacheService.CleanupBookmarks([seriesId]); throw; } } @@ -203,12 +202,13 @@ public async Task GetBookmarkImage(int seriesId, string apiKey, in /// /// [HttpGet("file-dimensions")] - [ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = new []{"chapterId", "extractPdf"})] + [ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = ["chapterId", "extractPdf"])] public async Task>> GetFileDimensions(int chapterId, bool extractPdf = false) { if (chapterId <= 0) return ArraySegment.Empty; var chapter = await _cacheService.Ensure(chapterId, extractPdf); if (chapter == null) return NoContent(); + return Ok(_cacheService.GetCachedFileDimensions(_cacheService.GetCachePath(chapterId))); } @@ -221,7 +221,8 @@ public async Task>> GetFileDimensions /// Include file dimensions. Only useful for image based reading /// [HttpGet("chapter-info")] - [ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = new []{"chapterId", "extractPdf", "includeDimensions"})] + [ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = ["chapterId", "extractPdf", "includeDimensions" + ])] public async Task> GetChapterInfo(int chapterId, bool extractPdf = false, bool includeDimensions = false) { if (chapterId <= 0) return Ok(null); // This can happen occasionally from UI, we should just ignore @@ -261,6 +262,7 @@ public async Task> GetChapterInfo(int chapterId, bo } if (info.ChapterTitle is {Length: > 0}) { + // TODO: Can we rework the logic of generating titles for the UI and instead calculate that in the DB? info.Title += " - " + info.ChapterTitle; } @@ -292,7 +294,7 @@ public async Task> GetChapterInfo(int chapterId, bo /// Include file dimensions (extra I/O). Defaults to true. /// [HttpGet("bookmark-info")] - [ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = new []{"seriesId", "includeDimensions"})] + [ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = ["seriesId", "includeDimensions"])] public async Task> GetBookmarkInfo(int seriesId, bool includeDimensions = true) { var totalPages = await _cacheService.CacheBookmarkForSeries(User.GetUserId(), seriesId); @@ -376,13 +378,10 @@ public async Task MarkVolumeAsUnread(MarkVolumeReadDto markVolumeR var chapters = await _unitOfWork.ChapterRepository.GetChaptersAsync(markVolumeReadDto.VolumeId); await _readerService.MarkChaptersAsUnread(user, markVolumeReadDto.SeriesId, chapters); - if (await _unitOfWork.CommitAsync()) - { - BackgroundJob.Enqueue(() => _scrobblingService.ScrobbleReadingUpdate(user.Id, markVolumeReadDto.SeriesId)); - return Ok(); - } + if (!await _unitOfWork.CommitAsync()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-read-progress")); - return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-read-progress")); + BackgroundJob.Enqueue(() => _scrobblingService.ScrobbleReadingUpdate(user.Id, markVolumeReadDto.SeriesId)); + return Ok(); } /// @@ -552,7 +551,7 @@ public async Task> GetProgress(int chapterId) } /// - /// Save page against Chapter for logged in user + /// Save page against Chapter for authenticated user /// /// /// @@ -770,7 +769,7 @@ public async Task UnBookmarkPage(BookmarkDto bookmarkDto) /// /// /// chapter id for next manga - [ResponseCache(CacheProfileName = "Hour", VaryByQueryKeys = new [] { "seriesId", "volumeId", "currentChapterId"})] + [ResponseCache(CacheProfileName = "Hour", VaryByQueryKeys = ["seriesId", "volumeId", "currentChapterId"])] [HttpGet("next-chapter")] public async Task> GetNextChapter(int seriesId, int volumeId, int currentChapterId) { @@ -788,7 +787,7 @@ public async Task> GetNextChapter(int seriesId, int volumeId, /// /// /// chapter id for next manga - [ResponseCache(CacheProfileName = "Hour", VaryByQueryKeys = new [] { "seriesId", "volumeId", "currentChapterId"})] + [ResponseCache(CacheProfileName = "Hour", VaryByQueryKeys = ["seriesId", "volumeId", "currentChapterId"])] [HttpGet("prev-chapter")] public async Task> GetPreviousChapter(int seriesId, int volumeId, int currentChapterId) { @@ -802,7 +801,7 @@ public async Task> GetPreviousChapter(int seriesId, int volume /// /// [HttpGet("time-left")] - [ResponseCache(CacheProfileName = "Hour", VaryByQueryKeys = new [] { "seriesId"})] + [ResponseCache(CacheProfileName = "Hour", VaryByQueryKeys = ["seriesId"])] public async Task> GetEstimateToCompletion(int seriesId) { var userId = User.GetUserId();