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

89 lines
2.2 KiB
JavaScript
Executable File

import axios from 'axios';
import { check } from 'meteor/check';
import Presentations from '/imports/api/presentations';
import Logger from '/imports/startup/server/logger';
import flat from 'flat';
import addSlide from '/imports/api/slides/server/modifiers/addSlide';
import setCurrentPresentation from './setCurrentPresentation';
const getSlideText = async (url) => {
let content = '';
try {
const request = await axios(url);
content = request.data.toString();
} catch (error) {
Logger.error(`No file found. ${error}`);
}
return content;
};
const addSlides = (meetingId, podId, presentationId, slides) => {
slides.forEach(async (slide) => {
const content = await getSlideText(slide.txtUri);
Object.assign(slide, { content });
addSlide(meetingId, podId, presentationId, slide);
});
};
export default function addPresentation(meetingId, podId, presentation) {
check(meetingId, String);
check(podId, String);
check(presentation, {
id: String,
name: String,
current: Boolean,
temporaryPresentationId: String,
pages: [
{
id: String,
num: Number,
thumbUri: String,
swfUri: String,
txtUri: String,
svgUri: String,
current: Boolean,
xCamera: Number,
yCamera: Number,
zoom: Number,
},
],
downloadable: Boolean,
removable: Boolean,
});
const selector = {
meetingId,
podId,
id: presentation.id,
};
const modifier = {
$set: Object.assign({
meetingId,
podId,
'conversion.done': true,
'conversion.error': false,
'exportation.isRunning': false,
'exportation.error': false,
}, flat(presentation, { safe: true })),
};
try {
const { insertedId } = Presentations.upsert(selector, modifier);
addSlides(meetingId, podId, presentation.id, presentation.pages);
if (presentation.current) {
setCurrentPresentation(meetingId, podId, presentation.id);
Logger.info(`Added presentation id=${presentation.id} meeting=${meetingId}`);
} else {
Logger.info(`Upserted presentation id=${presentation.id} meeting=${meetingId}`);
}
} catch (err) {
Logger.error(`Adding presentation to collection: ${err}`);
}
}