Add Controller

This commit is contained in:
2025-09-21 16:59:12 +02:00
parent 4e3968f4b1
commit 55a8b09310
8 changed files with 76 additions and 8 deletions

View 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; }
}

View File

@@ -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();
}
}

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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)

View File

@@ -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,

View File

@@ -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
}