bigbluebutton-Github/bigbluebutton-html5/imports/api/presentations/server/handlers/presentationConversionUpdate.js

91 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-05-06 04:17:38 +08:00
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Presentations from '/imports/api/presentations';
2017-05-06 04:17:38 +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';
const PDF_HAS_BIG_PAGE_KEY = 'PDF_HAS_BIG_PAGE';
2017-05-06 04:17:38 +08:00
const GENERATED_SLIDE_KEY = 'GENERATED_SLIDE';
// 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
2017-09-08 02:18:14 +08:00
export default function handlePresentationConversionUpdate({ body }, meetingId) {
2017-09-29 21:50:46 +08:00
check(body, Object);
const {
presentationId, podId, messageKey: status, presName: presentationName,
} = body;
2017-05-06 04:17:38 +08:00
check(meetingId, String);
check(presentationId, String);
check(podId, String);
2017-05-06 04:17:38 +08:00
check(status, String);
const statusModifier = {
2017-05-06 04:17:38 +08:00
'conversion.status': status,
'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;
break;
2017-05-06 04:17:38 +08:00
case UNSUPPORTED_DOCUMENT_KEY:
case OFFICE_DOC_CONVERSION_FAILED_KEY:
case OFFICE_DOC_CONVERSION_INVALID_KEY:
case PAGE_COUNT_FAILED_KEY:
case PAGE_COUNT_EXCEEDED_KEY:
case PDF_HAS_BIG_PAGE_KEY:
2017-09-23 04:43:07 +08:00
statusModifier.id = presentationId;
statusModifier.name = presentationName;
2017-05-06 04:17:38 +08:00
statusModifier['conversion.error'] = true;
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;
default:
2017-05-06 04:17:38 +08:00
break;
}
const selector = {
meetingId,
podId,
2017-09-08 02:18:14 +08:00
id: presentationId,
2017-05-06 04:17:38 +08:00
};
const modifier = {
$set: Object.assign({ meetingId, podId }, statusModifier),
2017-05-06 04:17:38 +08:00
};
2017-09-27 03:45:33 +08:00
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Updating conversion status presentation to collection: ${err}`);
2017-09-27 03:45:33 +08:00
}
const { insertedId } = numChanged;
if (insertedId) {
return Logger.info(`Updated presentation conversion status=${status} id=${presentationId} meeting=${meetingId}`);
2017-09-27 03:45:33 +08:00
}
return Logger.debug(`Upserted presentation conversion status=${status} id=${presentationId} meeting=${meetingId}`);
2017-09-27 03:45:33 +08:00
};
return Presentations.upsert(selector, modifier, cb);
}