2020-04-26 11:36:41 +02:00
|
|
|
import axios from '@nextcloud/axios';
|
|
|
|
import { generateOcsUrl, generateUrl } from '@nextcloud/router';
|
2020-08-27 17:21:34 +02:00
|
|
|
import { Room } from './Common/Api';
|
2020-04-26 11:36:41 +02:00
|
|
|
|
|
|
|
declare const OCA: any;
|
|
|
|
|
|
|
|
class BigBlueButton {
|
2020-04-27 16:47:32 +02:00
|
|
|
public async getRooms(): Promise<Room[]> {
|
2020-04-27 16:50:45 +02:00
|
|
|
const response = await axios.get(OC.generateUrl('/apps/bbb/rooms'));
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2020-04-27 16:50:45 +02:00
|
|
|
return response.data;
|
2020-04-27 16:47:32 +02:00
|
|
|
}
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$(() => {
|
|
|
|
|
2020-04-27 16:47:32 +02:00
|
|
|
if (!OCA?.Files?.fileActions) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const mimeTypes = [
|
|
|
|
'application/pdf',
|
|
|
|
'application/vnd.oasis.opendocument.presentation',
|
|
|
|
'application/vnd.oasis.opendocument.text',
|
2020-04-28 08:18:41 +02:00
|
|
|
'application/vnd.oasis.opendocument.spreadsheet',
|
|
|
|
'application/vnd.oasis.opendocument.graphics',
|
2020-04-27 16:47:32 +02:00
|
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
|
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
2020-04-28 08:18:41 +02:00
|
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
2020-04-27 16:47:32 +02:00
|
|
|
'application/msword',
|
|
|
|
'application/vnd.ms-powerpoint',
|
2020-04-28 08:18:41 +02:00
|
|
|
'application/vnd.ms-excel',
|
|
|
|
'image/jpeg',
|
|
|
|
'image/png',
|
|
|
|
'text/plain',
|
|
|
|
'text/rtf',
|
2020-04-27 16:47:32 +02:00
|
|
|
];
|
2020-04-27 16:50:45 +02:00
|
|
|
const bbb = new BigBlueButton();
|
2020-04-27 16:47:32 +02:00
|
|
|
|
|
|
|
bbb.getRooms().then(rooms => {
|
|
|
|
rooms.forEach(room => {
|
|
|
|
mimeTypes.forEach(mime => registerFileAction(mime, room.id, room.uid, room.name));
|
2020-04-27 16:50:45 +02:00
|
|
|
});
|
2020-04-27 16:47:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function registerFileAction(mime, id, uid, name) {
|
|
|
|
OCA.Files.fileActions.registerAction({
|
|
|
|
name: 'bbb-' + id,
|
|
|
|
displayName: name,
|
|
|
|
mime,
|
|
|
|
permissions: OC.PERMISSION_SHARE,
|
|
|
|
icon: OC.imagePath('bbb', 'app-dark.svg'),
|
|
|
|
actionHandler: (fileName, context) => {
|
2020-05-22 14:07:18 +02:00
|
|
|
share(context.fileInfoModel.id, fileName, uid);
|
2020-04-27 16:47:32 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-22 14:07:18 +02:00
|
|
|
async function share(fileId: number, filename: string, roomUid) {
|
|
|
|
const shareUrl = await createDirectShare(fileId);
|
2020-04-27 16:47:32 +02:00
|
|
|
const joinUrl = generateUrl('/apps/bbb/b/{uid}?u={url}&filename={filename}', {
|
|
|
|
uid: roomUid,
|
2020-05-23 12:22:54 +02:00
|
|
|
url: shareUrl,
|
2020-04-27 16:47:32 +02:00
|
|
|
filename,
|
|
|
|
});
|
|
|
|
|
|
|
|
window.open(joinUrl, '_blank', 'noopener,noreferrer');
|
|
|
|
}
|
|
|
|
|
2020-05-22 14:07:18 +02:00
|
|
|
async function createDirectShare(fileId: number): Promise<string> {
|
|
|
|
const url = generateOcsUrl('apps/dav/api/v1', 1) + 'direct';
|
2020-04-27 16:47:32 +02:00
|
|
|
const createResponse = await axios.post(url, {
|
2020-05-22 14:07:18 +02:00
|
|
|
fileId,
|
2020-04-27 16:47:32 +02:00
|
|
|
});
|
|
|
|
|
2020-05-22 14:07:18 +02:00
|
|
|
return createResponse.data?.ocs?.data?.url;
|
2020-04-27 16:47:32 +02:00
|
|
|
}
|
2020-08-27 17:21:34 +02:00
|
|
|
});
|