2017-05-06 04:17:38 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-06-07 20:28:41 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Presentations from '/imports/api/presentations';
|
2017-05-06 04:17:38 +08:00
|
|
|
|
2017-06-07 20:28:41 +08:00
|
|
|
// const OFFICE_DOC_CONVERSION_SUCCESS_KEY = 'OFFICE_DOC_CONVERSION_SUCCESS';
|
2017-05-06 04:17:38 +08:00
|
|
|
const OFFICE_DOC_CONVERSION_FAILED_KEY = 'OFFICE_DOC_CONVERSION_FAILED';
|
|
|
|
const OFFICE_DOC_CONVERSION_INVALID_KEY = 'OFFICE_DOC_CONVERSION_INVALID';
|
|
|
|
const SUPPORTED_DOCUMENT_KEY = 'SUPPORTED_DOCUMENT';
|
|
|
|
const UNSUPPORTED_DOCUMENT_KEY = 'UNSUPPORTED_DOCUMENT';
|
|
|
|
const PAGE_COUNT_FAILED_KEY = 'PAGE_COUNT_FAILED';
|
|
|
|
const PAGE_COUNT_EXCEEDED_KEY = 'PAGE_COUNT_EXCEEDED';
|
2019-10-16 15:37:03 +08:00
|
|
|
const PDF_HAS_BIG_PAGE_KEY = 'PDF_HAS_BIG_PAGE';
|
2017-05-06 04:17:38 +08:00
|
|
|
const GENERATED_SLIDE_KEY = 'GENERATED_SLIDE';
|
2021-04-21 01:21:12 +08:00
|
|
|
const FILE_TOO_LARGE_KEY = 'FILE_TOO_LARGE';
|
2022-09-14 21:33:41 +08:00
|
|
|
const CONVERSION_TIMEOUT_KEY = "CONVERSION_TIMEOUT";
|
2022-11-23 04:41:57 +08:00
|
|
|
const IVALID_MIME_TYPE_KEY = "IVALID_MIME_TYPE";
|
2023-01-15 01:00:29 +08:00
|
|
|
const NO_CONTENT = '204';
|
2017-06-07 20:28:41 +08:00
|
|
|
// const GENERATING_THUMBNAIL_KEY = 'GENERATING_THUMBNAIL';
|
|
|
|
// const GENERATED_THUMBNAIL_KEY = 'GENERATED_THUMBNAIL';
|
|
|
|
// const GENERATING_TEXTFILES_KEY = 'GENERATING_TEXTFILES';
|
|
|
|
// const GENERATED_TEXTFILES_KEY = 'GENERATED_TEXTFILES';
|
|
|
|
// const GENERATING_SVGIMAGES_KEY = 'GENERATING_SVGIMAGES';
|
|
|
|
// const GENERATED_SVGIMAGES_KEY = 'GENERATED_SVGIMAGES';
|
|
|
|
// const CONVERSION_COMPLETED_KEY = 'CONVERSION_COMPLETED';
|
2017-05-06 04:17:38 +08:00
|
|
|
|
2023-03-15 01:27:52 +08:00
|
|
|
export default async function handlePresentationConversionUpdate({ body }, meetingId) {
|
2017-09-29 21:50:46 +08:00
|
|
|
check(body, Object);
|
|
|
|
|
2018-04-10 03:48:37 +08:00
|
|
|
const {
|
2022-09-03 02:24:29 +08:00
|
|
|
presentationId, podId, messageKey: status, presName: presentationName, temporaryPresentationId,
|
2018-04-10 03:48:37 +08:00
|
|
|
} = body;
|
2017-05-06 04:17:38 +08:00
|
|
|
|
|
|
|
check(meetingId, String);
|
2021-04-21 01:21:12 +08:00
|
|
|
check(presentationId, Match.Maybe(String));
|
2023-02-21 19:41:05 +08:00
|
|
|
check(podId, Match.Maybe(String));
|
2017-05-06 04:17:38 +08:00
|
|
|
check(status, String);
|
2022-09-03 02:24:29 +08:00
|
|
|
check(temporaryPresentationId, Match.Maybe(String));
|
2017-05-06 04:17:38 +08:00
|
|
|
|
2017-06-07 20:28:41 +08:00
|
|
|
const statusModifier = {
|
2017-05-06 04:17:38 +08:00
|
|
|
'conversion.status': status,
|
2017-06-07 20:28:41 +08:00
|
|
|
'conversion.error': false,
|
2017-05-06 04:17:38 +08:00
|
|
|
'conversion.done': false,
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case SUPPORTED_DOCUMENT_KEY:
|
2017-09-23 04:43:07 +08:00
|
|
|
statusModifier.id = presentationId;
|
|
|
|
statusModifier.name = presentationName;
|
2017-06-07 20:28:41 +08:00
|
|
|
break;
|
2017-05-06 04:17:38 +08:00
|
|
|
|
2021-04-21 01:21:12 +08:00
|
|
|
case FILE_TOO_LARGE_KEY:
|
|
|
|
statusModifier['conversion.maxFileSize'] = body.maxFileSize;
|
2017-05-06 04:17:38 +08:00
|
|
|
case UNSUPPORTED_DOCUMENT_KEY:
|
|
|
|
case OFFICE_DOC_CONVERSION_FAILED_KEY:
|
2022-11-23 04:41:57 +08:00
|
|
|
case IVALID_MIME_TYPE_KEY:
|
|
|
|
statusModifier['conversion.error'] = true;
|
2022-11-23 20:22:35 +08:00
|
|
|
statusModifier['conversion.fileMime'] = body.fileMime;
|
|
|
|
statusModifier['conversion.fileExtension'] = body.fileExtension;
|
2017-05-06 04:17:38 +08:00
|
|
|
case OFFICE_DOC_CONVERSION_INVALID_KEY:
|
|
|
|
case PAGE_COUNT_FAILED_KEY:
|
|
|
|
case PAGE_COUNT_EXCEEDED_KEY:
|
2021-04-21 01:21:12 +08:00
|
|
|
statusModifier['conversion.maxNumberPages'] = body.maxNumberPages;
|
2019-10-16 15:37:03 +08:00
|
|
|
case PDF_HAS_BIG_PAGE_KEY:
|
2021-04-21 01:21:12 +08:00
|
|
|
statusModifier.id = presentationId ?? body.presentationToken;
|
|
|
|
statusModifier.name = presentationName ?? body.presentationName;
|
2017-05-06 04:17:38 +08:00
|
|
|
statusModifier['conversion.error'] = true;
|
2021-04-21 01:21:12 +08:00
|
|
|
statusModifier['conversion.bigPageSize'] = body.bigPageSize;
|
2022-09-14 21:33:41 +08:00
|
|
|
break;
|
|
|
|
case CONVERSION_TIMEOUT_KEY:
|
|
|
|
statusModifier['conversion.error'] = true;
|
2022-09-23 03:58:37 +08:00
|
|
|
statusModifier['conversion.maxNumberOfAttempts'] = body.maxNumberOfAttempts;
|
2022-09-14 21:33:41 +08:00
|
|
|
statusModifier['conversion.numberPageError'] = body.page;
|
|
|
|
|
2017-06-07 20:28:41 +08:00
|
|
|
break;
|
2017-05-06 04:17:38 +08:00
|
|
|
case GENERATED_SLIDE_KEY:
|
2017-09-08 02:18:14 +08:00
|
|
|
statusModifier['conversion.pagesCompleted'] = body.pagesCompleted;
|
2017-09-23 04:43:07 +08:00
|
|
|
statusModifier['conversion.numPages'] = body.numberOfPages;
|
2017-05-06 04:17:38 +08:00
|
|
|
break;
|
|
|
|
|
2023-01-15 01:00:29 +08:00
|
|
|
case NO_CONTENT:
|
|
|
|
statusModifier['conversion.done'] = false;
|
|
|
|
statusModifier['conversion.error'] = true;
|
|
|
|
statusModifier.id = presentationId;
|
|
|
|
statusModifier.name = presentationName;
|
|
|
|
break;
|
|
|
|
|
2017-06-07 20:28:41 +08:00
|
|
|
default:
|
2017-05-06 04:17:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2018-04-10 03:48:37 +08:00
|
|
|
podId,
|
2021-04-21 01:21:12 +08:00
|
|
|
id: presentationId ?? body.presentationToken,
|
2017-05-06 04:17:38 +08:00
|
|
|
};
|
|
|
|
|
2022-08-22 20:21:33 +08:00
|
|
|
let modifier
|
|
|
|
if (temporaryPresentationId){
|
|
|
|
modifier = {
|
2022-09-03 02:24:29 +08:00
|
|
|
$set: Object.assign({ meetingId, podId, renderedInToast: false, temporaryPresentationId, }, statusModifier),
|
2022-08-22 20:21:33 +08:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
modifier = {
|
2022-09-03 02:24:29 +08:00
|
|
|
$set: Object.assign({ meetingId, renderedInToast: false, podId }, statusModifier),
|
2022-08-22 20:21:33 +08:00
|
|
|
};
|
|
|
|
}
|
2022-09-03 02:24:29 +08:00
|
|
|
|
2020-11-25 21:54:18 +08:00
|
|
|
try {
|
2023-03-22 01:36:06 +08:00
|
|
|
const presentations = await Presentations.find(selector).fetchAsync();
|
|
|
|
const isPresentationPersisted = await Promise.all(presentations.map(async (item) => {
|
2023-03-15 01:27:52 +08:00
|
|
|
if (item.temporaryPresentationId && temporaryPresentationId) {
|
2022-09-14 21:33:41 +08:00
|
|
|
return item.temporaryPresentationId === temporaryPresentationId;
|
2023-03-22 01:36:06 +08:00
|
|
|
} else {
|
2022-09-14 21:33:41 +08:00
|
|
|
return item.id === presentationId;
|
2023-03-15 01:27:52 +08:00
|
|
|
}
|
2023-03-22 01:36:06 +08:00
|
|
|
}));
|
|
|
|
const isPersisted = isPresentationPersisted.some((item) => item === true);
|
|
|
|
|
2022-09-14 21:33:41 +08:00
|
|
|
let insertedID;
|
2023-03-22 01:36:06 +08:00
|
|
|
if (!isPersisted) {
|
2023-03-15 01:27:52 +08:00
|
|
|
const { insertedId } = await Presentations.upsertAsync(selector, modifier);
|
2022-09-14 21:33:41 +08:00
|
|
|
insertedID = insertedId;
|
|
|
|
} else {
|
|
|
|
selector['conversion.error'] = false;
|
2023-03-15 01:27:52 +08:00
|
|
|
const { insertedId } = await Presentations.updateAsync(selector, modifier);
|
2022-09-14 21:33:41 +08:00
|
|
|
insertedID = insertedId;
|
|
|
|
}
|
2023-03-22 01:36:06 +08:00
|
|
|
|
2022-09-14 21:33:41 +08:00
|
|
|
if (insertedID) {
|
2020-11-25 21:54:18 +08:00
|
|
|
Logger.info(`Updated presentation conversion status=${status} id=${presentationId} meeting=${meetingId}`);
|
|
|
|
} else {
|
|
|
|
Logger.debug('Upserted presentation conversion', { status, presentationId, meetingId });
|
2017-09-27 03:45:33 +08:00
|
|
|
}
|
2020-11-25 21:54:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Updating conversion status presentation to collection: ${err}`);
|
|
|
|
}
|
2017-06-07 20:28:41 +08:00
|
|
|
}
|