From 30da08689d364da12cbcae57fa53c56d52e1eb44 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Fri, 12 Sep 2025 17:42:24 +0200 Subject: [PATCH] Implemented new Backend in E-Mail Sending Implemented Blob Return Method for File Download --- composables/useFiles.ts | 20 ++++++++++++++------ pages/email/new.vue | 28 +++++++++++++++++++--------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/composables/useFiles.ts b/composables/useFiles.ts index 11a02ce..657824d 100644 --- a/composables/useFiles.ts +++ b/composables/useFiles.ts @@ -83,7 +83,7 @@ export const useFiles = () => { return res.files[0] } - const downloadFile = async (id?: string, ids?: string[]) => { + const downloadFile = async (id?: string, ids?: string[], returnAsBlob: Boolean = false) => { const url = id ? `/api/files/download/${id}` : `/api/files/download` const body = ids ? { ids } : undefined @@ -109,11 +109,19 @@ export const useFiles = () => { // Direkt speichern const blob = res._data as Blob - const link = document.createElement("a") - link.href = URL.createObjectURL(blob) - link.download = filename - link.click() - URL.revokeObjectURL(link.href) + + if(returnAsBlob) { + return blob + } else { + const link = document.createElement("a") + link.href = URL.createObjectURL(blob) + link.download = filename + link.click() + URL.revokeObjectURL(link.href) + } + + + } diff --git a/pages/email/new.vue b/pages/email/new.vue index 50d3ae2..2c38b97 100644 --- a/pages/email/new.vue +++ b/pages/email/new.vue @@ -31,7 +31,7 @@ const setupPage = async () => { } else { emailData.value.account = emailAccounts.value[0].id - preloadedContent.value = `

${profileStore.activeProfile.emailSignature || ""}` + preloadedContent.value = `

${auth.profile.email_signature || ""}` //Check Query if(route.query.to) emailData.value.to = route.query.to @@ -133,25 +133,35 @@ const sendEmail = async () => { for await (const doc of loadedDocuments.value) { - const {data,error} = await supabase.storage.from("filesdev").download(doc.path) + //const {data,error} = await supabase.storage.from("filesdev").download(doc.path) + + const res = await useFiles().downloadFile(doc.id, null, true) body.attachments.push({ filename: doc.path.split("/")[doc.path.split("/").length -1], - content: await blobToBase64(data), - contentType: data.type, + content: await blobToBase64(res), + contentType: res.type, encoding: "base64", contentDisposition: "attachment" }) } - const { data, error } = await supabase.functions.invoke('send_email', { - body + const res = await useNuxtApp().$api("/api/emailasuser/send",{ + method: "POST", + body: body, }) - if(error) { + + console.log(res) + + + /*const { data, error } = await supabase.functions.invoke('send_email', { + body + })*/ + if(!res.success) { toast.add({title: "Fehler beim Absenden der E-Mail", color: "rose"}) - } else if(data) { - router.push("/") + } else { + //router.push("/") toast.add({title: "E-Mail zum Senden eingereiht"}) }