Merge pull request #4249 from mikekaganski/private/mk/insertRemoteMultimedia

Implement support for insertion of multimedia from Nextcloud assets
This commit is contained in:
Elizabeth Danzberger 2024-11-22 20:22:31 +00:00 committed by GitHub
commit 48688df30a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 7 deletions

View file

@ -100,6 +100,10 @@ The following handlers are currently supported:
- insertGraphic: will be called when an image from the Nextcloud storage should be inserted
- Arguments
- insertFileFromPath(path): Callback to trigger the actual inserting of the graphic from an absolute file path
- insertFile: will be called when a file (e.g., multimedia) from the Nextcloud storage should be inserted (generalized insertGraphic)
- Arguments
- mimeTypeFilter: array of MIME types (strings) to filter in the UI
- insertFileFromPath(path): Callback to trigger the actual inserting of the file from an absolute file path
In addition, the following handlers can be used to overwrite the handling of file actions that are rendered in the Nextcloud header bar:
- actionDetails

View file

@ -145,6 +145,7 @@ class WopiController extends Controller {
'SupportsRename' => !$isVersion && !$wopi->isRemoteToken(),
'UserCanRename' => !$isPublic && !$isVersion && !$wopi->isRemoteToken(),
'EnableInsertRemoteImage' => !$isPublic,
'EnableInsertRemoteFile' => !$isPublic,
'EnableShare' => $file->isShareable() && !$isVersion && !$isPublic,
'HideUserList' => '',
'EnableOwnerTermination' => $wopi->getCanwrite() && !$isPublic,

View file

@ -148,30 +148,33 @@ export default {
}
},
insertGraphic(insertFile) {
/**
* @private
*/
insertFile_impl(mimeTypeFilter, insertFileProc, insertHandler) {
if (isPublicShare()) {
console.error('[FilesAppIntegration] insertGraphic is not supported')
console.error('[FilesAppIntegration] insertFile is not supported')
}
const insertFileFromPath = async (path) => {
const filename = path.substring(path.lastIndexOf('/') + 1)
const { data } = await axios.post(generateUrl('apps/richdocuments/assets'), { path })
insertFile(filename, data.url)
insertFileProc(filename, data.url)
}
if (this.handlers.insertGraphic && this.handlers.insertGraphic(this, { insertFileFromPath })) {
if (insertHandler && insertHandler(this, mimeTypeFilter, { insertFileFromPath })) {
return
}
getFilePickerBuilder(t('richdocuments', 'Insert image from {name}', { name: OC.theme.name }))
.setMimeTypeFilter(['image/png', 'image/gif', 'image/jpeg', 'image/svg'])
getFilePickerBuilder(t('richdocuments', 'Insert file from {name}', { name: OC.theme.name }))
.setMimeTypeFilter(mimeTypeFilter)
.setFilter((node) => {
const downloadShareAttribute = JSON.parse(node.attributes['share-attributes']).find((shareAttribute) => shareAttribute.key === 'download')
const downloadPermissions = downloadShareAttribute !== undefined ? (downloadShareAttribute.enabled || downloadShareAttribute.value) : true
return (node.permissions & OC.PERMISSION_READ) && downloadPermissions
})
.addButton({
label: t('richdocuments', 'Insert image'),
label: t('richdocuments', 'Insert file'),
callback: (files) => {
if (files && files.length) {
insertFileFromPath(files[0].path)
@ -182,6 +185,16 @@ export default {
.pick()
},
insertGraphic(insertFileProc) {
this.insertFile_impl(['image/png', 'image/gif', 'image/jpeg', 'image/svg'],
insertFileProc,
(filesAppIntegration, mimeTypeFilter, { insertFileFromPath }) => { return this.handlers.insertGraphic && this.handlers.insertGraphic(filesAppIntegration, { insertFileFromPath }) })
},
insertFile(mimeTypeFilter, insertFileProc) {
this.insertFile_impl(mimeTypeFilter, insertFileProc, this.handlers.insertFile)
},
getFileList() {
if (this.fileList) {
return this.fileList

View file

@ -432,6 +432,14 @@ export default {
})
})
break
case 'UI_InsertFile':
FilesAppIntegration.insertFile(args.mimeTypeFilter, (filename, url) => {
this.postMessage.sendWOPIPostMessage(FRAME_DOCUMENT, args.callback, {
filename,
url,
})
})
break
case 'UI_Mention':
this.uiMention(parsed.args)
break