Compare commits
No commits in common. "89c5f4b820214d5f2ea296a1d0b2cb2e76af64c6" and "9f30e52713e3931057f19d4234a547466b45574b" have entirely different histories.
89c5f4b820
...
9f30e52713
@ -26,8 +26,8 @@ public abstract class GlobalBase
|
||||
{
|
||||
this.logger = logger;
|
||||
this.settings = settings;
|
||||
this.notificationConnectors = settings.LoadNotificationConnectors(this);
|
||||
this.libraryConnectors = settings.LoadLibraryConnectors(this);
|
||||
this.notificationConnectors = settings.LoadNotificationConnectors();
|
||||
this.libraryConnectors = settings.LoadLibraryConnectors();
|
||||
this.cachedPublications = new();
|
||||
}
|
||||
|
||||
@ -58,10 +58,10 @@ public abstract class GlobalBase
|
||||
File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
|
||||
}
|
||||
|
||||
protected void DeleteNotificationConnector(NotificationConnector.NotificationConnectorType notificationConnectorType)
|
||||
protected void DeleteNotificationConnector(NotificationConnector.NotificationManagerType notificationManagerType)
|
||||
{
|
||||
Log($"Removing {notificationConnectorType}");
|
||||
notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnectorType);
|
||||
Log($"Removing {notificationManagerType}");
|
||||
notificationConnectors.RemoveWhere(nc => nc.notificationManagerType == notificationManagerType);
|
||||
}
|
||||
|
||||
protected void UpdateLibraries()
|
||||
|
@ -5,13 +5,6 @@ namespace Tranga.LibraryConnectors;
|
||||
|
||||
public class LibraryManagerJsonConverter : JsonConverter
|
||||
{
|
||||
private GlobalBase _clone;
|
||||
|
||||
internal LibraryManagerJsonConverter(GlobalBase clone)
|
||||
{
|
||||
this._clone = clone;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (objectType == typeof(LibraryConnector));
|
||||
@ -20,15 +13,11 @@ public class LibraryManagerJsonConverter : JsonConverter
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
||||
{
|
||||
JObject jo = JObject.Load(reader);
|
||||
if (jo["libraryType"]!.Value<byte>() == (byte)LibraryConnector.LibraryType.Komga)
|
||||
return new Komga(this._clone,
|
||||
jo.GetValue("baseUrl")!.Value<string>()!,
|
||||
jo.GetValue("auth")!.Value<string>()!);
|
||||
if (jo["libraryType"]!.Value<Int64>() == (Int64)LibraryConnector.LibraryType.Komga)
|
||||
return jo.ToObject<Komga>(serializer)!;
|
||||
|
||||
if (jo["libraryType"]!.Value<byte>() == (byte)LibraryConnector.LibraryType.Kavita)
|
||||
return new Kavita(this._clone,
|
||||
jo.GetValue("baseUrl")!.Value<string>()!,
|
||||
jo.GetValue("auth")!.Value<string>()!);
|
||||
if (jo["libraryType"]!.Value<Int64>() == (Int64)LibraryConnector.LibraryType.Kavita)
|
||||
return jo.ToObject<Kavita>(serializer)!;
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class Gotify : NotificationConnector
|
||||
private readonly HttpClient _client = new();
|
||||
|
||||
[JsonConstructor]
|
||||
public Gotify(GlobalBase clone, string endpoint, string appToken) : base(clone, NotificationConnectorType.Gotify)
|
||||
public Gotify(GlobalBase clone, string endpoint, string appToken) : base(clone, NotificationManagerType.Gotify)
|
||||
{
|
||||
this.endpoint = endpoint;
|
||||
this.appToken = appToken;
|
||||
|
@ -10,7 +10,7 @@ public class LunaSea : NotificationConnector
|
||||
private readonly HttpClient _client = new();
|
||||
|
||||
[JsonConstructor]
|
||||
public LunaSea(GlobalBase clone, string id) : base(clone, NotificationConnectorType.LunaSea)
|
||||
public LunaSea(GlobalBase clone, string id) : base(clone, NotificationManagerType.LunaSea)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
public abstract class NotificationConnector : GlobalBase
|
||||
{
|
||||
public readonly NotificationConnectorType notificationConnectorType;
|
||||
public readonly NotificationManagerType notificationManagerType;
|
||||
|
||||
protected NotificationConnector(GlobalBase clone, NotificationConnectorType notificationConnectorType) : base(clone)
|
||||
protected NotificationConnector(GlobalBase clone, NotificationManagerType notificationManagerType) : base(clone)
|
||||
{
|
||||
this.notificationConnectorType = notificationConnectorType;
|
||||
this.notificationManagerType = notificationManagerType;
|
||||
}
|
||||
|
||||
public enum NotificationConnectorType : byte { Gotify = 0, LunaSea = 1 }
|
||||
public enum NotificationManagerType : byte { Gotify = 0, LunaSea = 1 }
|
||||
|
||||
public abstract void SendNotification(string title, string notificationText);
|
||||
}
|
@ -5,13 +5,6 @@ namespace Tranga.NotificationConnectors;
|
||||
|
||||
public class NotificationManagerJsonConverter : JsonConverter
|
||||
{
|
||||
private GlobalBase _clone;
|
||||
|
||||
public NotificationManagerJsonConverter(GlobalBase clone)
|
||||
{
|
||||
this._clone = clone;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (objectType == typeof(NotificationConnector));
|
||||
@ -21,11 +14,10 @@ public class NotificationManagerJsonConverter : JsonConverter
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
JObject jo = JObject.Load(reader);
|
||||
if (jo["notificationConnectorType"]!.Value<byte>() == (byte)NotificationConnector.NotificationConnectorType.Gotify)
|
||||
return new Gotify(this._clone, jo.GetValue("endpoint")!.Value<string>()!, jo.GetValue("appToken")!.Value<string>()!);
|
||||
else if (jo["notificationConnectorType"]!.Value<byte>() ==
|
||||
(byte)NotificationConnector.NotificationConnectorType.LunaSea)
|
||||
return new LunaSea(this._clone, jo.GetValue("id")!.Value<string>()!);
|
||||
if (jo["notificationManagerType"]!.Value<byte>() == (byte)NotificationConnector.NotificationManagerType.Gotify)
|
||||
return jo.ToObject<Gotify>(serializer)!;
|
||||
else if (jo["notificationManagerType"]!.Value<byte>() == (byte)NotificationConnector.NotificationManagerType.LunaSea)
|
||||
return jo.ToObject<LunaSea>(serializer)!;
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
|
@ -165,25 +165,20 @@ public class Server : GlobalBase
|
||||
case "Jobs/Waiting":
|
||||
SendResponse(HttpStatusCode.OK, response, _parent._jobBoss.jobs.Where(jjob => jjob.progressToken.state is ProgressToken.State.Standby));
|
||||
break;
|
||||
case "Jobs/MonitorJobs":
|
||||
SendResponse(HttpStatusCode.OK, response, _parent._jobBoss.jobs.Where(jjob => jjob is DownloadNewChapters));
|
||||
break;
|
||||
case "Settings":
|
||||
SendResponse(HttpStatusCode.OK, response, settings);
|
||||
break;
|
||||
case "NotificationConnectors":
|
||||
SendResponse(HttpStatusCode.OK, response, notificationConnectors);
|
||||
break;
|
||||
case "NotificationConnectors/Types":
|
||||
SendResponse(HttpStatusCode.OK, response,
|
||||
Enum.GetValues<NotificationConnector.NotificationConnectorType>().Select(nc => new KeyValuePair<byte, string?>((byte)nc, Enum.GetName(nc))));
|
||||
case "NotificationsConnectors/Types":
|
||||
SendResponse(HttpStatusCode.OK, response, Enum.GetNames(typeof(NotificationConnector.NotificationManagerType)));
|
||||
break;
|
||||
case "LibraryConnectors":
|
||||
SendResponse(HttpStatusCode.OK, response, libraryConnectors);
|
||||
break;
|
||||
case "LibraryConnectors/Types":
|
||||
SendResponse(HttpStatusCode.OK, response,
|
||||
Enum.GetValues<LibraryConnector.LibraryType>().Select(lc => new KeyValuePair<byte, string?>((byte)lc, Enum.GetName(lc))));
|
||||
SendResponse(HttpStatusCode.OK, response, Enum.GetNames(typeof(LibraryConnector.LibraryType)));
|
||||
break;
|
||||
default:
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
@ -262,13 +257,13 @@ public class Server : GlobalBase
|
||||
break;*/
|
||||
case "NotificationConnectors/Update":
|
||||
if (!requestVariables.TryGetValue("notificationConnector", out string? notificationConnectorStr) ||
|
||||
!Enum.TryParse(notificationConnectorStr, out NotificationConnector.NotificationConnectorType notificationConnectorType))
|
||||
!Enum.TryParse(notificationConnectorStr, out NotificationConnector.NotificationManagerType notificationManagerType))
|
||||
{
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
break;
|
||||
}
|
||||
|
||||
if (notificationConnectorType is NotificationConnector.NotificationConnectorType.Gotify)
|
||||
if (notificationManagerType is NotificationConnector.NotificationManagerType.Gotify)
|
||||
{
|
||||
if (!requestVariables.TryGetValue("gotifyUrl", out string? gotifyUrl) ||
|
||||
!requestVariables.TryGetValue("gotifyAppToken", out string? gotifyAppToken))
|
||||
@ -281,7 +276,7 @@ public class Server : GlobalBase
|
||||
break;
|
||||
}
|
||||
|
||||
if (notificationConnectorType is NotificationConnector.NotificationConnectorType.LunaSea)
|
||||
if (notificationManagerType is NotificationConnector.NotificationManagerType.LunaSea)
|
||||
{
|
||||
if (!requestVariables.TryGetValue("lunaseaWebhook", out string? lunaseaWebhook))
|
||||
{
|
||||
@ -293,16 +288,16 @@ public class Server : GlobalBase
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "LibraryConnectors/Update":
|
||||
if (!requestVariables.TryGetValue("libraryConnector", out string? libraryConnectorStr) ||
|
||||
!Enum.TryParse(libraryConnectorStr,
|
||||
out LibraryConnector.LibraryType libraryConnectorType))
|
||||
case "LibraryManagers/Update":
|
||||
if (!requestVariables.TryGetValue("libraryManager", out string? libraryManagerStr) ||
|
||||
!Enum.TryParse(libraryManagerStr,
|
||||
out LibraryConnector.LibraryType libraryManagerType))
|
||||
{
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
break;
|
||||
}
|
||||
|
||||
if (libraryConnectorType is LibraryConnector.LibraryType.Kavita)
|
||||
if (libraryManagerType is LibraryConnector.LibraryType.Kavita)
|
||||
{
|
||||
if (!requestVariables.TryGetValue("kavitaUrl", out string? kavitaUrl) ||
|
||||
!requestVariables.TryGetValue("kavitaUsername", out string? kavitaUsername) ||
|
||||
@ -316,7 +311,7 @@ public class Server : GlobalBase
|
||||
break;
|
||||
}
|
||||
|
||||
if (libraryConnectorType is LibraryConnector.LibraryType.Komga)
|
||||
if (libraryManagerType is LibraryConnector.LibraryType.Komga)
|
||||
{
|
||||
if (!requestVariables.TryGetValue("komgaUrl", out string? komgaUrl) ||
|
||||
!requestVariables.TryGetValue("komgaAuth", out string? komgaAuth))
|
||||
@ -397,23 +392,23 @@ public class Server : GlobalBase
|
||||
break;
|
||||
case "NotificationConnectors":
|
||||
if (!requestVariables.TryGetValue("notificationConnector", out string? notificationConnectorStr) ||
|
||||
!Enum.TryParse(notificationConnectorStr, out NotificationConnector.NotificationConnectorType notificationConnectorType))
|
||||
!Enum.TryParse(notificationConnectorStr, out NotificationConnector.NotificationManagerType notificationManagerType))
|
||||
{
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
break;
|
||||
}
|
||||
DeleteNotificationConnector(notificationConnectorType);
|
||||
DeleteNotificationConnector(notificationManagerType);
|
||||
SendResponse(HttpStatusCode.Accepted, response);
|
||||
break;
|
||||
case "LibraryConnectors":
|
||||
if (!requestVariables.TryGetValue("libraryConnectors", out string? libraryConnectorStr) ||
|
||||
!Enum.TryParse(libraryConnectorStr,
|
||||
out LibraryConnector.LibraryType libraryConnectoryType))
|
||||
case "LibraryManagers":
|
||||
if (!requestVariables.TryGetValue("libraryManager", out string? libraryManagerStr) ||
|
||||
!Enum.TryParse(libraryManagerStr,
|
||||
out LibraryConnector.LibraryType libraryManagerType))
|
||||
{
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
break;
|
||||
}
|
||||
DeleteLibraryConnector(libraryConnectoryType);
|
||||
DeleteLibraryConnector(libraryManagerType);
|
||||
SendResponse(HttpStatusCode.Accepted, response);
|
||||
break;
|
||||
default:
|
||||
|
@ -50,7 +50,7 @@ public class TrangaSettings
|
||||
UpdateDownloadLocation(this.downloadLocation!, false);
|
||||
}
|
||||
|
||||
public HashSet<LibraryConnector> LoadLibraryConnectors(GlobalBase clone)
|
||||
public HashSet<LibraryConnector> LoadLibraryConnectors()
|
||||
{
|
||||
if (!File.Exists(libraryConnectorsFilePath))
|
||||
return new HashSet<LibraryConnector>();
|
||||
@ -59,21 +59,21 @@ public class TrangaSettings
|
||||
{
|
||||
Converters =
|
||||
{
|
||||
new LibraryManagerJsonConverter(clone)
|
||||
new LibraryManagerJsonConverter()
|
||||
}
|
||||
})!;
|
||||
}
|
||||
|
||||
public HashSet<NotificationConnector> LoadNotificationConnectors(GlobalBase clone)
|
||||
public HashSet<NotificationConnector> LoadNotificationConnectors()
|
||||
{
|
||||
if (!File.Exists(notificationConnectorsFilePath))
|
||||
return new HashSet<NotificationConnector>();
|
||||
return JsonConvert.DeserializeObject<HashSet<NotificationConnector>>(File.ReadAllText(notificationConnectorsFilePath),
|
||||
return JsonConvert.DeserializeObject<HashSet<NotificationConnector>>(File.ReadAllText(libraryConnectorsFilePath),
|
||||
new JsonSerializerSettings()
|
||||
{
|
||||
Converters =
|
||||
{
|
||||
new NotificationManagerJsonConverter(clone)
|
||||
new NotificationManagerJsonConverter()
|
||||
}
|
||||
})!;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user