API: Updated /Tasks/GetProgress to return progress of specific task (by sortNumber)

This commit is contained in:
glax 2023-06-09 23:42:18 +02:00
parent a3a96b6b55
commit 6485b8744f

View File

@ -144,14 +144,24 @@ app.MapGet("/Tasks/Get", (string taskType, string? connectorName, string? search
}
});
app.MapGet("/Tasks/GetProgress", (string taskType, string? connectorName, string? publicationId) =>
app.MapGet("/Tasks/GetProgress", (string taskType, string connectorName, string publicationId, string? chapterSortNumber) =>
{
Connector? connector =
taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
if (connector is null)
return -1f;
try
{
TrangaTask? task = null;
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
TrangaTask? task = taskManager
.GetTasksMatching(pTask, connectorName: connectorName, internalId: publicationId)?.First();
if (pTask is TrangaTask.Task.DownloadNewChapters)
{
task = taskManager.GetTasksMatching(pTask, connectorName: connectorName, internalId: publicationId).FirstOrDefault();
}else if (pTask is TrangaTask.Task.DownloadChapter && chapterSortNumber is not null)
{
task = taskManager.GetTasksMatching(pTask, connectorName: connectorName, internalId: publicationId,
chapterSortNumber: chapterSortNumber).FirstOrDefault();
}
if (task is null)
return -1f;