diff --git a/Tranga/Server/Server.cs b/Tranga/Server/Server.cs index d2a8640..43732d2 100644 --- a/Tranga/Server/Server.cs +++ b/Tranga/Server/Server.cs @@ -24,7 +24,9 @@ public partial class Server : GlobalBase, IDisposable new ("GET", @"/v2/Connector/Types", GetV2ConnectorTypes), new ("GET", @"/v2/Connector/([a-zA-Z]+)/GetManga", GetV2ConnectorConnectorNameGetManga), new ("GET", @"/v2/Mangas", GetV2Mangas), + new ("GET", @"/v2/Manga/Search", GetV2MangaSearch), new ("GET", @"/v2/Manga", GetV2Manga), + new ("GET", @"/v2/Manga/sear", GetV2Manga), new ("GET", @"/v2/Manga/([-A-Za-z0-9]*={0,3})", GetV2MangaInternalId), new ("DELETE", @"/v2/Manga/([-A-Za-z0-9]*={0,3})", DeleteV2MangaInternalId), new ("GET", @"/v2/Manga/([-A-Za-z0-9]*={0,3})/Cover", GetV2MangaInternalIdCover), diff --git a/Tranga/Server/v2Manga.cs b/Tranga/Server/v2Manga.cs index f983ec0..44ff843 100644 --- a/Tranga/Server/v2Manga.cs +++ b/Tranga/Server/v2Manga.cs @@ -1,6 +1,7 @@ using System.Net; using System.Text.RegularExpressions; using Tranga.Jobs; +using Tranga.MangaConnectors; namespace Tranga.Server; @@ -26,6 +27,27 @@ public partial class Server return new ValueTuple(HttpStatusCode.OK, ret); } + + private ValueTuple GetV2MangaSearch(GroupCollection groups, Dictionary requestParameters) + { + if(!requestParameters.TryGetValue("title", out string? title)) + return new ValueTuple(HttpStatusCode.BadRequest, "Missing parameter 'title'."); + List ret = new(); + List threads = new(); + foreach (MangaConnector mangaConnector in _connectors) + { + Thread t = new (() => + { + ret.AddRange(mangaConnector.GetManga(title)); + }); + t.Start(); + threads.Add(t); + } + while(threads.Any(t => t.ThreadState is ThreadState.Running or ThreadState.WaitSleepJoin)) + Thread.Sleep(10); + + return new ValueTuple(HttpStatusCode.OK, ret); + } private ValueTuple GetV2MangaInternalId(GroupCollection groups, Dictionary requestParameters) { diff --git a/docs/API_Calls_v2.md b/docs/API_Calls_v2.md index f928ca6..545e1d4 100644 --- a/docs/API_Calls_v2.md +++ b/docs/API_Calls_v2.md @@ -77,6 +77,29 @@ Returns all known Manga. List of internalIds. +### ![GET](https://img.shields.io/badge/GET-0f0) `/v2/Manga/Search` + +Initiates a search for a Manga on all Connectors. + +
+ Request + + + | Parameter | Value | + |-----------|-------------------------------------------------| + | title | Search Term | +
+ +
+ Returns + + List of [Manga](Types.md#Manga) + + | StatusCode | Meaning | + |------------|-------------------| + | 400 | Parameter missing | +
+ ### ![GET](https://img.shields.io/badge/GET-0f0) `/v2/Manga/` Returns the specified Manga.