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';
|
2017-10-12 10:00:28 +08:00
|
|
|
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';
|
2017-10-12 10:00:28 +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
|
|
|
|
2019-02-15 02:42:13 +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);
|
2022-06-20 21:50:49 +08:00
|
|
|
content = request.data.toString();
|
2019-02-21 00:38:52 +08:00
|
|
|
} catch (error) {
|
|
|
|
Logger.error(`No file found. ${error}`);
|
|
|
|
}
|
|
|
|
return content;
|
2019-02-15 02:42:13 +08:00
|
|
|
};
|
|
|
|
|
2018-04-10 03:48:37 +08:00
|
|
|
const addSlides = (meetingId, podId, presentationId, slides) => {
|
2019-02-15 02:42:13 +08:00
|
|
|
slides.forEach(async (slide) => {
|
2019-02-21 00:38:52 +08:00
|
|
|
const content = await getSlideText(slide.txtUri);
|
2019-02-15 02:42:13 +08:00
|
|
|
|
|
|
|
Object.assign(slide, { content });
|
|
|
|
|
2019-08-01 03:10:41 +08:00
|
|
|
addSlide(meetingId, podId, presentationId, slide);
|
2016-11-12 03:02:46 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-04-10 03:48:37 +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,
|
2022-03-14 23:10:27 +08:00
|
|
|
temporaryPresentationId: String,
|
2017-10-12 08:40:51 +08:00
|
|
|
pages: [
|
|
|
|
{
|
|
|
|
id: String,
|
|
|
|
num: Number,
|
|
|
|
thumbUri: String,
|
|
|
|
txtUri: String,
|
|
|
|
svgUri: String,
|
|
|
|
current: Boolean,
|
2022-08-16 20:12:43 +08:00
|
|
|
xOffset: Number,
|
|
|
|
yOffset: Number,
|
|
|
|
widthRatio: Number,
|
|
|
|
heightRatio: Number,
|
2017-10-12 08:40:51 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
downloadable: Boolean,
|
2022-02-03 22:37:14 +08:00
|
|
|
removable: Boolean,
|
2017-10-12 08:40:51 +08:00
|
|
|
});
|
2016-11-12 03:02:46 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2018-04-10 03:48:37 +08:00
|
|
|
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,
|
2018-04-10 03:48:37 +08:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-11-25 21:54:18 +08:00
|
|
|
try {
|
2022-02-09 21:37:40 +08:00
|
|
|
const { insertedId } = Presentations.upsert(selector, modifier);
|
2016-11-12 03:02:46 +08:00
|
|
|
|
2018-04-10 03:48:37 +08:00
|
|
|
addSlides(meetingId, podId, presentation.id, presentation.pages);
|
2022-11-17 21:55:19 +08:00
|
|
|
|
2022-02-09 21:37:40 +08:00
|
|
|
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}`);
|
|
|
|
}
|
|
|
|
|
2020-11-25 21:54:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Adding presentation to collection: ${err}`);
|
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|