From 3bb41bb9cf2ebcdd9aa0bbaa70547d059e97690d Mon Sep 17 00:00:00 2001 From: alan <67932758+alan16742@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:04:33 +0800 Subject: [PATCH 1/3] fix: orderby url encode --- back-end-cf/index.js | 2 +- front-end/index.html | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/back-end-cf/index.js b/back-end-cf/index.js index 2aa1c0d3..9bc676d6 100644 --- a/back-end-cf/index.js +++ b/back-end-cf/index.js @@ -213,7 +213,7 @@ async function fetchFiles(path, passwd, skipToken, orderby) { const accessToken = await fetchAccessToken(); const expand = [ '/children?select=name,size,parentReference,lastModifiedDateTime,@microsoft.graph.downloadUrl', - orderby ? `&$orderby=${orderby}` : '', + orderby ? `&$orderby=${encodeURIComponent(orderby)}` : '', skipToken ? `&skiptoken=${skipToken}` : '', ].join(''); const uri = OAUTH.apiUrl + path + expand; diff --git a/front-end/index.html b/front-end/index.html index 70e980fa..baa6a2a5 100644 --- a/front-end/index.html +++ b/front-end/index.html @@ -3,8 +3,8 @@
@@ -847,8 +847,8 @@ if (page.orderby) { // Not changing file cache, so file tree order is untouched. - const sortField = page.orderby.split(' ').shift(); - const files = page.files.toSorted((a, b) => + const sortField = page.orderby.split(' ').shift().replace('lastModifiedDateTime', 'time'); + const files = page.files.slice().sort((a, b) => a[sortField] < b[sortField] ? -1 : 1 ); if (page.orderby.includes('desc')) { @@ -1627,7 +1627,7 @@ window.fileCache.get(`${loadedPages.parent}/.password`), { skipToken: loadedPages.skipToken, - // orderby: loadedPages.orderby, + orderby: loadedPages.orderby?.replace('time', 'lastModifiedDateTime'), } ), window.api.headers, @@ -1853,8 +1853,6 @@ }); } - // Currently Microsoft API only supports sort by name, with a broken back end sorting, we only make the UI sorted. - // see https://stackoverflow.com/questions/71395284/ordering-the-driveitems-from-the-graph-api-only-possible-on-name-property function sortList(clickedElem) { const loadedPages = window.fileCache.get( window.backForwardCache.current @@ -1866,7 +1864,12 @@ ? 'desc' : 'asc'; loadedPages.orderby = `${sortField} ${sortOrder}`; - renderFileList(loadedPages); + if (loadedPages.skipToken) { + window.fileCache.set(window.backForwardCache.current, false); + fetchFileList(window.backForwardCache.current, loadedPages.orderby.replace('time', 'lastModifiedDateTime')); + } else { + renderFileList(loadedPages); + } } function fetchFileList(path, orderby) { @@ -1893,9 +1896,8 @@ window.api.url, window.api.formatPayload( path, - window.fileCache.get(`${path}/.password`) - // Orderby is not working, do not send it. - // { orderby: orderby } + window.fileCache.get(`${path}/.password`), + { orderby: orderby } ), window.api.headers, (data) => { From f6d5510d09eacdf8cdfbb40a83cffc8587774c03 Mon Sep 17 00:00:00 2001 From: alan <67932758+alan16742@users.noreply.github.com> Date: Tue, 29 Oct 2024 21:09:42 +0800 Subject: [PATCH 2/3] fix: Business Edition Compatible --- back-end-cf/index.js | 2 +- front-end/index.html | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/back-end-cf/index.js b/back-end-cf/index.js index 9bc676d6..199e3f98 100644 --- a/back-end-cf/index.js +++ b/back-end-cf/index.js @@ -213,7 +213,7 @@ async function fetchFiles(path, passwd, skipToken, orderby) { const accessToken = await fetchAccessToken(); const expand = [ '/children?select=name,size,parentReference,lastModifiedDateTime,@microsoft.graph.downloadUrl', - orderby ? `&$orderby=${encodeURIComponent(orderby)}` : '', + orderby ? `&orderby=${encodeURIComponent(orderby)}` : '', skipToken ? `&skiptoken=${skipToken}` : '', ].join(''); const uri = OAUTH.apiUrl + path + expand; diff --git a/front-end/index.html b/front-end/index.html index baa6a2a5..eca5f5f9 100644 --- a/front-end/index.html +++ b/front-end/index.html @@ -6,6 +6,7 @@ SCF_GATEWAY: '//tight-bar-e3b3.logi.workers.dev', // Worker 或云函数网关地址 SITE_NAME: 'FODI', // 站点名称 PRELOAD: false, // 是否预加载文件列表,文件夹非常少才建议开启 + IS_BUSINESS: false, // 是否为商业版用户 }; @@ -1864,12 +1865,13 @@ ? 'desc' : 'asc'; loadedPages.orderby = `${sortField} ${sortOrder}`; - if (loadedPages.skipToken) { - window.fileCache.set(window.backForwardCache.current, false); - fetchFileList(window.backForwardCache.current, loadedPages.orderby.replace('time', 'lastModifiedDateTime')); - } else { + const noSortRequest = (window.GLOBAL_CONFIG.IS_BUSINESS && sortField !== 'name') || !loadedPages.skipToken; + if (noSortRequest) { renderFileList(loadedPages); + return; } + window.fileCache.set(window.backForwardCache.current, false); + fetchFileList(window.backForwardCache.current, loadedPages.orderby.replace('time', 'lastModifiedDateTime')); } function fetchFileList(path, orderby) { From fdcc584a253df9ad2be13a53a96f1065f1e5fabe Mon Sep 17 00:00:00 2001 From: LOGI <18008498+vcheckzen@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:05:52 +0800 Subject: [PATCH 3/3] Update index.html --- front-end/index.html | 49 ++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/front-end/index.html b/front-end/index.html index eca5f5f9..1f5d875b 100644 --- a/front-end/index.html +++ b/front-end/index.html @@ -3,10 +3,10 @@ @@ -848,8 +848,8 @@ if (page.orderby) { // Not changing file cache, so file tree order is untouched. - const sortField = page.orderby.split(' ').shift().replace('lastModifiedDateTime', 'time'); - const files = page.files.slice().sort((a, b) => + const sortField = page.orderby.split(' ').shift(); + const files = page.files.toSorted((a, b) => a[sortField] < b[sortField] ? -1 : 1 ); if (page.orderby.includes('desc')) { @@ -886,10 +886,10 @@ fileWrapper.querySelector('i').className = `zmdi zmdi-${type}`; fileWrapper.querySelector('.name').innerText = name; fileWrapper.querySelector('.time').innerText = formatDate(time); - const formattedSize = formatSize(size); - fileWrapper.querySelector('.size .value').innerText = - formattedSize[0]; - fileWrapper.querySelector('.size .unit').innerText = formattedSize[1]; + [ + fileWrapper.querySelector('.size .value').innerText, + fileWrapper.querySelector('.size .unit').innerText, + ] = formatSize(size); addFileListLineListener( fileWrapper.querySelector('.row.file-wrapper'), path, @@ -1628,7 +1628,7 @@ window.fileCache.get(`${loadedPages.parent}/.password`), { skipToken: loadedPages.skipToken, - orderby: loadedPages.orderby?.replace('time', 'lastModifiedDateTime'), + orderby: loadedPages.orderby, } ), window.api.headers, @@ -1865,13 +1865,15 @@ ? 'desc' : 'asc'; loadedPages.orderby = `${sortField} ${sortOrder}`; - const noSortRequest = (window.GLOBAL_CONFIG.IS_BUSINESS && sortField !== 'name') || !loadedPages.skipToken; + const noSortRequest = + (window.GLOBAL_CONFIG.IS_BUSINESS && sortField !== 'name') || + !loadedPages.skipToken; if (noSortRequest) { renderFileList(loadedPages); return; } - window.fileCache.set(window.backForwardCache.current, false); - fetchFileList(window.backForwardCache.current, loadedPages.orderby.replace('time', 'lastModifiedDateTime')); + window.fileCache.set(loadedPages.parent, false); + fetchFileList(loadedPages.parent, loadedPages.orderby); } function fetchFileList(path, orderby) { @@ -1899,7 +1901,7 @@ window.api.formatPayload( path, window.fileCache.get(`${path}/.password`), - { orderby: orderby } + { orderby } ), window.api.headers, (data) => { @@ -2104,12 +2106,19 @@ root: '/', url: window.GLOBAL_CONFIG.SCF_GATEWAY, method: 'POST', - formatPayload: (path, passwd, kvs) => - JSON.stringify({ - path, - passwd, - ...kvs, - }), + formatPayload: (path, passwd, kvs) => { + const payload = { path, passwd, ...kvs }; + const orderby = payload.orderby; + if ( + window.GLOBAL_CONFIG.IS_BUSINESS && + !orderby?.startsWith('name') + ) { + delete payload['orderby']; + } else if (orderby) { + payload.orderby = orderby.replace('time', 'lastModifiedDateTime'); + } + return JSON.stringify(payload); + }, headers: { 'Content-type': 'application/json; charset=utf-8', },