mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-01-30 00:17:29 +01:00
parent
0c580933f9
commit
5d98295c59
@ -17,7 +17,7 @@ TrangaSettings settings;
|
|||||||
if (File.Exists(settingsFilePath))
|
if (File.Exists(settingsFilePath))
|
||||||
settings = TrangaSettings.LoadSettings(settingsFilePath, logger);
|
settings = TrangaSettings.LoadSettings(settingsFilePath, logger);
|
||||||
else
|
else
|
||||||
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, null);
|
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, new HashSet<LibraryManager>());
|
||||||
|
|
||||||
Directory.CreateDirectory(settings.workingDirectory);
|
Directory.CreateDirectory(settings.workingDirectory);
|
||||||
Directory.CreateDirectory(settings.downloadLocation);
|
Directory.CreateDirectory(settings.downloadLocation);
|
||||||
@ -211,6 +211,8 @@ app.MapDelete("/Queue/Dequeue", (string taskType, string? connectorName, string?
|
|||||||
|
|
||||||
app.MapGet("/Settings/Get", () => taskManager.settings);
|
app.MapGet("/Settings/Get", () => taskManager.settings);
|
||||||
|
|
||||||
app.MapPost("/Settings/Update", (string? downloadLocation, string? komgaUrl, string? komgaAuth) => taskManager.UpdateSettings(downloadLocation, komgaUrl, komgaAuth) );
|
app.MapPost("/Settings/Update",
|
||||||
|
(string? downloadLocation, string? komgaUrl, string? komgaAuth, string? kavitaUrl, string? kavitaAuth) =>
|
||||||
|
taskManager.UpdateSettings(downloadLocation, komgaUrl, komgaAuth, kavitaUrl, kavitaAuth));
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
@ -29,7 +29,7 @@ public static class Tranga_Cli
|
|||||||
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, Console.Out.Encoding, logFilePath);
|
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, Console.Out.Encoding, logFilePath);
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
||||||
TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath, logger) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, null);
|
TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath, logger) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, new HashSet<LibraryManager>());
|
||||||
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "User Input");
|
logger.WriteLine("Tranga_CLI", "User Input");
|
||||||
@ -39,8 +39,10 @@ public static class Tranga_Cli
|
|||||||
tmpPath = Console.ReadLine();
|
tmpPath = Console.ReadLine();
|
||||||
if (tmpPath.Length > 0)
|
if (tmpPath.Length > 0)
|
||||||
settings.downloadLocation = tmpPath;
|
settings.downloadLocation = tmpPath;
|
||||||
|
|
||||||
|
Komga? komga = (Komga?)settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Komga));
|
||||||
|
|
||||||
Console.WriteLine($"Komga BaseURL [{settings.komga?.baseUrl}]:");
|
Console.WriteLine($"Komga BaseURL [{komga?.baseUrl}]:");
|
||||||
string? tmpUrl = Console.ReadLine();
|
string? tmpUrl = Console.ReadLine();
|
||||||
while (tmpUrl is null)
|
while (tmpUrl is null)
|
||||||
tmpUrl = Console.ReadLine();
|
tmpUrl = Console.ReadLine();
|
||||||
@ -70,8 +72,9 @@ public static class Tranga_Cli
|
|||||||
tmpPass += keyInfo.KeyChar;
|
tmpPass += keyInfo.KeyChar;
|
||||||
}
|
}
|
||||||
} while (key != ConsoleKey.Enter);
|
} while (key != ConsoleKey.Enter);
|
||||||
|
|
||||||
settings.komga = new Komga(tmpUrl, tmpUser, tmpPass, logger);
|
settings.libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Komga));
|
||||||
|
settings.libraryManagers.Add(new Komga(tmpUrl, tmpUser, tmpPass, logger));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Loaded.");
|
logger.WriteLine("Tranga_CLI", "Loaded.");
|
||||||
@ -333,7 +336,7 @@ public static class Tranga_Cli
|
|||||||
TrangaTask.Task task = (TrangaTask.Task)tmpTask;
|
TrangaTask.Task task = (TrangaTask.Task)tmpTask;
|
||||||
|
|
||||||
Connector? connector = null;
|
Connector? connector = null;
|
||||||
if (task != TrangaTask.Task.UpdateKomgaLibrary)
|
if (task != TrangaTask.Task.UpdateLibraries)
|
||||||
{
|
{
|
||||||
connector = SelectConnector(taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
connector = SelectConnector(taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
||||||
if (connector is null)
|
if (connector is null)
|
||||||
@ -341,7 +344,7 @@ public static class Tranga_Cli
|
|||||||
}
|
}
|
||||||
|
|
||||||
Publication? publication = null;
|
Publication? publication = null;
|
||||||
if (task != TrangaTask.Task.UpdateKomgaLibrary)
|
if (task != TrangaTask.Task.UpdateLibraries)
|
||||||
{
|
{
|
||||||
publication = SelectPublication(taskManager, connector!, logger);
|
publication = SelectPublication(taskManager, connector!, logger);
|
||||||
if (publication is null)
|
if (publication is null)
|
||||||
|
15
Tranga/LibraryManagers/Kavita.cs
Normal file
15
Tranga/LibraryManagers/Kavita.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using Logging;
|
||||||
|
|
||||||
|
namespace Tranga.LibraryManagers;
|
||||||
|
|
||||||
|
public class Kavita : LibraryManager
|
||||||
|
{
|
||||||
|
public Kavita(string baseUrl, string auth, Logger? logger) : base(baseUrl, auth, logger)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateLibrary()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,6 @@ public class TaskManager
|
|||||||
private readonly Dictionary<Connector, List<TrangaTask>> _taskQueue = new();
|
private readonly Dictionary<Connector, List<TrangaTask>> _taskQueue = new();
|
||||||
public TrangaSettings settings { get; }
|
public TrangaSettings settings { get; }
|
||||||
private Logger? logger { get; }
|
private Logger? logger { get; }
|
||||||
public Komga? komga => settings.komga;
|
|
||||||
|
|
||||||
/// <param name="downloadFolderPath">Local path to save data (Manga) to</param>
|
/// <param name="downloadFolderPath">Local path to save data (Manga) to</param>
|
||||||
/// <param name="workingDirectory">Path to the working directory</param>
|
/// <param name="workingDirectory">Path to the working directory</param>
|
||||||
@ -28,16 +27,12 @@ public class TaskManager
|
|||||||
/// <param name="komgaUsername">The Komga username</param>
|
/// <param name="komgaUsername">The Komga username</param>
|
||||||
/// <param name="komgaPassword">The Komga password</param>
|
/// <param name="komgaPassword">The Komga password</param>
|
||||||
/// <param name="logger"></param>
|
/// <param name="logger"></param>
|
||||||
public TaskManager(string downloadFolderPath, string workingDirectory, string imageCachePath, string? komgaBaseUrl = null, string? komgaUsername = null, string? komgaPassword = null, Logger? logger = null)
|
public TaskManager(string downloadFolderPath, string workingDirectory, string imageCachePath, HashSet<LibraryManager> libraryManagers, Logger? logger = null)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
_allTasks = new HashSet<TrangaTask>();
|
_allTasks = new HashSet<TrangaTask>();
|
||||||
|
|
||||||
Komga? newKomga = null;
|
this.settings = new TrangaSettings(downloadFolderPath, workingDirectory, libraryManagers);
|
||||||
if (komgaBaseUrl != null && komgaUsername != null && komgaPassword != null)
|
|
||||||
newKomga = new Komga(komgaBaseUrl, komgaUsername, komgaPassword, logger);
|
|
||||||
|
|
||||||
this.settings = new TrangaSettings(downloadFolderPath, workingDirectory, newKomga);
|
|
||||||
ExportDataAndSettings();
|
ExportDataAndSettings();
|
||||||
|
|
||||||
this._connectors = new Connector[]
|
this._connectors = new Connector[]
|
||||||
@ -52,10 +47,18 @@ public class TaskManager
|
|||||||
taskChecker.Start();
|
taskChecker.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateSettings(string? downloadLocation, string? komgaUrl, string? komgaAuth)
|
public void UpdateSettings(string? downloadLocation, string? komgaUrl, string? komgaAuth, string? kavitaUrl, string? kavitaAuth)
|
||||||
{
|
{
|
||||||
if (komgaUrl is not null && komgaAuth is not null && komgaUrl.Length > 0 && komgaAuth.Length > 0)
|
if (komgaUrl is not null && komgaAuth is not null && komgaUrl.Length > 0 && komgaAuth.Length > 0)
|
||||||
settings.komga = new Komga(komgaUrl, komgaAuth, logger);
|
{
|
||||||
|
settings.libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Komga));
|
||||||
|
settings.libraryManagers.Add(new Komga(komgaUrl, komgaAuth, logger));
|
||||||
|
}
|
||||||
|
if (kavitaUrl is not null && kavitaAuth is not null && kavitaUrl.Length > 0 && kavitaAuth.Length > 0)
|
||||||
|
{
|
||||||
|
settings.libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Kavita));
|
||||||
|
settings.libraryManagers.Add(new Kavita(kavitaUrl, kavitaAuth, logger));
|
||||||
|
}
|
||||||
if (downloadLocation is not null && downloadLocation.Length > 0)
|
if (downloadLocation is not null && downloadLocation.Length > 0)
|
||||||
settings.downloadLocation = downloadLocation;
|
settings.downloadLocation = downloadLocation;
|
||||||
ExportDataAndSettings();
|
ExportDataAndSettings();
|
||||||
@ -104,7 +107,7 @@ public class TaskManager
|
|||||||
foreach (TrangaTask task in _allTasks.Where(aTask => aTask.ShouldExecute()))
|
foreach (TrangaTask task in _allTasks.Where(aTask => aTask.ShouldExecute()))
|
||||||
{
|
{
|
||||||
task.state = TrangaTask.ExecutionState.Enqueued;
|
task.state = TrangaTask.ExecutionState.Enqueued;
|
||||||
if(task.task == TrangaTask.Task.UpdateKomgaLibrary)
|
if(task.task == TrangaTask.Task.UpdateLibraries)
|
||||||
ExecuteTaskNow(task);
|
ExecuteTaskNow(task);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -147,12 +150,12 @@ public class TaskManager
|
|||||||
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {task} {connectorName} {publication?.sortName}");
|
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {task} {connectorName} {publication?.sortName}");
|
||||||
|
|
||||||
TrangaTask? newTask = null;
|
TrangaTask? newTask = null;
|
||||||
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
if (task == TrangaTask.Task.UpdateLibraries)
|
||||||
{
|
{
|
||||||
newTask = new UpdateKomgaLibraryTask(task, reoccurrence);
|
newTask = new UpdateLibrariesTask(task, reoccurrence);
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Removing old {task}-Task.");
|
logger?.WriteLine(this.GetType().ToString(), $"Removing old {task}-Task.");
|
||||||
//Only one UpdateKomgaLibrary Task
|
//Only one UpdateKomgaLibrary Task
|
||||||
_allTasks.RemoveWhere(trangaTask => trangaTask.task is TrangaTask.Task.UpdateKomgaLibrary);
|
_allTasks.RemoveWhere(trangaTask => trangaTask.task is TrangaTask.Task.UpdateLibraries);
|
||||||
_allTasks.Add(newTask);
|
_allTasks.Add(newTask);
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask}");
|
logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask}");
|
||||||
}else if (task == TrangaTask.Task.DownloadNewChapters)
|
}else if (task == TrangaTask.Task.DownloadNewChapters)
|
||||||
@ -193,9 +196,9 @@ public class TaskManager
|
|||||||
public void DeleteTask(TrangaTask.Task task, string? connectorName, Publication? publication)
|
public void DeleteTask(TrangaTask.Task task, string? connectorName, Publication? publication)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task} {publication?.sortName}");
|
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task} {publication?.sortName}");
|
||||||
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
if (task == TrangaTask.Task.UpdateLibraries)
|
||||||
{
|
{
|
||||||
_allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateKomgaLibrary);
|
_allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateLibraries);
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} from all Tasks.");
|
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} from all Tasks.");
|
||||||
}
|
}
|
||||||
else if (connectorName is null)
|
else if (connectorName is null)
|
||||||
|
@ -12,26 +12,27 @@ public class TrangaSettings
|
|||||||
[JsonIgnore]public string tasksFilePath => Path.Join(workingDirectory, "tasks.json");
|
[JsonIgnore]public string tasksFilePath => Path.Join(workingDirectory, "tasks.json");
|
||||||
[JsonIgnore]public string knownPublicationsPath => Path.Join(workingDirectory, "knownPublications.json");
|
[JsonIgnore]public string knownPublicationsPath => Path.Join(workingDirectory, "knownPublications.json");
|
||||||
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
||||||
public Komga? komga { get; set; }
|
public readonly HashSet<LibraryManager> libraryManagers;
|
||||||
|
|
||||||
public TrangaSettings(string downloadLocation, string workingDirectory, Komga? komga)
|
public TrangaSettings(string downloadLocation, string workingDirectory, HashSet<LibraryManager> libraryManagers)
|
||||||
{
|
{
|
||||||
if (downloadLocation.Length < 1 || workingDirectory.Length < 1)
|
if (downloadLocation.Length < 1 || workingDirectory.Length < 1)
|
||||||
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
|
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
|
||||||
this.workingDirectory = workingDirectory;
|
this.workingDirectory = workingDirectory;
|
||||||
this.downloadLocation = downloadLocation;
|
this.downloadLocation = downloadLocation;
|
||||||
this.komga = komga;
|
this.libraryManagers = libraryManagers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TrangaSettings LoadSettings(string importFilePath, Logger? logger)
|
public static TrangaSettings LoadSettings(string importFilePath, Logger? logger)
|
||||||
{
|
{
|
||||||
if (!File.Exists(importFilePath))
|
if (!File.Exists(importFilePath))
|
||||||
return new TrangaSettings(Path.Join(Directory.GetCurrentDirectory(), "Downloads"), Directory.GetCurrentDirectory(), null);
|
return new TrangaSettings(Path.Join(Directory.GetCurrentDirectory(), "Downloads"), Directory.GetCurrentDirectory(), new HashSet<LibraryManager>());
|
||||||
|
|
||||||
string toRead = File.ReadAllText(importFilePath);
|
string toRead = File.ReadAllText(importFilePath);
|
||||||
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(toRead)!;
|
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(toRead)!;
|
||||||
if(settings.komga is not null && logger is not null)
|
if(logger is not null)
|
||||||
settings.komga.AddLogger(logger);
|
foreach(LibraryManager lm in settings.libraryManagers)
|
||||||
|
lm.AddLogger(logger);
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ public abstract class TrangaTask
|
|||||||
public enum Task : byte
|
public enum Task : byte
|
||||||
{
|
{
|
||||||
DownloadNewChapters = 2,
|
DownloadNewChapters = 2,
|
||||||
UpdateKomgaLibrary = 3
|
UpdateLibraries = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@ -95,8 +95,8 @@ public abstract class TrangaTask
|
|||||||
if (jo["task"]!.Value<Int64>() == (Int64)Task.DownloadNewChapters)
|
if (jo["task"]!.Value<Int64>() == (Int64)Task.DownloadNewChapters)
|
||||||
return jo.ToObject<DownloadNewChaptersTask>(serializer)!;
|
return jo.ToObject<DownloadNewChaptersTask>(serializer)!;
|
||||||
|
|
||||||
if (jo["task"]!.Value<Int64>() == (Int64)Task.UpdateKomgaLibrary)
|
if (jo["task"]!.Value<Int64>() == (Int64)Task.UpdateLibraries)
|
||||||
return jo.ToObject<UpdateKomgaLibraryTask>(serializer)!;
|
return jo.ToObject<UpdateLibrariesTask>(serializer)!;
|
||||||
|
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
using Logging;
|
|
||||||
|
|
||||||
namespace Tranga.TrangaTasks;
|
|
||||||
|
|
||||||
public class UpdateKomgaLibraryTask : TrangaTask
|
|
||||||
{
|
|
||||||
public UpdateKomgaLibraryTask(Task task, TimeSpan reoccurrence) : base(task, null, null, reoccurrence)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ExecuteTask(TaskManager taskManager, Logger? logger)
|
|
||||||
{
|
|
||||||
taskManager.komga?.UpdateLibrary();
|
|
||||||
}
|
|
||||||
}
|
|
16
Tranga/TrangaTasks/UpdateLibrariesTask.cs
Normal file
16
Tranga/TrangaTasks/UpdateLibrariesTask.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using Logging;
|
||||||
|
|
||||||
|
namespace Tranga.TrangaTasks;
|
||||||
|
|
||||||
|
public class UpdateLibrariesTask : TrangaTask
|
||||||
|
{
|
||||||
|
public UpdateLibrariesTask(Task task, TimeSpan reoccurrence) : base(task, null, null, reoccurrence)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ExecuteTask(TaskManager taskManager, Logger? logger)
|
||||||
|
{
|
||||||
|
foreach(LibraryManager lm in taskManager.settings.libraryManagers)
|
||||||
|
lm.UpdateLibrary();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user