Skip to content

Commit

Permalink
Show previews in the upload editor
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
  • Loading branch information
marcoambrosini committed Aug 5, 2020
1 parent d42ad70 commit 3568660
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class="file-preview"
:class="{ 'file-preview--viewer-available': isViewerAvailable, 'file-preview--upload-editor': isUploadEditor }"
@click="showPreview">
<img v-if="!isLoading && !failed"
<img v-if="(!isLoading && !failed) || hasTemporaryImageUrl"
:class="previewSizeClass"
alt=""
:src="previewUrl">
Expand Down Expand Up @@ -109,6 +109,12 @@ export default {
type: Boolean,
default: false,
},

// The link to the file for displaying it in the preview
localUrl: {
type: String,
default: '',
},
},
data() {
return {
Expand Down Expand Up @@ -138,13 +144,21 @@ export default {
defaultIconUrl() {
return imagePath('core', 'filetypes/file')
},

previewSizeClass() {
if (this.previewSize === 64) {
return 'preview-64'
}
return 'preview'
},

previewUrl() {
if (this.hasTemporaryImageUrl) {
if (this.localUrl) {
return this.localUrl
}
}

if (this.previewAvailable !== 'yes' || this.$store.getters.getUserId() === null) {
return OC.MimeType.getIconUrl(this.mimetype)
}
Expand All @@ -156,6 +170,7 @@ export default {
height: previewSize,
})
},

isViewerAvailable() {
if (!OCA.Viewer) {
return false
Expand All @@ -170,16 +185,19 @@ export default {

return false
},

internalAbsolutePath() {
if (this.path.startsWith('/')) {
return this.path
}

return '/' + this.path
},

isTemporaryUpload() {
return this.id.startsWith('temp') && this.index && this.uploadId
},

uploadProgress() {
if (this.isTemporaryUpload) {
if (this.$store.getters.uploadProgress(this.uploadId, this.index)) {
Expand All @@ -188,6 +206,10 @@ export default {
}
return 0
},

hasTemporaryImageUrl() {
return this.mimetype.startsWith('image/') && this.localUrl
},
},
mounted() {
const img = new Image()
Expand Down
4 changes: 3 additions & 1 deletion src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ const actions = {
commit('markFileAsInitialised', { uploadId, index })
// currentFile to be uploaded
const currentFile = state.uploads[uploadId].files[index].file
// Get localurl for previews
const localUrl = URL.createObjectURL(currentFile)
// Create temporary message for the file and add it to the message list
const temporaryMessage = createTemporaryMessage('{file}', token, uploadId, index, currentFile)
const temporaryMessage = createTemporaryMessage('{file}', token, uploadId, index, currentFile, localUrl)
// Add the temporary messages to the store
commit('setTemporaryMessageForFile', { uploadId, index, temporaryMessage })
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/temporaryMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import store from '../store/index'
import SHA1 from 'crypto-js/sha1'
import Hex from 'crypto-js/enc-hex'

const createTemporaryMessage = (text, token, uploadId, index, file) => {
const createTemporaryMessage = (text, token, uploadId, index, file, localUrl) => {
const messageToBeReplied = store.getters.getMessageToBeReplied(token)
const date = new Date()
let tempId = 'temp-' + date.getTime()
Expand All @@ -39,6 +39,7 @@ const createTemporaryMessage = (text, token, uploadId, index, file) => {
'name': file.name,
index,
uploadId,
localUrl,
}
}
const message = Object.assign({}, {
Expand All @@ -54,6 +55,7 @@ const createTemporaryMessage = (text, token, uploadId, index, file) => {
token: token,
isReplyable: false,
referenceId: Hex.stringify(SHA1(tempId)),

})

if (store.getters.getActorType() === 'guests') {
Expand Down

0 comments on commit 3568660

Please sign in to comment.