Added new API-Calls:
POST: Jobs/StartNow DELETE: Jobs
This commit is contained in:
parent
1fd36c91d6
commit
9f30e52713
@ -63,13 +63,32 @@ public class JobBoss : GlobalBase
|
|||||||
return GetJobsLike(mangaConnector?.name, publication?.internalId, chapter?.chapterNumber);
|
return GetJobsLike(mangaConnector?.name, publication?.internalId, chapter?.chapterNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Job? GetJobById(string jobId)
|
||||||
|
{
|
||||||
|
if (this.jobs.FirstOrDefault(jjob => jjob.id == jobId) is { } job)
|
||||||
|
return job;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGetJobById(string jobId, out Job? job)
|
||||||
|
{
|
||||||
|
if (this.jobs.FirstOrDefault(jjob => jjob.id == jobId) is { } ret)
|
||||||
|
{
|
||||||
|
job = ret;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
job = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool QueueContainsJob(Job job)
|
private bool QueueContainsJob(Job job)
|
||||||
{
|
{
|
||||||
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>());
|
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>());
|
||||||
return mangaConnectorJobQueue[job.mangaConnector].Contains(job);
|
return mangaConnectorJobQueue[job.mangaConnector].Contains(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddJobToQueue(Job job)
|
public void AddJobToQueue(Job job)
|
||||||
{
|
{
|
||||||
Log($"Adding Job to Queue. {job}");
|
Log($"Adding Job to Queue. {job}");
|
||||||
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>());
|
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>());
|
||||||
|
@ -225,6 +225,16 @@ public class Server : GlobalBase
|
|||||||
_parent._jobBoss.AddJob(new DownloadNewChapters(this, connector, manga, false));
|
_parent._jobBoss.AddJob(new DownloadNewChapters(this, connector, manga, false));
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
SendResponse(HttpStatusCode.Accepted, response);
|
||||||
break;
|
break;
|
||||||
|
case "Jobs/StartNow":
|
||||||
|
if (!requestVariables.TryGetValue("jobId", out string? jobId) ||
|
||||||
|
!_parent._jobBoss.TryGetJobById(jobId, out Job? job))
|
||||||
|
{
|
||||||
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_parent._jobBoss.AddJobToQueue(job!);
|
||||||
|
SendResponse(HttpStatusCode.Accepted, response);
|
||||||
|
break;
|
||||||
case "Settings/UpdateDownloadLocation":
|
case "Settings/UpdateDownloadLocation":
|
||||||
if (!requestVariables.TryGetValue("downloadLocation", out string? downloadLocation) ||
|
if (!requestVariables.TryGetValue("downloadLocation", out string? downloadLocation) ||
|
||||||
!requestVariables.TryGetValue("moveFiles", out string? moveFilesStr) ||
|
!requestVariables.TryGetValue("moveFiles", out string? moveFilesStr) ||
|
||||||
@ -329,6 +339,16 @@ public class Server : GlobalBase
|
|||||||
string path = Regex.Match(request.Url!.LocalPath, @"[A-z0-9]+(\/[A-z0-9]+)*").Value;
|
string path = Regex.Match(request.Url!.LocalPath, @"[A-z0-9]+(\/[A-z0-9]+)*").Value;
|
||||||
switch (path)
|
switch (path)
|
||||||
{
|
{
|
||||||
|
case "Jobs":
|
||||||
|
if (!requestVariables.TryGetValue("jobID", out string? jobId) ||
|
||||||
|
!_parent._jobBoss.TryGetJobById(jobId, out Job? job))
|
||||||
|
{
|
||||||
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_parent._jobBoss.RemoveJob(job!);
|
||||||
|
SendResponse(HttpStatusCode.Accepted, response);
|
||||||
|
break;
|
||||||
case "Jobs/DownloadChapter":
|
case "Jobs/DownloadChapter":
|
||||||
if(!requestVariables.TryGetValue("connector", out connectorName) ||
|
if(!requestVariables.TryGetValue("connector", out connectorName) ||
|
||||||
!requestVariables.TryGetValue("internalId", out internalId) ||
|
!requestVariables.TryGetValue("internalId", out internalId) ||
|
||||||
|
Loading…
Reference in New Issue
Block a user