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]
|
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 url = id ? `/api/files/download/${id}` : `/api/files/download`
|
||||||
const body = ids ? { ids } : undefined
|
const body = ids ? { ids } : undefined
|
||||||
|
|
||||||
@@ -109,11 +109,19 @@ export const useFiles = () => {
|
|||||||
|
|
||||||
// Direkt speichern
|
// Direkt speichern
|
||||||
const blob = res._data as Blob
|
const blob = res._data as Blob
|
||||||
const link = document.createElement("a")
|
|
||||||
link.href = URL.createObjectURL(blob)
|
if(returnAsBlob) {
|
||||||
link.download = filename
|
return blob
|
||||||
link.click()
|
} else {
|
||||||
URL.revokeObjectURL(link.href)
|
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 {
|
} else {
|
||||||
emailData.value.account = emailAccounts.value[0].id
|
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
|
//Check Query
|
||||||
if(route.query.to) emailData.value.to = route.query.to
|
if(route.query.to) emailData.value.to = route.query.to
|
||||||
@@ -133,25 +133,35 @@ const sendEmail = async () => {
|
|||||||
|
|
||||||
for await (const doc of loadedDocuments.value) {
|
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({
|
body.attachments.push({
|
||||||
filename: doc.path.split("/")[doc.path.split("/").length -1],
|
filename: doc.path.split("/")[doc.path.split("/").length -1],
|
||||||
content: await blobToBase64(data),
|
content: await blobToBase64(res),
|
||||||
contentType: data.type,
|
contentType: res.type,
|
||||||
encoding: "base64",
|
encoding: "base64",
|
||||||
contentDisposition: "attachment"
|
contentDisposition: "attachment"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data, error } = await supabase.functions.invoke('send_email', {
|
const res = await useNuxtApp().$api("/api/emailasuser/send",{
|
||||||
body
|
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"})
|
toast.add({title: "Fehler beim Absenden der E-Mail", color: "rose"})
|
||||||
|
|
||||||
} else if(data) {
|
} else {
|
||||||
router.push("/")
|
//router.push("/")
|
||||||
toast.add({title: "E-Mail zum Senden eingereiht"})
|
toast.add({title: "E-Mail zum Senden eingereiht"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user