Hello all, I have the following .js in my NextCloud app:
import { registerFileAction, FileAction, Node, Permission, View } from '@nextcloud/files'
const nextcloudVersionIsGreaterThanOr28 = parseInt(OC.config.version.split('.')[0]) >= 28
if (nextcloudVersionIsGreaterThanOr28) {
OCA.Files.fileActions.registerFileAction(new FileAction({
id: "test",
displayName: () => t('test', 'Test'),
default: DefaultType.DEFAULT,
mime,
enabled: (nodes) => {
return nodes.every((node) => node.mime === mime && (node.permissions & Permission.READ))
},
iconSvgInline: () => ContactSvg,
async exec(file) {
console.log("executing...")
return true
},
}))
} else {
window.addEventListener('DOMContentLoaded', () => {
if (OCA.Files && OCA.Files.fileActions) {
OCA.Files.fileActions.registerAction({
name: "Test",
displayName: t('test', 'Test'),
mime,
permissions: OC.PERMISSION_READ,
iconClass: 'icon-contacts-dark',
actionHandler(fileName, context) {
console.log("executing...")
},
})
OCA.Files.fileActions.setDefault(mime, name)
return
}
console.error('Unable to register vcf import action')
})
}
Originally I was only running the “else” case for NextCloud <28, but now I’m trying to update my app (this is a generic proof of concept)
With this new code I get “SyntaxError: import declarations may only appear at top level of a module (line 1)”
Could anyone point me to the error I am making?