bigbluebutton-Github/bigbluebutton-html5/imports/api/presentations/server/modifiers/addPresentation.js

80 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-11-12 03:02:46 +08:00
import { check } from 'meteor/check';
import Presentations from '/imports/api/presentations';
2016-11-12 03:02:46 +08:00
import Logger from '/imports/startup/server/logger';
2017-10-12 08:40:51 +08:00
import flat from 'flat';
2016-11-12 03:02:46 +08:00
import addSlide from '/imports/api/slides/server/modifiers/addSlide';
2017-10-12 08:40:51 +08:00
import setCurrentPresentation from './setCurrentPresentation';
2016-11-12 03:02:46 +08:00
const addSlides = (meetingId, podId, presentationId, slides) => {
2017-06-03 03:25:02 +08:00
const slidesAdded = [];
2016-11-12 03:02:46 +08:00
2017-06-03 03:25:02 +08:00
slides.forEach((slide) => {
slidesAdded.push(addSlide(meetingId, podId, presentationId, slide));
2016-11-12 03:02:46 +08:00
});
return slidesAdded;
};
export default function addPresentation(meetingId, podId, presentation) {
check(meetingId, String);
check(podId, String);
2017-10-12 08:40:51 +08:00
check(presentation, {
id: String,
name: String,
current: Boolean,
pages: [
{
id: String,
num: Number,
thumbUri: String,
swfUri: String,
txtUri: String,
svgUri: String,
current: Boolean,
xOffset: Number,
yOffset: Number,
widthRatio: Number,
heightRatio: Number,
},
],
downloadable: Boolean,
});
2016-11-12 03:02:46 +08:00
const selector = {
meetingId,
podId,
2017-10-12 08:40:51 +08:00
id: presentation.id,
2016-11-12 03:02:46 +08:00
};
const modifier = {
2017-10-12 08:40:51 +08:00
$set: Object.assign({
2016-11-12 03:02:46 +08:00
meetingId,
podId,
2017-10-12 08:40:51 +08:00
'conversion.done': true,
'conversion.error': false,
}, flat(presentation, { safe: true })),
2016-11-12 03:02:46 +08:00
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Adding presentation to collection: ${err}`);
2016-11-12 03:02:46 +08:00
}
addSlides(meetingId, podId, presentation.id, presentation.pages);
2016-11-12 03:02:46 +08:00
const { insertedId } = numChanged;
if (insertedId) {
2017-10-12 08:40:51 +08:00
if (presentation.current) {
setCurrentPresentation(meetingId, podId, presentation.id);
2017-10-12 08:40:51 +08:00
}
2016-11-12 03:02:46 +08:00
return Logger.info(`Added presentation id=${presentation.id} meeting=${meetingId}`);
2016-11-12 03:02:46 +08:00
}
2017-10-12 08:40:51 +08:00
return Logger.info(`Upserted presentation id=${presentation.id} meeting=${meetingId}`);
2016-11-12 03:02:46 +08:00
};
return Presentations.upsert(selector, modifier, cb);
2017-06-03 03:25:02 +08:00
}