Skip to content

Commit

Permalink
Upload working
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym committed Dec 10, 2023
1 parent d57e5bf commit 96242f7
Show file tree
Hide file tree
Showing 7 changed files with 544 additions and 49 deletions.
1 change: 1 addition & 0 deletions packages/dashboard-v2/quasar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = configure(function (/* ctx */) {
boot: [
'axios',
'auth',
'bus',
],

// https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#css
Expand Down
93 changes: 83 additions & 10 deletions packages/dashboard-v2/src/appUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,26 @@ export const bytesToMegabytes = (bytes) => {
return Math.round(bytes / Math.pow(1024, 2));
};

export const downloadFile = (bucket, file, previewConfig, onDownloadProgress, abortControl) => {
export const encode = (key) => {
return btoa(unescape(encodeURIComponent(key)));
};

export const decode = (key) => {
return decodeURIComponent(escape(atob(key)));
};

export const apiHandler = {
createFolder: (key, bucket) => {
return api.post(`/buckets/${bucket}/folder`, {
key: encode(key)
})
},
deleteObject: (key, bucket) => {
return api.post(`/buckets/${bucket}/delete`, {
key: encode(key)
})
},
downloadFile: (bucket, file, previewConfig, onDownloadProgress, abortControl) => {
const extra = {};
if (previewConfig.downloadType === "objectUrl" || previewConfig.downloadType === "blob") {
extra.responseType = "arraybuffer";
Expand All @@ -66,12 +85,66 @@ export const downloadFile = (bucket, file, previewConfig, onDownloadProgress, ab
`/buckets/${bucket}/${encode(file.key)}`,
extra
);
}

export const encode = (key) => {
return btoa(unescape(encodeURIComponent(key)));
};

export const decode = (key) => {
return decodeURIComponent(escape(atob(key)));
};
},
// renameObject: (oldName, newName) => {
// return axios.post(`/buckets/${store.state.activeBucket}/move`, {
// oldKey: encodeKey(oldName, store.state.currentFolder),
// newKey: encodeKey(newName, store.state.currentFolder)
// })
// },
// updateMetadata: (file, metadata) => {
// const filePath = encodeKey(file.name, getCurrentFolder())
//
// return axios.post(
// `/buckets/${store.state.activeBucket}/${filePath}`,
// {
// customMetadata: metadata
// }
// )
// },
multipartCreate: (file, key, bucket) => {
return api.post(`/buckets/${bucket}/multipart/create`, null, {
params: {
key: encode(key),
httpMetadata: encode(JSON.stringify({
contentType: file.type
}))
}
})
},
multipartComplete: (file, key, bucket, parts, uploadId) => {
return api.post(`/buckets/${bucket}/multipart/complete`, {
key: encode(key),
uploadId,
parts
})
},
multipartUpload: (uploadId, partNumber, bucket, key, chunk, callback) => {
return api.post(`/buckets/${bucket}/multipart/upload`, chunk, {
params: {
key: encode(key),
uploadId,
partNumber
},
onUploadProgress: callback,
headers: {
'Content-Type': 'multipart/form-data'
}
})
},
uploadObjects: (file, key, bucket, callback) => {
console.log(key)
return api.post(`/buckets/${bucket}/upload`, file, {
params: {
key: encode(key),
httpMetadata: encode(JSON.stringify({
contentType: file.type
}))
},
headers: {
'Content-Type': 'multipart/form-data'
},
onUploadProgress: callback
})
},
}
12 changes: 12 additions & 0 deletions packages/dashboard-v2/src/boot/bus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { EventBus } from 'quasar'
import { boot } from 'quasar/wrappers'

export default boot(({ app }) => {
const bus = new EventBus()

// for Options API
app.config.globalProperties.$bus = bus

// for Composition API
app.provide('bus', bus)
})
4 changes: 2 additions & 2 deletions packages/dashboard-v2/src/components/preview/FilePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import PdfViewer from "components/preview/PdfViewer.vue";
import LogGz from "components/preview/logGz.vue";
import EmailViewer from "components/preview/EmailViewer.vue";
import { parseMarkdown } from "src/parsers/markdown";
import { bytesToMegabytes, downloadFile, ROOT_FOLDER } from "src/appUtils";
import { bytesToMegabytes, apiHandler, ROOT_FOLDER } from "src/appUtils";
import { useQuasar } from "quasar";
export default {
Expand Down Expand Up @@ -221,7 +221,7 @@ export default {
if (previewConfig) {
this.type = previewConfig.type;
const response = await downloadFile(this.$route.params.bucket, file, previewConfig, (progressEvent) => {
const response = await apiHandler.downloadFile(this.$route.params.bucket, file, previewConfig, (progressEvent) => {
this.downloadProgress = progressEvent.loaded / progressEvent.total;
}, this.abortControl);
Expand Down
Loading

0 comments on commit 96242f7

Please sign in to comment.