From 8b58e7dd13f06b09180f99d1f0247f0fa84c7a8c Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 15 Jun 2023 17:14:20 +0200 Subject: [PATCH] Website: On Download Chapters only show chapters that have not yet been downloaded API: Added new variables to /Publications/GetChapters: onlyNew and onlyExisting. API will return only new, only existing or all chapters depending on variables. #19 --- Tranga-API/Program.cs | 10 ++++++++-- Website/apiConnector.js | 4 ++-- Website/interaction.js | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Tranga-API/Program.cs b/Tranga-API/Program.cs index 30477a5..78b4253 100644 --- a/Tranga-API/Program.cs +++ b/Tranga-API/Program.cs @@ -75,7 +75,7 @@ app.MapGet("/Publications/GetFromConnector", (string connectorName, string title return taskManager.GetPublicationsFromConnector(connector, title); }); -app.MapGet("/Publications/GetChapters", (string connectorName, string internalId, string? language) => +app.MapGet("/Publications/GetChapters", (string connectorName, string internalId, bool onlyNew, bool onlyExisting, string? language) => { Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value; if (connector is null) @@ -83,7 +83,13 @@ app.MapGet("/Publications/GetChapters", (string connectorName, string internalId Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId); if (publication is null) return Array.Empty(); - return connector.GetChapters((Publication)publication, language??"en"); + + if(onlyNew) + return taskManager.GetNewChaptersList(connector, (Publication)publication, language??"en").ToArray(); + else if (onlyExisting) + return taskManager.GetExistingChaptersList(connector, (Publication)publication, language ?? "en").ToArray(); + else + return connector.GetChapters((Publication)publication, language??"en"); }); app.MapGet("/Tasks/GetTypes", () => Enum.GetNames(typeof(TrangaTask.Task))); diff --git a/Website/apiConnector.js b/Website/apiConnector.js index 88012c4..38d1175 100644 --- a/Website/apiConnector.js +++ b/Website/apiConnector.js @@ -66,8 +66,8 @@ async function GetPublication(internalId){ return json; } -async function GetChapters(internalId, connectorName, language){ - var uri = apiUri + `/Publications/GetChapters?internalId=${internalId}&connectorName=${connectorName}&language=${language}`; +async function GetChapters(internalId, connectorName, onlyNew, language){ + var uri = apiUri + `/Publications/GetChapters?internalId=${internalId}&connectorName=${connectorName}&onlyNew=${onlyNew}&language=${language}`; let json = await GetData(uri); return json; } diff --git a/Website/interaction.js b/Website/interaction.js index bf3960d..6592a78 100644 --- a/Website/interaction.js +++ b/Website/interaction.js @@ -154,7 +154,7 @@ function OpenDownloadChapterTaskPopup(){ selectedChapters.value = ""; chapterOutput.replaceChildren(); createDownloadChaptersTask.style.display = "block"; - GetChapters(toEditId, connectorSelect.value, "en").then((json) => { + GetChapters(toEditId, connectorSelect.value, true, "en").then((json) => { var i = 0; json.forEach(chapter => { var chapterDom = document.createElement("div");