bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/pads/service.js

135 lines
3.5 KiB
JavaScript
Raw Normal View History

import Pads, { PadsUpdates } from '/imports/api/pads';
import { makeCall } from '/imports/ui/services/api';
import Auth from '/imports/ui/services/auth';
import Settings from '/imports/ui/services/settings';
import PresentationUploaderService from '/imports/ui/components/presentation/presentation-uploader/service';
const PADS_CONFIG = Meteor.settings.public.pads;
2022-03-08 22:33:30 +08:00
const PRESENTATION_CONFIG = Meteor.settings.public.presentation;
const getLang = () => {
const { locale } = Settings.application;
return locale ? locale.toLowerCase() : '';
};
const getParams = () => {
const config = {};
config.lang = getLang();
config.rtl = document.documentElement.getAttribute('dir') === 'rtl';
const params = Object.keys(config)
.map((key) => `${key}=${encodeURIComponent(config[key])}`)
.join('&');
return params;
};
const getPadId = (externalId) => makeCall('getPadId', externalId);
const createGroup = (externalId, model, name) => makeCall('createGroup', externalId, model, name);
const hasPad = (externalId) => {
const pad = Pads.findOne(
{
meetingId: Auth.meetingID,
externalId,
},
);
return pad !== undefined;
};
const createSession = (externalId) => makeCall('createSession', externalId);
const buildPadURL = (padId) => {
if (padId) {
const params = getParams();
const url = Auth.authenticateURL(`${PADS_CONFIG.url}/p/${padId}?${params}`);
return url;
}
return null;
};
const getRev = (externalId) => {
const updates = PadsUpdates.findOne(
{
meetingId: Auth.meetingID,
externalId,
}, { fields: { rev: 1 } },
);
return updates ? updates.rev : 0;
};
const getPadTail = (externalId) => {
const updates = PadsUpdates.findOne(
{
meetingId: Auth.meetingID,
externalId,
}, { fields: { tail: 1 } },
);
if (updates && updates.tail) return updates.tail;
return '';
};
const getPadContent = (externalId) => {
const updates = PadsUpdates.findOne(
{
meetingId: Auth.meetingID,
externalId,
}, { fields: { content: 1 } },
);
if (updates && updates.content) return updates.content;
return '';
};
async function convertAndUpload(externalId) {
const params = getParams();
const padId = await makeCall('getPadId', externalId);
const exportUrl = Auth.authenticateURL(`${PADS_CONFIG.url}/p/${padId}/export/pdf?${params}`);
const sharedNotesAsPdf = await fetch(exportUrl, { credentials: 'include' });
const data = await sharedNotesAsPdf.blob();
2022-03-12 20:09:14 +08:00
const sharedNotesData = new File([data], 'SharedNotes.pdf', {
type: data.type,
});
const formData = new FormData();
2022-03-08 23:29:11 +08:00
formData.append('presentation_name', 'SharedNotes.pdf');
formData.append('Filename', 'SharedNotes.pdf');
formData.append('conference', Auth.meetingID);
formData.append('room', Auth.meetingID);
formData.append('pod_id', 'DEFAULT_PRESENTATION_POD');
formData.append('is_downloadable', false);
2022-03-12 20:09:14 +08:00
formData.append('current', true);
2022-03-08 23:29:11 +08:00
formData.append('fileUpload', sharedNotesData);
const presentationUploadToken = await PresentationUploaderService.requestPresentationUploadToken('DEFAULT_PRESENTATION_POD', Auth.meetingID, 'SharedNotes.pdf');
2022-03-12 20:09:14 +08:00
fetch(PRESENTATION_CONFIG.uploadEndpoint.replace('upload', `${presentationUploadToken}/upload`), {
body: formData,
method: 'post',
2022-03-08 23:29:11 +08:00
});
makeCall('setUsedToken', presentationUploadToken);
return null;
}
export default {
getPadId,
createGroup,
hasPad,
createSession,
buildPadURL,
getRev,
getPadTail,
getPadContent,
convertAndUpload,
};