Skip to content

Commit

Permalink
Merge pull request #53 from alan16742/master
Browse files Browse the repository at this point in the history
support upload empty file
  • Loading branch information
vcheckzen authored Sep 21, 2024
2 parents 89da5a5 + f1625a4 commit 8cc8a86
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
8 changes: 3 additions & 5 deletions back-end-cf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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())
Expand Down Expand Up @@ -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: {},
})),
Expand Down
32 changes: 2 additions & 30 deletions front-end/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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');
// }
</script>
<meta charset="utf-8" />
<meta
Expand Down Expand Up @@ -1446,43 +1443,17 @@
}

if (display === 'preview') {
// document.querySelector('.list-header').style.display = 'none';
// document.querySelector('#file-list').style.display = 'none';
// document.querySelector('.markdown-body').style.display = 'none';
// document.querySelector('.password').style.display = 'none';
// document.querySelector('.preview').style.display = 'initial';
document.querySelector('.preview').dataset.hidden = '0';
} else if (display === 'encrypted') {
// document.querySelector('.list-header').style.display = 'none';
// document.querySelector('#file-list').style.display = 'none';
// document.querySelector('.markdown-body').style.display = 'none';
// document.querySelector('.preview').style.display = 'none';
// document.querySelector('.password-wrapper').style.display = 'initial';
document.querySelector('.password-wrapper').dataset.hidden = '0';
// document.querySelector('#readme').innerHTML = '';
// let content = document.querySelector('.preview .content');
// if (content) {
// document.querySelector('.preview .content').innerHTML = '';
// }
} else if (display === 'upload') {
document.querySelector('.file-upload-progress').innerHTML = '';
document.querySelector('.file-upload-progress').dataset.hidden = '1';
document.querySelector('.file-upload-wrapper').dataset.hidden = '0';
} else {
// document.querySelector('.list-header').style.display = 'initial';
// document.querySelector('#file-list').style.display = 'initial';

document.querySelector('.list-header').dataset.hidden = '0';
document.querySelector('#file-list').dataset.hidden = '0';
document.querySelector('.markdown-body').dataset.hidden = '0';
// document.querySelector('.markdown-body').style.display = 'none';
// document.querySelector('.preview').style.display = 'none';
// document.querySelector('.password').style.display = 'none';
// document.querySelector('#readme').innerHTML = '';
// let content = document.querySelector('.preview .content');
// if (content) {
// document.querySelector('.preview .content').innerHTML = '';
// }
}

document.querySelector('.main').dataset.hidden = '0';
Expand Down Expand Up @@ -1672,6 +1643,7 @@
const odPath = window.backFordwardCache.current;
const upFileList = fileInput.map((f) => ({
remotePath: `${odPath}/${f.webkitRelativePath || f.name}`,
fileSize: f.size ? 1 : 0,
}));

function paginate(array, size) {
Expand Down Expand Up @@ -1750,7 +1722,7 @@
}

if (fileSize === 0) {
progressText.innerHTML = `${file.name}: 0 byte, skipped.`;
progressText.innerHTML = `${file.name}: Upload completed!`;
} else {
progressText.innerHTML += ' Upload completed!';
}
Expand Down

0 comments on commit 8cc8a86

Please sign in to comment.