Added Logo

Added Document Download
Added zipjs
This commit is contained in:
2023-12-11 12:04:32 +01:00
parent 6ffc4f01d9
commit 5503c572f1
10 changed files with 528 additions and 22 deletions

View File

@@ -2,6 +2,11 @@
<div>
<div class="controlHeader">
<UButton @click="uploadModalOpen = true">Hochladen</UButton>
<UButton
@click="downloadSelected"
class="ml-2"
:disabled="documents.filter(doc => doc.selected).length === 0"
>Herunterladen</UButton>
<UModal
v-model="uploadModalOpen"
>
@@ -69,11 +74,11 @@
fullscreen
>
<UCard class="h-full">
<embed
{{selectedDocument}}
<!-- <embed
class="bigPreview mb-3"
:src="selectedDocument.url"
/>
/>-->
<UBadge
v-for="tag in selectedDocument.tags"
@@ -107,7 +112,7 @@
>
<template #item="{item}">
<div class="documentList">
<div
<a
v-if="documents.filter(doc => doc.folder === item.label).length > 0"
v-for="document in documents.filter(doc => doc.folder === item.label)"
class="documentListItem"
@@ -122,6 +127,10 @@
>
<UIcon name="i-heroicons-eye-solid" />
</UButton>
<UToggle
v-model="document.selected"
class="ml-2"
/>
<!-- {{document.name}}<br>-->
<!-- <UBadge
@@ -134,7 +143,7 @@
variant="outline"
>{{document.state}}</UBadge>-->
</div>
</a>
<div v-else>
<p>Keine Dokumente in diesem Ordner</p>
<UButton
@@ -153,6 +162,8 @@
<script setup>
import {BlobReader, BlobWriter, ZipWriter} from "@zip.js/zip.js";
definePageMeta({
middleware: "auth"
})
@@ -230,19 +241,24 @@ const uploadFile = async () => {
const changeFolder = async () => {
console.log("Change Folder")
console.log(selectedDocument.value.path)
console.log(selectedDocument.value)
let filename = selectedDocument.value.path.split("/")[2]
let oldPath = selectedDocument.value.path
let newPath = `${user.value.app_metadata.tenant}/${newFolder.value}/${filename}`
console.log(oldPath)
console.log(newPath)
const { data, error } = await supabase
.storage
.from('documents')
.move(selectedDocument.value.path, newPath )
.move(oldPath,newPath )
console.log(data)
console.log(error)
if(error) {
console.log(error)
} else {
console.log(data)
}
}
@@ -257,6 +273,67 @@ const openDocument = async (document) => {
showDocumentModal.value = true
}
const downloadSelected = async () => {
const bucket = "documents";
let files = []
documents.value.filter(doc => doc.selected).forEach(doc => files.push(doc.path))
console.log(files)
// If there are no files in the folder, throw an error
if (!files || !files.length) {
throw new Error("No files to download");
}
const promises = [];
// Download each file in the folder
files.forEach((file) => {
promises.push(
supabase.storage.from(bucket).download(`${file}`)
);
});
// Wait for all the files to download
const response = await Promise.allSettled(promises);
// Map the response to an array of objects containing the file name and blob
const downloadedFiles = response.map((result, index) => {
if (result.status === "fulfilled") {
return {
name: files[index],
blob: result.value.data,
};
}
});
// Create a new zip file
const zipFileWriter = new BlobWriter("application/zip");
const zipWriter = new ZipWriter(zipFileWriter, { bufferedWrite: true });
// Add each file to the zip file
downloadedFiles.forEach((downloadedFile) => {
if (downloadedFile) {
zipWriter.add(downloadedFile.name, new BlobReader(downloadedFile.blob));
}
});
// Download the zip file
const url = URL.createObjectURL(await zipWriter.close());
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", "documents.zip");
document.body.appendChild(link);
link.click();
}
</script>
<style scoped>