bigbluebutton-Github/bigbluebutton-html5/imports/api/slides/server/modifiers/addSlideToCollection.js

72 lines
2.5 KiB
JavaScript
Raw Normal View History

import sizeOf from 'image-size';
2016-05-17 02:05:44 +08:00
import Slides from '/imports/api/slides';
2016-05-13 01:43:59 +08:00
export function addSlideToCollection(meetingId, presentationId, slideObject) {
const APP_CONFIG = Meteor.settings.public.app;
const url = Npm.require('url');
2016-07-27 01:33:35 +08:00
const imageUri = slideObject.svg_uri != null ? slideObject.svg_uri : slideObject.png_uri;
2016-05-13 01:43:59 +08:00
if (Slides.findOne({
meetingId: meetingId,
'slide.id': slideObject.id,
}) == null) {
const options = url.parse(imageUri);
2016-07-27 01:33:35 +08:00
2016-07-27 01:47:36 +08:00
let addSlideHelper = function (response) {
let contentType = response.headers['content-type'];
2016-07-27 01:33:35 +08:00
if (contentType.match(/svg/gi) || contentType.match(/png/gi)) {
let chunks = [];
response.on('data', Meteor.bindEnvironment(function (chunk) {
chunks.push(chunk);
})).on('end', Meteor.bindEnvironment(function () {
let buffer = Buffer.concat(chunks);
const dimensions = sizeOf(buffer);
const entry = {
meetingId: meetingId,
presentationId: presentationId,
slide: {
height_ratio: slideObject.height_ratio,
y_offset: slideObject.y_offset,
num: slideObject.num,
x_offset: slideObject.x_offset,
current: slideObject.current,
img_uri: slideObject.svg_uri != null ? slideObject.svg_uri : slideObject.png_uri,
txt_uri: slideObject.txt_uri,
id: slideObject.id,
width_ratio: slideObject.width_ratio,
swf_uri: slideObject.swf_uri,
thumb_uri: slideObject.thumb_uri,
width: dimensions.width,
height: dimensions.height,
},
};
Slides.insert(entry);
}));
} else {
console.log(`Slide file is not accessible or not ready yet`);
console.log(`response content-type`, response.headers['content-type']);
}
2016-07-27 01:47:36 +08:00
};
// HTTPS connection
if (APP_CONFIG.httpsConnection) {
const https = Npm.require('https');
2016-07-27 01:47:36 +08:00
https.get(options, Meteor.bindEnvironment(function (response) {
2016-07-27 01:47:36 +08:00
addSlideHelper(response);
2016-07-27 01:33:35 +08:00
}));
} else {
// HTTP connection
const http = Npm.require('http');
2016-07-27 01:33:35 +08:00
http.get(options, Meteor.bindEnvironment(function (response) {
2016-07-27 01:47:36 +08:00
addSlideHelper(response);
2016-07-27 01:33:35 +08:00
}));
}
2016-05-13 01:43:59 +08:00
2016-05-16 22:35:59 +08:00
//logger.info "added slide id =[#{id}]:#{slideObject.id} in #{meetingId}. Now there
2016-05-13 01:43:59 +08:00
// are #{Slides.find({meetingId: meetingId}).count()} slides in the meeting"
}
};