Implemented new Backend in E-Mail Sending
Implemented Blob Return Method for File Download
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ const setupPage = async () => {
|
||||
} else {
|
||||
emailData.value.account = emailAccounts.value[0].id
|
||||
|
||||
preloadedContent.value = `<p></p><p></p><p></p>${profileStore.activeProfile.emailSignature || ""}`
|
||||
preloadedContent.value = `<p></p><p></p><p></p>${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"})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user