Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions src/components/ComposerAttachment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<li class="composer-attachment" :class="{ 'composer-attachment--with-error': attachment.error }">
<li class="composer-attachment" :class="{ 'composer-attachment--with-error': attachment.error }" @click="onPreview">
<div class="attachment-preview">
<img :src="previewSrc" class="attachment-preview-image">
<img
:src="previewSrc"
class="attachment-preview-image">
<span v-if="attachment.type === 'cloud'" class="cloud-attachment-icon">
<Cloud :size="20" />
</span>
Expand Down Expand Up @@ -87,9 +89,12 @@
onDelete(attachment) {
this.$emit('on-delete-attachment', attachment)
},
},

onPreview() {
this.$emit('preview', this.attachment)
}
},
}

Check failure on line 97 in src/components/ComposerAttachment.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Missing trailing comma
</script>

<style lang="scss" scoped>
Expand Down
74 changes: 72 additions & 2 deletions src/components/ComposerAttachments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
:key="attachment.id"
:attachment="attachment"
:uploading="uploading"
@on-delete-attachment="onDelete(attachment)" />
@on-delete-attachment="onDelete(attachment)"
@preview="onPreviewAttachment"

Check failure on line 32 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected no line breaks before closing bracket, but 1 line break found
/>
</ul>

<input
Expand Down Expand Up @@ -157,6 +159,29 @@
}
return total
},

previewableFilesInfos() {
return this.attachments
.filter((attachment) => {
const mime = attachment.mime || attachment.fileType
return mime &&

Check failure on line 167 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'&&' should be placed at the beginning of the line
(
mime.startsWith('image/') ||

Check failure on line 169 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'||' should be placed at the beginning of the line
mime.startsWith('video/') ||

Check failure on line 170 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'||' should be placed at the beginning of the line
mime.startsWith('audio/') ||

Check failure on line 171 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'||' should be placed at the beginning of the line
mime === 'application/pdf'
)
})
.map((attachment) => ({
filename: attachment.previewBlobUrl,
source: attachment.previewBlobUrl,
basename: attachment.fileName,
mime: attachment.mime || attachment.fileType,
etag: 'fixme',
hasPreview: false,
fileid: parseInt(attachment.id, 10),
}))
},
},

watch: {
Expand Down Expand Up @@ -243,7 +268,6 @@
this.uploading = true
// BUG - if choose again - progress lost/ move to complete()
Vue.set(this, 'uploads', {})

const toUpload = sumBy(prop('size'), Object.values(e.target.files))
const newTotal = toUpload + this.totalSizeOfUpload()
logger.debug('checking upload size limit', {
Expand Down Expand Up @@ -275,6 +299,7 @@
fileName: file.name,
fileType: file.type,
imageBlobURL: this.generatePreview(file),
previewBlobUrl: this.generatePreviewBlobUrl(file),
displayName: trimStart('/', file.name),
progress: null,
percent: 0,
Expand Down Expand Up @@ -356,6 +381,7 @@
size: filesFromCloud[i].size,

}

const _toAttachmentData = {
finished: true,
imageBlobURL: this.generatePreview(_cloudFile),
Expand Down Expand Up @@ -425,6 +451,10 @@
attachment.controller.abort()
}

if (attachment.previewBlobUrl) {
URL.revokeObjectURL(attachment.previewBlobUrl)
}

const val = {
fileName: attachment.fileName,
displayName: attachment.displayName,
Expand Down Expand Up @@ -498,9 +528,49 @@
}
},

generatePreviewBlobUrl(file) {
return this.isPreviewable(file)
? URL.createObjectURL(file)
: null
},

isPreviewable(file) {
return file.type.startsWith('image/')
|| file.type.startsWith('video/')
|| file.type.startsWith('audio/')
|| file.type === 'application/pdf'

Check failure on line 541 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Block must not be padded by blank lines

},

isImage(file) {
return file.type && mimes.indexOf(file.type) !== -1
},

onPreviewAttachment(attachment) {
if (!attachment.finished) {
return
}

if (!attachment.previewBlobUrl) {
return
}

let fileInfo = {

Check failure on line 558 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'fileInfo' is never reassigned. Use 'const' instead
filename: attachment?.previewBlobUrl,
source: attachment?.previewBlobUrl,
basename: attachment?.fileName,
mime: attachment?.mime || attachment?.fileType,
etag: 'fixme',
hasPreview: false,
fileid: parseInt(attachment.id, 10),
}

OCA.Viewer.open({

Check failure on line 568 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 3 tabs but found 4
fileInfo,

Check failure on line 569 in src/components/ComposerAttachments.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 4 tabs but found 5
list: this.previewableFilesInfos
})
},

},
}
</script>
Expand Down
Loading