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

90 lines
2.2 KiB
JavaScript
Raw Normal View History

import { HTTP } from 'meteor/http';
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';
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 getSlideText = async (url) => {
2019-02-21 00:38:52 +08:00
let content = '';
try {
content = await HTTP.get(url).content;
} catch (error) {
Logger.error(`No file found. ${error}`);
}
return content;
};
const addSlides = (meetingId, podId, presentationId, slides) => {
slides.forEach(async (slide) => {
2019-02-21 00:38:52 +08:00
const content = await getSlideText(slide.txtUri);
Object.assign(slide, { content });
addSlide(meetingId, podId, presentationId, slide);
2016-11-12 03:02:46 +08:00
});
};
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
}