Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/components/ComposerAttachments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
:buttons="attachementPickerButtons"
:filter-fn="filterAttachements"
@close="() => isAttachementPickerOpen = false" />
<input
ref="cloudUpload"
type="file"
style="display: none;"
@change="onCloudUploadSelected">
<FilePicker
v-if="isLinkPickerOpen"
:name="t('mail', 'Choose a file to share as a link')"
Expand All @@ -67,6 +72,7 @@ import Vue from 'vue'
import ChevronDown from 'vue-material-design-icons/ChevronDown.vue'
import ChevronUp from 'vue-material-design-icons/ChevronUp.vue'
import ComposerAttachment from './ComposerAttachment.vue'
import { getClient } from '../dav/client'
import logger from '../logger.js'
import { uploadLocalAttachment } from '../service/AttachmentService.js'
import { getFileData } from '../service/FileService.js'
Expand Down Expand Up @@ -130,6 +136,12 @@ export default {
callback: this.onAddCloudAttachmentLink,
type: 'primary',
},

{
label: t('mail', 'Upload'),
callback: this.onUploadCloudAttachment,
type: 'primary',
},
],

}
Expand Down Expand Up @@ -224,6 +236,10 @@ export default {
this.$refs.localAttachments.click()
},

onUploadCloudAttachment() {
this.$refs.cloudUpload.click()
},

emitNewAttachments(attachments) {
this.$emit('input', this.value.concat(attachments))
},
Expand Down Expand Up @@ -387,6 +403,36 @@ export default {
}
},

async onCloudUploadSelected(e) {
const file = e.target.files[0]
if (!file) {
return
}

const client = getClient('files')
const folder = '/Email Attachments'
const path = `${folder}/${file.name}`

try {
await client.createDirectory(folder)
} catch (error) {
if (error?.status !== 405) {
logger.error('could not create Email Attachments folder', { error })
return
}
}

try {
const buffer = await file.arrayBuffer()
await client.putFileContents(path, buffer, { contentLength: file.size })
const url = await shareFile(path, getRequestToken())
this.appendToBodyAtCursor(`<a href="${url}">${url}</a>`)
} catch (error) {
logger.error('could not upload and share file', { error, file })
}
e.target.value = ''
},

/**
* Add a forwarded message as an attachment
*
Expand Down