Skip to content

Commit

Permalink
feat: use direct share for presentation
Browse files Browse the repository at this point in the history
fix #1
  • Loading branch information
sualko committed May 22, 2020
1 parent 43260c8 commit c9ab270
Showing 1 changed file with 7 additions and 36 deletions.
43 changes: 7 additions & 36 deletions ts/filelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -68,40 +67,12 @@ $(() => {
window.open(joinUrl, '_blank', 'noopener,noreferrer');
}

async function createShare(path: string): Promise<number> {
const url = generateOcsUrl('apps/files_sharing/api/v1', 2) + 'shares';

async function createDirectShare(fileId: number): Promise<string> {
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<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;
return createResponse.data?.ocs?.data?.url;
}
});

0 comments on commit c9ab270

Please sign in to comment.