move api path info to vars.js

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-01-19 20:33:05 +00:00
parent c99f6cef2d
commit 2d1d64a765
4 changed files with 25 additions and 24 deletions

View File

@ -1,9 +1,8 @@
import {requestPVE, goToPage, getURIData, reload} from "./utils.js"; import {requestPVE, goToPage, getURIData, reload, resources} from "./utils.js";
import {pveconfig} from "./meta.js";
window.addEventListener("DOMContentLoaded", init); window.addEventListener("DOMContentLoaded", init);
let diskMetaData = pveconfig.diskMetaData; let diskMetaData = resources.disk;
let node; let node;
let type; let type;

View File

@ -1,19 +0,0 @@
export const pveconfig = {
pveAPI: "https://pve.tronnet.net/api2/json",
diskMetaData: {
//actionBarOrder: ["config", "move", "reassign", "resize", "delete_detach_attach"],
actionBarOrder: ["config", "move", "resize", "delete_detach_attach"], // handle reassign later
lxc: {
prefixOrder: ["rootfs", "mp", "unused"],
rootfs: {name: "ROOTFS", icon: "images/resources/drive.svg", actions: ["move", "resize"]},
mp: {name: "MP", icon: "images/resources/drive.svg", actions: ["config", "detach", "move", "reassign", "resize"]},
unused: {name: "UNUSED", icon: "images/resources/drive.svg", actions: ["attach", "delete", "reassign"]}
},
qemu: {
prefixOrder: ["ide", "sata", "unused"],
ide: {name: "IDE", icon: "images/resources/disk.svg", actions: ["config", "delete"]},
sata: {name: "SATA", icon: "images/resources/drive.svg", actions: ["detach", "move", "reassign", "resize"]},
unused: {name: "UNUSED", icon: "images/resources/drive.svg", actions: ["attach", "delete", "reassign"]}
}
}
}

View File

@ -1,4 +1,4 @@
import {pveconfig} from "./meta.js"; import {pveAPI} from "/vars.js";
export class ResponseError extends Error { export class ResponseError extends Error {
constructor(message) { constructor(message) {
@ -14,6 +14,25 @@ export class NetworkError extends Error {
} }
} }
export const resources = {
disk: {
//actionBarOrder: ["config", "move", "reassign", "resize", "delete_detach_attach"],
actionBarOrder: ["config", "move", "resize", "delete_detach_attach"], // handle reassign later
lxc: {
prefixOrder: ["rootfs", "mp", "unused"],
rootfs: {name: "ROOTFS", icon: "images/resources/drive.svg", actions: ["move", "resize"]},
mp: {name: "MP", icon: "images/resources/drive.svg", actions: ["config", "detach", "move", "reassign", "resize"]},
unused: {name: "UNUSED", icon: "images/resources/drive.svg", actions: ["attach", "delete", "reassign"]}
},
qemu: {
prefixOrder: ["ide", "sata", "unused"],
ide: {name: "IDE", icon: "images/resources/disk.svg", actions: ["config", "delete"]},
sata: {name: "SATA", icon: "images/resources/drive.svg", actions: ["detach", "move", "reassign", "resize"]},
unused: {name: "UNUSED", icon: "images/resources/drive.svg", actions: ["attach", "delete", "reassign"]}
}
}
}
function getCookie(cname) { function getCookie(cname) {
let name = cname + "="; let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie); let decodedCookie = decodeURIComponent(document.cookie);
@ -59,7 +78,7 @@ export async function requestPVE (path, method, body = null, auth = true) {
content.headers.CSRFPreventionToken = getCookie("CSRFPreventionToken"); content.headers.CSRFPreventionToken = getCookie("CSRFPreventionToken");
} }
let response = await fetch(`${pveconfig.pveAPI}${path}`, content) let response = await fetch(`${pveAPI}${path}`, content)
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
throw new ResponseError(`recieved response status code ${response.status}`); throw new ResponseError(`recieved response status code ${response.status}`);

2
vars.js Normal file
View File

@ -0,0 +1,2 @@
export const pveAPI = "";
export const paasAPI = ""