From 577eea5fa4e5f6a6743f5326aec21208a1b25344 Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 1 Jun 2023 22:22:36 +0800 Subject: [PATCH] chore: ui js refactor --- assets/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/assets/index.js b/assets/index.js index dfbe98a..05f6c48 100644 --- a/assets/index.js +++ b/assets/index.js @@ -218,7 +218,7 @@ Uploader.runQueue = async () => { let uploader = Uploader.queues.shift(); if (!Uploader.auth) { Uploader.auth = true; - const success = await login(true); + const success = await checkAuth(true); Uploader.auth = !!success; } uploader.ajax(); @@ -439,7 +439,7 @@ function setupAuth() { } else { const $loginBtn = document.querySelector(".login-btn"); $loginBtn.classList.remove("hidden"); - $loginBtn.addEventListener("click", () => login(true)); + $loginBtn.addEventListener("click", () => checkAuth(true)); } } @@ -573,7 +573,7 @@ async function deletePath(index) { async function doDeletePath(name, url, cb) { if (!confirm(`Delete \`${name}\`?`)) return; try { - await login(); + await checkAuth(); const res = await fetch(url, { method: "DELETE", }); @@ -613,7 +613,7 @@ async function doMovePath(fileUrl) { const newFileUrl = fileUrlObj.origin + prefix + newPath.split("/").map(encodeURIComponent).join("/"); try { - await login(); + await checkAuth(); const res1 = await fetch(newFileUrl, { method: "HEAD", }); @@ -651,7 +651,7 @@ async function saveChange() { } } -async function login(alert = false) { +async function checkAuth(alert = false) { if (!DATA.auth) return; try { const res = await fetch(baseUrl(), { @@ -663,7 +663,7 @@ async function login(alert = false) { $userBtn.title = ""; return true; } catch (err) { - let message = `Cannot login, ${err.message}`; + let message = `Check auth, ${err.message}`; if (alert) { alert(message); } else { @@ -679,7 +679,7 @@ async function login(alert = false) { async function createFolder(name) { const url = newUrl(name); try { - await login(); + await checkAuth(); const res = await fetch(url, { method: "MKCOL", }); @@ -693,7 +693,7 @@ async function createFolder(name) { async function createFile(name) { const url = newUrl(name); try { - await login(); + await checkAuth(); const res = await fetch(url, { method: "PUT", body: "",