fix: do not register file action without authentication

pull/129/head
sualko 2021-02-24 15:11:19 +01:00
parent cc566608b2
commit dedfd37cae
1 changed files with 17 additions and 19 deletions

View File

@ -2,8 +2,6 @@ import axios from '@nextcloud/axios';
import { generateOcsUrl, generateUrl } from '@nextcloud/router';
import { api } from './Common/Api';
declare const OCA: any;
const mimeTypes = [
'application/pdf',
'application/vnd.oasis.opendocument.presentation',
@ -42,8 +40,8 @@ async function share(fileId: number, filename: string, roomUid) {
window.open(joinUrl, '_blank', 'noopener,noreferrer');
}
function registerFileAction(mime, id, uid, name) {
OCA.Files.fileActions.registerAction({
function registerFileAction(fileActions, mime, id, uid, name) {
fileActions.registerAction({
name: 'bbb-' + id,
displayName: name,
mime,
@ -55,22 +53,22 @@ function registerFileAction(mime, id, uid, name) {
});
}
function addRoomsAsFileAction() {
if (!OCA?.Files?.fileActions) {
console.warn('[BBB] "OCA.Files.fileActions" not available');
const BBBFileListPlugin = {
ignoreLists: [
'trashbin',
],
attach(fileList) {
if (this.ignoreLists.includes(fileList.id) || !OC.currentUser) {
return;
}
api.getRooms().then(rooms => {
rooms.forEach(room => {
mimeTypes.forEach(mime => registerFileAction(mime, room.id, room.uid, room.name));
mimeTypes.forEach(mime => registerFileAction(fileList.fileActions, mime, room.id, room.uid, room.name));
});
});
}
},
};
if (document.readyState === 'complete') {
addRoomsAsFileAction();
} else {
document.addEventListener('DOMContentLoaded', addRoomsAsFileAction);
}
OC.Plugins.register('OCA.Files.FileList', BBBFileListPlugin);