mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-17 16:57:54 +02:00
#168 Multiple Base-Paths (Libraries) Support
Some checks failed
Docker Image CI / build (push) Has been cancelled
Some checks failed
Docker Image CI / build (push) Has been cancelled
This commit is contained in:
30
API/Schema/Jobs/MoveMangaLibraryJob.cs
Normal file
30
API/Schema/Jobs/MoveMangaLibraryJob.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace API.Schema.Jobs;
|
||||
|
||||
public class MoveMangaLibraryJob(string mangaId, string toLibraryId, string? parentJobId = null, ICollection<string>? dependsOnJobsIds = null)
|
||||
: Job(TokenGen.CreateToken(typeof(MoveMangaLibraryJob)), JobType.MoveMangaLibraryJob, 0, parentJobId, dependsOnJobsIds)
|
||||
{
|
||||
[StringLength(64)]
|
||||
[Required]
|
||||
public string MangaId { get; init; } = mangaId;
|
||||
[StringLength(64)]
|
||||
[Required]
|
||||
public string ToLibraryId { get; init; } = toLibraryId;
|
||||
|
||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||
{
|
||||
Manga? manga = context.Mangas.Find(MangaId);
|
||||
if(manga is null)
|
||||
throw new KeyNotFoundException();
|
||||
LocalLibrary? library = context.LocalLibraries.Find(ToLibraryId);
|
||||
if(library is null)
|
||||
throw new KeyNotFoundException();
|
||||
Chapter[] chapters = context.Chapters.Where(c => c.ParentMangaId == MangaId).ToArray();
|
||||
Dictionary<Chapter, string> oldPath = chapters.ToDictionary(c => c, c => c.FullArchiveFilePath!);
|
||||
manga.Library = library;
|
||||
context.SaveChanges();
|
||||
|
||||
return chapters.Select(c => new MoveFileOrFolderJob(oldPath[c], c.FullArchiveFilePath!));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user