diff --git a/Tranga/Server/Server.cs b/Tranga/Server/Server.cs index f2d4256..863b9d9 100644 --- a/Tranga/Server/Server.cs +++ b/Tranga/Server/Server.cs @@ -23,10 +23,11 @@ public partial class Server : GlobalBase, IDisposable { new ("GET", @"/v2/Connector/Types", GetV2ConnectorTypes), new ("GET", @"/v2/Connector/([a-zA-Z]+)/GetManga", GetV2ConnectorConnectorNameGetManga), - 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), - new ("GET", @"/v2/Manga/([-A-Za-z0-9+/]*={0,3})/Chapters", GetV2MangaInternalIdChapters), + new ("GET", @"/v2/Manga", 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), + new ("GET", @"/v2/Manga/([-A-Za-z0-9]*={0,3})/Chapters", GetV2MangaInternalIdChapters), new ("GET", @"/v2/Jobs", GetV2Jobs), new ("GET", @"/v2/Jobs/Running", GetV2JobsRunning), new ("GET", @"/v2/Jobs/Waiting", GetV2JobsWaiting), diff --git a/Tranga/Server/v2Manga.cs b/Tranga/Server/v2Manga.cs index 834cb4f..b8c3a28 100644 --- a/Tranga/Server/v2Manga.cs +++ b/Tranga/Server/v2Manga.cs @@ -1,27 +1,63 @@ using System.Net; using System.Text.RegularExpressions; +using Tranga.Jobs; namespace Tranga.Server; public partial class Server { + private ValueTuple GetV2Manga(GroupCollection groups, Dictionary requestParameters) + { + return new ValueTuple(HttpStatusCode.OK, cachedPublications.Select(m => m.internalId)); + } + private ValueTuple GetV2MangaInternalId(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + if(groups.Count < 1 || + !_parent.TryGetPublicationById(groups[1].Value, out Manga? manga) || + manga is null) + return new ValueTuple(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'"); + return new ValueTuple(HttpStatusCode.OK, manga); } private ValueTuple DeleteV2MangaInternalId(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + if(groups.Count < 1 || + !_parent.TryGetPublicationById(groups[1].Value, out Manga? manga) || + manga is null) + return new ValueTuple(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'"); + Job[] jobs = _parent.jobBoss.GetJobsLike(publication: manga).ToArray(); + _parent.jobBoss.RemoveJobs(jobs); + return new ValueTuple(HttpStatusCode.OK, null); } private ValueTuple GetV2MangaInternalIdCover(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + if(groups.Count < 1 || + !_parent.TryGetPublicationById(groups[1].Value, out Manga? manga) || + manga is null) + return new ValueTuple(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'"); + string filePath = settings.GetFullCoverPath((Manga)manga!); + if (File.Exists(filePath)) + { + FileStream coverStream = new(filePath, FileMode.Open); + return new ValueTuple(HttpStatusCode.OK, coverStream); + } + return new ValueTuple(HttpStatusCode.NotFound, "Cover-File not found."); } private ValueTuple GetV2MangaInternalIdChapters(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + if(groups.Count < 1 || + !_parent.TryGetPublicationById(groups[1].Value, out Manga? manga) || + manga is null) + return new ValueTuple(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'"); + + Chapter[] chapters = requestParameters.TryGetValue("language", out string? parameter) switch + { + true => manga.Value.mangaConnector.GetChapters((Manga)manga, parameter), + false => manga.Value.mangaConnector.GetChapters((Manga)manga) + }; + return new ValueTuple(HttpStatusCode.OK, chapters); } } \ No newline at end of file diff --git a/docs/API_Calls_v2.md b/docs/API_Calls_v2.md index f5bc867..056a26c 100644 --- a/docs/API_Calls_v2.md +++ b/docs/API_Calls_v2.md @@ -67,6 +67,16 @@ Returns the Manga from the specified Manga Connector. ## Manga [^top](#top) +### ![GET](https://img.shields.io/badge/GET-0f0) `/v2/Manga` + +Returns all known Manga. + +
+ Returns + + List of internalIds. +
+ ### ![GET](https://img.shields.io/badge/GET-0f0) `/v2/Manga/` Returns the specified Manga. @@ -75,6 +85,7 @@ Returns the specified Manga. Request `internalId` is returned in the response of + * [GET /v2/Manga](#-v2manga) * [GET /v2/Connector/*ConnectorName*/GetManga](#-v2connectorconnectornamegetmanga) * [GET /v2/Job/*jobId*](#-v2jobjobid) @@ -97,6 +108,7 @@ Deletes all associated Jobs for the specified Manga Request `internalId` is returned in the response of + * [GET /v2/Manga](#-v2manga) * [GET /v2/Connector/*ConnectorName*/GetManga](#-v2connectorconnectornamegetmanga) * [GET /v2/Job/*jobId*](#-v2jobjobid) @@ -118,6 +130,7 @@ Returns the URL for the Cover of the specified Manga. Request `internalId` is returned in the response of + * [GET /v2/Manga](#-v2manga) * [GET /v2/Connector/*ConnectorName*/GetManga](#-v2connectorconnectornamegetmanga) * [GET /v2/Job/*jobId*](#-v2jobjobid) @@ -140,8 +153,13 @@ Returns the Chapter-list for the specified Manga. Request `internalId` is returned in the response of + * [GET /v2/Manga](#-v2manga) * [GET /v2/Connector/*ConnectorName*/GetManga](#-v2connectorconnectornamegetmanga) * [GET /v2/Job/*jobId*](#-v2jobjobid) + + | Parameter | Value | + |------------|------------------------| + | *language* | Language to search for |
@@ -162,6 +180,7 @@ Returns the latest Chapter of the specified Manga. Request `internalId` is returned in the response of + * [GET /v2/Manga](#-v2manga) * [GET /v2/Connector/*ConnectorName*/GetManga](#-v2connectorconnectornamegetmanga) * [GET /v2/Job/*jobId*](#-v2jobjobid)
@@ -245,6 +264,7 @@ Creates a Job. `internalId` is returned in the response of + * [GET /v2/Manga](#-v2manga) * [GET /v2/Connector/*ConnectorName*/GetManga](#-v2connectorconnectornamegetmanga) * [GET /v2/Job/*jobId*](#-v2jobjobid)