From 96b5921ed6bce2853aed4fa647c44e82150aac44 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 23 Oct 2024 02:29:08 +0200 Subject: [PATCH] GET LibraryTypes Create and Test set url to lowercase Set Komga to also require username and password --- Tranga/Server/v2LibraryConnectors.cs | 28 ++++++++---------- docs/API_Calls_v2.md | 44 +++++++--------------------- 2 files changed, 22 insertions(+), 50 deletions(-) diff --git a/Tranga/Server/v2LibraryConnectors.cs b/Tranga/Server/v2LibraryConnectors.cs index f989edf..85c2ee0 100644 --- a/Tranga/Server/v2LibraryConnectors.cs +++ b/Tranga/Server/v2LibraryConnectors.cs @@ -39,24 +39,22 @@ public partial class Server return new ValueTuple(HttpStatusCode.NotFound, $"LibraryType {groups[1].Value} does not exist."); } - if(!requestParameters.TryGetValue("URL", out string? url)) + if(!requestParameters.TryGetValue("url", out string? url)) return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'url' missing."); + if(!requestParameters.TryGetValue("username", out string? username)) + return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'username' missing."); + if(!requestParameters.TryGetValue("password", out string? password)) + return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'password' missing."); switch (libraryType) { case LibraryConnector.LibraryType.Kavita: - if(!requestParameters.TryGetValue("username", out string? username)) - return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'username' missing."); - if(!requestParameters.TryGetValue("password", out string? password)) - return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'password' missing."); Kavita kavita = new (this, url, username, password); libraryConnectors.RemoveWhere(lc => lc.libraryType == LibraryConnector.LibraryType.Kavita); libraryConnectors.Add(kavita); return new ValueTuple(HttpStatusCode.OK, kavita); case LibraryConnector.LibraryType.Komga: - if(!requestParameters.TryGetValue("auth", out string? auth)) - return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'auth' missing."); - Komga komga = new (this, url, auth); + Komga komga = new (this, url, username, password); libraryConnectors.RemoveWhere(lc => lc.libraryType == LibraryConnector.LibraryType.Komga); libraryConnectors.Add(komga); return new ValueTuple(HttpStatusCode.OK, komga); @@ -72,16 +70,16 @@ public partial class Server return new ValueTuple(HttpStatusCode.NotFound, $"LibraryType {groups[1].Value} does not exist."); } - if(!requestParameters.TryGetValue("URL", out string? url)) + if(!requestParameters.TryGetValue("url", out string? url)) return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'url' missing."); + if(!requestParameters.TryGetValue("username", out string? username)) + return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'username' missing."); + if(!requestParameters.TryGetValue("password", out string? password)) + return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'password' missing."); switch (libraryType) { case LibraryConnector.LibraryType.Kavita: - if(!requestParameters.TryGetValue("username", out string? username)) - return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'username' missing."); - if(!requestParameters.TryGetValue("password", out string? password)) - return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'password' missing."); Kavita kavita = new (this, url, username, password); return kavita.Test() switch { @@ -89,9 +87,7 @@ public partial class Server _ => new ValueTuple(HttpStatusCode.FailedDependency, kavita) }; case LibraryConnector.LibraryType.Komga: - if(!requestParameters.TryGetValue("auth", out string? auth)) - return new ValueTuple(HttpStatusCode.NotAcceptable, "Parameter 'auth' missing."); - Komga komga = new (this, url, auth); + Komga komga = new (this, url, username, password); return komga.Test() switch { true => new ValueTuple(HttpStatusCode.OK, komga), diff --git a/docs/API_Calls_v2.md b/docs/API_Calls_v2.md index bdd3cde..5f4f77f 100644 --- a/docs/API_Calls_v2.md +++ b/docs/API_Calls_v2.md @@ -803,23 +803,11 @@ Creates a Library-Connector of the specified Type. `Type` is returned by [GET /v2/LibraryConnector/Types](#-v2libraryconnectortypes) - | Parameter | Value | - |-------------|--------------------| - | URL | URL of the Library | - - #### Type specific Parameters (must be included for each) - * Komga - - | Parameter | Value | - |-----------|-------------------------------------------------------------------------------------------------------------------| - | auth | [Base64 encoded Basic-Authentication-String](https://datatracker.ietf.org/doc/html/rfc7617) (`username:password`) | - - * Kavita - - | Parameter | Value | - |-----------|-----------------| - | username | Kavita Username | - | password | Kavita Password | + | Parameter | Value | + |-----------|--------------------| + | url | URL of the Library | + | username | Username | + | password | Password |
@@ -843,23 +831,11 @@ Tests a Library-Connector of the specified Type. `Type` is returned by [GET /v2/LibraryConnector/Types](#-v2libraryconnectortypes) - | Parameter | Value | - |-------------|--------------------| - | URL | URL of the Library | - - #### Type specific Parameters (must be included for each) - * Komga - - | Parameter | Value | - |-----------|-------------------------------------------------------------------------------------------------------------------| - | auth | [Base64 encoded Basic-Authentication-String](https://datatracker.ietf.org/doc/html/rfc7617) (`username:password`) | - - * Kavita - - | Parameter | Value | - |-----------|-----------------| - | username | Kavita Username | - | password | Kavita Password | + | Parameter | Value | + |-----------|--------------------| + | url | URL of the Library | + | username | Username | + | password | Password |