mirror of
https://github.com/C9Glax/tranga.git
synced 2025-10-11 05:09:49 +02:00
Add Controller
This commit is contained in:
22
API/Controllers/Requests/PatchLibraryRefreshRecord.cs
Normal file
22
API/Controllers/Requests/PatchLibraryRefreshRecord.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Workers;
|
||||
|
||||
namespace API.Controllers.Requests;
|
||||
|
||||
public record PatchLibraryRefreshRecord
|
||||
{
|
||||
/// <summary>
|
||||
/// When to refresh the Library
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("When to refresh the Library")]
|
||||
public required LibraryRefreshSetting Setting { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// When <see cref="LibraryRefreshSetting.WhileDownloading"/> is selected, update the time between refreshes
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("When WhileDownloadingis selected, update the time between refreshes")]
|
||||
public required int? RefreshLibraryWhileDownloadingEveryMinutes { get; init; }
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using API.MangaDownloadClients;
|
||||
using API.Controllers.Requests;
|
||||
using API.MangaDownloadClients;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -290,4 +291,19 @@ public class SettingsController() : Controller
|
||||
Tranga.Settings.SetDownloadLanguage(Language);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sets the time when Libraries are refreshed
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpPatch("LibraryRefresh")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
public Ok SetLibraryRefresh([FromBody]PatchLibraryRefreshRecord requestData)
|
||||
{
|
||||
Tranga.Settings.SetLibraryRefreshSetting(requestData.Setting);
|
||||
if(requestData.RefreshLibraryWhileDownloadingEveryMinutes is { } value)
|
||||
Tranga.Settings.SetRefreshLibraryWhileDownloadingEveryMinutes(value);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
}
|
@@ -2,6 +2,8 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using log4net;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace API.Schema.LibraryContext.LibraryConnectors;
|
||||
|
||||
@@ -40,8 +42,16 @@ public abstract class LibraryConnector : Identifiable
|
||||
internal abstract Task<bool> Test(CancellationToken ct);
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum LibraryType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// <seealso cref="Komga"/>
|
||||
/// </summary>
|
||||
Komga = 0,
|
||||
|
||||
/// <summary>
|
||||
/// <seealso cref="Kavita"/>
|
||||
/// </summary>
|
||||
Kavita = 1
|
||||
}
|
@@ -1,13 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using API.Workers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.ImageSharp.Processing.Processors.Transforms;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using static System.IO.UnixFileMode;
|
||||
|
||||
namespace API.Schema.MangaContext;
|
||||
@@ -138,6 +135,7 @@ public class Manga : Identifiable
|
||||
public override string ToString() => $"{base.ToString()} {Name}";
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum MangaReleaseStatus : byte
|
||||
{
|
||||
Continuing = 0,
|
||||
|
@@ -1,5 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace API.Schema.NotificationsContext;
|
||||
|
||||
@@ -48,6 +50,7 @@ public class Notification : Identifiable
|
||||
public override string ToString() => $"{base.ToString()} {Urgency} {Title} {Message}";
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum NotificationUrgency : byte
|
||||
{
|
||||
Low = 1,
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using API.MangaDownloadClients;
|
||||
using API.Workers;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace API;
|
||||
|
||||
@@ -63,12 +64,12 @@ public struct TrangaSettings()
|
||||
{
|
||||
if (!File.Exists(SettingsFilePath))
|
||||
new TrangaSettings().Save();
|
||||
return JsonConvert.DeserializeObject<TrangaSettings>(File.ReadAllText(SettingsFilePath));
|
||||
return JsonConvert.DeserializeObject<TrangaSettings>(File.ReadAllText(SettingsFilePath), new StringEnumConverter());
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
File.WriteAllText(SettingsFilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||
File.WriteAllText(SettingsFilePath, JsonConvert.SerializeObject(this, Formatting.Indented, new StringEnumConverter()));
|
||||
}
|
||||
|
||||
public void SetUserAgent(string value)
|
||||
|
@@ -1,5 +1,7 @@
|
||||
using API.Schema;
|
||||
using log4net;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
@@ -116,6 +118,7 @@ public abstract class BaseWorker : Identifiable
|
||||
}
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum WorkerExecutionState
|
||||
{
|
||||
Failed = 0,
|
||||
|
@@ -1,6 +1,8 @@
|
||||
using API.Schema.LibraryContext;
|
||||
using API.Schema.LibraryContext.LibraryConnectors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
@@ -20,10 +22,23 @@ public class RefreshLibrariesWorker(IEnumerable<BaseWorker>? dependsOn = null) :
|
||||
}
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum LibraryRefreshSetting : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Refresh Libraries after all Manga are downloaded
|
||||
/// </summary>
|
||||
AfterAllFinished = 0,
|
||||
/// <summary>
|
||||
/// Refresh Libraries after a Manga is downloaded
|
||||
/// </summary>
|
||||
AfterMangaFinished = 1,
|
||||
/// <summary>
|
||||
/// Refresh Libraries after every download
|
||||
/// </summary>
|
||||
AfterEveryChapter = 2,
|
||||
/// <summary>
|
||||
/// Refresh Libraries while downloading chapters, every x minutes
|
||||
/// </summary>
|
||||
WhileDownloading = 3
|
||||
}
|
Reference in New Issue
Block a user