Kavita authorization

This commit is contained in:
glax 2023-06-03 15:39:48 +02:00
parent e0e7abb62b
commit 4f29eff48e
2 changed files with 5 additions and 31 deletions

View File

@ -82,32 +82,12 @@ public static class Tranga_Cli
if (tmpUrlKavita.Length > 0) if (tmpUrlKavita.Length > 0)
{ {
Console.WriteLine("Username:"); Console.WriteLine("Username:");
string? tmpUser = Console.ReadLine(); string? tmpApiKey = Console.ReadLine();
while (tmpUser is null || tmpUser.Length < 1) while (tmpApiKey is null || tmpApiKey.Length < 1)
tmpUser = Console.ReadLine(); tmpApiKey = Console.ReadLine();
Console.WriteLine("Password:");
string tmpPass = string.Empty;
ConsoleKey key;
do
{
var keyInfo = Console.ReadKey(intercept: true);
key = keyInfo.Key;
if (key == ConsoleKey.Backspace && tmpPass.Length > 0)
{
Console.Write("\b \b");
tmpPass = tmpPass[0..^1];
}
else if (!char.IsControl(keyInfo.KeyChar))
{
Console.Write("*");
tmpPass += keyInfo.KeyChar;
}
} while (key != ConsoleKey.Enter);
settings.libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Kavita)); settings.libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Kavita));
settings.libraryManagers.Add(new Kavita(tmpUrlKavita, tmpUser, tmpPass, logger)); settings.libraryManagers.Add(new Kavita(tmpUrlKavita, tmpApiKey, logger));
} }
logger.WriteLine("Tranga_CLI", "Loaded."); logger.WriteLine("Tranga_CLI", "Loaded.");

View File

@ -6,13 +6,7 @@ namespace Tranga.LibraryManagers;
public class Kavita : LibraryManager public class Kavita : LibraryManager
{ {
public Kavita(string baseUrl, string username, string password, Logger? logger) public Kavita(string baseUrl, string apiKey, Logger? logger) : base(baseUrl, apiKey, logger)
: base(baseUrl, Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")), logger)
{
this.libraryType = LibraryType.Kavita;
}
public Kavita(string baseUrl, string auth, Logger? logger) : base(baseUrl, auth, logger)
{ {
this.libraryType = LibraryType.Kavita; this.libraryType = LibraryType.Kavita;
} }