mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-13 14:57:53 +02:00
Changed the Creation Job API to a single Endpoint /v2/Job/Create/<Type>
Added and implemented GET /v2/Job/Types Implemented /v2/Job/<jobId> Implemented /v2/Job/<jobId>/StartNow Implemented /v2/Job/<jobId>/Cancel Implemented /v2/Job/<jobId>/SetInterval
This commit is contained in:
@ -13,7 +13,7 @@ public abstract class Job : GlobalBase
|
||||
public string id => GetId();
|
||||
internal IEnumerable<Job>? subJobs { get; private set; }
|
||||
public string? parentJobId { get; init; }
|
||||
public enum JobType : byte { DownloadChapterJob, DownloadNewChaptersJob, UpdateMetaDataJob }
|
||||
public enum JobType : byte { DownloadChapterJob, DownloadNewChaptersJob, UpdateMetaDataJob, MonitorManga }
|
||||
|
||||
public JobType jobType;
|
||||
|
||||
|
@ -31,10 +31,8 @@ public partial class Server : GlobalBase, IDisposable
|
||||
new ("GET", @"/v2/Jobs/Running", GetV2JobsRunning),
|
||||
new ("GET", @"/v2/Jobs/Waiting", GetV2JobsWaiting),
|
||||
new ("GET", @"/v2/Jobs/Monitoring", GetV2JobsMonitoring),
|
||||
new ("POST", @"/v2/Jobs/Create/Monitor/(^[-A-Za-z0-9+/]*={0,3}$)", PostV2JobsCreateMonitorInternalId),
|
||||
new ("POST", @"/v2/Jobs/Create/DownloadNewChapters/(^[-A-Za-z0-9+/]*={0,3}$)", PostV2JobsCreateDownloadNewChaptersInternalId),
|
||||
new ("POST", @"/v2/Jobs/Create/UpdateMetadata", PostV2JobsCreateUpdateMetadata),
|
||||
new ("POST", @"/v2/Jobs/Create/UpdateMetadata/(^[-A-Za-z0-9+/]*={0,3}$)", PostV2JobsCreateUpdateMetadataInternalId),
|
||||
new ("Get", @"/v2/Job/Types", GetV2JobTypes),
|
||||
new ("POST", @"/v2/Job/Create/([a-zA-Z]+)>", PostV2JobsCreateType),
|
||||
new ("GET", @"/v2/Job/([a-zA-Z\.]+-[-A-Za-z0-9+/]*={0,3}(?:-[0-9]+)?)", GetV2JobJobId),
|
||||
new ("DELETE", @"/v2/Job/([a-zA-Z\.]+-[-A-Za-z0-9+/]*={0,3}(?:-[0-9]+)?)", DeleteV2JobJobId),
|
||||
new ("GET", @"/v2/Job/([a-zA-Z\.]+-[-A-Za-z0-9+/]*={0,3}(?:-[0-9]+)?)/Progress", GetV2JobJobIdProgress),
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using Tranga.Jobs;
|
||||
using Tranga.MangaConnectors;
|
||||
|
||||
namespace Tranga.Server;
|
||||
|
||||
@ -32,24 +33,55 @@ public partial class Server
|
||||
.Select(job => job.id));
|
||||
}
|
||||
|
||||
private ValueTuple<HttpStatusCode, object?> PostV2JobsCreateMonitorInternalId(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
private ValueTuple<HttpStatusCode, object?> GetV2JobTypes(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, Enum.GetNames(typeof(Job.JobType)));
|
||||
}
|
||||
|
||||
private ValueTuple<HttpStatusCode, object?> PostV2JobsCreateDownloadNewChaptersInternalId(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
private ValueTuple<HttpStatusCode, object?> PostV2JobsCreateType(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
|
||||
}
|
||||
|
||||
private ValueTuple<HttpStatusCode, object?> PostV2JobsCreateUpdateMetadata(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
|
||||
}
|
||||
|
||||
private ValueTuple<HttpStatusCode, object?> PostV2JobsCreateUpdateMetadataInternalId(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
|
||||
if (groups.Count < 1 ||
|
||||
!Enum.TryParse(groups[1].Value, true, out Job.JobType jobType))
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Manga with ID: '{groups[1].Value}' does not exist.");
|
||||
}
|
||||
|
||||
string? connectorStr, mangaId;
|
||||
MangaConnector? connector;
|
||||
Manga? manga;
|
||||
switch (jobType)
|
||||
{
|
||||
case Job.JobType.MonitorManga:
|
||||
if(!requestParameters.TryGetValue("connector", out connectorStr) ||
|
||||
!_parent.TryGetConnector(connectorStr, out connector) ||
|
||||
connector is null)
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, "Connector Parameter missing, or is not a valid connector.");
|
||||
if(!requestParameters.TryGetValue("internalId", out mangaId) ||
|
||||
!_parent.TryGetPublicationById(mangaId, out manga) ||
|
||||
manga is null)
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, "InternalId Parameter missing, or is not a valid ID.");
|
||||
if(!requestParameters.TryGetValue("interval", out string? intervalStr) ||
|
||||
!TimeSpan.TryParse(intervalStr, out TimeSpan interval))
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "Interval Parameter missing, or is not in correct format.");
|
||||
requestParameters.TryGetValue("language", out string? language);
|
||||
_parent.jobBoss.AddJob(new DownloadNewChapters(this, connector, (Manga)manga, true, interval, language));
|
||||
break;
|
||||
case Job.JobType.UpdateMetaDataJob:
|
||||
if(!requestParameters.TryGetValue("connector", out connectorStr) ||
|
||||
!_parent.TryGetConnector(connectorStr, out connector) ||
|
||||
connector is null)
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, "Connector Parameter missing, or is not a valid connector.");
|
||||
if(!requestParameters.TryGetValue("internalId", out mangaId) ||
|
||||
!_parent.TryGetPublicationById(mangaId, out manga) ||
|
||||
manga is null)
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, "InternalId Parameter missing, or is not a valid ID.");
|
||||
_parent.jobBoss.AddJob(new UpdateMetadata(this, connector, (Manga)manga));
|
||||
break;
|
||||
case Job.JobType.DownloadNewChaptersJob: //TODO
|
||||
case Job.JobType.DownloadChapterJob: //TODO
|
||||
default: return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.MethodNotAllowed, $"JobType {Enum.GetName(jobType)} is not supported.");
|
||||
}
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "How'd you get here.");
|
||||
}
|
||||
|
||||
private ValueTuple<HttpStatusCode, object?> GetV2JobJobId(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
@ -58,14 +90,22 @@ public partial class Server
|
||||
!_parent.jobBoss.TryGetJobById(groups[1].Value, out Job? job) ||
|
||||
job is null)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.BadRequest, $"Job with ID: '{groups[1].Value}' does not exist.");
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Job with ID: '{groups[1].Value}' does not exist.");
|
||||
}
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, job);
|
||||
}
|
||||
|
||||
private ValueTuple<HttpStatusCode, object?> DeleteV2JobJobId(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
|
||||
if (groups.Count < 1 ||
|
||||
!_parent.jobBoss.TryGetJobById(groups[1].Value, out Job? job) ||
|
||||
job is null)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Job with ID: '{groups[1].Value}' does not exist.");
|
||||
}
|
||||
|
||||
_parent.jobBoss.RemoveJob(job);
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
||||
}
|
||||
|
||||
private ValueTuple<HttpStatusCode, object?> GetV2JobJobIdProgress(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
@ -82,12 +122,26 @@ public partial class Server
|
||||
|
||||
private ValueTuple<HttpStatusCode, object?> PostV2JobJobIdStartNow(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
|
||||
if (groups.Count < 1 ||
|
||||
!_parent.jobBoss.TryGetJobById(groups[1].Value, out Job? job) ||
|
||||
job is null)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Job with ID: '{groups[1].Value}' does not exist.");
|
||||
}
|
||||
_parent.jobBoss.AddJobs(job.ExecuteReturnSubTasks(_parent.jobBoss));
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
||||
}
|
||||
|
||||
private ValueTuple<HttpStatusCode, object?> PostV2JobJobIdCancel(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
|
||||
if (groups.Count < 1 ||
|
||||
!_parent.jobBoss.TryGetJobById(groups[1].Value, out Job? job) ||
|
||||
job is null)
|
||||
{
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Job with ID: '{groups[1].Value}' does not exist.");
|
||||
}
|
||||
job.Cancel();
|
||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user