public virtual async ValueTask <Tuple <ResponseStatus, object> > UpdateTag(Tag tag) { var success = await MangaManager.Update(tag); return(new Tuple <ResponseStatus, object>( success ? ResponseStatus.Success : ResponseStatus.BadRequest, success)); }
public async ValueTask Execute(ScanMangaTask scanMangaTask) { try { if (scanMangaTask.MangaPath.IsNewItem) { scanMangaTask.Update(TaskStatus.Executing); var manga = await FileTreeNodeToMangaConverter.CreateManga(scanMangaTask.MangaPath); FileTreeNode coverPath = null; if (manga.Cover == null) { coverPath = LibraryManager.GenerateThumbnail(manga.Chapters.First().Images.First().Path); manga.Cover = FileTreeNodeToMangaConverter.CreateImage(coverPath); manga.CoverId = manga.Cover.ObjectId; } if (scanMangaTask.Scraper != null) { var context = new MangaDetail() { Name = manga.Title }; await scanMangaTask.Scraper.ScrapeMetadata(context); manga = await FileTreeNodeToMangaConverter.UpdateManga(manga, context); } manga.Tags = await MangaManager.Insert(manga.Tags); var success = await MangaManager.Insert(manga); if (!success) { Logger.Info($"Update {manga.Title} fail"); if (coverPath != null) { } scanMangaTask.Update(TaskStatus.Fail); } else { LibraryManager.StoreFileTree(scanMangaTask.MangaPath); if (coverPath != null) { LibraryManager.StoreFileTree(coverPath); } scanMangaTask.Update(TaskStatus.Success); } } else { var manga = await FileTreeNodeToMangaConverter.UpdateManga(scanMangaTask.MangaPath); manga.Tags = await MangaManager.Insert(manga.Tags); var success = await MangaManager.Update(manga, true); if (!success) { Logger.Info($"Update {manga.Title} fail"); scanMangaTask.Update(TaskStatus.Fail); } else { LibraryManager.StoreFileTree(scanMangaTask.MangaPath); scanMangaTask.Update(TaskStatus.Success); } } } catch (Exception e) { Logger.Warn(e); scanMangaTask.Update(TaskStatus.Fail); } }