mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-11 12:28:18 +02:00
Add API
This commit is contained in:
29
API/Schema/Jobs/JobJsonDeserializer.cs
Normal file
29
API/Schema/Jobs/JobJsonDeserializer.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using JsonSerializer = Newtonsoft.Json.JsonSerializer;
|
||||
|
||||
namespace API.Schema.Jobs;
|
||||
|
||||
public class JobJsonDeserializer : JsonConverter<Job>
|
||||
{
|
||||
public override bool CanWrite { get; } = false;
|
||||
|
||||
public override void WriteJson(JsonWriter writer, Job? value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Job? ReadJson(JsonReader reader, Type objectType, Job? existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
JObject j = JObject.Load(reader);
|
||||
JobType? type = Enum.Parse<JobType>(j.GetValue("jobType")!.Value<string>()!);
|
||||
return type switch
|
||||
{
|
||||
JobType.DownloadSingleChapterJob => j.ToObject<DownloadSingleChapterJob>(),
|
||||
JobType.DownloadNewChaptersJob => j.ToObject<DownloadNewChaptersJob>(),
|
||||
JobType.UpdateMetaDataJob => j.ToObject<UpdateMetadataJob>(),
|
||||
JobType.MoveFileOrFolderJob => j.ToObject<MoveFileOrFolderJob>(),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user