From fbdcc015fe91c9d3d367daaa17fc9d6470eb9df8 Mon Sep 17 00:00:00 2001
From: alan <67932758+alan16742@users.noreply.github.com>
Date: Tue, 22 Oct 2024 17:33:53 +0800
Subject: [PATCH 1/3] fix: download api add
---
back-end-cf/index.js | 22 ++++++++++------------
front-end/index.html | 4 ----
2 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/back-end-cf/index.js b/back-end-cf/index.js
index 7eecdc76..06dd2e87 100644
--- a/back-end-cf/index.js
+++ b/back-end-cf/index.js
@@ -43,7 +43,7 @@ async function handleRequest(request) {
? ''
: decodeURIComponent(requestUrl.pathname));
// Download a file
- if (file) {
+ if (file && request.method === 'GET') {
const fileName = file.split('/').pop();
if (fileName.toLowerCase() === PASSWD_FILENAME.toLowerCase()) {
throw new Error('access denied');
@@ -181,11 +181,11 @@ async function fetchFiles(path, fileName, passwd, authOnly) {
const parent = path || '/';
if (path === '/') path = '';
if (path || EXPOSE_PATH)
- path = ':' + encodeURIComponent(EXPOSE_PATH + path) + ':';
+ path = ':' + EXPOSE_PATH + path;
const accessToken = await fetchAccessToken();
- const expand =
- '/children?select=name,size,parentReference,lastModifiedDateTime,@microsoft.graph.downloadUrl&$top=200';
+ const expand = fileName ? `/${fileName}` :
+ ':/children?select=name,size,parentReference,lastModifiedDateTime,@microsoft.graph.downloadUrl&$top=200';
const uri = OAUTH.apiUrl + path + expand;
let pageRes = await getContent(uri, {
@@ -195,7 +195,7 @@ async function fetchFiles(path, fileName, passwd, authOnly) {
throw new Error('request failed');
}
- let children = pageRes.value;
+ let children = pageRes?.value || pageRes;
while (pageRes['@odata.nextLink']) {
pageRes = await getContent(pageRes['@odata.nextLink'], {
Authorization: 'Bearer ' + accessToken,
@@ -203,6 +203,11 @@ async function fetchFiles(path, fileName, passwd, authOnly) {
children = children.concat(pageRes.value);
}
+ // Download a file
+ if (fileName) {
+ return children?.['@microsoft.graph.downloadUrl'];
+ }
+
const pwFile = children.find((file) => file.name === PASSWD_FILENAME);
let authPassed = false;
if (pwFile) {
@@ -231,13 +236,6 @@ async function fetchFiles(path, fileName, passwd, authOnly) {
});
}
- // Download a file
- if (fileName) {
- return children.find(
- (file) => file.name === decodeURIComponent(fileName)
- )?.['@microsoft.graph.downloadUrl'];
- }
-
// List a folder
return JSON.stringify({
parent,
diff --git a/front-end/index.html b/front-end/index.html
index baf1076a..676cc0b9 100644
--- a/front-end/index.html
+++ b/front-end/index.html
@@ -18,10 +18,6 @@
type="module"
src="//lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/ionicons/4.6.3/ionicons/ionicons.esm.js"
>
-