mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-08-30 23:00:06 -04:00
Cleaned up the bookmarking code to use the generic method.
This commit is contained in:
parent
f59d1de559
commit
527bae4cfc
@ -724,59 +724,51 @@ public class ReaderController : BaseApiController
|
|||||||
[HttpPost("bookmark")]
|
[HttpPost("bookmark")]
|
||||||
public async Task<ActionResult> BookmarkPage(BookmarkDto bookmarkDto)
|
public async Task<ActionResult> BookmarkPage(BookmarkDto bookmarkDto)
|
||||||
{
|
{
|
||||||
// Don't let user save past total pages.
|
try
|
||||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
{
|
||||||
if (user == null) return new UnauthorizedResult();
|
// Don't let user save past total pages.
|
||||||
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(),
|
||||||
|
AppUserIncludes.Bookmarks);
|
||||||
|
if (user == null) return new UnauthorizedResult();
|
||||||
|
|
||||||
if (!await _accountService.HasBookmarkPermission(user))
|
if (!await _accountService.HasBookmarkPermission(user))
|
||||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "bookmark-permission"));
|
return BadRequest(await _localizationService.Translate(User.GetUserId(), "bookmark-permission"));
|
||||||
|
|
||||||
var chapter = await _cacheService.Ensure(bookmarkDto.ChapterId);
|
var chapter = await _cacheService.Ensure(bookmarkDto.ChapterId);
|
||||||
if (chapter == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "cache-file-find"));
|
if (chapter == null || chapter.Files.Count == 0)
|
||||||
|
return BadRequest(await _localizationService.Translate(User.GetUserId(), "cache-file-find"));
|
||||||
|
|
||||||
bookmarkDto.Page = _readerService.CapPageToChapter(chapter, bookmarkDto.Page);
|
bookmarkDto.Page = _readerService.CapPageToChapter(chapter, bookmarkDto.Page);
|
||||||
|
|
||||||
var path = _cacheService.GetCachedPagePath(chapter.Id, bookmarkDto.Page);
|
|
||||||
|
|
||||||
if (!await _bookmarkService.BookmarkPage(user, bookmarkDto, path))
|
string path;
|
||||||
|
if (Parser.IsEpub(chapter.Files.First().Extension!))
|
||||||
|
{
|
||||||
|
var cachedFilePath = _cacheService.GetCachedFile(chapter);
|
||||||
|
path = await _bookService.CopyImageToTempFromBook(chapter.Id, bookmarkDto, cachedFilePath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path = _cacheService.GetCachedPagePath(chapter.Id, bookmarkDto.Page);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(path) || !await _bookmarkService.BookmarkPage(user, bookmarkDto, path))
|
||||||
|
{
|
||||||
|
return BadRequest(await _localizationService.Translate(User.GetUserId(), "bookmark-save"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BackgroundJob.Enqueue(() => _cacheService.CleanupBookmarkCache(bookmarkDto.SeriesId));
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (KavitaException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "There was an exception when trying to create a bookmark");
|
||||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "bookmark-save"));
|
return BadRequest(await _localizationService.Translate(User.GetUserId(), "bookmark-save"));
|
||||||
|
}
|
||||||
BackgroundJob.Enqueue(() => _cacheService.CleanupBookmarkCache(bookmarkDto.SeriesId));
|
|
||||||
return Ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a bookmark for an epub image
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bookmarkDto"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("bookmark-epub")]
|
|
||||||
public async Task<ActionResult> BookmarkEpubPage(BookmarkDto bookmarkDto)
|
|
||||||
{
|
|
||||||
|
|
||||||
// Don't let user save past total pages.
|
|
||||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
|
||||||
if (user == null) return new UnauthorizedResult();
|
|
||||||
|
|
||||||
if (!await _accountService.HasBookmarkPermission(user))
|
|
||||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "bookmark-permission"));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var chapter = await _cacheService.Ensure(bookmarkDto.ChapterId);
|
|
||||||
if (chapter == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "cache-file-find"));
|
|
||||||
|
|
||||||
bookmarkDto.Page = _readerService.CapPageToChapter(chapter, bookmarkDto.Page);
|
|
||||||
|
|
||||||
var cachedFilePath = _cacheService.GetCachedFile(chapter);
|
|
||||||
var path = await _bookService.CopyImageToTempFromBook(chapter.Id, bookmarkDto, cachedFilePath);
|
|
||||||
|
|
||||||
if (!await _bookmarkService.BookmarkPage(user, bookmarkDto, path))
|
|
||||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "bookmark-save"));
|
|
||||||
|
|
||||||
BackgroundJob.Enqueue(() => _cacheService.CleanupBookmarkCache(bookmarkDto.SeriesId));
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes a bookmarked page for a Chapter
|
/// Removes a bookmarked page for a Chapter
|
||||||
|
@ -102,8 +102,8 @@ export class ReaderService {
|
|||||||
return `${this.baseUrl}reader/pdf?chapterId=${chapterId}&apiKey=${this.encodedKey}`;
|
return `${this.baseUrl}reader/pdf?chapterId=${chapterId}&apiKey=${this.encodedKey}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
bookmark(seriesId: number, volumeId: number, chapterId: number, page: number, xPath: string | null = null) {
|
bookmark(seriesId: number, volumeId: number, chapterId: number, page: number, imageNumber: number = 0) {
|
||||||
return this.httpClient.post(this.baseUrl + 'reader/bookmark', {seriesId, volumeId, chapterId, page, xPath});
|
return this.httpClient.post(this.baseUrl + 'reader/bookmark', {seriesId, volumeId, chapterId, page, imageNumber});
|
||||||
}
|
}
|
||||||
|
|
||||||
unbookmark(seriesId: number, volumeId: number, chapterId: number, page: number, imageNumber: number = 0) {
|
unbookmark(seriesId: number, volumeId: number, chapterId: number, page: number, imageNumber: number = 0) {
|
||||||
|
@ -1041,7 +1041,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
this.loadImageBookmarks();
|
this.loadImageBookmarks();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.readerService.bookmarkEpub(this.seriesId, this.volumeId, this.chapterId, this.pageNum(), index).subscribe(bookmark => {
|
this.readerService.bookmark(this.seriesId, this.volumeId, this.chapterId, this.pageNum(), index).subscribe(bookmark => {
|
||||||
const newState = !hasBookmark;
|
const newState = !hasBookmark;
|
||||||
icon.className = 'bookmark-overlay ' + (newState ? 'fa-solid' : 'fa-regular') + ' fa-bookmark';
|
icon.className = 'bookmark-overlay ' + (newState ? 'fa-solid' : 'fa-regular') + ' fa-bookmark';
|
||||||
hasBookmark = !hasBookmark;
|
hasBookmark = !hasBookmark;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user