From f1625a435c0176b9440e99a0da63ac34ba56b939 Mon Sep 17 00:00:00 2001 From: alan <67932758+alan16742@users.noreply.github.com> Date: Sat, 21 Sep 2024 16:45:01 +0800 Subject: [PATCH] support upload empty file --- back-end-cf/index.js | 8 +++----- front-end/index.html | 32 ++------------------------------ 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/back-end-cf/index.js b/back-end-cf/index.js index 9c8591e4..e4c23ad8 100644 --- a/back-end-cf/index.js +++ b/back-end-cf/index.js @@ -43,7 +43,6 @@ const PATH_AUTH_STATES = Object.freeze({ async function handleRequest(request) { let queryString, querySplited, requestPath; - let abnormalWay = false; const returnHeaders = { 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'max-age=3600', @@ -55,10 +54,9 @@ async function handleRequest(request) { queryString = decodeURIComponent( 'file=/' + request.url.split('://')[1].split(/\/(.+)/)[1] ); - abnormalWay = true; } if (queryString) querySplited = queryString.split('='); - if ((querySplited && querySplited[0] === 'file') || abnormalWay) { + if ((querySplited && querySplited[0] === 'file')) { const file = querySplited[1]; const fileName = file.split('/').pop(); if (fileName.toLowerCase() === PASSWD_FILENAME.toLowerCase()) @@ -279,10 +277,10 @@ async function uploadFiles(fileJsonList) { const batchRequest = { requests: fileList.map((file, index) => ({ id: `${index + 1}`, - method: 'POST', + method: file['fileSize'] ? 'POST' : 'PUT', url: `/me/drive/root:${encodeURI( EXPOSE_PATH + file['remotePath'] - )}:/createUploadSession`, + )}${file['fileSize'] ? ':/createUploadSession' : ':/content'}`, headers: { 'Content-Type': 'application/json' }, body: {}, })), diff --git a/front-end/index.html b/front-end/index.html index f320b010..d7c9dd1b 100644 --- a/front-end/index.html +++ b/front-end/index.html @@ -15,9 +15,6 @@ // window.GLOBAL_CONFIG.SCF_GATEWAY += "/fodi/"; // window.GLOBAL_CONFIG.IS_CF = false; // } - // if (location.protocol === 'http:') { - // location.href = location.href.replace(/http/, 'https'); - // } ({ remotePath: `${odPath}/${f.webkitRelativePath || f.name}`, + fileSize: f.size ? 1 : 0, })); function paginate(array, size) { @@ -1737,7 +1709,7 @@ } if (fileSize === 0) { - progressText.innerHTML = `${file.name}: 0 byte, skipped.`; + progressText.innerHTML = `${file.name}: Upload completed!`; } else { progressText.innerHTML += ' Upload completed!'; }