Skip to content

Commit

Permalink
add support of multiple mimes
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Borysenko <[email protected]>
  • Loading branch information
andrey18106 committed Dec 5, 2023
1 parent 86ae743 commit 9691f8f
Showing 1 changed file with 53 additions and 43 deletions.
96 changes: 53 additions & 43 deletions src/filesplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,49 +31,52 @@ function generateAppAPIProxyUrl(appId, route) {

if (OCA.Files && OCA.Files.fileActions) {
state.fileActions.forEach(fileAction => {
const action = {
name: fileAction.name,
displayName: t(fileAction.appid, fileAction.display_name),
mime: fileAction.mime,
permissions: Number(fileAction.permissions),
order: Number(fileAction.order),
icon: fileAction.icon !== '' ? generateAppAPIProxyUrl(fileAction.appid, fileAction.icon) : null,
iconClass: fileAction.icon === '' ? 'icon-app-api' : '',
actionHandler: (fileName, context) => {
const file = context.$file[0]
const exAppFileActionHandler = generateAppAPIProxyUrl(fileAction.appid, fileAction.action_handler)
axios.post(exAppFileActionHandler, {
fileId: Number(file.dataset.id),
name: fileName,
directory: file.dataset.path,
etag: file.dataset.etag,
mime: file.dataset.mime,
favorite: file.dataset.favorite || 'false',
permissions: Number(file.dataset.permissions),
fileType: file.dataset.type,
size: Number(file.dataset.size),
mtime: Number(file.dataset.mtime) / 1000, // convert ms to s
shareTypes: file.dataset?.shareTypes || null,
shareAttributes: file.dataset?.shareAttributes || null,
sharePermissions: file.dataset?.sharePermissions || null,
shareOwner: file.dataset?.shareOwner || null,
shareOwnerId: file.dataset?.shareOwnerId || null,
userId: getCurrentUser().uid,
instanceId: state.instanceId,
}).then((response) => {
if (response.status === 200) {
OC.dialogs.info(t('app_api', 'Action request sent to ExApp'), t(fileAction.appid, fileAction.display_name))
} else {
console.debug(response)
const mimes = fileAction.mime.split(',') // multiple mimes are separated by comma
mimes.forEach((mimeType) => {
const action = {
name: fileAction.name,
displayName: t(fileAction.appid, fileAction.display_name),
mime: mimeType,
permissions: Number(fileAction.permissions),
order: Number(fileAction.order),
icon: fileAction.icon !== '' ? generateAppAPIProxyUrl(fileAction.appid, fileAction.icon) : null,
iconClass: fileAction.icon === '' ? 'icon-app-api' : '',
actionHandler: (fileName, context) => {
const file = context.$file[0]
const exAppFileActionHandler = generateAppAPIProxyUrl(fileAction.appid, fileAction.action_handler)
axios.post(exAppFileActionHandler, {
fileId: Number(file.dataset.id),
name: fileName,
directory: file.dataset.path,
etag: file.dataset.etag,
mime: file.dataset.mime,
favorite: file.dataset.favorite || 'false',
permissions: Number(file.dataset.permissions),
fileType: file.dataset.type,
size: Number(file.dataset.size),
mtime: Number(file.dataset.mtime) / 1000, // convert ms to s
shareTypes: file.dataset?.shareTypes || null,
shareAttributes: file.dataset?.shareAttributes || null,
sharePermissions: file.dataset?.sharePermissions || null,
shareOwner: file.dataset?.shareOwner || null,
shareOwnerId: file.dataset?.shareOwnerId || null,
userId: getCurrentUser().uid,
instanceId: state.instanceId,
}).then((response) => {
if (response.status === 200) {
OC.dialogs.info(t('app_api', 'Action request sent to ExApp'), t(fileAction.appid, fileAction.display_name))
} else {
console.debug(response)
OC.dialogs.info(t('app_api', 'Error while sending File action request to ExApp'), t(fileAction.appid, fileAction.display_name))
}
}).catch((error) => {
console.error('error', error)
OC.dialogs.info(t('app_api', 'Error while sending File action request to ExApp'), t(fileAction.appid, fileAction.display_name))
}
}).catch((error) => {
console.error('error', error)
OC.dialogs.info(t('app_api', 'Error while sending File action request to ExApp'), t(fileAction.appid, fileAction.display_name))
})
},
}
OCA.Files.fileActions.registerAction(action)
})
},
}
OCA.Files.fileActions.registerAction(action)
})
})
} else {
state.fileActions.forEach(fileAction => {
Expand All @@ -99,7 +102,14 @@ if (OCA.Files && OCA.Files.fileActions) {
return false
}

return (files[0].mime.indexOf(fileAction.mime) !== -1)
// Check for multiple mimes separated by comma
fileAction.mime.split(',').forEach((mime) => {
if (files[0].mime.indexOf(mime) !== -1) {
return true
}
})

return false
},
async exec(node) {
const exAppFileActionHandler = generateAppAPIProxyUrl(fileAction.appid, fileAction.action_handler)
Expand Down

0 comments on commit 9691f8f

Please sign in to comment.