mirror of
https://github.com/C9Glax/tranga.git
synced 2025-04-18 14:23:18 +02:00
DownloadSingleChapterJob update coverfilename in cache in database
This commit is contained in:
parent
0d931bc835
commit
5c0ace291b
@ -20,15 +20,9 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu
|
|||||||
|
|
||||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||||
{
|
{
|
||||||
Chapter c = Chapter ?? context.Chapters.Find(ChapterId)!;
|
Chapter chapter = Chapter ?? context.Chapters.Find(ChapterId)!;
|
||||||
Manga m = c.ParentManga ?? context.Manga.Find(c.ParentMangaId)!;
|
Manga manga = chapter.ParentManga ?? context.Manga.Find(chapter.ParentMangaId)!;
|
||||||
MangaConnector connector = m.MangaConnector ?? context.MangaConnectors.Find(m.MangaConnectorId)!;
|
MangaConnector connector = manga.MangaConnector ?? context.MangaConnectors.Find(manga.MangaConnectorId)!;
|
||||||
DownloadChapterImages(c, connector, m);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool DownloadChapterImages(Chapter chapter, MangaConnector connector, Manga manga)
|
|
||||||
{
|
|
||||||
string[] imageUrls = connector.GetChapterImageUrls(chapter);
|
string[] imageUrls = connector.GetChapterImageUrls(chapter);
|
||||||
string saveArchiveFilePath = chapter.GetArchiveFilePath();
|
string saveArchiveFilePath = chapter.GetArchiveFilePath();
|
||||||
|
|
||||||
@ -52,7 +46,7 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu
|
|||||||
if (imageUrls.Length == 0)
|
if (imageUrls.Length == 0)
|
||||||
{
|
{
|
||||||
Directory.Delete(tempFolder, true);
|
Directory.Delete(tempFolder, true);
|
||||||
return false;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string imageUrl in imageUrls)
|
foreach (string imageUrl in imageUrls)
|
||||||
@ -61,10 +55,10 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu
|
|||||||
string imagePath = Path.Join(tempFolder, $"{chapterNum++}.{extension}");
|
string imagePath = Path.Join(tempFolder, $"{chapterNum++}.{extension}");
|
||||||
bool status = DownloadImage(imageUrl, imagePath);
|
bool status = DownloadImage(imageUrl, imagePath);
|
||||||
if (status is false)
|
if (status is false)
|
||||||
return false;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyCoverFromCacheToDownloadLocation(manga);
|
CopyCoverFromCacheToDownloadLocation(context, manga);
|
||||||
|
|
||||||
File.WriteAllText(Path.Join(tempFolder, "ComicInfo.xml"), chapter.GetComicInfoXmlString());
|
File.WriteAllText(Path.Join(tempFolder, "ComicInfo.xml"), chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
@ -74,7 +68,10 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu
|
|||||||
File.SetUnixFileMode(saveArchiveFilePath, UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute | OtherRead | OtherExecute);
|
File.SetUnixFileMode(saveArchiveFilePath, UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute | OtherRead | OtherExecute);
|
||||||
Directory.Delete(tempFolder, true); //Cleanup
|
Directory.Delete(tempFolder, true); //Cleanup
|
||||||
|
|
||||||
return true;
|
chapter.Downloaded = true;
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessImage(string imagePath)
|
private void ProcessImage(string imagePath)
|
||||||
@ -92,7 +89,7 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyCoverFromCacheToDownloadLocation(Manga manga, int? retries = 1)
|
private void CopyCoverFromCacheToDownloadLocation(PgsqlContext context, Manga manga, int? retries = 1)
|
||||||
{
|
{
|
||||||
//Check if Publication already has a Folder and cover
|
//Check if Publication already has a Folder and cover
|
||||||
string publicationFolder = manga.CreatePublicationFolder();
|
string publicationFolder = manga.CreatePublicationFolder();
|
||||||
@ -107,8 +104,9 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu
|
|||||||
{
|
{
|
||||||
if (retries > 0)
|
if (retries > 0)
|
||||||
{
|
{
|
||||||
manga.SaveCoverImageToCache();
|
manga.CoverFileNameInCache = manga.SaveCoverImageToCache();
|
||||||
CopyCoverFromCacheToDownloadLocation(manga, --retries);
|
context.SaveChanges();
|
||||||
|
CopyCoverFromCacheToDownloadLocation(context, manga, --retries);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user