Skip to content

Commit

Permalink
Merge pull request #13616 from nextcloud/backport/13607/stable30
Browse files Browse the repository at this point in the history
  • Loading branch information
Antreesy authored Oct 23, 2024
2 parents 502d12c + b231b7b commit 8e5d778
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ export default {
},
fallbackLocalUrl() {
if (!this.file.mimetype.startsWith('image/') && !this.file.mimetype.startsWith('video/')) {
return undefined
}
return this.$store.getters.getLocalUrl(this.referenceId)
},
Expand All @@ -238,6 +235,7 @@ export default {
name: this.file.name,
path: this.file.path,
link: this.file.link,
localUrl: this.fallbackLocalUrl,
messageId: Number(this.messageId),
nextMessageId: Number(this.nextMessageId),
}
Expand Down
1 change: 0 additions & 1 deletion src/components/NewMessage/NewMessageAudioRecorder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ export default {
const fileName = this.generateFileName()
// Convert blob to file
const audioFile = new File([this.blob], fileName)
audioFile.localURL = window.URL.createObjectURL(this.blob)
this.$emit('audio-file', audioFile)
this.$emit('recording', false)
}
Expand Down
5 changes: 1 addition & 4 deletions src/components/NewMessage/NewMessageUploadEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ export default {
},
voiceMessageLocalURL() {
if (!this.firstFile?.file?.localURL) {
return ''
}
return this.firstFile.file.localURL
return this.$store.getters.getLocalUrl(this.firstFile.temporaryMessage.referenceId)
},
},
Expand Down
18 changes: 8 additions & 10 deletions src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ const mutations = {
totalSize: file.size,
temporaryMessage,
})
Vue.set(state.localUrls, temporaryMessage.referenceId, localUrl)
if (localUrl) {
Vue.set(state.localUrls, temporaryMessage.referenceId, localUrl)
}
},

// Marks a given file as initialized (for retry)
Expand Down Expand Up @@ -238,15 +240,11 @@ const actions = {
+ getFileExtension(file.name)
}

// Get localurl for some image previews
let localUrl = ''
if (SHARED_ITEM.MEDIA_ALLOWED_PREVIEW.includes(file.type)) {
localUrl = URL.createObjectURL(file)
} else if (isVoiceMessage) {
localUrl = file.localUrl
} else {
localUrl = OC.MimeType.getIconUrl(file.type)
}
// Get localUrl for allowed image previews and voice messages uploads
const localUrl = (isVoiceMessage || SHARED_ITEM.MEDIA_ALLOWED_PREVIEW.includes(file.type))
? URL.createObjectURL(file)
: undefined

// Create a unique index for each file
const date = new Date()
const index = 'temp_' + date.getTime() + Math.random()
Expand Down
5 changes: 1 addition & 4 deletions src/store/fileUploadStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ describe('fileUploadStore', () => {
}

global.URL.createObjectURL = jest.fn().mockImplementation((file) => 'local-url:' + file.name)
global.OC.MimeType = {
getIconUrl: jest.fn().mockImplementation((type) => 'icon-url:' + type),
}

storeConfig = cloneDeep(fileUploadStore)
storeConfig.actions = Object.assign(storeConfig.actions, mockedActions)
Expand Down Expand Up @@ -127,7 +124,7 @@ describe('fileUploadStore', () => {
lastModified: Date.UTC(2021, 3, 25, 15, 30, 0),
},
]
const localUrls = ['local-url:pngimage.png', 'local-url:jpgimage.jpg', 'icon-url:text/plain']
const localUrls = ['local-url:pngimage.png', 'local-url:jpgimage.jpg', undefined]

await store.dispatch('initialiseUpload', {
uploadId: 'upload-id1',
Expand Down

0 comments on commit 8e5d778

Please sign in to comment.