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

88 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-03-10 00:41:53 +08:00
import axios from 'axios';
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 {
2022-03-10 00:41:53 +08:00
const request = await axios(url);
content = request.data.toString();
2019-02-21 00:38:52 +08:00
} 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 });
await addSlide(meetingId, podId, presentationId, slide);
2016-11-12 03:02:46 +08:00
});
};
export default async 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,
temporaryPresentationId: String,
2017-10-12 08:40:51 +08:00
pages: [
{
id: String,
num: Number,
thumbUri: String,
txtUri: String,
svgUri: String,
current: Boolean,
xOffset: Number,
yOffset: Number,
widthRatio: Number,
heightRatio: Number,
2017-10-12 08:40:51 +08:00
},
],
downloadable: Boolean,
removable: Boolean,
isInitialPresentation: Boolean,
2017-10-12 08:40:51 +08:00
});
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,
2022-07-26 05:56:26 +08:00
'exportation.status': null,
2017-10-12 08:40:51 +08:00
}, flat(presentation, { safe: true })),
2016-11-12 03:02:46 +08:00
};
try {
const { insertedId } = await Presentations.upsertAsync(selector, modifier);
2016-11-12 03:02:46 +08:00
await 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}`);
}
2017-06-03 03:25:02 +08:00
}