2016-10-21 19:41:17 +08:00
|
|
|
import probe from 'probe-image-size';
|
2016-11-12 03:02:46 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2016-10-21 19:41:17 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 08:59:35 +08:00
|
|
|
import flat from 'flat';
|
2017-10-12 10:00:28 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2019-08-01 03:10:41 +08:00
|
|
|
import { Slides } from '/imports/api/slides';
|
2016-10-21 19:41:17 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { SVG, PNG } from '/imports/utils/mimeTypes';
|
2017-10-12 10:00:28 +08:00
|
|
|
import calculateSlideData from '/imports/api/slides/server/helpers';
|
2019-08-01 03:10:41 +08:00
|
|
|
import addSlidePositions from './addSlidePositions';
|
2016-05-13 01:43:59 +08:00
|
|
|
|
2019-05-21 06:00:36 +08:00
|
|
|
const loadSlidesFromHttpAlways = Meteor.settings.private.app.loadSlidesFromHttpAlways || false;
|
|
|
|
|
2016-11-12 03:02:46 +08:00
|
|
|
const requestWhiteboardHistory = (meetingId, slideId) => {
|
2018-01-08 08:24:05 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
2017-10-12 08:59:35 +08:00
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'GetWhiteboardAnnotationsReqMsg';
|
|
|
|
const USER_ID = 'nodeJSapp';
|
2016-11-12 03:02:46 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const payload = {
|
2017-10-12 08:59:35 +08:00
|
|
|
whiteboardId: slideId,
|
2016-11-12 03:02:46 +08:00
|
|
|
};
|
|
|
|
|
2017-10-12 08:59:35 +08:00
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, USER_ID, payload);
|
2016-11-12 03:02:46 +08:00
|
|
|
};
|
|
|
|
|
2016-10-21 19:41:17 +08:00
|
|
|
const SUPPORTED_TYPES = [SVG, PNG];
|
2016-07-27 01:33:35 +08:00
|
|
|
|
2019-05-21 06:00:36 +08:00
|
|
|
const fetchImageSizes = imageUri => probe(imageUri)
|
|
|
|
.then((result) => {
|
|
|
|
if (!SUPPORTED_TYPES.includes(result.mime)) {
|
|
|
|
throw new Meteor.Error('invalid-image-type', `received ${result.mime} expecting ${SUPPORTED_TYPES.join()}`);
|
|
|
|
}
|
2017-10-12 08:59:35 +08:00
|
|
|
|
2019-05-21 06:00:36 +08:00
|
|
|
return {
|
|
|
|
width: result.width,
|
|
|
|
height: result.height,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.catch((reason) => {
|
|
|
|
Logger.error(`Error parsing image size. ${reason}. uri=${imageUri}`);
|
|
|
|
return reason;
|
|
|
|
});
|
2017-10-12 08:59:35 +08:00
|
|
|
|
2018-04-10 03:48:37 +08:00
|
|
|
export default function addSlide(meetingId, podId, presentationId, slide) {
|
|
|
|
check(podId, String);
|
2016-10-21 19:41:17 +08:00
|
|
|
check(presentationId, String);
|
2017-10-12 08:59:35 +08:00
|
|
|
|
|
|
|
check(slide, {
|
|
|
|
id: String,
|
|
|
|
num: Number,
|
|
|
|
thumbUri: String,
|
|
|
|
swfUri: String,
|
|
|
|
txtUri: String,
|
|
|
|
svgUri: String,
|
|
|
|
current: Boolean,
|
2022-05-12 05:58:16 +08:00
|
|
|
xCamera: Number,
|
|
|
|
yCamera: Number,
|
|
|
|
zoom: Number,
|
2019-02-15 02:42:13 +08:00
|
|
|
content: String,
|
2017-10-12 08:59:35 +08:00
|
|
|
});
|
2016-07-27 01:33:35 +08:00
|
|
|
|
2019-08-01 03:10:41 +08:00
|
|
|
const {
|
|
|
|
id: slideId,
|
2022-05-12 05:58:16 +08:00
|
|
|
xCamera,
|
|
|
|
yCamera,
|
|
|
|
zoom,
|
2019-08-01 03:10:41 +08:00
|
|
|
...restSlide
|
|
|
|
} = slide;
|
|
|
|
|
2016-10-21 19:41:17 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2018-04-10 03:48:37 +08:00
|
|
|
podId,
|
2016-10-21 19:41:17 +08:00
|
|
|
presentationId,
|
2019-08-01 03:10:41 +08:00
|
|
|
id: slideId,
|
2016-10-21 19:41:17 +08:00
|
|
|
};
|
2016-07-27 01:33:35 +08:00
|
|
|
|
2017-10-12 08:59:35 +08:00
|
|
|
const imageUri = slide.svgUri || slide.pngUri;
|
2016-07-27 01:47:36 +08:00
|
|
|
|
2016-10-21 19:41:17 +08:00
|
|
|
const modifier = {
|
2017-10-12 08:59:35 +08:00
|
|
|
$set: Object.assign(
|
|
|
|
{ meetingId },
|
2018-04-10 03:48:37 +08:00
|
|
|
{ podId },
|
2017-10-12 08:59:35 +08:00
|
|
|
{ presentationId },
|
2019-08-01 03:10:41 +08:00
|
|
|
{ id: slideId },
|
|
|
|
{ imageUri },
|
|
|
|
flat(restSlide),
|
|
|
|
{ safe: true },
|
2017-10-12 08:59:35 +08:00
|
|
|
),
|
2016-10-21 19:41:17 +08:00
|
|
|
};
|
2016-07-27 01:47:36 +08:00
|
|
|
|
2019-05-21 06:00:36 +08:00
|
|
|
const imageSizeUri = (loadSlidesFromHttpAlways ? imageUri.replace(/^https/i, 'http') : imageUri);
|
|
|
|
|
|
|
|
return fetchImageSizes(imageSizeUri)
|
2016-11-12 03:02:46 +08:00
|
|
|
.then(({ width, height }) => {
|
2019-08-01 03:10:41 +08:00
|
|
|
// there is a rare case when for a very long not-active meeting the presentation
|
|
|
|
// files just disappear and width/height can't be retrieved
|
|
|
|
if (width && height) {
|
|
|
|
// pre-calculating the width, height, and vieBox coordinates / dimensions
|
|
|
|
// to unload the client-side
|
|
|
|
const slideData = {
|
|
|
|
width,
|
|
|
|
height,
|
2022-05-20 01:24:47 +08:00
|
|
|
xCamera,
|
|
|
|
yCamera,
|
2022-05-12 05:58:16 +08:00
|
|
|
zoom,
|
2019-08-01 03:10:41 +08:00
|
|
|
};
|
2022-05-20 01:24:47 +08:00
|
|
|
//const slidePosition = calculateSlideData(slideData);
|
2019-08-01 03:10:41 +08:00
|
|
|
|
2022-05-12 05:58:16 +08:00
|
|
|
addSlidePositions(meetingId, podId, presentationId, slideId, slideData);
|
2017-10-12 08:59:35 +08:00
|
|
|
}
|
|
|
|
|
2020-11-27 00:23:57 +08:00
|
|
|
try {
|
|
|
|
const { insertedId, numberAffected } = Slides.upsert(selector, modifier);
|
|
|
|
|
|
|
|
requestWhiteboardHistory(meetingId, slideId);
|
|
|
|
|
|
|
|
if (insertedId) {
|
|
|
|
Logger.info(`Added slide id=${slideId} pod=${podId} presentation=${presentationId}`);
|
|
|
|
} else if (numberAffected) {
|
|
|
|
Logger.info(`Upserted slide id=${slideId} pod=${podId} presentation=${presentationId}`);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Error on adding slide to collection: ${err}`);
|
|
|
|
}
|
2016-11-12 03:02:46 +08:00
|
|
|
})
|
2019-08-01 03:10:41 +08:00
|
|
|
.catch(reason => Logger.error(`Error parsing image size. ${reason}. slide=${slideId} uri=${imageUri}`));
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|