Bookmark RBS + Dynamic PGO (#1503)
* Allow .NET to optimize code as it's running. * Implemented the ability to restrict users Bookmark ability. By default, users will need to now opt-in to get bookmark roles. * Fixed a tachiyomi progress syncing logic bug
This commit is contained in:
parent
30500a441c
commit
2283ae5d61
14 changed files with 75 additions and 28 deletions
|
@ -31,10 +31,12 @@ namespace API.Controllers
|
|||
private readonly IEventHub _eventHub;
|
||||
private readonly ILogger<DownloadController> _logger;
|
||||
private readonly IBookmarkService _bookmarkService;
|
||||
private readonly IAccountService _accountService;
|
||||
private const string DefaultContentType = "application/octet-stream";
|
||||
|
||||
public DownloadController(IUnitOfWork unitOfWork, IArchiveService archiveService, IDirectoryService directoryService,
|
||||
IDownloadService downloadService, IEventHub eventHub, ILogger<DownloadController> logger, IBookmarkService bookmarkService)
|
||||
IDownloadService downloadService, IEventHub eventHub, ILogger<DownloadController> logger, IBookmarkService bookmarkService,
|
||||
IAccountService accountService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_archiveService = archiveService;
|
||||
|
@ -43,6 +45,7 @@ namespace API.Controllers
|
|||
_eventHub = eventHub;
|
||||
_logger = logger;
|
||||
_bookmarkService = bookmarkService;
|
||||
_accountService = accountService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -109,7 +112,7 @@ namespace API.Controllers
|
|||
private async Task<bool> HasDownloadPermission()
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
return await _downloadService.HasDownloadPermission(user);
|
||||
return await _accountService.HasDownloadPermission(user);
|
||||
}
|
||||
|
||||
private ActionResult GetFirstFileDownload(IEnumerable<MangaFile> files)
|
||||
|
|
|
@ -32,6 +32,7 @@ public class OpdsController : BaseApiController
|
|||
private readonly ICacheService _cacheService;
|
||||
private readonly IReaderService _readerService;
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IAccountService _accountService;
|
||||
|
||||
|
||||
private readonly XmlSerializer _xmlSerializer;
|
||||
|
@ -65,7 +66,8 @@ public class OpdsController : BaseApiController
|
|||
|
||||
public OpdsController(IUnitOfWork unitOfWork, IDownloadService downloadService,
|
||||
IDirectoryService directoryService, ICacheService cacheService,
|
||||
IReaderService readerService, ISeriesService seriesService)
|
||||
IReaderService readerService, ISeriesService seriesService,
|
||||
IAccountService accountService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_downloadService = downloadService;
|
||||
|
@ -73,6 +75,7 @@ public class OpdsController : BaseApiController
|
|||
_cacheService = cacheService;
|
||||
_readerService = readerService;
|
||||
_seriesService = seriesService;
|
||||
_accountService = accountService;
|
||||
|
||||
_xmlSerializer = new XmlSerializer(typeof(Feed));
|
||||
_xmlOpenSearchSerializer = new XmlSerializer(typeof(OpenSearchDescription));
|
||||
|
@ -619,7 +622,7 @@ public class OpdsController : BaseApiController
|
|||
if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)
|
||||
return BadRequest("OPDS is not enabled on this server");
|
||||
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(await GetUser(apiKey));
|
||||
if (!await _downloadService.HasDownloadPermission(user))
|
||||
if (!await _accountService.HasDownloadPermission(user))
|
||||
{
|
||||
return BadRequest("User does not have download permissions");
|
||||
}
|
||||
|
|
|
@ -29,17 +29,20 @@ namespace API.Controllers
|
|||
private readonly ILogger<ReaderController> _logger;
|
||||
private readonly IReaderService _readerService;
|
||||
private readonly IBookmarkService _bookmarkService;
|
||||
private readonly IAccountService _accountService;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ReaderController(ICacheService cacheService,
|
||||
IUnitOfWork unitOfWork, ILogger<ReaderController> logger,
|
||||
IReaderService readerService, IBookmarkService bookmarkService)
|
||||
IReaderService readerService, IBookmarkService bookmarkService,
|
||||
IAccountService accountService)
|
||||
{
|
||||
_cacheService = cacheService;
|
||||
_unitOfWork = unitOfWork;
|
||||
_logger = logger;
|
||||
_readerService = readerService;
|
||||
_bookmarkService = bookmarkService;
|
||||
_accountService = accountService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -657,8 +660,13 @@ namespace API.Controllers
|
|||
public async Task<ActionResult> BookmarkPage(BookmarkDto bookmarkDto)
|
||||
{
|
||||
// Don't let user save past total pages.
|
||||
bookmarkDto.Page = await _readerService.CapPageToChapter(bookmarkDto.ChapterId, bookmarkDto.Page);
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
||||
if (user == null) return new UnauthorizedResult();
|
||||
|
||||
if (!await _accountService.HasBookmarkPermission(user))
|
||||
return BadRequest("You do not have permission to bookmark");
|
||||
|
||||
bookmarkDto.Page = await _readerService.CapPageToChapter(bookmarkDto.ChapterId, bookmarkDto.Page);
|
||||
var chapter = await _cacheService.Ensure(bookmarkDto.ChapterId);
|
||||
if (chapter == null) return BadRequest("Could not find cached image. Reload and try again.");
|
||||
var path = _cacheService.GetCachedPagePath(chapter, bookmarkDto.Page);
|
||||
|
@ -681,8 +689,12 @@ namespace API.Controllers
|
|||
public async Task<ActionResult> UnBookmarkPage(BookmarkDto bookmarkDto)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
||||
if (user == null) return new UnauthorizedResult();
|
||||
if (user.Bookmarks == null) return Ok();
|
||||
|
||||
if (!await _accountService.HasBookmarkPermission(user))
|
||||
return BadRequest("You do not have permission to unbookmark");
|
||||
|
||||
if (await _bookmarkService.RemoveBookmarkPage(user, bookmarkDto))
|
||||
{
|
||||
BackgroundJob.Enqueue(() => _cacheService.CleanupBookmarkCache(bookmarkDto.SeriesId));
|
||||
|
|
|
@ -50,7 +50,7 @@ public class TachiyomiController : BaseApiController
|
|||
if (prevChapterId == -1)
|
||||
{
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);
|
||||
var userHasProgress = series.PagesRead != 0 && series.PagesRead < series.Pages;
|
||||
var userHasProgress = series.PagesRead != 0 && series.PagesRead <= series.Pages;
|
||||
|
||||
// If the user doesn't have progress, then return null, which the extension will catch as 204 (no content) and report nothing as read
|
||||
if (!userHasProgress) return null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue