2020-04-26 11:36:41 +02:00
|
|
|
import axios from '@nextcloud/axios';
|
|
|
|
import { generateOcsUrl, generateUrl } from '@nextcloud/router';
|
2020-10-22 11:00:15 +02:00
|
|
|
import { api } from './Common/Api';
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2020-10-22 11:00:15 +02:00
|
|
|
const mimeTypes = [
|
|
|
|
'application/pdf',
|
|
|
|
'application/vnd.oasis.opendocument.presentation',
|
|
|
|
'application/vnd.oasis.opendocument.text',
|
|
|
|
'application/vnd.oasis.opendocument.spreadsheet',
|
|
|
|
'application/vnd.oasis.opendocument.graphics',
|
|
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
|
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
|
|
'application/msword',
|
|
|
|
'application/vnd.ms-powerpoint',
|
|
|
|
'application/vnd.ms-excel',
|
|
|
|
'image/jpeg',
|
|
|
|
'image/png',
|
|
|
|
'text/plain',
|
|
|
|
'text/rtf',
|
|
|
|
];
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2020-10-22 11:00:15 +02:00
|
|
|
async function createDirectShare(fileId: number): Promise<string> {
|
2022-03-16 11:27:11 +01:00
|
|
|
const url = generateOcsUrl('apps/dav/api/v1/', undefined, {
|
|
|
|
ocsVersion: 1,
|
|
|
|
escape: true,
|
|
|
|
noRewrite: true,
|
|
|
|
}) + 'direct';
|
2020-10-22 11:00:15 +02:00
|
|
|
const createResponse = await axios.post(url, {
|
|
|
|
fileId,
|
|
|
|
});
|
|
|
|
|
|
|
|
return createResponse.data?.ocs?.data?.url;
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
2020-10-22 11:00:15 +02:00
|
|
|
async function share(fileId: number, filename: string, roomUid) {
|
|
|
|
const shareUrl = await createDirectShare(fileId);
|
|
|
|
const joinUrl = generateUrl('/apps/bbb/b/{uid}?u={url}&filename={filename}', {
|
|
|
|
uid: roomUid,
|
|
|
|
url: shareUrl,
|
|
|
|
filename,
|
|
|
|
});
|
|
|
|
|
|
|
|
window.open(joinUrl, '_blank', 'noopener,noreferrer');
|
|
|
|
}
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2021-02-24 15:11:19 +01:00
|
|
|
function registerFileAction(fileActions, mime, id, uid, name) {
|
|
|
|
fileActions.registerAction({
|
2020-10-22 11:00:15 +02:00
|
|
|
name: 'bbb-' + id,
|
|
|
|
displayName: name,
|
|
|
|
mime,
|
|
|
|
permissions: OC.PERMISSION_SHARE,
|
|
|
|
icon: OC.imagePath('bbb', 'app-dark.svg'),
|
|
|
|
actionHandler: (fileName, context) => {
|
|
|
|
share(context.fileInfoModel.id, fileName, uid);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-24 15:11:19 +01:00
|
|
|
const BBBFileListPlugin = {
|
|
|
|
ignoreLists: [
|
|
|
|
'trashbin',
|
|
|
|
],
|
2020-10-22 11:00:15 +02:00
|
|
|
|
2021-02-24 15:11:19 +01:00
|
|
|
attach(fileList) {
|
|
|
|
if (this.ignoreLists.includes(fileList.id) || !OC.currentUser) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-27 16:47:32 +02:00
|
|
|
|
2021-02-24 15:11:19 +01:00
|
|
|
api.getRooms().then(rooms => {
|
|
|
|
rooms.forEach(room => {
|
|
|
|
mimeTypes.forEach(mime => registerFileAction(fileList.fileActions, mime, room.id, room.uid, room.name));
|
|
|
|
});
|
2020-04-27 16:50:45 +02:00
|
|
|
});
|
2021-02-24 15:11:19 +01:00
|
|
|
},
|
|
|
|
};
|
2020-04-27 16:47:32 +02:00
|
|
|
|
2021-02-24 15:11:19 +01:00
|
|
|
OC.Plugins.register('OCA.Files.FileList', BBBFileListPlugin);
|