From cd3027c35ecdeb8fb298b36a37de0e275dbd2c25 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Mon, 15 May 2023 20:16:38 +0000 Subject: [PATCH] code cleanup Signed-off-by: Arthur Lu --- scripts/index.js | 14 +++++++------- scripts/instance.js | 3 ++- scripts/login.js | 2 +- scripts/utils.js | 1 - vars.js.template | 3 ++- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/index.js b/scripts/index.js index 81f5ba7..33e4e3b 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -125,13 +125,6 @@ async function handleInstanceAdd () { } }); - let userResources = await requestAPI("/user/resources", "GET"); - let userInstances = await requestAPI("/user/instances", "GET") - d.querySelector("#cores").max = userResources.avail.cores; - d.querySelector("#memory").max = userResources.avail.memory; - d.querySelector("#vmid").min = userInstances.vmid.min; - d.querySelector("#vmid").max = userInstances.vmid.max; - let typeSelect = d.querySelector("#type"); typeSelect.selectedIndex = -1; typeSelect.addEventListener("change", () => { @@ -193,4 +186,11 @@ async function handleInstanceAdd () { }); templateImage.selectedIndex = -1; }); + + let userResources = await requestAPI("/user/resources", "GET"); + let userInstances = await requestAPI("/user/instances", "GET"); + d.querySelector("#cores").max = userResources.avail.cores; + d.querySelector("#memory").max = userResources.avail.memory; + d.querySelector("#vmid").min = userInstances.vmid.min; + d.querySelector("#vmid").max = userInstances.vmid.max; } \ No newline at end of file diff --git a/scripts/instance.js b/scripts/instance.js index 2f6c601..a2ef802 100644 --- a/scripts/instance.js +++ b/scripts/instance.js @@ -1,5 +1,6 @@ import {requestPVE, requestAPI, goToPage, goToURL, instances, nodes} from "./utils.js"; import {alert, dialog} from "./dialog.js"; +import {PVE} from "../vars.js" export class Instance extends HTMLElement { constructor () { @@ -168,7 +169,7 @@ export class Instance extends HTMLElement { if (!this.actionLock && this.status === "running") { let data = {console: `${this.type === "qemu" ? "kvm" : "lxc"}`, vmid: this.vmid, vmname: this.name, node: this.node.name, resize: "off", cmd: ""}; data[`${this.type === "qemu" ? "novnc" : "xtermjs"}`] = 1; - goToURL("https://pve.tronnet.net", data, true); + goToURL(PVE, data, true); } } diff --git a/scripts/login.js b/scripts/login.js index 007ea95..c86a251 100644 --- a/scripts/login.js +++ b/scripts/login.js @@ -1,4 +1,4 @@ -import {requestTicket, NetworkError, goToPage, deleteAllCookies, requestPVE} from "./utils.js"; +import {requestTicket, goToPage, deleteAllCookies, requestPVE} from "./utils.js"; import {alert} from "./dialog.js"; window.addEventListener("DOMContentLoaded", init); diff --git a/scripts/utils.js b/scripts/utils.js index 3fbd6b0..cb08be8 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -197,6 +197,5 @@ export function getURIData () { } export async function deleteAllCookies () { - document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/;domain=.client.tronnet.net;"); }); await requestAPI("/ticket", "DELETE"); } \ No newline at end of file diff --git a/vars.js.template b/vars.js.template index a481a28..8db649e 100644 --- a/vars.js.template +++ b/vars.js.template @@ -1 +1,2 @@ -export const API = "https://client.mydomain.example/api"; // the proxmox-aas api \ No newline at end of file +export const API = "https://client.mydomain.example/api"; // the proxmox-aas api +export const PVE = "https://pve.mydomain.example"; // the proxmox api \ No newline at end of file