2024-02-24 16:27:14 +01:00
|
|
|
|
let apiUri = `${window.location.protocol}//${window.location.host.split(':')[0]}:6531`
|
2023-05-25 10:42:19 +02:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2024-02-11 22:59:05 +01:00
|
|
|
|
async function PostData(uri){
|
|
|
|
|
let request = await fetch(uri, {
|
2023-05-23 13:52:35 +02:00
|
|
|
|
method: 'POST'
|
|
|
|
|
});
|
2024-02-11 23:01:37 +01:00
|
|
|
|
//console.log(request);
|
2023-05-23 13:52:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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(){
|
2023-06-20 23:15:56 +02:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 14:30:13 +02:00
|
|
|
|
async function GetChapters(connector, internalId, language){
|
|
|
|
|
var uri = `${apiUri}/Manga/Chapters?connector=${connector}&internalId=${internalId}&translatedLanguage=${language}`;
|
2023-06-08 19:24:46 +02:00
|
|
|
|
let json = await GetData(uri);
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-01 23:42:31 +02:00
|
|
|
|
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-06-08 19:24:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
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-06-08 19:24:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-11 22:59:05 +01:00
|
|
|
|
async function GetRateLimits() {
|
|
|
|
|
var uri = `${apiUri}/Settings/customRequestLimit`
|
|
|
|
|
let json = await GetData(uri);
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 14:30:13 +02:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 14:30:13 +02:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-11-02 19:28:28 +01:00
|
|
|
|
function RefreshLibraryMetadata() {
|
|
|
|
|
var uri = `${apiUri}/Jobs/UpdateMetadata`;
|
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-09 17:17:33 +01:00
|
|
|
|
async function DownloadLogs() {
|
|
|
|
|
var uri = `${apiUri}/LogFile`;
|
2024-02-12 00:39:27 +01:00
|
|
|
|
|
|
|
|
|
//Below taken from https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
|
|
|
|
|
fetch(uri)
|
|
|
|
|
.then((response) => response.body)
|
|
|
|
|
.then((rb) => {
|
|
|
|
|
const reader = rb.getReader();
|
|
|
|
|
|
|
|
|
|
return new ReadableStream({
|
|
|
|
|
start(controller) {
|
|
|
|
|
// The following function handles each data chunk
|
|
|
|
|
function push() {
|
|
|
|
|
// "done" is a Boolean and value a "Uint8Array"
|
|
|
|
|
reader.read().then(({ done, value }) => {
|
|
|
|
|
// If there is no more data to read
|
|
|
|
|
if (done) {
|
|
|
|
|
console.log("done", done);
|
|
|
|
|
controller.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Get the data and send it to the browser via the controller
|
|
|
|
|
controller.enqueue(value);
|
|
|
|
|
// Check chunks by logging to the console
|
|
|
|
|
console.log(done, value);
|
|
|
|
|
push();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
push();
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.then((stream) =>
|
|
|
|
|
// Respond with our stream
|
|
|
|
|
new Response(stream, { headers: { "Content-Type": "text/html" } }).text(),
|
|
|
|
|
)
|
|
|
|
|
.then((result) => {
|
|
|
|
|
// Do things with result
|
2024-02-12 00:41:21 +01:00
|
|
|
|
//console.log(result);
|
2024-02-12 00:39:27 +01:00
|
|
|
|
|
|
|
|
|
//Below download taken from https://stackoverflow.com/questions/3665115/how-to-create-a-file-in-memory-for-user-to-download-but-not-through-server
|
|
|
|
|
var element = document.createElement('a');
|
|
|
|
|
element.setAttribute('href', 'data:text/plain;charset-utf-8,' + encodeURIComponent(result));
|
|
|
|
|
var newDate = new Date();
|
|
|
|
|
var filename = "Tranga_Logs_" + newDate.today() + "_" + newDate.timeNow() + ".log";
|
|
|
|
|
element.setAttribute('download', filename);
|
|
|
|
|
element.click();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Following date-time code taken from: https://stackoverflow.com/questions/10211145/getting-current-date-and-time-in-javascript
|
|
|
|
|
// For todays date;
|
|
|
|
|
Date.prototype.today = function () {
|
|
|
|
|
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For the time now
|
|
|
|
|
Date.prototype.timeNow = function () {
|
|
|
|
|
return ((this.getHours() < 10)?"0":"") + this.getHours() +"_"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +"_"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
|
2024-02-09 17:17:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 21:47:13 +01:00
|
|
|
|
//Komga
|
2023-06-15 18:38:47 +02:00
|
|
|
|
function UpdateKomga(komgaUrl, komgaAuth){
|
2023-08-31 16:24:04 +02:00
|
|
|
|
var uri = `${apiUri}/LibraryConnectors/Update?libraryConnector=Komga&komgaUrl=${komgaUrl}&komgaAuth=${komgaAuth}`;
|
2023-06-15 18:38:47 +02:00
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 21:47:13 +01:00
|
|
|
|
function ResetKomga(){
|
|
|
|
|
var uri = `${apiUri}/LibraryConnectors/Reset?libraryConnector=Komga`;
|
2024-02-04 22:02:09 +01:00
|
|
|
|
PostData(uri);
|
2024-02-04 21:47:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function TestKomga(komgaUrl, komgaAuth){
|
|
|
|
|
var uri = `${apiUri}/LibraryConnectors/Test?libraryConnector=Komga&komgaUrl=${komgaUrl}&komgaAuth=${komgaAuth}`;
|
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Kavita
|
2023-08-31 16:45:17 +02:00
|
|
|
|
function UpdateKavita(kavitaUrl, kavitaUsername, kavitaPassword){
|
2023-10-30 13:36:02 +01:00
|
|
|
|
var uri = `${apiUri}/LibraryConnectors/Update?libraryConnector=Kavita&kavitaUrl=${kavitaUrl}&kavitaUsername=${kavitaUsername}&kavitaPassword=${kavitaPassword}`;
|
2023-06-15 18:38:47 +02:00
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 21:47:13 +01:00
|
|
|
|
function ResetKavita(){
|
|
|
|
|
var uri = `${apiUri}/LibraryConnectors/Reset?libraryConnector=Kavita`;
|
2024-02-04 22:02:09 +01:00
|
|
|
|
PostData(uri);
|
2024-02-04 21:47:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function TestKavita(kavitaUrl, kavitaUsername, kavitaPassword){
|
|
|
|
|
var uri = `${apiUri}/LibraryConnectors/Test?libraryConnector=Kavita&kavitaUrl=${kavitaUrl}&kavitaUsername=${kavitaUsername}&kavitaPassword=${kavitaPassword}`;
|
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Gotify
|
2023-06-15 18:38:47 +02:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 21:47:13 +01:00
|
|
|
|
function ResetGotify(){
|
2024-02-11 22:59:05 +01:00
|
|
|
|
var uri = `${apiUri}/NotificationConnectors/Reset?notificationConnector=Gotify`;
|
2024-02-04 22:02:09 +01:00
|
|
|
|
PostData(uri);
|
2024-02-04 21:47:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function TestGotify(gotifyUrl, gotifyAppToken){
|
|
|
|
|
var uri = `${apiUri}/NotificationConnectors/Test?notificationConnector=Gotify&gotifyUrl=${gotifyUrl}&gotifyAppToken=${gotifyAppToken}`;
|
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LunaSea
|
2023-06-15 18:57:21 +02:00
|
|
|
|
function UpdateLunaSea(lunaseaWebhook){
|
2023-08-31 12:56:09 +02:00
|
|
|
|
var uri = `${apiUri}/NotificationConnectors/Update?notificationConnector=LunaSea&lunaseaWebhook=${lunaseaWebhook}`;
|
2023-06-15 18:57:21 +02:00
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 21:47:13 +01:00
|
|
|
|
function ResetLunaSea(){
|
2024-02-11 22:59:05 +01:00
|
|
|
|
var uri = `${apiUri}/NotificationConnectors/Reset?notificationConnector=LunaSea`;
|
2024-02-04 22:02:09 +01:00
|
|
|
|
PostData(uri);
|
2024-02-04 21:47:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function TestLunaSea(lunaseaWebhook){
|
|
|
|
|
var uri = `${apiUri}/NotificationConnectors/Test?notificationConnector=LunaSea&lunaseaWebhook=${lunaseaWebhook}`;
|
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Ntfy
|
2023-10-27 13:55:42 +02:00
|
|
|
|
function UpdateNtfy(ntfyEndpoint, ntfyAuth){
|
|
|
|
|
var uri = `${apiUri}/NotificationConnectors/Update?notificationConnector=Ntfy&ntfyUrl=${ntfyEndpoint}&ntfyAuth=${ntfyAuth}`;
|
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 21:47:13 +01:00
|
|
|
|
function ResetNtfy(){
|
2024-02-11 22:59:05 +01:00
|
|
|
|
var uri = `${apiUri}/NotificationConnectors/Reset?notificationConnector=Ntfy`;
|
2024-02-04 22:02:09 +01:00
|
|
|
|
PostData(uri);
|
2024-02-04 21:47:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function TestNtfy(ntfyEndpoint, ntfyAuth){
|
|
|
|
|
var uri = `${apiUri}/NotificationConnectors/Test?notificationConnector=Ntfy&ntfyUrl=${ntfyEndpoint}&ntfyAuth=${ntfyAuth}`;
|
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 19:12:05 +01:00
|
|
|
|
function UpdateUserAgent(userAgent){
|
|
|
|
|
var uri = `${apiUri}/Settings/userAgent?userAgent=${userAgent}`;
|
|
|
|
|
PostData(uri);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-11 22:59:05 +01:00
|
|
|
|
function UpdateRateLimit(byteValue, rateLimit) {
|
|
|
|
|
var uri = `${apiUri}/Settings/customRequestLimit?requestType=${byteValue}&requestsPerMinute=${rateLimit}`;
|
2024-02-09 05:31:31 +01:00
|
|
|
|
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);
|
2024-02-04 21:47:13 +01:00
|
|
|
|
console.log(json);
|
2023-09-26 20:05:50 +02:00
|
|
|
|
return json;
|
2023-05-23 12:51:21 +02:00
|
|
|
|
}
|