Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
dd0733fa54 | |||
290761bfb0 |
@ -22,7 +22,7 @@ jobs:
|
||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3.7.1
|
||||
uses: docker/setup-buildx-action@v3.6.1
|
||||
|
||||
# https://github.com/docker/login-action#docker-hub
|
||||
- name: Login to Docker Hub
|
||||
@ -33,7 +33,7 @@ jobs:
|
||||
|
||||
# https://github.com/docker/build-push-action#multi-platform-image
|
||||
- name: Build and push API
|
||||
uses: docker/build-push-action@v6.9.0
|
||||
uses: docker/build-push-action@v6.7.0
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
|
4
.github/workflows/docker-image-dev.yml
vendored
4
.github/workflows/docker-image-dev.yml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3.7.1
|
||||
uses: docker/setup-buildx-action@v3.6.1
|
||||
|
||||
# https://github.com/docker/login-action#docker-hub
|
||||
- name: Login to Docker Hub
|
||||
@ -33,7 +33,7 @@ jobs:
|
||||
|
||||
# https://github.com/docker/build-push-action#multi-platform-image
|
||||
- name: Build and push API
|
||||
uses: docker/build-push-action@v6.9.0
|
||||
uses: docker/build-push-action@v6.7.0
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
|
4
.github/workflows/docker-image-master.yml
vendored
4
.github/workflows/docker-image-master.yml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3.7.1
|
||||
uses: docker/setup-buildx-action@v3.6.1
|
||||
|
||||
# https://github.com/docker/login-action#docker-hub
|
||||
- name: Login to Docker Hub
|
||||
@ -33,7 +33,7 @@ jobs:
|
||||
|
||||
# https://github.com/docker/build-push-action#multi-platform-image
|
||||
- name: Build and push API
|
||||
uses: docker/build-push-action@v6.9.0
|
||||
uses: docker/build-push-action@v6.7.0
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
|
4
.github/workflows/docker-image-serverv2.yml
vendored
4
.github/workflows/docker-image-serverv2.yml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3.7.1
|
||||
uses: docker/setup-buildx-action@v3.6.1
|
||||
|
||||
# https://github.com/docker/login-action#docker-hub
|
||||
- name: Login to Docker Hub
|
||||
@ -33,7 +33,7 @@ jobs:
|
||||
|
||||
# https://github.com/docker/build-push-action#multi-platform-image
|
||||
- name: Build and push API
|
||||
uses: docker/build-push-action@v6.9.0
|
||||
uses: docker/build-push-action@v6.7.0
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
|
@ -1,7 +1,7 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
ARG DOTNET=8.0
|
||||
|
||||
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/runtime:$DOTNET AS base
|
||||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/runtime:$DOTNET AS base
|
||||
WORKDIR /publish
|
||||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
||||
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
||||
@ -22,7 +22,7 @@ RUN dotnet restore /src/Tranga.sln
|
||||
COPY . /src/
|
||||
RUN dotnet publish -c Release --property:OutputPath=/publish -maxcpucount:1
|
||||
|
||||
FROM --platform=$TARGETPLATFORM base AS runtime
|
||||
FROM --platform=$BUILDPLATFORM base AS runtime
|
||||
EXPOSE 6531
|
||||
ARG UNAME=tranga
|
||||
ARG UID=1000
|
||||
|
26
README.md
26
README.md
@ -51,12 +51,11 @@ Tranga can download Chapters and Metadata from "Scanlation" sites such as
|
||||
- [Bato.to](https://bato.to/v3x) (en)
|
||||
- [Manga4Life](https://manga4life.com) (en)
|
||||
- [ManhuaPlus](https://manhuaplus.org/) (en)
|
||||
- [MangaHere](https://www.mangahere.cc/) (en) (Their covers aren't scrapeable.)
|
||||
- ❓ Open an [issue](https://github.com/C9Glax/tranga/issues/new?assignees=&labels=New+Connector&projects=&template=new_connector.yml&title=%5BNew+Connector%5D%3A+)
|
||||
- [MangaHere](https://www.mangahere.cc/) (en) (Their covers suck)
|
||||
- ❓ Open an [issue](https://github.com/C9Glax/tranga/issues)
|
||||
|
||||
and trigger a library-scan with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/).
|
||||
Notifications can be sent to your devices using [Gotify](https://gotify.net/), [LunaSea](https://www.lunasea.app/) or [Ntfy](https://ntfy.sh/
|
||||
).
|
||||
Notifications can be sent to your devices using [Gotify](https://gotify.net/) and [LunaSea](https://www.lunasea.app/).
|
||||
|
||||
### What this does and doesn't do
|
||||
|
||||
@ -93,16 +92,6 @@ That is why I wanted to create my own project, in a language I understand, and t
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
## Star History
|
||||
|
||||
<a href="https://star-history.com/#c9glax/tranga&Date">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=c9glax/tranga&type=Date&theme=dark" />
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=c9glax/tranga&type=Date" />
|
||||
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=c9glax/tranga&type=Date" />
|
||||
</picture>
|
||||
</a>
|
||||
|
||||
<!-- GETTING STARTED -->
|
||||
## Getting Started
|
||||
|
||||
@ -118,9 +107,14 @@ access the folder.
|
||||
### Prerequisites
|
||||
|
||||
#### To Build
|
||||
[.NET-Core 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
|
||||
[.NET-Core 7.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
|
||||
#### To Run
|
||||
[.NET-Core 8.0 Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) scroll down a bit, should be on the right the second item.
|
||||
[.NET-Core 7.0 Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) scroll down a bit, should be on the right the second item.
|
||||
|
||||
<!-- ROADMAP -->
|
||||
## Roadmap
|
||||
|
||||
- [ ] ❓
|
||||
|
||||
See the [open issues](https://github.com/C9Glax/tranga/issues) for a full list of proposed features (and known issues).
|
||||
|
||||
|
@ -66,10 +66,10 @@ public abstract class GlobalBase
|
||||
Log(string.Format(fStr, replace));
|
||||
}
|
||||
|
||||
protected void SendNotifications(string title, string text, bool buffer = false)
|
||||
protected void SendNotifications(string title, string text)
|
||||
{
|
||||
foreach (NotificationConnector nc in notificationConnectors)
|
||||
nc.SendNotification(title, text, buffer);
|
||||
nc.SendNotification(title, text);
|
||||
}
|
||||
|
||||
protected void AddNotificationConnector(NotificationConnector notificationConnector)
|
||||
|
@ -37,7 +37,7 @@ public class DownloadChapter : Job
|
||||
if (success == HttpStatusCode.OK)
|
||||
{
|
||||
UpdateLibraries();
|
||||
SendNotifications("Chapter downloaded", $"{chapter.parentManga.sortName} - {chapter.chapterNumber}", true);
|
||||
SendNotifications("Chapter downloaded", $"{chapter.parentManga.sortName} - {chapter.chapterNumber}");
|
||||
}
|
||||
});
|
||||
downloadTask.Start();
|
||||
|
@ -61,7 +61,7 @@ public class Kavita : LibraryConnector
|
||||
return "";
|
||||
}
|
||||
|
||||
protected override void UpdateLibraryInternal()
|
||||
public override void UpdateLibrary()
|
||||
{
|
||||
Log("Updating libraries.");
|
||||
foreach (KavitaLibrary lib in GetLibraries())
|
||||
|
@ -25,7 +25,7 @@ public class Komga : LibraryConnector
|
||||
return $"Komga {baseUrl}";
|
||||
}
|
||||
|
||||
protected override void UpdateLibraryInternal()
|
||||
public override void UpdateLibrary()
|
||||
{
|
||||
Log("Updating libraries.");
|
||||
foreach (KomgaLibrary lib in GetLibraries())
|
||||
|
@ -17,9 +17,6 @@ public abstract class LibraryConnector : GlobalBase
|
||||
public string baseUrl { get; }
|
||||
// ReSharper disable once MemberCanBeProtected.Global
|
||||
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
||||
private DateTime? _updateLibraryRequested = null;
|
||||
private readonly Thread? _libraryBufferThread = null;
|
||||
private const int NoChangeTimeout = 2, BiggestInterval = 20;
|
||||
|
||||
protected LibraryConnector(GlobalBase clone, string baseUrl, string auth, LibraryType libraryType) : base(clone)
|
||||
{
|
||||
@ -31,47 +28,8 @@ public abstract class LibraryConnector : GlobalBase
|
||||
this.baseUrl = baseUrlRex.Match(baseUrl).Value;
|
||||
this.auth = auth;
|
||||
this.libraryType = libraryType;
|
||||
|
||||
if (TrangaSettings.bufferLibraryUpdates)
|
||||
{
|
||||
_libraryBufferThread = new(CheckLibraryBuffer);
|
||||
_libraryBufferThread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckLibraryBuffer()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (_updateLibraryRequested is not null && DateTime.Now.Subtract((DateTime)_updateLibraryRequested) > TimeSpan.FromMinutes(NoChangeTimeout)) //If no updates have been requested for NoChangeTimeout minutes, update library
|
||||
{
|
||||
UpdateLibraryInternal();
|
||||
_updateLibraryRequested = null;
|
||||
}
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateLibrary()
|
||||
{
|
||||
_updateLibraryRequested ??= DateTime.Now;
|
||||
if (!TrangaSettings.bufferLibraryUpdates)
|
||||
{
|
||||
UpdateLibraryInternal();
|
||||
return;
|
||||
}else if (_updateLibraryRequested is not null &&
|
||||
DateTime.Now.Subtract((DateTime)_updateLibraryRequested) > TimeSpan.FromMinutes(BiggestInterval)) //If the last update has been more than BiggestInterval minutes ago, update library
|
||||
{
|
||||
UpdateLibraryInternal();
|
||||
_updateLibraryRequested = null;
|
||||
}
|
||||
else if(_updateLibraryRequested is not null)
|
||||
{
|
||||
Log($"Buffering Library Updates (Updates in latest {((DateTime)_updateLibraryRequested).Add(TimeSpan.FromMinutes(BiggestInterval)).Subtract(DateTime.Now)} or {((DateTime)_updateLibraryRequested).Add(TimeSpan.FromMinutes(NoChangeTimeout)).Subtract(DateTime.Now)})");
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void UpdateLibraryInternal();
|
||||
public abstract void UpdateLibrary();
|
||||
internal abstract bool Test();
|
||||
|
||||
protected static class NetClient
|
||||
|
@ -15,7 +15,7 @@ public class MangaKatana : MangaConnector
|
||||
public override Manga[] GetManga(string publicationTitle = "")
|
||||
{
|
||||
Log($"Searching Publications. Term=\"{publicationTitle}\"");
|
||||
string sanitizedTitle = string.Join("%20", Regex.Matches(publicationTitle, "[A-z]*").Where(m => m.Value.Length > 0)).ToLower();
|
||||
string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*").Where(m => m.Value.Length > 0)).ToLower();
|
||||
string requestUrl = $"https://mangakatana.com/?search={sanitizedTitle}&search_by=book_name";
|
||||
RequestResult requestResult =
|
||||
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||
|
@ -24,7 +24,7 @@ public class Gotify : NotificationConnector
|
||||
return $"Gotify {endpoint}";
|
||||
}
|
||||
|
||||
protected override void SendNotificationInternal(string title, string notificationText)
|
||||
public override void SendNotification(string title, string notificationText)
|
||||
{
|
||||
Log($"Sending notification: {title} - {notificationText}");
|
||||
MessageData message = new(title, notificationText);
|
||||
|
@ -20,7 +20,7 @@ public class LunaSea : NotificationConnector
|
||||
return $"LunaSea {id}";
|
||||
}
|
||||
|
||||
protected override void SendNotificationInternal(string title, string notificationText)
|
||||
public override void SendNotification(string title, string notificationText)
|
||||
{
|
||||
Log($"Sending notification: {title} - {notificationText}");
|
||||
MessageData message = new(title, notificationText);
|
||||
|
@ -3,72 +3,14 @@
|
||||
public abstract class NotificationConnector : GlobalBase
|
||||
{
|
||||
public readonly NotificationConnectorType notificationConnectorType;
|
||||
private DateTime? _notificationRequested = null;
|
||||
private readonly Thread? _notificationBufferThread = null;
|
||||
private const int NoChangeTimeout = 3, BiggestInterval = 30;
|
||||
private List<KeyValuePair<string, string>> _notifications = new();
|
||||
|
||||
protected NotificationConnector(GlobalBase clone, NotificationConnectorType notificationConnectorType) : base(clone)
|
||||
{
|
||||
Log($"Creating notificationConnector {Enum.GetName(notificationConnectorType)}");
|
||||
this.notificationConnectorType = notificationConnectorType;
|
||||
|
||||
|
||||
if (TrangaSettings.bufferLibraryUpdates)
|
||||
{
|
||||
_notificationBufferThread = new(CheckNotificationBuffer);
|
||||
_notificationBufferThread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckNotificationBuffer()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (_notificationRequested is not null && DateTime.Now.Subtract((DateTime)_notificationRequested) > TimeSpan.FromMinutes(NoChangeTimeout)) //If no updates have been requested for NoChangeTimeout minutes, update library
|
||||
{
|
||||
string[] uniqueTitles = _notifications.DistinctBy(n => n.Key).Select(n => n.Key).ToArray();
|
||||
Log($"Notification Buffer sending! Notifications: {string.Join(", ", uniqueTitles)}");
|
||||
foreach (string ut in uniqueTitles)
|
||||
{
|
||||
string[] texts = _notifications.Where(n => n.Key == ut).Select(n => n.Value).ToArray();
|
||||
SendNotificationInternal($"{ut} ({texts.Length})", string.Join('\n', texts));
|
||||
}
|
||||
_notificationRequested = null;
|
||||
_notifications.Clear();
|
||||
}
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
public enum NotificationConnectorType : byte { Gotify = 0, LunaSea = 1, Ntfy = 2 }
|
||||
|
||||
public void SendNotification(string title, string notificationText, bool buffer = false)
|
||||
{
|
||||
_notificationRequested ??= DateTime.Now;
|
||||
if (!TrangaSettings.bufferNotifications || !buffer)
|
||||
{
|
||||
SendNotificationInternal(title, notificationText);
|
||||
return;
|
||||
}
|
||||
_notifications.Add(new(title, notificationText));
|
||||
if (_notificationRequested is not null &&
|
||||
DateTime.Now.Subtract((DateTime)_notificationRequested) > TimeSpan.FromMinutes(BiggestInterval)) //If the last update has been more than BiggestInterval minutes ago, update library
|
||||
{
|
||||
string[] uniqueTitles = _notifications.DistinctBy(n => n.Key).Select(n => n.Key).ToArray();
|
||||
foreach (string ut in uniqueTitles)
|
||||
{
|
||||
string[] texts = _notifications.Where(n => n.Key == ut).Select(n => n.Value).ToArray();
|
||||
SendNotificationInternal(ut, string.Join('\n', texts));
|
||||
}
|
||||
_notificationRequested = null;
|
||||
_notifications.Clear();
|
||||
}
|
||||
else if(_notificationRequested is not null)
|
||||
{
|
||||
Log($"Buffering Notifications (Updates in latest {((DateTime)_notificationRequested).Add(TimeSpan.FromMinutes(BiggestInterval)).Subtract(DateTime.Now)} or {((DateTime)_notificationRequested).Add(TimeSpan.FromMinutes(NoChangeTimeout)).Subtract(DateTime.Now)})");
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void SendNotificationInternal(string title, string notificationText);
|
||||
public abstract void SendNotification(string title, string notificationText);
|
||||
}
|
@ -54,7 +54,7 @@ public class Ntfy : NotificationConnector
|
||||
return $"Ntfy {endpoint} {topic}";
|
||||
}
|
||||
|
||||
protected override void SendNotificationInternal(string title, string notificationText)
|
||||
public override void SendNotification(string title, string notificationText)
|
||||
{
|
||||
Log($"Sending notification: {title} - {notificationText}");
|
||||
MessageData message = new(title, topic, notificationText);
|
||||
|
@ -34,7 +34,6 @@ public partial class Tranga : GlobalBase
|
||||
this._server = new Server(this);
|
||||
string[] emojis = { "(•‿•)", "(づ \u25d5‿\u25d5 )づ", "( \u02d8\u25bd\u02d8)っ\u2668", "=\uff3e\u25cf \u22cf \u25cf\uff3e=", "(ΦωΦ)", "(\u272a\u3268\u272a)", "( ノ・o・ )ノ", "(〜^\u2207^ )〜", "~(\u2267ω\u2266)~","૮ \u00b4• ﻌ \u00b4• ა", "(\u02c3ᆺ\u02c2)", "(=\ud83d\udf66 \u0f1d \ud83d\udf66=)"};
|
||||
SendNotifications("Tranga Started", emojis[Random.Shared.Next(0,emojis.Length-1)]);
|
||||
Log(TrangaSettings.AsJObject().ToString());
|
||||
}
|
||||
|
||||
public MangaConnector? GetConnector(string name)
|
||||
|
@ -15,8 +15,6 @@ public static class TrangaSettings
|
||||
public static string workingDirectory { get; private set; } = Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
|
||||
public static int apiPortNumber { get; private set; } = 6531;
|
||||
public static string userAgent { get; private set; } = DefaultUserAgent;
|
||||
public static bool bufferLibraryUpdates { get; private set; } = false;
|
||||
public static bool bufferNotifications { get; private set; } = false;
|
||||
[JsonIgnore] public static string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
||||
[JsonIgnore] public static string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
|
||||
[JsonIgnore] public static string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
|
||||
@ -48,17 +46,15 @@ public static class TrangaSettings
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void CreateOrUpdate(string? downloadDirectory = null, string? pWorkingDirectory = null, int? pApiPortNumber = null, string? pUserAgent = null, bool? pAprilFoolsMode = null, bool? pBufferLibraryUpdates = null, bool? pBufferNotifications = null)
|
||||
public static void CreateOrUpdate(string? downloadDirectory = null, string? pWorkingDirectory = null, int? pApiPortNumber = null, string? pUserAgent = null, bool? pAprilFoolsMode = null)
|
||||
{
|
||||
if(pWorkingDirectory is null && File.Exists(settingsFilePath))
|
||||
LoadFromWorkingDirectory(workingDirectory);
|
||||
downloadLocation = downloadDirectory ?? downloadLocation;
|
||||
workingDirectory = pWorkingDirectory ?? workingDirectory;
|
||||
apiPortNumber = pApiPortNumber ?? apiPortNumber;
|
||||
userAgent = pUserAgent ?? userAgent;
|
||||
aprilFoolsMode = pAprilFoolsMode ?? aprilFoolsMode;
|
||||
bufferLibraryUpdates = pBufferLibraryUpdates ?? bufferLibraryUpdates;
|
||||
bufferNotifications = pBufferNotifications ?? bufferNotifications;
|
||||
TrangaSettings.downloadLocation = downloadDirectory ?? TrangaSettings.downloadLocation;
|
||||
TrangaSettings.workingDirectory = pWorkingDirectory ?? TrangaSettings.workingDirectory;
|
||||
TrangaSettings.apiPortNumber = pApiPortNumber ?? TrangaSettings.apiPortNumber;
|
||||
TrangaSettings.userAgent = pUserAgent ?? TrangaSettings.userAgent;
|
||||
TrangaSettings.aprilFoolsMode = pAprilFoolsMode ?? TrangaSettings.aprilFoolsMode;
|
||||
Directory.CreateDirectory(downloadLocation);
|
||||
Directory.CreateDirectory(workingDirectory);
|
||||
ExportSettings();
|
||||
@ -94,7 +90,7 @@ public static class TrangaSettings
|
||||
|
||||
public static void UpdateAprilFoolsMode(bool enabled)
|
||||
{
|
||||
aprilFoolsMode = enabled;
|
||||
TrangaSettings.aprilFoolsMode = enabled;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
@ -106,10 +102,10 @@ public static class TrangaSettings
|
||||
else
|
||||
Directory.CreateDirectory(newPath);
|
||||
|
||||
if (moveFiles && Directory.Exists(downloadLocation))
|
||||
Directory.Move(downloadLocation, newPath);
|
||||
if (moveFiles && Directory.Exists(TrangaSettings.downloadLocation))
|
||||
Directory.Move(TrangaSettings.downloadLocation, newPath);
|
||||
|
||||
downloadLocation = newPath;
|
||||
TrangaSettings.downloadLocation = newPath;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
@ -120,26 +116,26 @@ public static class TrangaSettings
|
||||
GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||
else
|
||||
Directory.CreateDirectory(newPath);
|
||||
Directory.Move(workingDirectory, newPath);
|
||||
workingDirectory = newPath;
|
||||
Directory.Move(TrangaSettings.workingDirectory, newPath);
|
||||
TrangaSettings.workingDirectory = newPath;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void UpdateUserAgent(string? customUserAgent)
|
||||
{
|
||||
userAgent = customUserAgent ?? DefaultUserAgent;
|
||||
TrangaSettings.userAgent = customUserAgent ?? DefaultUserAgent;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void UpdateRateLimit(RequestType requestType, int newLimit)
|
||||
{
|
||||
requestLimits[requestType] = newLimit;
|
||||
TrangaSettings.requestLimits[requestType] = newLimit;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void ResetRateLimits()
|
||||
{
|
||||
requestLimits = DefaultRequestLimits;
|
||||
TrangaSettings.requestLimits = DefaultRequestLimits;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
@ -158,15 +154,13 @@ public static class TrangaSettings
|
||||
public static JObject AsJObject()
|
||||
{
|
||||
JObject jobj = new JObject();
|
||||
jobj.Add("downloadLocation", JToken.FromObject(downloadLocation));
|
||||
jobj.Add("workingDirectory", JToken.FromObject(workingDirectory));
|
||||
jobj.Add("apiPortNumber", JToken.FromObject(apiPortNumber));
|
||||
jobj.Add("userAgent", JToken.FromObject(userAgent));
|
||||
jobj.Add("aprilFoolsMode", JToken.FromObject(aprilFoolsMode));
|
||||
jobj.Add("version", JToken.FromObject(version));
|
||||
jobj.Add("requestLimits", JToken.FromObject(requestLimits));
|
||||
jobj.Add("bufferLibraryUpdates", JToken.FromObject(bufferLibraryUpdates));
|
||||
jobj.Add("bufferNotifications", JToken.FromObject(bufferNotifications));
|
||||
jobj.Add("downloadLocation", JToken.FromObject(TrangaSettings.downloadLocation));
|
||||
jobj.Add("workingDirectory", JToken.FromObject(TrangaSettings.workingDirectory));
|
||||
jobj.Add("apiPortNumber", JToken.FromObject(TrangaSettings.apiPortNumber));
|
||||
jobj.Add("userAgent", JToken.FromObject(TrangaSettings.userAgent));
|
||||
jobj.Add("aprilFoolsMode", JToken.FromObject(TrangaSettings.aprilFoolsMode));
|
||||
jobj.Add("version", JToken.FromObject(TrangaSettings.version));
|
||||
jobj.Add("requestLimits", JToken.FromObject(TrangaSettings.requestLimits));
|
||||
return jobj;
|
||||
}
|
||||
|
||||
@ -176,20 +170,16 @@ public static class TrangaSettings
|
||||
{
|
||||
JObject jobj = JObject.Parse(serialized);
|
||||
if (jobj.TryGetValue("downloadLocation", out JToken? dl))
|
||||
downloadLocation = dl.Value<string>()!;
|
||||
TrangaSettings.downloadLocation = dl.Value<string>()!;
|
||||
if (jobj.TryGetValue("workingDirectory", out JToken? wd))
|
||||
workingDirectory = wd.Value<string>()!;
|
||||
TrangaSettings.workingDirectory = wd.Value<string>()!;
|
||||
if (jobj.TryGetValue("apiPortNumber", out JToken? apn))
|
||||
apiPortNumber = apn.Value<int>();
|
||||
TrangaSettings.apiPortNumber = apn.Value<int>();
|
||||
if (jobj.TryGetValue("userAgent", out JToken? ua))
|
||||
userAgent = ua.Value<string>()!;
|
||||
TrangaSettings.userAgent = ua.Value<string>()!;
|
||||
if (jobj.TryGetValue("aprilFoolsMode", out JToken? afm))
|
||||
aprilFoolsMode = afm.Value<bool>()!;
|
||||
TrangaSettings.aprilFoolsMode = afm.Value<bool>()!;
|
||||
if (jobj.TryGetValue("requestLimits", out JToken? rl))
|
||||
requestLimits = rl.ToObject<Dictionary<RequestType, int>>()!;
|
||||
if (jobj.TryGetValue("bufferLibraryUpdates", out JToken? blu))
|
||||
bufferLibraryUpdates = blu.Value<bool>()!;
|
||||
if (jobj.TryGetValue("bufferNotifications", out JToken? bn))
|
||||
bufferNotifications = bn.Value<bool>()!;
|
||||
TrangaSettings.requestLimits = rl.ToObject<Dictionary<RequestType, int>>()!;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user