Tranga-Website/Website/apiConnector.js

205 lines
5.3 KiB
JavaScript
Raw Normal View History

2023-05-25 10:42:19 +02:00
let apiUri = `http://${window.location.host.split(':')[0]}:6531`
if(getCookie("apiUri") != ""){
apiUri = getCookie("apiUri");
}
2023-08-31 16:45:17 +02:00
setCookie("apiUri", apiUri);
function setCookie(cname, cvalue) {
const d = new Date();
d.setTime(d.getTime() + (365*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;samesite=strict";
}
2023-05-25 10:42:19 +02:00
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
2023-05-23 12:51:21 +02:00
2023-05-23 13:52:35 +02:00
async function GetData(uri){
let request = await fetch(uri, {
2023-05-23 13:15:29 +02:00
method: 'GET',
headers: {
'Accept': 'application/json'
}
2023-05-23 13:52:35 +02:00
});
let json = await request.json();
return json;
2023-05-23 13:15:29 +02:00
}
2023-05-23 13:52:35 +02:00
function PostData(uri){
fetch(uri, {
method: 'POST'
});
}
function DeleteData(uri){
fetch(uri, {
method: 'DELETE'
});
}
2023-09-08 16:31:55 +02:00
async function Ping(){
let ret = await GetData(`${apiUri}/Ping`);
return ret;
}
2023-05-23 13:52:35 +02:00
async function GetAvailableControllers(){
var uri = apiUri + "/Connectors";
2023-05-23 13:52:35 +02:00
let json = await GetData(uri);
return json;
}
2023-08-31 12:56:09 +02:00
async function GetPublicationFromConnector(connector, title){
2023-09-02 22:14:44 +02:00
var uri;
if(title.includes("http")){
uri = `${apiUri}/Manga/FromConnector?connector=${connector}&url=${title}`;
}else{
uri = `${apiUri}/Manga/FromConnector?connector=${connector}&title=${title}`;
}
let json = await GetData(uri);
return json;
2023-05-23 13:52:35 +02:00
}
async function GetChapters(connector, internalId, language){
var uri = `${apiUri}/Manga/Chapters?connector=${connector}&internalId=${internalId}&translatedLanguage=${language}`;
let json = await GetData(uri);
return json;
}
function GetCoverUrl(internalId){
return `${apiUri}/Manga/Cover?internalId=${internalId}`;
}
2023-08-31 12:56:09 +02:00
async function GetAllJobs(){
var uri = `${apiUri}/Jobs`;
let json = await GetData(uri);
return json;
}
2023-08-31 12:56:09 +02:00
async function GetRunningJobs(){
var uri = `${apiUri}/Jobs/Running`;
2023-05-23 13:52:35 +02:00
let json = await GetData(uri);
return json;
}
2023-08-31 12:56:09 +02:00
async function GetWaitingJobs(){
var uri = `${apiUri}/Jobs/Waiting`;
2023-05-23 13:52:35 +02:00
let json = await GetData(uri);
return json;
}
2023-05-23 13:15:29 +02:00
2023-08-31 16:45:17 +02:00
async function GetMonitorJobs(){
var uri = `${apiUri}/Jobs/MonitorJobs`;
let json = await GetData(uri);
return json;
}
2023-08-31 12:56:09 +02:00
async function GetProgress(jobId){
var uri = `${apiUri}/Jobs/Progress?jobId=${jobId}`;
2023-05-23 13:52:35 +02:00
let json = await GetData(uri);
return json;
2023-05-23 13:15:29 +02:00
}
async function GetSettings(){
2023-08-31 12:56:09 +02:00
var uri = `${apiUri}/Settings`;
2023-05-23 13:52:35 +02:00
let json = await GetData(uri);
return json;
}
2023-08-31 12:56:09 +02:00
async function GetAvailableNotificationConnectors(){
var uri = `${apiUri}/NotificationConnectors/Types`;
let json = await GetData(uri);
return json;
2023-05-24 21:48:54 +02:00
}
2023-08-31 12:56:09 +02:00
async function GetNotificationConnectors(){
var uri = `${apiUri}/NotificationConnectors`;
let json = await GetData(uri);
return json;
}
2023-08-31 12:56:09 +02:00
async function GetAvailableLibraryConnectors(){
var uri = `${apiUri}/LibraryConnectors/Types`;
let json = await GetData(uri);
return json;
2023-05-23 13:52:35 +02:00
}
2023-08-31 12:56:09 +02:00
async function GetLibraryConnectors(){
var uri = `${apiUri}/LibraryConnectors`;
let json = await GetData(uri);
return json;
}
function CreateMonitorJob(connector, internalId, language){
var uri = `${apiUri}/Jobs/MonitorManga?connector=${connector}&internalId=${internalId}&interval=03:00:00&translatedLanguage=${language}`;
2023-05-23 13:52:35 +02:00
PostData(uri);
}
function CreateDownloadNewChaptersJob(connector, internalId, language){
var uri = `${apiUri}/Jobs/DownloadNewChapters?connector=${connector}&internalId=${internalId}&translatedLanguage=${language}`;
2023-05-23 13:52:35 +02:00
PostData(uri);
}
2023-08-31 13:12:20 +02:00
function StartJob(jobId){
var uri = `${apiUri}/Jobs/StartNow?jobId=${jobId}`;
PostData(uri);
}
2023-06-15 18:38:47 +02:00
function UpdateDownloadLocation(downloadLocation){
2023-08-31 12:56:09 +02:00
var uri = `${apiUri}/Settings/UpdateDownloadLocation?downloadLocation=${downloadLocation}`;
PostData(uri);
2023-06-15 18:38:47 +02:00
}
function ChangeStyleSheet(sheet){
var uri = `${apiUri}/Settings/ChangeStyleSheet?styleSheet=${sheet}`;
PostData(uri);
}
2023-06-15 18:38:47 +02:00
function UpdateKomga(komgaUrl, komgaAuth){
var uri = `${apiUri}/LibraryConnectors/Update?libraryConnector=Komga&komgaUrl=${komgaUrl}&komgaAuth=${komgaAuth}`;
2023-06-15 18:38:47 +02:00
PostData(uri);
}
2023-08-31 16:45:17 +02:00
function UpdateKavita(kavitaUrl, kavitaUsername, kavitaPassword){
var uri = `${apiUri}/LibraryConnectors/Update?libraryConnector=Kavita&kavitaUrl=${kavitaUrl}&kavitaUsername=${kavitaUsername}&kavitaPassword={kavitaPassword}`;
2023-06-15 18:38:47 +02:00
PostData(uri);
}
function UpdateGotify(gotifyUrl, gotifyAppToken){
2023-08-31 12:56:09 +02:00
var uri = `${apiUri}/NotificationConnectors/Update?notificationConnector=Gotify&gotifyUrl=${gotifyUrl}&gotifyAppToken=${gotifyAppToken}`;
2023-05-23 13:52:35 +02:00
PostData(uri);
}
function UpdateLunaSea(lunaseaWebhook){
2023-08-31 12:56:09 +02:00
var uri = `${apiUri}/NotificationConnectors/Update?notificationConnector=LunaSea&lunaseaWebhook=${lunaseaWebhook}`;
PostData(uri);
}
2023-08-31 12:56:09 +02:00
function RemoveJob(jobId){
var uri = `${apiUri}/Jobs?jobId=${jobId}`;
2023-05-23 13:52:35 +02:00
DeleteData(uri);
2023-09-02 15:05:45 +02:00
}
function CancelJob(jobId){
var uri = `${apiUri}/Jobs/Cancel?jobId=${jobId}`;
PostData(uri);
2023-09-26 20:05:50 +02:00
}
async function GetLogmessages(count){
var uri = `${apiUri}/LogMessages?count=${count}`;
let json = await GetData(uri);
return json;
2023-05-23 12:51:21 +02:00
}