Progress Overhaul + Profile Page and a LOT more! (#4262)

Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com>
Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
Joe Milazzo
2025-12-09 10:00:11 -07:00
committed by GitHub
parent 4ac13f1f25
commit 9f29fa593d
645 changed files with 25585 additions and 4805 deletions
+18 -18
View File
@@ -3,11 +3,11 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using API.Constants;
using API.Data;
using API.DTOs.Downloads;
using API.Entities;
using API.Entities.Enums;
using API.Extensions;
using API.Services;
using API.SignalR;
using Kavita.Common;
@@ -22,7 +22,7 @@ namespace API.Controllers;
/// <summary>
/// All APIs related to downloading entities from the system. Requires Download Role or Admin Role.
/// </summary>
[Authorize(Policy="RequireDownloadRole")]
[Authorize(PolicyGroups.DownloadPolicy)]
public class DownloadController : BaseApiController
{
private readonly IUnitOfWork _unitOfWork;
@@ -93,18 +93,18 @@ public class DownloadController : BaseApiController
/// </summary>
/// <param name="volumeId"></param>
/// <returns></returns>
[Authorize(Policy="RequireDownloadRole")]
[Authorize(PolicyGroups.DownloadPolicy)]
[HttpGet("volume")]
public async Task<ActionResult> DownloadVolume(int volumeId)
{
if (!await HasDownloadPermission()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "permission-denied"));
if (!await HasDownloadPermission()) return BadRequest(await _localizationService.Translate(UserId, "permission-denied"));
var volume = await _unitOfWork.VolumeRepository.GetVolumeByIdAsync(volumeId);
if (volume == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "volume-doesnt-exist"));
if (volume == null) return BadRequest(await _localizationService.Translate(UserId, "volume-doesnt-exist"));
var files = await _unitOfWork.VolumeRepository.GetFilesForVolume(volumeId);
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(volume.SeriesId);
try
{
return await DownloadFiles(files, $"download_{User.GetUsername()}_v{volumeId}", $"{series!.Name} - Volume {volume.Name}.zip");
return await DownloadFiles(files, $"download_{Username!}_v{volumeId}", $"{series!.Name} - Volume {volume.Name}.zip");
}
catch (KavitaException ex)
{
@@ -114,7 +114,7 @@ public class DownloadController : BaseApiController
private async Task<bool> HasDownloadPermission()
{
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(Username!);
if (user == null) return false;
return await _accountService.HasDownloadPermission(user);
}
@@ -133,15 +133,15 @@ public class DownloadController : BaseApiController
[HttpGet("chapter")]
public async Task<ActionResult> DownloadChapter(int chapterId)
{
if (!await HasDownloadPermission()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "permission-denied"));
if (!await HasDownloadPermission()) return BadRequest(await _localizationService.Translate(UserId, "permission-denied"));
var files = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId);
var chapter = await _unitOfWork.ChapterRepository.GetChapterAsync(chapterId);
if (chapter == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "chapter-doesnt-exist"));
if (chapter == null) return BadRequest(await _localizationService.Translate(UserId, "chapter-doesnt-exist"));
var volume = await _unitOfWork.VolumeRepository.GetVolumeByIdAsync(chapter.VolumeId);
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(volume!.SeriesId);
try
{
return await DownloadFiles(files, $"download_{User.GetUsername()}_c{chapterId}", $"{series!.Name} - Chapter {chapter.GetNumberTitle()}.zip");
return await DownloadFiles(files, $"download_{Username!}_c{chapterId}", $"{series!.Name} - Chapter {chapter.GetNumberTitle()}.zip");
}
catch (KavitaException ex)
{
@@ -151,7 +151,7 @@ public class DownloadController : BaseApiController
private async Task<ActionResult> DownloadFiles(ICollection<MangaFile> files, string tempFolder, string downloadName)
{
var username = User.GetUsername();
var username = Username!;
var filename = Path.GetFileNameWithoutExtension(downloadName);
try
{
@@ -186,7 +186,7 @@ public class DownloadController : BaseApiController
{
_logger.LogError(ex, "There was an exception when trying to download files");
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(User.GetUsername(),
MessageFactory.DownloadProgressEvent(Username!,
filename, "Download Complete", 1F, "ended"));
throw;
}
@@ -195,7 +195,7 @@ public class DownloadController : BaseApiController
[HttpGet("series")]
public async Task<ActionResult> DownloadSeries(int seriesId)
{
if (!await HasDownloadPermission()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "permission-denied"));
if (!await HasDownloadPermission()) return BadRequest(await _localizationService.Translate(UserId, "permission-denied"));
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId);
if (series == null) return BadRequest("Invalid Series");
@@ -203,7 +203,7 @@ public class DownloadController : BaseApiController
var files = await _unitOfWork.SeriesRepository.GetFilesForSeries(seriesId);
try
{
return await DownloadFiles(files, $"download_{User.GetUsername()}_s{seriesId}", $"{series.Name}.zip");
return await DownloadFiles(files, $"download_{Username!}_s{seriesId}", $"{series.Name}.zip");
}
catch (KavitaException ex)
{
@@ -219,12 +219,12 @@ public class DownloadController : BaseApiController
[HttpPost("bookmarks")]
public async Task<ActionResult> DownloadBookmarkPages(DownloadBookmarkDto downloadBookmarkDto)
{
if (!await HasDownloadPermission()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "permission-denied"));
if (!downloadBookmarkDto.Bookmarks.Any()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "bookmarks-empty"));
if (!await HasDownloadPermission()) return BadRequest(await _localizationService.Translate(UserId, "permission-denied"));
if (!downloadBookmarkDto.Bookmarks.Any()) return BadRequest(await _localizationService.Translate(UserId, "bookmarks-empty"));
// We know that all bookmarks will be for one single seriesId
var userId = User.GetUserId()!;
var username = User.GetUsername()!;
var userId = UserId;
var username = Username!;
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(downloadBookmarkDto.Bookmarks.First().SeriesId);
var files = await _bookmarkService.GetBookmarkFilesById(downloadBookmarkDto.Bookmarks.Select(b => b.Id));