Skip to content

Commit 48688df

Browse files
authored
Merge pull request #4249 from mikekaganski/private/mk/insertRemoteMultimedia
Implement support for insertion of multimedia from Nextcloud assets
2 parents 71c3692 + 68ebfaa commit 48688df

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
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
@@ -145,6 +145,7 @@ public function checkFileInfo(string $fileId, string $access_token): JSONRespons
145145
'SupportsRename' => !$isVersion && !$wopi->isRemoteToken(),
146146
'UserCanRename' => !$isPublic && !$isVersion && !$wopi->isRemoteToken(),
147147
'EnableInsertRemoteImage' => !$isPublic,
148+
'EnableInsertRemoteFile' => !$isPublic,
148149
'EnableShare' => $file->isShareable() && !$isVersion && !$isPublic,
149150
'HideUserList' => '',
150151
'EnableOwnerTermination' => $wopi->getCanwrite() && !$isPublic,

src/view/FilesAppIntegration.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,30 +148,33 @@ export default {
148148
}
149149
},
150150

151-
insertGraphic(insertFile) {
151+
/**
152+
* @private
153+
*/
154+
insertFile_impl(mimeTypeFilter, insertFileProc, insertHandler) {
152155
if (isPublicShare()) {
153-
console.error('[FilesAppIntegration] insertGraphic is not supported')
156+
console.error('[FilesAppIntegration] insertFile is not supported')
154157
}
155158

156159
const insertFileFromPath = async (path) => {
157160
const filename = path.substring(path.lastIndexOf('/') + 1)
158161
const { data } = await axios.post(generateUrl('apps/richdocuments/assets'), { path })
159-
insertFile(filename, data.url)
162+
insertFileProc(filename, data.url)
160163
}
161164

162-
if (this.handlers.insertGraphic && this.handlers.insertGraphic(this, { insertFileFromPath })) {
165+
if (insertHandler && insertHandler(this, mimeTypeFilter, { insertFileFromPath })) {
163166
return
164167
}
165168

166-
getFilePickerBuilder(t('richdocuments', 'Insert image from {name}', { name: OC.theme.name }))
167-
.setMimeTypeFilter(['image/png', 'image/gif', 'image/jpeg', 'image/svg'])
169+
getFilePickerBuilder(t('richdocuments', 'Insert file from {name}', { name: OC.theme.name }))
170+
.setMimeTypeFilter(mimeTypeFilter)
168171
.setFilter((node) => {
169172
const downloadShareAttribute = JSON.parse(node.attributes['share-attributes']).find((shareAttribute) => shareAttribute.key === 'download')
170173
const downloadPermissions = downloadShareAttribute !== undefined ? (downloadShareAttribute.enabled || downloadShareAttribute.value) : true
171174
return (node.permissions & OC.PERMISSION_READ) && downloadPermissions
172175
})
173176
.addButton({
174-
label: t('richdocuments', 'Insert image'),
177+
label: t('richdocuments', 'Insert file'),
175178
callback: (files) => {
176179
if (files && files.length) {
177180
insertFileFromPath(files[0].path)
@@ -182,6 +185,16 @@ export default {
182185
.pick()
183186
},
184187

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

src/view/Office.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,14 @@ export default {
432432
})
433433
})
434434
break
435+
case 'UI_InsertFile':
436+
FilesAppIntegration.insertFile(args.mimeTypeFilter, (filename, url) => {
437+
this.postMessage.sendWOPIPostMessage(FRAME_DOCUMENT, args.callback, {
438+
filename,
439+
url,
440+
})
441+
})
442+
break
435443
case 'UI_Mention':
436444
this.uiMention(parsed.args)
437445
break

0 commit comments

Comments
 (0)