API changes:
/Tranga/GetAvailableControllers => /Controllers/Get /Tranga/GetKnownPublications =>/Publications/GetKnown /Tranga/GetPublicationsFromConnector => /Publications/GetFromConnector /Tasks/GetTaskTypes => /Tasks/GetTypes /Tasks/GetTaskProgress => /Tasks/GetProgress /Tasks/Create is now split in 3: /Tasks/CreateMonitorTask /Tasks/CreateUpdateLibraryTask /Tasks/CreateDownloadChaptersTask
This commit is contained in:
parent
4895079887
commit
7784f2024e
@ -1,6 +1,7 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Logging;
|
using Logging;
|
||||||
using Tranga;
|
using Tranga;
|
||||||
|
using Tranga.TrangaTasks;
|
||||||
|
|
||||||
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
|
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
|
||||||
string downloadFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(applicationFolderPath, "Manga");
|
string downloadFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(applicationFolderPath, "Manga");
|
||||||
@ -54,11 +55,17 @@ app.UseSwaggerUI();
|
|||||||
|
|
||||||
app.UseCors(corsHeader);
|
app.UseCors(corsHeader);
|
||||||
|
|
||||||
app.MapGet("/Tranga/GetAvailableControllers", () => taskManager.GetAvailableConnectors().Keys.ToArray());
|
app.MapGet("/Controllers/Get", () => taskManager.GetAvailableConnectors().Keys.ToArray());
|
||||||
|
|
||||||
app.MapGet("/Tranga/GetKnownPublications", () => taskManager.GetAllPublications());
|
app.MapGet("/Publications/GetKnown", (string? internalId) =>
|
||||||
|
{
|
||||||
|
if(internalId is null)
|
||||||
|
return taskManager.GetAllPublications();
|
||||||
|
|
||||||
app.MapGet("/Tranga/GetPublicationsFromConnector", (string connectorName, string title) =>
|
return new [] { taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId) };
|
||||||
|
});
|
||||||
|
|
||||||
|
app.MapGet("/Publications/GetFromConnector", (string connectorName, string title) =>
|
||||||
{
|
{
|
||||||
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
||||||
if (connector is null)
|
if (connector is null)
|
||||||
@ -68,13 +75,65 @@ app.MapGet("/Tranga/GetPublicationsFromConnector", (string connectorName, string
|
|||||||
return taskManager.GetPublicationsFromConnector(connector, title);
|
return taskManager.GetPublicationsFromConnector(connector, title);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapGet("/Tasks/GetTaskTypes", () => Enum.GetNames(typeof(TrangaTask.Task)));
|
app.MapGet("/Publications/GetChapters", (string connectorName, string internalId, string? language) =>
|
||||||
|
|
||||||
|
|
||||||
app.MapPost("/Tasks/Create", (string taskType, string? connectorName, string? internalId, string reoccurrenceTime, string? language) =>
|
|
||||||
{
|
{
|
||||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
||||||
taskManager.AddTask(task, connectorName, internalId, TimeSpan.Parse(reoccurrenceTime), language);
|
if (connector is null)
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId);
|
||||||
|
if (publication is null)
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
return connector.GetChapters((Publication)publication, language??"en");
|
||||||
|
});
|
||||||
|
|
||||||
|
app.MapGet("/Tasks/GetTypes", () => Enum.GetNames(typeof(TrangaTask.Task)));
|
||||||
|
|
||||||
|
|
||||||
|
app.MapPost("/Tasks/CreateMonitorTask",
|
||||||
|
(string connectorName, string internalId, string reoccurrenceTime, string? language) =>
|
||||||
|
{
|
||||||
|
Connector? connector =
|
||||||
|
taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
||||||
|
if (connector is null)
|
||||||
|
return;
|
||||||
|
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId);
|
||||||
|
if (publication is null)
|
||||||
|
return;
|
||||||
|
taskManager.AddTask(new DownloadNewChaptersTask(TrangaTask.Task.DownloadNewChapters, connectorName,
|
||||||
|
(Publication)publication,
|
||||||
|
TimeSpan.Parse(reoccurrenceTime), language ?? "en"));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.MapPost("/Tasks/CreateUpdateLibraryTask", (string reoccurrenceTime) =>
|
||||||
|
{
|
||||||
|
taskManager.AddTask(new UpdateLibrariesTask(TrangaTask.Task.UpdateLibraries, TimeSpan.Parse(reoccurrenceTime)));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.MapPost("/Tasks/CreateDownloadChaptersTask", (string connectorName, string internalId, string chapters, string? language) => {
|
||||||
|
|
||||||
|
Connector? connector =
|
||||||
|
taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
||||||
|
if (connector is null)
|
||||||
|
return;
|
||||||
|
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId);
|
||||||
|
if (publication is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Chapter[] availableChapters = connector.GetChapters((Publication)publication, language??"en");;
|
||||||
|
|
||||||
|
if (chapters.Contains('-'))
|
||||||
|
{
|
||||||
|
int start = Convert.ToInt32(chapters.Split('-')[0]);
|
||||||
|
int end = Convert.ToInt32(chapters.Split('-')[1]) + 1;
|
||||||
|
foreach (Chapter chapter in availableChapters[start..end])
|
||||||
|
{
|
||||||
|
taskManager.AddTask(new DownloadChapterTask(TrangaTask.Task.DownloadChapter, connectorName,
|
||||||
|
(Publication)publication, chapter, "en"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
taskManager.AddTask(new DownloadChapterTask(TrangaTask.Task.DownloadChapter, connectorName,
|
||||||
|
(Publication)publication, availableChapters[Convert.ToInt32(chapters)], "en"));
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapDelete("/Tasks/Delete", (string taskType, string? connectorName, string? publicationId) =>
|
app.MapDelete("/Tasks/Delete", (string taskType, string? connectorName, string? publicationId) =>
|
||||||
@ -96,7 +155,7 @@ app.MapGet("/Tasks/Get", (string taskType, string? connectorName, string? search
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapGet("/Tasks/GetTaskProgress", (string taskType, string? connectorName, string? publicationId) =>
|
app.MapGet("/Tasks/GetProgress", (string taskType, string? connectorName, string? publicationId) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -43,25 +43,37 @@ function DeleteData(uri){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function GetAvailableControllers(){
|
async function GetAvailableControllers(){
|
||||||
var uri = apiUri + "/Tranga/GetAvailableControllers";
|
var uri = apiUri + "/Controllers/Get";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetPublication(connectorName, title){
|
async function GetPublicationFromConnector(connectorName, title){
|
||||||
var uri = apiUri + `/Tranga/GetPublicationsFromConnector?connectorName=${connectorName}&title=${title}`;
|
var uri = apiUri + `/Publications/GetFromConnector?connectorName=${connectorName}&title=${title}`;
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetKnownPublications(){
|
async function GetKnownPublications(){
|
||||||
var uri = apiUri + "/Tranga/GetKnownPublications";
|
var uri = apiUri + "/Publications/GetKnown";
|
||||||
|
let json = await GetData(uri);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function GetPublication(internalId){
|
||||||
|
var uri = apiUri + `/Publications/GetKnown?internalId=${internalId}`;
|
||||||
|
let json = await GetData(uri);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function GetChapters(internalId, connectorName, language){
|
||||||
|
var uri = apiUri + `/Publications/GetChapters?internalId=${internalId}&connectorName=${connectorName}&language=${language}`;
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetTaskTypes(){
|
async function GetTaskTypes(){
|
||||||
var uri = apiUri + "/Tasks/GetTaskTypes";
|
var uri = apiUri + "/Tasks/GetTypes";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
@ -89,8 +101,18 @@ async function GetKomgaTask(){
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
function CreateTask(taskType, reoccurrence, connectorName, internalId, language){
|
function CreateMonitorTask(connectorName, internalId, reoccurrence, language){
|
||||||
var uri = apiUri + `/Tasks/Create?taskType=${taskType}&connectorName=${connectorName}&internalId=${internalId}&reoccurrenceTime=${reoccurrence}&language=${language}`;
|
var uri = apiUri + `/Tasks/CreateMonitorTask?connectorName=${connectorName}&internalId=${internalId}&reoccurrenceTime=${reoccurrence}&language=${language}`;
|
||||||
|
PostData(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CreateUpdateLibraryTask(reoccurrence){
|
||||||
|
var uri = apiUri + `/Tasks/CreateUpdateLibraryTask?reoccurrenceTime=${reoccurrence}`;
|
||||||
|
PostData(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CreateDownloadChaptersTask(connectorName, internalId, chapters, language){
|
||||||
|
var uri = apiUri + `/Tasks/CreateDownloadChaptersTask?connectorName=${connectorName}&internalId=${internalId}&chapters=${chapters}&language=${language}`;
|
||||||
PostData(uri);
|
PostData(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ function NewSearch(){
|
|||||||
|
|
||||||
//Empty previous results
|
//Empty previous results
|
||||||
selectPublication.replaceChildren();
|
selectPublication.replaceChildren();
|
||||||
GetPublication(connectorSelect.value, searchPublicationQuery.value)
|
GetPublicationFromConnector(connectorSelect.value, searchPublicationQuery.value)
|
||||||
.then(json =>
|
.then(json =>
|
||||||
json.forEach(publication => {
|
json.forEach(publication => {
|
||||||
var option = CreatePublication(publication, connectorSelect.value);
|
var option = CreatePublication(publication, connectorSelect.value);
|
||||||
@ -288,7 +288,7 @@ function UpdateLibrarySettings(){
|
|||||||
if(settingKavitaUrl.value != "" && settingKavitaUser.value != "" && settingKavitaPass.value != ""){
|
if(settingKavitaUrl.value != "" && settingKavitaUser.value != "" && settingKavitaPass.value != ""){
|
||||||
UpdateSettings("", "", "", settingKavitaUrl.value, settingKavitaUser.value, settingKavitaPass.value);
|
UpdateSettings("", "", "", settingKavitaUrl.value, settingKavitaUser.value, settingKavitaPass.value);
|
||||||
}
|
}
|
||||||
CreateTask("UpdateLibraries", libraryUpdateTime.value, "","","");
|
CreateUpdateLibraryTask(libraryUpdateTime.value);
|
||||||
setTimeout(() => GetSettingsClick(), 200);
|
setTimeout(() => GetSettingsClick(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user