From c9ab2701ede41e3b26e20926ed4a3e04e63326f0 Mon Sep 17 00:00:00 2001 From: sualko Date: Fri, 22 May 2020 14:07:18 +0200 Subject: [PATCH] feat: use direct share for presentation fix #1 --- ts/filelist.ts | 43 +++++++------------------------------------ 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/ts/filelist.ts b/ts/filelist.ts index 11d7738..def8387 100644 --- a/ts/filelist.ts +++ b/ts/filelist.ts @@ -51,14 +51,13 @@ $(() => { permissions: OC.PERMISSION_SHARE, icon: OC.imagePath('bbb', 'app-dark.svg'), actionHandler: (fileName, context) => { - share(context.fileInfoModel.getFullPath(), fileName, uid); + share(context.fileInfoModel.id, fileName, uid); }, }); } - async function share(path: string, filename: string, roomUid) { - const id = await createShare(path); - const shareUrl = await configureShare(id); + 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 + '/download', @@ -68,40 +67,12 @@ $(() => { window.open(joinUrl, '_blank', 'noopener,noreferrer'); } - async function createShare(path: string): Promise { - const url = generateOcsUrl('apps/files_sharing/api/v1', 2) + 'shares'; - + async function createDirectShare(fileId: number): Promise { + const url = generateOcsUrl('apps/dav/api/v1', 1) + 'direct'; const createResponse = await axios.post(url, { - path, - shareType: OC.Share.SHARE_TYPE_LINK, + fileId, }); - const { meta, data } = createResponse.data.ocs; - - if (meta.statuscode !== 200) { - throw new Error('Failed to create share'); - } - - return data.id; - } - - async function configureShare(id: number): Promise { - 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; + return createResponse.data?.ocs?.data?.url; } }); \ No newline at end of file