2
0

Add Endpoint GET /v2/Manga/Search GlobalSearch

Resolves #124
#167
This commit is contained in:
Glax 2024-04-26 00:51:18 +02:00
parent 7ed3846c5f
commit 4021237888
3 changed files with 47 additions and 0 deletions

View File

@ -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),

View File

@ -1,6 +1,7 @@
using System.Net;
using System.Text.RegularExpressions;
using Tranga.Jobs;
using Tranga.MangaConnectors;
namespace Tranga.Server;
@ -27,6 +28,27 @@ public partial class Server
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, ret);
}
private ValueTuple<HttpStatusCode, object?> GetV2MangaSearch(GroupCollection groups, Dictionary<string, string> requestParameters)
{
if(!requestParameters.TryGetValue("title", out string? title))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.BadRequest, "Missing parameter 'title'.");
List<Manga> ret = new();
List<Thread> 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, object?>(HttpStatusCode.OK, ret);
}
private ValueTuple<HttpStatusCode, object?> GetV2MangaInternalId(GroupCollection groups, Dictionary<string, string> requestParameters)
{
if(groups.Count < 1 ||

View File

@ -77,6 +77,29 @@ Returns all known Manga.
List of internalIds.
</details>
### <sub>![GET](https://img.shields.io/badge/GET-0f0)</sub> `/v2/Manga/Search`
Initiates a search for a Manga on all Connectors.
<details>
<summary>Request</summary>
| Parameter | Value |
|-----------|-------------------------------------------------|
| title | Search Term |
</details>
<details>
<summary>Returns</summary>
List of [Manga](Types.md#Manga)
| StatusCode | Meaning |
|------------|-------------------|
| 400 | Parameter missing |
</details>
### <sub>![GET](https://img.shields.io/badge/GET-0f0)</sub> `/v2/Manga/<internalId>`
Returns the specified Manga.