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
19 changes: 18 additions & 1 deletion cypress/e2e/attachments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,23 @@ describe('Test all attachment insertion methods', () => {
})

it('Upload a local media file (file.txt.gz)', () => {
const checkPreviewAttachment = (documentId, fileName, fileId) => {
cy.log(
'Check the attachment is visible and well formed',
documentId,
fileName,
)

// keep track that we have created this attachment in the attachment dir
if (!attachmentFileNameToId[documentId]) {
attachmentFileNameToId[documentId] = {}
}

attachmentFileNameToId[documentId][fileName] = fileId

return cy.get('.text-editor__main .widget-file__link').should('contain', `.attachments.${documentId}`)
}

cy.visit('/apps/files')
cy.openFile('test.md')
// in this case we almost could just attach the file to the input
Expand All @@ -263,7 +280,7 @@ describe('Test all attachment insertion methods', () => {

attachFile('file.txt.gz', requestAlias)

return waitForRequestAndCheckAttachment(requestAlias, undefined, false)
return waitForRequestAndCheckAttachment(requestAlias, undefined, false, checkPreviewAttachment)
})
cy.closeFile()
})
Expand Down
23 changes: 14 additions & 9 deletions src/components/Editor/MediaHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,17 @@ export default {

return uploadAttachment(this.connection, file)
.then((response) => {
this.insertAttachment(
response.data?.name,
response.data?.id,
file.type,
position,
response.data?.dirname,
)
if (file.type.startsWith('image/')) {
this.insertAttachment(
response.data?.name,
response.data?.id,
file.type,
position,
response.data?.dirname,
)
} else {
this.insertAttachmentPreview(response.data?.id, position)
}
})
.catch((error) => {
logger.error('Uploading attachment failed', { error })
Expand Down Expand Up @@ -232,10 +236,11 @@ export default {
})
},

insertAttachmentPreview(fileId) {
insertAttachmentPreview(fileId, position = null) {
const url = new URL(generateUrl(`/f/${fileId}`), window.origin)
const href = url.href.replaceAll(' ', '%20')
this.editor.chain().focus().insertPreview(href).run()
const chain = position ? this.editor.chain().focus(position) : this.editor.chain().focus()
chain.insertPreview(href).run()
},

insertAttachment(name, fileId, mimeType, position = null, dirname = '') {
Expand Down
Loading