From 2d1d64a76549e1a286f45c4ed6be3d0dcaf658f4 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Thu, 19 Jan 2023 20:33:05 +0000 Subject: [PATCH] move api path info to vars.js Signed-off-by: Arthur Lu --- scripts/config.js | 5 ++--- scripts/meta.js | 19 ------------------- scripts/utils.js | 23 +++++++++++++++++++++-- vars.js | 2 ++ 4 files changed, 25 insertions(+), 24 deletions(-) delete mode 100644 scripts/meta.js create mode 100644 vars.js diff --git a/scripts/config.js b/scripts/config.js index e0794fe..1cc8e84 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -1,9 +1,8 @@ -import {requestPVE, goToPage, getURIData, reload} from "./utils.js"; -import {pveconfig} from "./meta.js"; +import {requestPVE, goToPage, getURIData, reload, resources} from "./utils.js"; window.addEventListener("DOMContentLoaded", init); -let diskMetaData = pveconfig.diskMetaData; +let diskMetaData = resources.disk; let node; let type; diff --git a/scripts/meta.js b/scripts/meta.js deleted file mode 100644 index 0a7b832..0000000 --- a/scripts/meta.js +++ /dev/null @@ -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"]} - } - } -} \ No newline at end of file diff --git a/scripts/utils.js b/scripts/utils.js index 09d7985..bbd1655 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -1,4 +1,4 @@ -import {pveconfig} from "./meta.js"; +import {pveAPI} from "/vars.js"; export class ResponseError extends Error { 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) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); @@ -59,7 +78,7 @@ export async function requestPVE (path, method, body = null, auth = true) { content.headers.CSRFPreventionToken = getCookie("CSRFPreventionToken"); } - let response = await fetch(`${pveconfig.pveAPI}${path}`, content) + let response = await fetch(`${pveAPI}${path}`, content) .then((response) => { if (!response.ok) { throw new ResponseError(`recieved response status code ${response.status}`); diff --git a/vars.js b/vars.js new file mode 100644 index 0000000..0df047c --- /dev/null +++ b/vars.js @@ -0,0 +1,2 @@ +export const pveAPI = ""; +export const paasAPI = "" \ No newline at end of file