Skip to content

Commit

Permalink
GET LibraryTypes Create and Test set url to lowercase
Browse files Browse the repository at this point in the history
Set Komga to also require username and password
  • Loading branch information
C9Glax committed Oct 23, 2024
1 parent 9d47445 commit 96b5921
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 50 deletions.
28 changes: 12 additions & 16 deletions Tranga/Server/v2LibraryConnectors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,22 @@ public partial class Server
return new ValueTuple<HttpStatusCode, object?>(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, object?>(HttpStatusCode.NotAcceptable, "Parameter 'url' missing.");
if(!requestParameters.TryGetValue("username", out string? username))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotAcceptable, "Parameter 'username' missing.");
if(!requestParameters.TryGetValue("password", out string? password))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotAcceptable, "Parameter 'password' missing.");

switch (libraryType)
{
case LibraryConnector.LibraryType.Kavita:
if(!requestParameters.TryGetValue("username", out string? username))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotAcceptable, "Parameter 'username' missing.");
if(!requestParameters.TryGetValue("password", out string? password))
return new ValueTuple<HttpStatusCode, object?>(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, object?>(HttpStatusCode.OK, kavita);
case LibraryConnector.LibraryType.Komga:
if(!requestParameters.TryGetValue("auth", out string? auth))
return new ValueTuple<HttpStatusCode, object?>(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, object?>(HttpStatusCode.OK, komga);
Expand All @@ -72,26 +70,24 @@ public partial class Server
return new ValueTuple<HttpStatusCode, object?>(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, object?>(HttpStatusCode.NotAcceptable, "Parameter 'url' missing.");
if(!requestParameters.TryGetValue("username", out string? username))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotAcceptable, "Parameter 'username' missing.");
if(!requestParameters.TryGetValue("password", out string? password))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotAcceptable, "Parameter 'password' missing.");

switch (libraryType)
{
case LibraryConnector.LibraryType.Kavita:
if(!requestParameters.TryGetValue("username", out string? username))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotAcceptable, "Parameter 'username' missing.");
if(!requestParameters.TryGetValue("password", out string? password))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotAcceptable, "Parameter 'password' missing.");
Kavita kavita = new (this, url, username, password);
return kavita.Test() switch
{
true => new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, kavita),
_ => new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.FailedDependency, kavita)
};
case LibraryConnector.LibraryType.Komga:
if(!requestParameters.TryGetValue("auth", out string? auth))
return new ValueTuple<HttpStatusCode, object?>(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, object?>(HttpStatusCode.OK, komga),
Expand Down
44 changes: 10 additions & 34 deletions docs/API_Calls_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
</details>

<details>
Expand All @@ -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 |
</details>

<details>
Expand Down

0 comments on commit 96b5921

Please sign in to comment.