From 4cb7c941a24f6b91e6fbd89323d225a7be8f1bc2 Mon Sep 17 00:00:00 2001 From: Glax Date: Sun, 21 Apr 2024 21:32:03 +0200 Subject: [PATCH] Implemented /v2/Connector//GetManga --- Tranga/Server/v2Connector.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Tranga/Server/v2Connector.cs b/Tranga/Server/v2Connector.cs index ac3b38a..29d4577 100644 --- a/Tranga/Server/v2Connector.cs +++ b/Tranga/Server/v2Connector.cs @@ -1,5 +1,6 @@ using System.Net; using System.Text.RegularExpressions; +using Tranga.MangaConnectors; namespace Tranga.Server; @@ -12,8 +13,19 @@ public partial class Server private ValueTuple GetV2ConnectorConnectorNameGetManga(GroupCollection groups, Dictionary requestParameters) { - if(groups.Count < 1 || !_parent.GetConnectors().Contains(groups[1].Value)) + if(groups.Count < 1 || + !_parent.GetConnectors().Contains(groups[1].Value) || + !_parent.TryGetConnector(groups[1].Value, out MangaConnector? connector) || + connector is null) return new ValueTuple(HttpStatusCode.BadRequest, $"Connector '{groups[1].Value}' does not exist."); - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + + if (requestParameters.TryGetValue("title", out string? title)) + { + return (HttpStatusCode.OK, connector.GetManga(title)); + }else if (requestParameters.TryGetValue("url", out string? url)) + { + return (HttpStatusCode.OK, connector.GetMangaFromUrl(url)); + }else + return new ValueTuple(HttpStatusCode.BadRequest, "Parameter 'title' or 'url' has to be set."); } } \ No newline at end of file