Compare commits

..

3 Commits

5 changed files with 11 additions and 5 deletions

View File

@ -1,4 +1,5 @@
using System.Globalization; using System.Globalization;
using System.Text.RegularExpressions;
using Logging; using Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Tranga.LibraryConnectors; using Tranga.LibraryConnectors;
@ -14,6 +15,7 @@ public abstract class GlobalBase
protected HashSet<LibraryConnector> libraryConnectors { get; init; } protected HashSet<LibraryConnector> libraryConnectors { get; init; }
protected List<Manga> cachedPublications { get; init; } protected List<Manga> cachedPublications { get; init; }
protected static readonly NumberFormatInfo numberFormatDecimalPoint = new (){ NumberDecimalSeparator = "." }; protected static readonly NumberFormatInfo numberFormatDecimalPoint = new (){ NumberDecimalSeparator = "." };
protected static readonly Regex baseUrlRex = new(@"https?:\/\/[0-9A-z\.]*");
protected GlobalBase(GlobalBase clone) protected GlobalBase(GlobalBase clone)
{ {

View File

@ -165,12 +165,12 @@ public class JobBoss : GlobalBase
public void ExportJob(Job job) public void ExportJob(Job job)
{ {
string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json"); string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json");
Log($"Exporting Job {jobFilePath}");
if (!this.jobs.Any(jjob => jjob.id == job.id)) if (!this.jobs.Any(jjob => jjob.id == job.id))
{ {
try try
{ {
Log($"Deleting Job-file {jobFilePath}");
while(IsFileInUse(jobFilePath)) while(IsFileInUse(jobFilePath))
Thread.Sleep(10); Thread.Sleep(10);
File.Delete(jobFilePath); File.Delete(jobFilePath);
@ -182,6 +182,7 @@ public class JobBoss : GlobalBase
} }
else else
{ {
Log($"Exporting Job {jobFilePath}");
string jobStr = JsonConvert.SerializeObject(job); string jobStr = JsonConvert.SerializeObject(job);
while(IsFileInUse(jobFilePath)) while(IsFileInUse(jobFilePath))
Thread.Sleep(10); Thread.Sleep(10);

View File

@ -21,10 +21,10 @@ public abstract class LibraryConnector : GlobalBase
protected LibraryConnector(GlobalBase clone, string baseUrl, string auth, LibraryType libraryType) : base(clone) protected LibraryConnector(GlobalBase clone, string baseUrl, string auth, LibraryType libraryType) : base(clone)
{ {
Regex urlRex = new(@"https?:\/\/[0-9A-z\.]*"); Log($"Creating libraryConnector {Enum.GetName(libraryType)}");
if (!urlRex.IsMatch(baseUrl)) if (!baseUrlRex.IsMatch(baseUrl))
throw new ArgumentException("Base url does not match pattern"); throw new ArgumentException("Base url does not match pattern");
this.baseUrl = urlRex.Match(baseUrl).Value; this.baseUrl = baseUrlRex.Match(baseUrl).Value;
this.auth = auth; this.auth = auth;
this.libraryType = libraryType; this.libraryType = libraryType;
} }

View File

@ -13,7 +13,9 @@ public class Gotify : NotificationConnector
[JsonConstructor] [JsonConstructor]
public Gotify(GlobalBase clone, string endpoint, string appToken) : base(clone, NotificationConnectorType.Gotify) public Gotify(GlobalBase clone, string endpoint, string appToken) : base(clone, NotificationConnectorType.Gotify)
{ {
this.endpoint = endpoint; if (!baseUrlRex.IsMatch(endpoint))
throw new ArgumentException("endpoint does not match pattern");
this.endpoint = baseUrlRex.Match(endpoint).Value;;
this.appToken = appToken; this.appToken = appToken;
} }

View File

@ -6,6 +6,7 @@ public abstract class NotificationConnector : GlobalBase
protected NotificationConnector(GlobalBase clone, NotificationConnectorType notificationConnectorType) : base(clone) protected NotificationConnector(GlobalBase clone, NotificationConnectorType notificationConnectorType) : base(clone)
{ {
Log($"Creating notificationConnector {Enum.GetName(notificationConnectorType)}");
this.notificationConnectorType = notificationConnectorType; this.notificationConnectorType = notificationConnectorType;
} }