mirror of https://github.com/sualko/cloud_bbb
parent
43260c821a
commit
c9ab2701ed
|
@ -51,14 +51,13 @@ $(() => {
|
||||||
permissions: OC.PERMISSION_SHARE,
|
permissions: OC.PERMISSION_SHARE,
|
||||||
icon: OC.imagePath('bbb', 'app-dark.svg'),
|
icon: OC.imagePath('bbb', 'app-dark.svg'),
|
||||||
actionHandler: (fileName, context) => {
|
actionHandler: (fileName, context) => {
|
||||||
share(context.fileInfoModel.getFullPath(), fileName, uid);
|
share(context.fileInfoModel.id, fileName, uid);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function share(path: string, filename: string, roomUid) {
|
async function share(fileId: number, filename: string, roomUid) {
|
||||||
const id = await createShare(path);
|
const shareUrl = await createDirectShare(fileId);
|
||||||
const shareUrl = await configureShare(id);
|
|
||||||
const joinUrl = generateUrl('/apps/bbb/b/{uid}?u={url}&filename={filename}', {
|
const joinUrl = generateUrl('/apps/bbb/b/{uid}?u={url}&filename={filename}', {
|
||||||
uid: roomUid,
|
uid: roomUid,
|
||||||
url: shareUrl + '/download',
|
url: shareUrl + '/download',
|
||||||
|
@ -68,40 +67,12 @@ $(() => {
|
||||||
window.open(joinUrl, '_blank', 'noopener,noreferrer');
|
window.open(joinUrl, '_blank', 'noopener,noreferrer');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createShare(path: string): Promise<number> {
|
async function createDirectShare(fileId: number): Promise<string> {
|
||||||
const url = generateOcsUrl('apps/files_sharing/api/v1', 2) + 'shares';
|
const url = generateOcsUrl('apps/dav/api/v1', 1) + 'direct';
|
||||||
|
|
||||||
const createResponse = await axios.post(url, {
|
const createResponse = await axios.post(url, {
|
||||||
path,
|
fileId,
|
||||||
shareType: OC.Share.SHARE_TYPE_LINK,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const { meta, data } = createResponse.data.ocs;
|
return createResponse.data?.ocs?.data?.url;
|
||||||
|
|
||||||
if (meta.statuscode !== 200) {
|
|
||||||
throw new Error('Failed to create share');
|
|
||||||
}
|
|
||||||
|
|
||||||
return data.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function configureShare(id: number): Promise<string> {
|
|
||||||
const url = generateOcsUrl('apps/files_sharing/api/v1', 2) + 'shares/' + id;
|
|
||||||
|
|
||||||
const tomorrow = new Date();
|
|
||||||
tomorrow.setDate(new Date().getDate() + 1);
|
|
||||||
|
|
||||||
const updateResponse = await axios.put(url, {
|
|
||||||
expireDate: tomorrow.toISOString().split('T')[0],
|
|
||||||
note: 'BigBlueButton',
|
|
||||||
});
|
|
||||||
|
|
||||||
const { meta, data } = updateResponse.data.ocs;
|
|
||||||
|
|
||||||
if (meta.statuscode !== 200) {
|
|
||||||
throw new Error('Failed to configure share');
|
|
||||||
}
|
|
||||||
|
|
||||||
return data.url;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in New Issue