From 658c3ed5b668f268dbb7ff7cc0229cac6f7dcd8a Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Sun, 17 Sep 2023 20:25:05 +0100 Subject: [PATCH] Add support for folders with more than 1000 files or truncated by the r2 api --- README.md | 1 - READMEes.md | 1 - READMEfr.md | 1 - READMEpt.md | 1 - packages/dashboard/src/api.js | 109 ++++++++++++++++++++-------------- 5 files changed, 64 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index e94a2b8..da40192 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,6 @@ wrangler publish - Delete folders - Image thumbnail's using Cloudflare workers - Tooltip when hovering a file with absolute time in "x days time ago" format -- Automatically load more files, when the bottom is reached (current limit is 1000 files) - bundle bootstrap icons instead of importing ## Known issues diff --git a/READMEes.md b/READMEes.md index 5049790..89e3b3d 100644 --- a/READMEes.md +++ b/READMEes.md @@ -62,7 +62,6 @@ wrangler publish - Eliminar carpetas - Miniaturas de imágenes usando workers de Cloudflare - Información sobre herramientas al pasar el ratón por encima de un archivo con el formato "hace x días" -- Cargar automáticamente más archivos cuando se alcance la parte inferior (el límite actual es de 1000 archivos) - Agrupar íconos de bootstrap en lugar de importarlos ## Problemas conocidos diff --git a/READMEfr.md b/READMEfr.md index 9cb9a62..ec39a60 100644 --- a/READMEfr.md +++ b/READMEfr.md @@ -62,7 +62,6 @@ wrangler publish - Supprimer des dossiers - Miniatures d'images avec les travailleurs Cloudflare - Info-bulle lors du survol d'un fichier avec le format "il y a x jours" -- Chargement automatique de plus de fichiers lorsque le bas de la liste est atteint (la limite actuelle est de 1000 fichiers) - Regrouper les icônes Bootstrap au lieu de les importer ## Problèmes connus diff --git a/READMEpt.md b/READMEpt.md index 29beb7d..219ccf7 100644 --- a/READMEpt.md +++ b/READMEpt.md @@ -61,7 +61,6 @@ wrangler publish - Excluir pastas - Miniaturas de imagens usando workers do Cloudflare - Informações de ferramentas ao passar o mouse sobre um arquivo no formato "há x dias" -- Carregar automaticamente mais arquivos quando chegar ao final (o limite atual é de 1000 arquivos) - Agrupar ícones do Bootstrap em vez de importá-los ## Problemas Conhecidos diff --git a/packages/dashboard/src/api.js b/packages/dashboard/src/api.js index 8f31e7a..b87ee41 100644 --- a/packages/dashboard/src/api.js +++ b/packages/dashboard/src/api.js @@ -115,58 +115,77 @@ const apiHandler = { listObjects: async () => { const prefix = getCurrentFolder() - const response = await axios.get(`/api/buckets/${store.state.activeBucket}?include=customMetadata&include=httpMetadata`, { - params: { - delimiter: '/', - prefix: encodeKey(prefix) - // limit: 1000 TODO: only use this parameter on 1.0.3 or above - } - }) - - let files = [] - if (response.data.objects) { - files = response.data.objects.filter(function (obj) { - return !obj.key.endsWith('/') - }) - files = files.map(function (obj) { - const name = obj.key.replace(prefix, '') - const extension = name.split('.').pop() - - return { - ...obj, - name, - path: store.state.currentFolder, - extension, - preview: preview.getType(name), - isFile: true, - hash: encodeKey(name) + let filesConc = [] + let foldersConc = [] + + let truncated = true + let cursor = null + + while (truncated) { + const response = await axios.get(`/api/buckets/${store.state.activeBucket}?include=customMetadata&include=httpMetadata`, { + params: { + delimiter: '/', + prefix: encodeKey(prefix), + cursor: cursor } - }).filter(obj => { - return !(store.state.config?.showHiddenFiles !== true && obj.name.startsWith('.')) }) - } - let folders = [] - if (response.data.delimitedPrefixes) { - folders = response.data.delimitedPrefixes.map(function (obj) { - const split = obj.split('/') - const name = split[split.length - 2] - - return { - name, - path: store.state.currentFolder, - key: obj, - isFolder: true, - hash: encodeKey(obj) + truncated = response.data.truncated + cursor = response.data.cursor + + let files = [] + if (response.data.objects) { + files = response.data.objects.filter(function (obj) { + return !obj.key.endsWith('/') + }) + files = files.map(function (obj) { + const name = obj.key.replace(prefix, '') + const extension = name.split('.').pop() + + return { + ...obj, + name, + path: store.state.currentFolder, + extension, + preview: preview.getType(name), + isFile: true, + hash: encodeKey(name) + } + }).filter(obj => { + return !(store.state.config?.showHiddenFiles !== true && obj.name.startsWith('.')) + }) + + for (const f of files) { + filesConc.push(f) } - }).filter(obj => { - return !(store.state.config?.showHiddenFiles !== true && obj.name.startsWith('.')) - }) + } + + let folders = [] + if (response.data.delimitedPrefixes) { + folders = response.data.delimitedPrefixes.map(function (obj) { + const split = obj.split('/') + const name = split[split.length - 2] + + return { + name, + path: store.state.currentFolder, + key: obj, + isFolder: true, + hash: encodeKey(obj) + } + }).filter(obj => { + return !(store.state.config?.showHiddenFiles !== true && obj.name.startsWith('.')) + }) + + for (const f of folders) { + foldersConc.push(f) + } + } } return { - files: files.reverse(), - folders + files: filesConc.reverse(), + folders: foldersConc } } }