2021-10-16 03:07:13 +08:00
|
|
|
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';
|
2022-03-08 08:25:44 +08:00
|
|
|
import PresentationUploaderService from '/imports/ui/components/presentation/presentation-uploader/service';
|
2021-10-16 03:07:13 +08:00
|
|
|
|
|
|
|
const PADS_CONFIG = Meteor.settings.public.pads;
|
2022-03-08 22:33:30 +08:00
|
|
|
const PRESENTATION_CONFIG = Meteor.settings.public.presentation;
|
2021-10-16 03:07:13 +08:00
|
|
|
|
|
|
|
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 '';
|
|
|
|
};
|
|
|
|
|
2022-03-08 08:25:44 +08:00
|
|
|
async function convertAndUpload(externalId) {
|
2022-03-11 05:46:34 +08:00
|
|
|
const params = getParams();
|
2022-03-08 08:25:44 +08:00
|
|
|
const padId = await makeCall('getPadId', externalId);
|
|
|
|
|
|
|
|
const exportUrl = Auth.authenticateURL(`${PADS_CONFIG.url}/p/${padId}/export/pdf?${params}`);
|
2022-03-11 05:46:34 +08:00
|
|
|
const sharedNotesAsPdf = await fetch(exportUrl, { credentials: 'include' });
|
|
|
|
const data = await sharedNotesAsPdf.blob();
|
2022-03-12 20:09:14 +08:00
|
|
|
|
2022-03-10 23:50:32 +08:00
|
|
|
const sharedNotesData = new File([data], 'SharedNotes.pdf', {
|
|
|
|
type: data.type,
|
2022-03-08 08:25:44 +08:00
|
|
|
});
|
|
|
|
|
2022-03-10 23:50:32 +08:00
|
|
|
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);
|
|
|
|
|
2022-03-11 05:46:34 +08:00
|
|
|
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`), {
|
2022-03-10 23:50:32 +08:00
|
|
|
body: formData,
|
|
|
|
method: 'post',
|
2022-03-08 23:29:11 +08:00
|
|
|
});
|
2022-03-08 08:25:44 +08:00
|
|
|
|
2022-03-11 05:46:34 +08:00
|
|
|
makeCall('setUsedToken', presentationUploadToken);
|
2022-03-08 08:25:44 +08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-10-16 03:07:13 +08:00
|
|
|
export default {
|
|
|
|
getPadId,
|
|
|
|
createGroup,
|
|
|
|
hasPad,
|
|
|
|
createSession,
|
|
|
|
buildPadURL,
|
|
|
|
getRev,
|
|
|
|
getPadTail,
|
|
|
|
getPadContent,
|
2022-03-08 08:25:44 +08:00
|
|
|
convertAndUpload,
|
2021-10-16 03:07:13 +08:00
|
|
|
};
|