Compare commits
No commits in common. "fe04af4a2bca14a230620eaf77921962b42bc768" and "a8f0f1af152050a9cb0fac34d4b42adc30e4f59b" have entirely different histories.
fe04af4a2b
...
a8f0f1af15
@ -57,11 +57,6 @@ public abstract class GlobalBase
|
|||||||
File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
|
File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DeleteNotificationConnector(NotificationConnector.NotificationManagerType notificationManagerType)
|
|
||||||
{
|
|
||||||
notificationConnectors.RemoveWhere(nc => nc.notificationManagerType == notificationManagerType);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void UpdateLibraries()
|
protected void UpdateLibraries()
|
||||||
{
|
{
|
||||||
foreach(LibraryConnector lc in libraryConnectors)
|
foreach(LibraryConnector lc in libraryConnectors)
|
||||||
@ -78,11 +73,6 @@ public abstract class GlobalBase
|
|||||||
File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors));
|
File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DeleteLibraryConnector(LibraryConnector.LibraryType libraryType)
|
|
||||||
{
|
|
||||||
libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryType);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected bool IsFileInUse(string filePath)
|
protected bool IsFileInUse(string filePath)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
|
@ -7,7 +7,7 @@ public class DownloadNewChapters : Job
|
|||||||
{
|
{
|
||||||
public Publication publication { get; init; }
|
public Publication publication { get; init; }
|
||||||
|
|
||||||
public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Publication publication, bool recurring = false, TimeSpan? recurrence = null) : base (clone, connector, recurring, recurrence)
|
public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Publication publication, bool recurring = false) : base (clone, connector, recurring)
|
||||||
{
|
{
|
||||||
this.publication = publication;
|
this.publication = publication;
|
||||||
}
|
}
|
||||||
|
@ -24,45 +24,6 @@ public class JobBoss : GlobalBase
|
|||||||
this.jobs.Remove(job);
|
this.jobs.Remove(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveJobs(IEnumerable<Job> jobs)
|
|
||||||
{
|
|
||||||
foreach (Job job in jobs)
|
|
||||||
{
|
|
||||||
job.Cancel();
|
|
||||||
this.jobs.Remove(job);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Job> GetJobsLike(string? connectorName = null, string? internalId = null, string? chapterNumber = null)
|
|
||||||
{
|
|
||||||
IEnumerable<Job> ret = this.jobs;
|
|
||||||
if (connectorName is not null)
|
|
||||||
ret = ret.Where(job => job.mangaConnector.name == connectorName);
|
|
||||||
|
|
||||||
if (internalId is not null && chapterNumber is not null)
|
|
||||||
ret = ret.Where(jjob =>
|
|
||||||
{
|
|
||||||
if (jjob is not DownloadChapter job)
|
|
||||||
return false;
|
|
||||||
return job.chapter.parentPublication.internalId == internalId &&
|
|
||||||
job.chapter.chapterNumber == chapterNumber;
|
|
||||||
});
|
|
||||||
else if (internalId is not null)
|
|
||||||
ret = ret.Where(jjob =>
|
|
||||||
{
|
|
||||||
if (jjob is not DownloadNewChapters job)
|
|
||||||
return false;
|
|
||||||
return job.publication.internalId == internalId;
|
|
||||||
});
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Job> GetJobsLike(MangaConnector? mangaConnector = null, Publication? publication = null,
|
|
||||||
Chapter? chapter = null)
|
|
||||||
{
|
|
||||||
return GetJobsLike(mangaConnector?.name, publication?.internalId, chapter?.chapterNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool QueueContainsJob(Job job)
|
private bool QueueContainsJob(Job job)
|
||||||
{
|
{
|
||||||
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>());
|
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>());
|
||||||
|
@ -7,13 +7,13 @@ namespace Tranga.LibraryConnectors;
|
|||||||
public class Kavita : LibraryConnector
|
public class Kavita : LibraryConnector
|
||||||
{
|
{
|
||||||
|
|
||||||
public Kavita(GlobalBase clone, string baseUrl, string username, string password) :
|
public Kavita(string baseUrl, string username, string password, GlobalBase clone) :
|
||||||
base(clone, baseUrl, GetToken(baseUrl, username, password), LibraryType.Kavita)
|
base(baseUrl, GetToken(baseUrl, username, password), LibraryType.Kavita, clone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public Kavita(GlobalBase clone, string baseUrl, string auth) : base(clone, baseUrl, auth, LibraryType.Kavita)
|
public Kavita(string baseUrl, string auth, GlobalBase clone) : base(baseUrl, auth, LibraryType.Kavita, clone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,13 +10,13 @@ namespace Tranga.LibraryConnectors;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Komga : LibraryConnector
|
public class Komga : LibraryConnector
|
||||||
{
|
{
|
||||||
public Komga(GlobalBase clone, string baseUrl, string username, string password)
|
public Komga(string baseUrl, string username, string password, GlobalBase clone)
|
||||||
: base(clone, baseUrl, Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")), LibraryType.Komga)
|
: base(baseUrl, Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")), LibraryType.Komga, clone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public Komga(GlobalBase clone, string baseUrl, string auth) : base(clone, baseUrl, auth, LibraryType.Komga)
|
public Komga(string baseUrl, string auth, GlobalBase clone) : base(baseUrl, auth, LibraryType.Komga, clone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ public abstract class LibraryConnector : GlobalBase
|
|||||||
// ReSharper disable once MemberCanBeProtected.Global
|
// ReSharper disable once MemberCanBeProtected.Global
|
||||||
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
||||||
|
|
||||||
protected LibraryConnector(GlobalBase clone, string baseUrl, string auth, LibraryType libraryType) : base(clone)
|
protected LibraryConnector(string baseUrl, string auth, LibraryType libraryType, GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
this.auth = auth;
|
this.auth = auth;
|
||||||
|
@ -11,7 +11,7 @@ public class Gotify : NotificationConnector
|
|||||||
private readonly HttpClient _client = new();
|
private readonly HttpClient _client = new();
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public Gotify(GlobalBase clone, string endpoint, string appToken) : base(clone, NotificationManagerType.Gotify)
|
public Gotify(string endpoint, string appToken, GlobalBase clone) : base(NotificationManagerType.Gotify, clone)
|
||||||
{
|
{
|
||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
this.appToken = appToken;
|
this.appToken = appToken;
|
||||||
|
@ -10,7 +10,7 @@ public class LunaSea : NotificationConnector
|
|||||||
private readonly HttpClient _client = new();
|
private readonly HttpClient _client = new();
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public LunaSea(GlobalBase clone, string id) : base(clone, NotificationManagerType.LunaSea)
|
public LunaSea(string id, GlobalBase clone) : base(NotificationManagerType.LunaSea, clone)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ public abstract class NotificationConnector : GlobalBase
|
|||||||
{
|
{
|
||||||
public NotificationManagerType notificationManagerType;
|
public NotificationManagerType notificationManagerType;
|
||||||
|
|
||||||
protected NotificationConnector(GlobalBase clone, NotificationManagerType notificationManagerType) : base(clone)
|
protected NotificationConnector(NotificationManagerType notificationManagerType, GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
this.notificationManagerType = notificationManagerType;
|
this.notificationManagerType = notificationManagerType;
|
||||||
}
|
}
|
||||||
|
217
Tranga/Server.cs
217
Tranga/Server.cs
@ -4,9 +4,7 @@ using System.Text;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Tranga.Jobs;
|
using Tranga.Jobs;
|
||||||
using Tranga.LibraryConnectors;
|
|
||||||
using Tranga.MangaConnectors;
|
using Tranga.MangaConnectors;
|
||||||
using Tranga.NotificationConnectors;
|
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
@ -157,15 +155,9 @@ public class Server : GlobalBase
|
|||||||
case "NotificationConnectors":
|
case "NotificationConnectors":
|
||||||
SendResponse(HttpStatusCode.OK, response, notificationConnectors);
|
SendResponse(HttpStatusCode.OK, response, notificationConnectors);
|
||||||
break;
|
break;
|
||||||
case "NotificationsConnectors/Types":
|
|
||||||
SendResponse(HttpStatusCode.OK, response, Enum.GetNames(typeof(NotificationConnectors.NotificationConnector.NotificationManagerType)));
|
|
||||||
break;
|
|
||||||
case "LibraryConnectors":
|
case "LibraryConnectors":
|
||||||
SendResponse(HttpStatusCode.OK, response, libraryConnectors);
|
SendResponse(HttpStatusCode.OK, response, libraryConnectors);
|
||||||
break;
|
break;
|
||||||
case "LibraryConnectors/Types":
|
|
||||||
SendResponse(HttpStatusCode.OK, response, Enum.GetNames(typeof(LibraryConnectors.LibraryConnector.LibraryType)));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
break;
|
break;
|
||||||
@ -174,217 +166,12 @@ public class Server : GlobalBase
|
|||||||
|
|
||||||
private void HandlePost(HttpListenerRequest request, Stream content, HttpListenerResponse response)
|
private void HandlePost(HttpListenerRequest request, Stream content, HttpListenerResponse response)
|
||||||
{
|
{
|
||||||
Dictionary<string, string> requestVariables = GetRequestVariables(request.Url!.Query);
|
|
||||||
string? connectorName, internalId;
|
|
||||||
MangaConnector connector;
|
|
||||||
Publication publication;
|
|
||||||
string path = Regex.Match(request.Url!.LocalPath, @"[A-z0-9]+(\/[A-z0-9]+)*").Value;
|
|
||||||
switch (path)
|
|
||||||
{
|
|
||||||
case "Tasks/MonitorManga":
|
|
||||||
if(!requestVariables.TryGetValue("connector", out connectorName) ||
|
|
||||||
!requestVariables.TryGetValue("internalId", out internalId) ||
|
|
||||||
!requestVariables.TryGetValue("interval", out string? intervalStr) ||
|
|
||||||
_parent.GetConnector(connectorName) is null ||
|
|
||||||
_parent.GetPublicationById(internalId) is null ||
|
|
||||||
!TimeSpan.TryParse(intervalStr, out TimeSpan interval))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
connector = _parent.GetConnector(connectorName)!;
|
|
||||||
publication = (Publication)_parent.GetPublicationById(internalId)!;
|
|
||||||
_parent._jobBoss.AddJob(new DownloadNewChapters(this, connector, publication, true, interval));
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
case "Tasks/DownloadNewChapters":
|
|
||||||
if(!requestVariables.TryGetValue("connector", out connectorName) ||
|
|
||||||
!requestVariables.TryGetValue("internalId", out internalId) ||
|
|
||||||
_parent.GetConnector(connectorName) is null ||
|
|
||||||
_parent.GetPublicationById(internalId) is null)
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
connector = _parent.GetConnector(connectorName)!;
|
|
||||||
publication = (Publication)_parent.GetPublicationById(internalId)!;
|
|
||||||
_parent._jobBoss.AddJob(new DownloadNewChapters(this, connector, publication, false));
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
case "Settings/UpdateDownloadLocation":
|
|
||||||
if (!requestVariables.TryGetValue("downloadLocation", out string? downloadLocation) ||
|
|
||||||
!requestVariables.TryGetValue("moveFiles", out string? moveFilesStr) ||
|
|
||||||
!Boolean.TryParse(moveFilesStr, out bool moveFiles))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
settings.UpdateDownloadLocation(downloadLocation, moveFiles);
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
/*case "Settings/UpdateWorkingDirectory":
|
|
||||||
if (!requestVariables.TryGetValue("workingDirectory", out string? workingDirectory))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
settings.UpdateWorkingDirectory(workingDirectory);
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;*/
|
|
||||||
case "NotificationConnectors/Update":
|
|
||||||
if (!requestVariables.TryGetValue("notificationConnector", out string? notificationConnectorStr) ||
|
|
||||||
!Enum.TryParse(notificationConnectorStr, out NotificationConnector.NotificationManagerType notificationManagerType))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notificationManagerType is NotificationConnector.NotificationManagerType.Gotify)
|
|
||||||
{
|
|
||||||
if (!requestVariables.TryGetValue("gotifyUrl", out string? gotifyUrl) ||
|
|
||||||
!requestVariables.TryGetValue("gotifyAppToken", out string? gotifyAppToken))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
AddNotificationConnector(new Gotify(this, gotifyUrl, gotifyAppToken));
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notificationManagerType is NotificationConnector.NotificationManagerType.LunaSea)
|
|
||||||
{
|
|
||||||
if (!requestVariables.TryGetValue("lunaseaWebhook", out string? lunaseaWebhook))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
AddNotificationConnector(new LunaSea(this, lunaseaWebhook));
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "LibraryManagers/Update":
|
|
||||||
if (!requestVariables.TryGetValue("libraryManager", out string? libraryManagerStr) ||
|
|
||||||
!Enum.TryParse(libraryManagerStr,
|
|
||||||
out LibraryConnectors.LibraryConnector.LibraryType libraryManagerType))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (libraryManagerType is LibraryConnector.LibraryType.Kavita)
|
|
||||||
{
|
|
||||||
if (!requestVariables.TryGetValue("kavitaUrl", out string? kavitaUrl) ||
|
|
||||||
!requestVariables.TryGetValue("kavitaUsername", out string? kavitaUsername) ||
|
|
||||||
!requestVariables.TryGetValue("kavitaPassword", out string? kavitaPassword))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
AddLibraryConnector(new Kavita(this, kavitaUrl, kavitaUsername, kavitaPassword));
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (libraryManagerType is LibraryConnector.LibraryType.Komga)
|
|
||||||
{
|
|
||||||
if (!requestVariables.TryGetValue("komgaUrl", out string? komgaUrl) ||
|
|
||||||
!requestVariables.TryGetValue("komgaAuth", out string? komgaAuth))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
AddLibraryConnector(new Komga(this, komgaUrl, komgaAuth));
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleDelete(HttpListenerRequest request, Stream content, HttpListenerResponse response)
|
private void HandleDelete(HttpListenerRequest request, Stream content, HttpListenerResponse response)
|
||||||
{
|
{
|
||||||
Dictionary<string, string> requestVariables = GetRequestVariables(request.Url!.Query);
|
|
||||||
string? connectorName, internalId;
|
|
||||||
MangaConnector connector;
|
|
||||||
Publication publication;
|
|
||||||
string path = Regex.Match(request.Url!.LocalPath, @"[A-z0-9]+(\/[A-z0-9]+)*").Value;
|
|
||||||
switch (path)
|
|
||||||
{
|
|
||||||
case "Tasks/DownloadChapter":
|
|
||||||
if(!requestVariables.TryGetValue("connector", out connectorName) ||
|
|
||||||
!requestVariables.TryGetValue("internalId", out internalId) ||
|
|
||||||
!requestVariables.TryGetValue("chapterNumber", out string? chapterNumber) ||
|
|
||||||
_parent.GetConnector(connectorName) is null ||
|
|
||||||
_parent.GetPublicationById(internalId) is null)
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
connector = _parent.GetConnector(connectorName)!;
|
|
||||||
publication = (Publication)_parent.GetPublicationById(internalId)!;
|
|
||||||
_parent._jobBoss.RemoveJobs(_parent._jobBoss.GetJobsLike(connectorName, internalId, chapterNumber));
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
case "Tasks/MonitorManga":
|
|
||||||
if(!requestVariables.TryGetValue("connector", out connectorName) ||
|
|
||||||
!requestVariables.TryGetValue("internalId", out internalId) ||
|
|
||||||
!requestVariables.TryGetValue("interval", out string? intervalStr) ||
|
|
||||||
_parent.GetConnector(connectorName) is null ||
|
|
||||||
_parent.GetPublicationById(internalId) is null ||
|
|
||||||
!TimeSpan.TryParse(intervalStr, out TimeSpan interval))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
connector = _parent.GetConnector(connectorName)!;
|
|
||||||
publication = (Publication)_parent.GetPublicationById(internalId)!;
|
|
||||||
_parent._jobBoss.RemoveJobs(_parent._jobBoss.GetJobsLike(connector, publication));
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
case "Tasks/DownloadNewChapters":
|
|
||||||
if(!requestVariables.TryGetValue("connector", out connectorName) ||
|
|
||||||
!requestVariables.TryGetValue("internalId", out internalId) ||
|
|
||||||
_parent.GetConnector(connectorName) is null ||
|
|
||||||
_parent.GetPublicationById(internalId) is null)
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
connector = _parent.GetConnector(connectorName)!;
|
|
||||||
publication = (Publication)_parent.GetPublicationById(internalId)!;
|
|
||||||
_parent._jobBoss.RemoveJobs(_parent._jobBoss.GetJobsLike(connector, publication));
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
case "NotificationConnectors":
|
|
||||||
if (!requestVariables.TryGetValue("notificationConnector", out string? notificationConnectorStr) ||
|
|
||||||
!Enum.TryParse(notificationConnectorStr, out NotificationConnector.NotificationManagerType notificationManagerType))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
DeleteNotificationConnector(notificationManagerType);
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
case "LibraryManagers":
|
|
||||||
if (!requestVariables.TryGetValue("libraryManager", out string? libraryManagerStr) ||
|
|
||||||
!Enum.TryParse(libraryManagerStr,
|
|
||||||
out LibraryConnectors.LibraryConnector.LibraryType libraryManagerType))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
DeleteLibraryConnector(libraryManagerType);
|
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
private void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
using System.Runtime.InteropServices;
|
using Logging;
|
||||||
using Logging;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Tranga.LibraryConnectors;
|
using Tranga.LibraryConnectors;
|
||||||
using Tranga.NotificationConnectors;
|
using Tranga.NotificationConnectors;
|
||||||
using static System.IO.UnixFileMode;
|
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
public class TrangaSettings
|
public class TrangaSettings
|
||||||
{
|
{
|
||||||
public string downloadLocation { get; private set; }
|
public string downloadLocation { get; private set; }
|
||||||
public string workingDirectory { get; private set; }
|
public string workingDirectory { get; init; }
|
||||||
public int apiPortNumber { get; init; }
|
public int apiPortNumber { get; init; }
|
||||||
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
||||||
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
|
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
|
||||||
@ -36,8 +34,6 @@ public class TrangaSettings
|
|||||||
this.downloadLocation = settings.downloadLocation;
|
this.downloadLocation = settings.downloadLocation;
|
||||||
this.workingDirectory = settings.workingDirectory;
|
this.workingDirectory = settings.workingDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateDownloadLocation(this.downloadLocation, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<LibraryConnector> LoadLibraryConnectors()
|
public HashSet<LibraryConnector> LoadLibraryConnectors()
|
||||||
@ -68,33 +64,6 @@ public class TrangaSettings
|
|||||||
})!;
|
})!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateDownloadLocation(string newPath, bool moveFiles = true)
|
|
||||||
{
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
||||||
Directory.CreateDirectory(newPath,
|
|
||||||
GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
|
|
||||||
else
|
|
||||||
Directory.CreateDirectory(newPath);
|
|
||||||
|
|
||||||
if (moveFiles && Directory.Exists(this.downloadLocation))
|
|
||||||
Directory.Move(this.downloadLocation, newPath);
|
|
||||||
|
|
||||||
this.downloadLocation = newPath;
|
|
||||||
ExportSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateWorkingDirectory(string newPath)
|
|
||||||
{
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
||||||
Directory.CreateDirectory(newPath,
|
|
||||||
GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
|
|
||||||
else
|
|
||||||
Directory.CreateDirectory(newPath);
|
|
||||||
Directory.Move(this.workingDirectory, newPath);
|
|
||||||
this.workingDirectory = newPath;
|
|
||||||
ExportSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ExportSettings()
|
public void ExportSettings()
|
||||||
{
|
{
|
||||||
while (File.Exists(settingsFilePath))
|
while (File.Exists(settingsFilePath))
|
||||||
|
Loading…
Reference in New Issue
Block a user