From 29872a7fa9948c862dea417e7c63246797bc9977 Mon Sep 17 00:00:00 2001 From: alan <67932758+alan16742@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:06:44 +0800 Subject: [PATCH 1/2] fix: 401 Unauthorized --- back-end-cf/index.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/back-end-cf/index.js b/back-end-cf/index.js index d2c204c1..43379a31 100644 --- a/back-end-cf/index.js +++ b/back-end-cf/index.js @@ -176,11 +176,23 @@ async function fetchAccessToken() { } async function authenticate(path, passwd) { - const pwFileContent = await downloadFile( + const pwFileRes = await downloadFile( `${path}/${PASSWD_FILENAME}`, null, true - ).then((resp) => (resp.status === 404 ? undefined : resp.text())); + ); + let pwFileContent; + switch (pwFileRes.status) { + case 302: + pwFileContent = pwFileRes.text(); + break; + case 401: + pwFileContent = await getContent(pwFileRes.url); + break; + default: + pwFileContent = undefined; + break; + } if (pwFileContent) { if (passwd !== pwFileContent) { From 8a50d0e3798a54cb17ee6108bf66c36b6e31331a Mon Sep 17 00:00:00 2001 From: LOGI <18008498+vcheckzen@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:34:05 +0800 Subject: [PATCH 2/2] Update index.js --- back-end-cf/index.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/back-end-cf/index.js b/back-end-cf/index.js index 43379a31..5b09ff05 100644 --- a/back-end-cf/index.js +++ b/back-end-cf/index.js @@ -176,23 +176,13 @@ async function fetchAccessToken() { } async function authenticate(path, passwd) { - const pwFileRes = await downloadFile( + const pwFileContent = await downloadFile( `${path}/${PASSWD_FILENAME}`, null, true - ); - let pwFileContent; - switch (pwFileRes.status) { - case 302: - pwFileContent = pwFileRes.text(); - break; - case 401: - pwFileContent = await getContent(pwFileRes.url); - break; - default: - pwFileContent = undefined; - break; - } + ) + .then((resp) => (resp.status === 401 ? cacheFetch(resp.url) : resp)) + .then((resp) => (resp.status === 404 ? undefined : resp.text())); if (pwFileContent) { if (passwd !== pwFileContent) {