mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 03:48:19 +02:00
Fix search not adding manga to database
This commit is contained in:
@@ -36,7 +36,9 @@ public class SearchController(MangaContext context) : Controller
|
||||
|
||||
(Manga manga, MangaConnectorId<Manga> id)[] mangas = connector.SearchManga(Query);
|
||||
|
||||
IEnumerable<MinimalManga> result = mangas.Select(manga => manga.manga).Select(m =>
|
||||
IEnumerable<(Manga manga, MangaConnectorId<Manga> id)> addedManga = mangas.Where(kv => context.AddMangaToContext(kv, HttpContext.RequestAborted).GetAwaiter().GetResult());
|
||||
|
||||
IEnumerable<MinimalManga> result = addedManga.Select(manga => manga.manga).Select(m =>
|
||||
{
|
||||
IEnumerable<MangaConnectorId> ids = m.MangaConnectorIds.Select(id =>
|
||||
new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||
@@ -57,15 +59,15 @@ public class SearchController(MangaContext context) : Controller
|
||||
[ProducesResponseType<MinimalManga>(Status200OK, "application/json")]
|
||||
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public Results<Ok<MinimalManga>, NotFound<string>, InternalServerError<string>> GetMangaFromUrl ([FromBody]string url)
|
||||
public async Task<Results<Ok<MinimalManga>, NotFound<string>, InternalServerError<string>>> GetMangaFromUrl ([FromBody]string url)
|
||||
{
|
||||
if(Tranga.MangaConnectors.FirstOrDefault(c => c.Name.Equals("Global", StringComparison.InvariantCultureIgnoreCase)) is not { } connector)
|
||||
return TypedResults.InternalServerError("Could not find Global Connector.");
|
||||
|
||||
if(connector.GetMangaFromUrl(url) is not { } manga)
|
||||
if(connector.GetMangaFromUrl(url) is not ({ } m, not null) manga)
|
||||
return TypedResults.NotFound("Could not retrieve Manga");
|
||||
|
||||
if(Tranga.AddMangaToContext(manga, context, out Manga? m, HttpContext.RequestAborted) == false)
|
||||
if(await context.AddMangaToContext(manga, HttpContext.RequestAborted) == false)
|
||||
return TypedResults.InternalServerError("Could not add Manga to context");
|
||||
|
||||
IEnumerable<MangaConnectorId> ids = m.MangaConnectorIds.Select(id =>
|
||||
|
@@ -158,13 +158,14 @@ public static class Tranga
|
||||
RunningWorkers.Remove(worker, out _);
|
||||
}
|
||||
|
||||
internal static bool AddMangaToContext((Manga, MangaConnectorId<Manga>) addManga, MangaContext context, [NotNullWhen(true)]out Manga? manga, CancellationToken token) =>
|
||||
AddMangaToContext(addManga.Item1, addManga.Item2, context, out manga, token);
|
||||
internal static async Task<bool> AddMangaToContext(this MangaContext context, (Manga, MangaConnectorId<Manga>) addManga, CancellationToken token) =>
|
||||
await AddMangaToContext(context, addManga.Item1, addManga.Item2, token);
|
||||
|
||||
internal static bool AddMangaToContext(Manga addManga, MangaConnectorId<Manga> addMcId, MangaContext context, [NotNullWhen(true)]out Manga? manga, CancellationToken token)
|
||||
internal static async Task<bool> AddMangaToContext(this MangaContext context, Manga addManga, MangaConnectorId<Manga> addMcId,
|
||||
CancellationToken token)
|
||||
{
|
||||
context.ChangeTracker.Clear();
|
||||
manga = context.FindMangaLike(addManga, token).Result;
|
||||
Manga? manga = await context.FindMangaLike(addManga, token);
|
||||
if (manga is not null)
|
||||
{
|
||||
foreach (MangaConnectorId<Manga> mcId in addManga.MangaConnectorIds)
|
||||
@@ -178,6 +179,8 @@ public static class Tranga
|
||||
manga.AltTitles = manga.AltTitles.UnionBy(addManga.AltTitles, altTitle => altTitle.Key).ToList();
|
||||
manga.Chapters = manga.Chapters.UnionBy(addManga.Chapters, chapter => chapter.Key).ToList();
|
||||
manga.MangaConnectorIds = manga.MangaConnectorIds.UnionBy(addManga.MangaConnectorIds, id => id.MangaConnectorName).ToList();
|
||||
|
||||
addManga = manga;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -199,7 +202,7 @@ public static class Tranga
|
||||
context.Mangas.Add(manga);
|
||||
}
|
||||
|
||||
if (context.Sync(token).Result is { success: false })
|
||||
if (await context.Sync(token) is { success: false })
|
||||
return false;
|
||||
|
||||
DownloadCoverFromMangaconnectorWorker downloadCoverWorker = new (addMcId);
|
||||
|
Reference in New Issue
Block a user