mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 15:50:13 +01:00
Rename TBaseObject -> GlobalBase
Remove Notification and Library Connectors from GlobalBase
This commit is contained in:
parent
c45e4ddf90
commit
e4086a8892
48
Tranga/GlobalBase.cs
Normal file
48
Tranga/GlobalBase.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using Logging;
|
||||||
|
|
||||||
|
namespace Tranga;
|
||||||
|
|
||||||
|
public class GlobalBase
|
||||||
|
{
|
||||||
|
protected Logger? logger { get; init; }
|
||||||
|
protected TrangaSettings settings { get; init; }
|
||||||
|
|
||||||
|
public GlobalBase(GlobalBase clone)
|
||||||
|
{
|
||||||
|
this.logger = clone.logger;
|
||||||
|
this.settings = clone.settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalBase(Logger? logger, TrangaSettings settings)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void Log(string message)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().Name, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void Log(string fStr, params object?[] replace)
|
||||||
|
{
|
||||||
|
Log(string.Format(fStr, replace));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected bool IsFileInUse(string filePath)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
return false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using FileStream stream = new (filePath, FileMode.Open, FileAccess.Read, FileShare.None);
|
||||||
|
stream.Close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (IOException)
|
||||||
|
{
|
||||||
|
Log($"File is in use {filePath}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,13 +7,13 @@ namespace Tranga.LibraryConnectors;
|
|||||||
public class Kavita : LibraryConnector
|
public class Kavita : LibraryConnector
|
||||||
{
|
{
|
||||||
|
|
||||||
public Kavita(string baseUrl, string username, string password, TBaseObject clone) :
|
public Kavita(string baseUrl, string username, string password, GlobalBase clone) :
|
||||||
base(baseUrl, GetToken(baseUrl, username, password), LibraryType.Kavita, clone)
|
base(baseUrl, GetToken(baseUrl, username, password), LibraryType.Kavita, clone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public Kavita(string baseUrl, string auth, TBaseObject clone) : base(baseUrl, auth, LibraryType.Kavita, clone)
|
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(string baseUrl, string username, string password, TBaseObject clone)
|
public Komga(string baseUrl, string username, string password, GlobalBase clone)
|
||||||
: base(baseUrl, Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")), LibraryType.Komga, clone)
|
: base(baseUrl, Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")), LibraryType.Komga, clone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public Komga(string baseUrl, string auth, TBaseObject clone) : base(baseUrl, auth, LibraryType.Komga, clone)
|
public Komga(string baseUrl, string auth, GlobalBase clone) : base(baseUrl, auth, LibraryType.Komga, clone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ using Logging;
|
|||||||
|
|
||||||
namespace Tranga.LibraryConnectors;
|
namespace Tranga.LibraryConnectors;
|
||||||
|
|
||||||
public abstract class LibraryConnector : TBaseObject
|
public abstract class LibraryConnector : GlobalBase
|
||||||
{
|
{
|
||||||
public enum LibraryType : byte
|
public enum LibraryType : byte
|
||||||
{
|
{
|
||||||
@ -18,7 +18,7 @@ public abstract class LibraryConnector : TBaseObject
|
|||||||
// 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(string baseUrl, string auth, LibraryType libraryType, TBaseObject clone) : 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,11 +11,11 @@ namespace Tranga.MangaConnectors;
|
|||||||
/// Base-Class for all Connectors
|
/// Base-Class for all Connectors
|
||||||
/// Provides some methods to be used by all Connectors, as well as a DownloadClient
|
/// Provides some methods to be used by all Connectors, as well as a DownloadClient
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class Connector : TBaseObject
|
public abstract class Connector : GlobalBase
|
||||||
{
|
{
|
||||||
internal DownloadClient downloadClient { get; init; } = null!;
|
internal DownloadClient downloadClient { get; init; } = null!;
|
||||||
|
|
||||||
protected Connector(TBaseObject clone) : base(clone)
|
protected Connector(GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(settings.coverImageCache))
|
if (!Directory.Exists(settings.coverImageCache))
|
||||||
Directory.CreateDirectory(settings.coverImageCache);
|
Directory.CreateDirectory(settings.coverImageCache);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Tranga.MangaConnectors;
|
namespace Tranga.MangaConnectors;
|
||||||
|
|
||||||
internal class DownloadClient : TBaseObject
|
internal class DownloadClient : GlobalBase
|
||||||
{
|
{
|
||||||
private static readonly HttpClient Client = new()
|
private static readonly HttpClient Client = new()
|
||||||
{
|
{
|
||||||
@ -12,7 +12,7 @@ internal class DownloadClient : TBaseObject
|
|||||||
private readonly Dictionary<byte, DateTime> _lastExecutedRateLimit;
|
private readonly Dictionary<byte, DateTime> _lastExecutedRateLimit;
|
||||||
private readonly Dictionary<byte, TimeSpan> _rateLimit;
|
private readonly Dictionary<byte, TimeSpan> _rateLimit;
|
||||||
|
|
||||||
public DownloadClient(Dictionary<byte, int> rateLimitRequestsPerMinute, TBaseObject clone) : base(clone)
|
public DownloadClient(Dictionary<byte, int> rateLimitRequestsPerMinute, GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
_lastExecutedRateLimit = new();
|
_lastExecutedRateLimit = new();
|
||||||
_rateLimit = new();
|
_rateLimit = new();
|
||||||
|
@ -17,7 +17,7 @@ public class MangaDex : Connector
|
|||||||
Author,
|
Author,
|
||||||
}
|
}
|
||||||
|
|
||||||
public MangaDex(TBaseObject clone) : base(clone)
|
public MangaDex(GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
name = "MangaDex";
|
name = "MangaDex";
|
||||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||||
|
@ -9,7 +9,7 @@ public class MangaKatana : Connector
|
|||||||
{
|
{
|
||||||
public override string name { get; }
|
public override string name { get; }
|
||||||
|
|
||||||
public MangaKatana(TBaseObject clone) : base(clone)
|
public MangaKatana(GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
this.name = "MangaKatana";
|
this.name = "MangaKatana";
|
||||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||||
|
@ -9,7 +9,7 @@ public class Manganato : Connector
|
|||||||
{
|
{
|
||||||
public override string name { get; }
|
public override string name { get; }
|
||||||
|
|
||||||
public Manganato(TBaseObject clone) : base(clone)
|
public Manganato(GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
this.name = "Manganato";
|
this.name = "Manganato";
|
||||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||||
|
@ -14,7 +14,7 @@ public class Mangasee : Connector
|
|||||||
private IBrowser? _browser;
|
private IBrowser? _browser;
|
||||||
private const string ChromiumVersion = "1154303";
|
private const string ChromiumVersion = "1154303";
|
||||||
|
|
||||||
public Mangasee(TBaseObject clone) : base(clone)
|
public Mangasee(GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
this.name = "Mangasee";
|
this.name = "Mangasee";
|
||||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||||
|
@ -11,7 +11,7 @@ public class Gotify : NotificationConnector
|
|||||||
private readonly HttpClient _client = new();
|
private readonly HttpClient _client = new();
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public Gotify(string endpoint, string appToken, TBaseObject clone) : base(NotificationManagerType.Gotify, clone)
|
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(string id, TBaseObject clone) : base(NotificationManagerType.LunaSea, clone)
|
public LunaSea(string id, GlobalBase clone) : base(NotificationManagerType.LunaSea, clone)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
namespace Tranga.NotificationConnectors;
|
namespace Tranga.NotificationConnectors;
|
||||||
|
|
||||||
public abstract class NotificationConnector : TBaseObject
|
public abstract class NotificationConnector : GlobalBase
|
||||||
{
|
{
|
||||||
public NotificationManagerType notificationManagerType;
|
public NotificationManagerType notificationManagerType;
|
||||||
|
|
||||||
protected NotificationConnector(NotificationManagerType notificationManagerType, TBaseObject clone) : base(clone)
|
protected NotificationConnector(NotificationManagerType notificationManagerType, GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
this.notificationManagerType = notificationManagerType;
|
this.notificationManagerType = notificationManagerType;
|
||||||
}
|
}
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
using Logging;
|
|
||||||
using Tranga.LibraryConnectors;
|
|
||||||
using Tranga.NotificationConnectors;
|
|
||||||
|
|
||||||
namespace Tranga;
|
|
||||||
|
|
||||||
public class TBaseObject
|
|
||||||
{
|
|
||||||
protected Logger? logger { get; init; }
|
|
||||||
protected TrangaSettings settings { get; init; }
|
|
||||||
protected HashSet<NotificationConnector> notificationConnectors { get; init; }
|
|
||||||
protected HashSet<LibraryConnector> libraryConnectors { get; init; }
|
|
||||||
|
|
||||||
public TBaseObject(TBaseObject clone)
|
|
||||||
{
|
|
||||||
this.logger = clone.logger;
|
|
||||||
this.settings = clone.settings;
|
|
||||||
this.notificationConnectors = clone.notificationConnectors;
|
|
||||||
this.libraryConnectors = clone.libraryConnectors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TBaseObject(Logger? logger, TrangaSettings settings, HashSet<NotificationConnector> notificationConnectors, HashSet<LibraryConnector> libraryConnectors)
|
|
||||||
{
|
|
||||||
this.logger = logger;
|
|
||||||
this.settings = settings;
|
|
||||||
this.notificationConnectors = notificationConnectors;
|
|
||||||
this.libraryConnectors = libraryConnectors;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Log(string message)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().Name, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Log(string fStr, params object?[] replace)
|
|
||||||
{
|
|
||||||
Log(string.Format(fStr, replace));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected bool IsFileInUse(string filePath)
|
|
||||||
{
|
|
||||||
if (!File.Exists(filePath))
|
|
||||||
return false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using FileStream stream = new (filePath, FileMode.Open, FileAccess.Read, FileShare.None);
|
|
||||||
stream.Close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (IOException)
|
|
||||||
{
|
|
||||||
Log($"File is in use {filePath}");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void SendNotification(string title, string message)
|
|
||||||
{
|
|
||||||
foreach(NotificationConnector nc in notificationConnectors)
|
|
||||||
nc.SendNotification(title, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void UpdateLibraries()
|
|
||||||
{
|
|
||||||
foreach (LibraryConnector libraryConnector in libraryConnectors)
|
|
||||||
libraryConnector.UpdateLibrary();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user