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();
} else {
const $loginBtn = document.querySelector(".login-btn");
$loginBtn.classList.remove("hidden");
- $loginBtn.addEventListener("click", () => login(true));
+ $loginBtn.addEventListener("click", () => checkAuth(true));
}
}
async function doDeletePath(name, url, cb) {
if (!confirm(`Delete \`${name}\`?`)) return;
try {
- await login();
+ await checkAuth();
const res = await fetch(url, {
method: "DELETE",
});
const newFileUrl = fileUrlObj.origin + prefix + newPath.split("/").map(encodeURIComponent).join("/");
try {
- await login();
+ await checkAuth();
const res1 = await fetch(newFileUrl, {
method: "HEAD",
});
}
}
-async function login(alert = false) {
+async function checkAuth(alert = false) {
if (!DATA.auth) return;
try {
const res = await fetch(baseUrl(), {
$userBtn.title = "";
return true;
} catch (err) {
- let message = `Cannot login, ${err.message}`;
+ let message = `Check auth, ${err.message}`;
if (alert) {
alert(message);
} else {
async function createFolder(name) {
const url = newUrl(name);
try {
- await login();
+ await checkAuth();
const res = await fetch(url, {
method: "MKCOL",
});
async function createFile(name) {
const url = newUrl(name);
try {
- await login();
+ await checkAuth();
const res = await fetch(url, {
method: "PUT",
body: "",