Skip to content

Commit b92bd58

Browse files
authored
Merge pull request #4286 from nextcloud/backport/4249/stable30
[stable30] Implement support for insertion of multimedia from Nextcloud assets
2 parents 18c4af0 + 2dbf4e3 commit b92bd58

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

docs/frontend-integration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ The following handlers are currently supported:
100100
- insertGraphic: will be called when an image from the Nextcloud storage should be inserted
101101
- Arguments
102102
- insertFileFromPath(path): Callback to trigger the actual inserting of the graphic from an absolute file path
103+
- insertFile: will be called when a file (e.g., multimedia) from the Nextcloud storage should be inserted (generalized insertGraphic)
104+
- Arguments
105+
- mimeTypeFilter: array of MIME types (strings) to filter in the UI
106+
- insertFileFromPath(path): Callback to trigger the actual inserting of the file from an absolute file path
103107
104108
In addition, the following handlers can be used to overwrite the handling of file actions that are rendered in the Nextcloud header bar:
105109
- actionDetails

lib/Controller/WopiController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public function checkFileInfo($fileId, $access_token) {
153153
'SupportsRename' => !$isVersion && !$wopi->isRemoteToken(),
154154
'UserCanRename' => !$isPublic && !$isVersion && !$wopi->isRemoteToken(),
155155
'EnableInsertRemoteImage' => !$isPublic,
156+
'EnableInsertRemoteFile' => !$isPublic,
156157
'EnableShare' => $file->isShareable() && !$isVersion && !$isPublic,
157158
'HideUserList' => '',
158159
'EnableOwnerTermination' => $wopi->getCanwrite() && !$isPublic,

src/components/Modal/ZoteroHint.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-->
55

66
<template>
7-
<NcModal :show="show" @close="close" :name="t('richdocument', 'Link to your Zotero library')">
7+
<NcModal :show="show" :name="t('richdocument', 'Link to your Zotero library')" @close="close">
88
<div class="zotero-hint">
99
<h2>{{ t('richdocument', 'Link to your Zotero library') }}</h2>
1010
<BookOpenPageVariantOutline :size="96" />

src/view/FilesAppIntegration.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,30 +149,30 @@ export default {
149149
}
150150
},
151151

152-
insertGraphic(insertFile) {
152+
insertFile_impl(mimeTypeFilter, insertFileProc, insertHandler) {
153153
if (isPublic) {
154-
console.error('[FilesAppIntegration] insertGraphic is not supported')
154+
console.error('[FilesAppIntegration] insertFile is not supported')
155155
}
156156

157157
const insertFileFromPath = async (path) => {
158158
const filename = path.substring(path.lastIndexOf('/') + 1)
159159
const { data } = await axios.post(generateUrl('apps/richdocuments/assets'), { path })
160-
insertFile(filename, data.url)
160+
insertFileProc(filename, data.url)
161161
}
162162

163-
if (this.handlers.insertGraphic && this.handlers.insertGraphic(this, { insertFileFromPath })) {
163+
if (insertHandler && insertHandler(this, mimeTypeFilter, { insertFileFromPath })) {
164164
return
165165
}
166166

167-
getFilePickerBuilder(t('richdocuments', 'Insert image from {name}', { name: OC.theme.name }))
168-
.setMimeTypeFilter(['image/png', 'image/gif', 'image/jpeg', 'image/svg'])
167+
getFilePickerBuilder(t('richdocuments', 'Insert file from {name}', { name: OC.theme.name }))
168+
.setMimeTypeFilter(mimeTypeFilter)
169169
.setFilter((node) => {
170170
const downloadShareAttribute = JSON.parse(node.attributes['share-attributes']).find((shareAttribute) => shareAttribute.key === 'download')
171171
const downloadPermissions = downloadShareAttribute !== undefined ? (downloadShareAttribute.enabled || downloadShareAttribute.value) : true
172172
return (node.permissions & OC.PERMISSION_READ) && downloadPermissions
173173
})
174174
.addButton({
175-
label: t('richdocuments', 'Insert image'),
175+
label: t('richdocuments', 'Insert file'),
176176
callback: (files) => {
177177
if (files && files.length) {
178178
insertFileFromPath(files[0].path)
@@ -183,6 +183,16 @@ export default {
183183
.pick()
184184
},
185185

186+
insertGraphic(insertFileProc) {
187+
this.insertFile_impl(['image/png', 'image/gif', 'image/jpeg', 'image/svg'],
188+
insertFileProc,
189+
(filesAppIntegration, mimeTypeFilter, { insertFileFromPath }) => { return this.handlers.insertGraphic && this.handlers.insertGraphic(filesAppIntegration, { insertFileFromPath }) })
190+
},
191+
192+
insertFile(mimeTypeFilter, insertFileProc) {
193+
this.insertFile_impl(mimeTypeFilter, insertFileProc, this.handlers.insertFile)
194+
},
195+
186196
getFileList() {
187197
if (this.fileList) {
188198
return this.fileList

src/view/Office.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,14 @@ export default {
428428
})
429429
})
430430
break
431+
case 'UI_InsertFile':
432+
FilesAppIntegration.insertFile(args.mimeTypeFilter, (filename, url) => {
433+
this.postMessage.sendWOPIPostMessage(FRAME_DOCUMENT, args.callback, {
434+
filename,
435+
url,
436+
})
437+
})
438+
break
431439
case 'UI_Mention':
432440
this.uiMention(parsed.args)
433441
break

0 commit comments

Comments
 (0)