From 099dbb753ea5a3f8db63a21f9c6f7332b5aa9681 Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Mon, 18 Dec 2023 09:49:38 +0000 Subject: [PATCH] Add folder deletion and bump itty-router-openapi --- packages/dashboard-v2/src/appUtils.js | 78 +++++++++++ .../src/components/files/FileOptions.vue | 131 ++++++++++++++++++ .../src/pages/files/FilesFolderPage.vue | 99 +++---------- worker/package-lock.json | 8 +- worker/package.json | 2 +- worker/src/buckets/api/listObjects.ts | 8 +- .../src/buckets/api/multipart/createUpload.ts | 4 +- worker/src/buckets/api/putObject.ts | 4 +- 8 files changed, 241 insertions(+), 93 deletions(-) create mode 100644 packages/dashboard-v2/src/components/files/FileOptions.vue diff --git a/packages/dashboard-v2/src/appUtils.js b/packages/dashboard-v2/src/appUtils.js index 6ef4a53..dd91d24 100644 --- a/packages/dashboard-v2/src/appUtils.js +++ b/packages/dashboard-v2/src/appUtils.js @@ -1,4 +1,5 @@ import { api } from "boot/axios"; +import { useMainStore } from "stores/main-store"; export const ROOT_FOLDER = "IA==" // IA== is a space @@ -147,4 +148,81 @@ export const apiHandler = { onUploadProgress: callback }) }, + fetchFile: async (bucket, prefix, delimiter = '/') => { + const mainStore = useMainStore(); + let truncated = true + let cursor = null + let contentFiles = [] + let contentFolders = [] + + while (truncated) { + const response = await api.get(`/buckets/${bucket}?include=customMetadata&include=httpMetadata`, { + params: { + delimiter: delimiter, + prefix: prefix && prefix !== '/' ? encode(prefix) : '', + cursor: cursor + } + }) + + truncated = response.data.truncated + cursor = response.data.cursor + + if (response.data.objects) { + const files = response.data.objects.filter(function(obj) { + return !(obj.key.endsWith('/') && delimiter !== '') && obj.key !== prefix // Remove selected folder when delimiter is defined + }).map(function(obj) { + const date = new Date(obj.uploaded) + + return { + ...obj, + hash: encode(obj.key), + name: obj.key.replace(prefix, ''), + lastModified: timeSince(date), + timestamp: date.getTime(), + size: bytesToSize(obj.size), + sizeRaw: obj.size, + type: 'file', + icon: 'article', + color: 'grey', + } + }).filter(obj => { + // Remove hidden files + return !(mainStore.showHiddenFiles !== true && obj.name.startsWith('.')) + }) + + for (const f of files) { + contentFiles.push(f) + } + } + + if (response.data.delimitedPrefixes) { + const folders = response.data.delimitedPrefixes.map(function (obj) { + return { + name: obj.replace(prefix, ''), + hash: encode(obj.key), + key: obj, + lastModified: '--', + timestamp: 0, + size: '--', + sizeRaw: 0, + type: 'folder', + icon: 'folder', + color: 'orange', + } + }).filter(obj => { + // Remove hidden files + return !(mainStore.showHiddenFiles !== true && obj.name.startsWith('.')) + }) + + for (const f of folders) { + contentFolders.push(f) + } + } + } + + return [ + ...contentFolders, + ...contentFiles + ] + } } diff --git a/packages/dashboard-v2/src/components/files/FileOptions.vue b/packages/dashboard-v2/src/components/files/FileOptions.vue new file mode 100644 index 0000000..74ed684 --- /dev/null +++ b/packages/dashboard-v2/src/components/files/FileOptions.vue @@ -0,0 +1,131 @@ + + + + + diff --git a/packages/dashboard-v2/src/pages/files/FilesFolderPage.vue b/packages/dashboard-v2/src/pages/files/FilesFolderPage.vue index 4446e26..483cdd3 100644 --- a/packages/dashboard-v2/src/pages/files/FilesFolderPage.vue +++ b/packages/dashboard-v2/src/pages/files/FilesFolderPage.vue @@ -17,8 +17,7 @@ :hide-pagination="true" :rows-per-page-options="[0]" column-sort-order="da" - :flat="true" - @rowClick="rowClick"> + :flat="true"> -