2022-07-20 03:36:00 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import setPresentationExporting from '/imports/api/presentations/server/modifiers/setPresentationExporting';
|
|
|
|
import Presentations from '/imports/api/presentations';
|
|
|
|
|
2022-08-02 21:53:40 +08:00
|
|
|
const EXPORTING_THRESHOLD_PER_SLIDE = 2500;
|
2022-07-20 03:36:00 +08:00
|
|
|
|
2023-08-18 21:57:50 +08:00
|
|
|
export default async function exportPresentation(presentationId, fileStateType) {
|
2022-07-20 03:36:00 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
2023-04-14 22:04:24 +08:00
|
|
|
const EVENT_NAME = 'MakePresentationDownloadReqMsg';
|
2022-07-20 03:36:00 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(presentationId, String);
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
presId: presentationId,
|
|
|
|
allPages: true,
|
2023-08-18 21:57:50 +08:00
|
|
|
fileStateType,
|
2022-07-20 03:36:00 +08:00
|
|
|
pages: [],
|
|
|
|
};
|
|
|
|
|
2023-03-15 01:27:52 +08:00
|
|
|
const setObserver = async () => {
|
2022-07-20 03:36:00 +08:00
|
|
|
let timeoutRef = null;
|
|
|
|
|
2022-07-25 20:35:08 +08:00
|
|
|
const selector = { meetingId, id: presentationId };
|
|
|
|
const cursor = Presentations.find(selector);
|
2023-05-02 22:14:40 +08:00
|
|
|
const pres = await Presentations.findOneAsync(selector);
|
|
|
|
const numPages = pres?.pages?.length ?? 1;
|
2022-07-26 05:56:26 +08:00
|
|
|
const threshold = EXPORTING_THRESHOLD_PER_SLIDE * numPages;
|
2022-07-20 03:36:00 +08:00
|
|
|
|
|
|
|
const observer = cursor.observe({
|
|
|
|
changed: (doc) => {
|
2022-07-26 05:56:26 +08:00
|
|
|
const { status } = doc.exportation;
|
2022-07-20 03:36:00 +08:00
|
|
|
|
2022-07-26 05:56:26 +08:00
|
|
|
if (status === 'EXPORTED') {
|
2022-07-21 21:49:36 +08:00
|
|
|
Meteor.clearTimeout(timeoutRef);
|
2022-07-20 03:36:00 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-03-15 01:27:52 +08:00
|
|
|
timeoutRef = Meteor.setTimeout(async () => {
|
2022-07-20 03:36:00 +08:00
|
|
|
observer.stop();
|
2023-03-15 01:27:52 +08:00
|
|
|
await setPresentationExporting(meetingId, presentationId, { status: 'TIMEOUT' });
|
2022-07-26 05:56:26 +08:00
|
|
|
}, threshold);
|
2022-07-20 03:36:00 +08:00
|
|
|
};
|
|
|
|
|
2023-03-15 01:27:52 +08:00
|
|
|
await setPresentationExporting(meetingId, presentationId, { status: 'RUNNING' });
|
|
|
|
await setObserver();
|
2022-07-20 03:36:00 +08:00
|
|
|
|
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
} catch (err) {
|
2023-05-04 19:48:32 +08:00
|
|
|
Logger.error(`Exception while invoking method exportPresentation ${err.stack}`);
|
2022-07-20 03:36:00 +08:00
|
|
|
}
|
|
|
|
}
|