Various bug fixes (#3667)

This commit is contained in:
Fesaa 2025-03-23 21:10:50 +01:00 committed by GitHub
parent a1d3aef39b
commit 1ad8a360cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 73 additions and 32 deletions

View file

@ -158,6 +158,7 @@ public class DownloadController : BaseApiController
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(username,
filename, $"Downloading {filename}", 0F, "started"));
if (files.Count == 1 && files.First().Format != MangaFormat.Image)
{
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
@ -167,15 +168,17 @@ public class DownloadController : BaseApiController
}
var filePath = _archiveService.CreateZipFromFoldersForDownload(files.Select(c => c.FilePath).ToList(), tempFolder, ProgressCallback);
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(username,
filename, "Download Complete", 1F, "ended"));
return PhysicalFile(filePath, DefaultContentType, Uri.EscapeDataString(downloadName), true);
async Task ProgressCallback(Tuple<string, float> progressInfo)
{
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(username, filename, $"Extracting {Path.GetFileNameWithoutExtension(progressInfo.Item1)}",
MessageFactory.DownloadProgressEvent(username, filename, $"Processing {Path.GetFileNameWithoutExtension(progressInfo.Item1)}",
Math.Clamp(progressInfo.Item2, 0F, 1F)));
}
}
@ -193,8 +196,10 @@ public class DownloadController : BaseApiController
public async Task<ActionResult> DownloadSeries(int seriesId)
{
if (!await HasDownloadPermission()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "permission-denied"));
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId);
if (series == null) return BadRequest("Invalid Series");
var files = await _unitOfWork.SeriesRepository.GetFilesForSeries(seriesId);
try
{

View file

@ -595,13 +595,7 @@ public class OpdsController : BaseApiController
return Unauthorized();
}
var readingLists = await _unitOfWork.ReadingListRepository.GetReadingListDtosForUserAsync(user.Id, true, GetUserParams(pageNumber), false);
if (readingLists == null)
{
return Unauthorized();
}
var readingList = readingLists.FirstOrDefault(rl => rl.Id == readingListId);
var readingList = await _unitOfWork.ReadingListRepository.GetReadingListDtoByIdAsync(readingListId, user.Id);
if (readingList == null)
{
return BadRequest(await _localizationService.Translate(userId, "reading-list-restricted"));

View file

@ -39,9 +39,15 @@ public class ReadingListController : BaseApiController
/// <param name="readingListId"></param>
/// <returns></returns>
[HttpGet]
public async Task<ActionResult<IEnumerable<ReadingListDto>>> GetList(int readingListId)
public async Task<ActionResult<ReadingListDto?>> GetList(int readingListId)
{
return Ok(await _unitOfWork.ReadingListRepository.GetReadingListDtoByIdAsync(readingListId, User.GetUserId()));
var readingList = await _unitOfWork.ReadingListRepository.GetReadingListDtoByIdAsync(readingListId, User.GetUserId());
if (readingList == null)
{
return BadRequest(await _localizationService.Translate(User.GetUserId(), "reading-list-restricted"));
}
return Ok(readingList);
}
/// <summary>

View file

@ -351,8 +351,10 @@ public class ReadingListRepository : IReadingListRepository
public async Task<ReadingListDto?> GetReadingListDtoByIdAsync(int readingListId, int userId)
{
var user = await _context.AppUser.FirstAsync(u => u.Id == userId);
return await _context.ReadingList
.Where(r => r.Id == readingListId && (r.AppUserId == userId || r.Promoted))
.RestrictAgainstAgeRestriction(user.GetAgeRestriction())
.ProjectTo<ReadingListDto>(_mapper.ConfigurationProvider)
.SingleOrDefaultAsync();
}

View file

@ -8,6 +8,7 @@ using API.Data;
using API.DTOs.Account;
using API.Entities;
using API.Errors;
using API.Extensions;
using Kavita.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
@ -78,8 +79,9 @@ public class AccountService : IAccountService
}
public async Task<IEnumerable<ApiException>> ValidateUsername(string username)
{
// Reverted because of https://go.microsoft.com/fwlink/?linkid=2129535
if (await _userManager.Users.AnyAsync(x => x.NormalizedUserName != null
&& x.NormalizedUserName.Equals(username, StringComparison.CurrentCultureIgnoreCase)))
&& x.NormalizedUserName == username.ToUpper()))
{
return
[

View file

@ -363,16 +363,15 @@ public class ArchiveService : IArchiveService
tempPath = Path.Join(tempLocation, parentDirectory ?? _directoryService.FileSystem.FileInfo.New(path).Name);
}
progressCallback(Tuple.Create(_directoryService.FileSystem.FileInfo.New(path).Name, (1.0f * totalFiles) / count));
if (Tasks.Scanner.Parser.Parser.IsArchive(path))
{
ExtractArchive(path, tempPath);
}
else
{
_directoryService.CopyFileToDirectory(path, tempPath);
// Archives don't need to be put into a subdirectory of the same name
tempPath = _directoryService.GetParentDirectoryName(tempPath);
}
progressCallback(Tuple.Create(_directoryService.FileSystem.FileInfo.New(path).Name, (1.0f * totalFiles) / count));
_directoryService.CopyFileToDirectory(path, tempPath);
count++;
}
}