mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 03:48:19 +02:00
Fix Manga ChangeLibrary Endpoint to be faster if library is the same.
Fix MoveMangaLibraryWorker.cs setting off new Library
This commit is contained in:
@@ -443,10 +443,13 @@ public class MangaController(MangaContext context) : Controller
|
|||||||
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
public async Task<Results<Ok, NotFound<string>>> ChangeLibrary(string MangaId, string LibraryId)
|
public async Task<Results<Ok, NotFound<string>>> ChangeLibrary(string MangaId, string LibraryId)
|
||||||
{
|
{
|
||||||
if (await context.MangaIncludeAll().FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
return TypedResults.NotFound(nameof(MangaId));
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
if (await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == LibraryId, HttpContext.RequestAborted) is not { } library)
|
if (await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == LibraryId, HttpContext.RequestAborted) is not { } library)
|
||||||
return TypedResults.NotFound(nameof(LibraryId));
|
return TypedResults.NotFound(nameof(LibraryId));
|
||||||
|
|
||||||
|
if(manga.LibraryId == library.Key)
|
||||||
|
return TypedResults.Ok();
|
||||||
|
|
||||||
MoveMangaLibraryWorker moveLibrary = new(manga, library);
|
MoveMangaLibraryWorker moveLibrary = new(manga, library);
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ public class MoveMangaLibraryWorker(Manga manga, FileLibrary toLibrary, IEnumera
|
|||||||
// Save old Path (to later move chapters)
|
// Save old Path (to later move chapters)
|
||||||
Dictionary<Chapter, string> oldPath = manga.Chapters.ToDictionary(c => c, c => c.FullArchiveFilePath);
|
Dictionary<Chapter, string> oldPath = manga.Chapters.ToDictionary(c => c, c => c.FullArchiveFilePath);
|
||||||
// Set new Path
|
// Set new Path
|
||||||
DbContext.Entry(manga).Property(m => m.Library).CurrentValue = toLibrary;
|
manga.Library = toLibrary;
|
||||||
|
|
||||||
if (await DbContext.Sync(CancellationToken) is { success: false })
|
if (await DbContext.Sync(CancellationToken) is { success: false })
|
||||||
return [];
|
return [];
|
||||||
|
Reference in New Issue
Block a user