2017-05-04 00:36:16 +08:00
|
|
|
import Presentations from '/imports/api/presentations';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
|
2017-05-04 04:51:17 +08:00
|
|
|
import { call } from '/imports/ui/services/api';
|
2017-05-04 00:36:16 +08:00
|
|
|
|
|
|
|
const getPresentations = () =>
|
|
|
|
Presentations
|
|
|
|
.find()
|
|
|
|
.fetch()
|
|
|
|
.map(p => ({
|
|
|
|
_id: p._id,
|
|
|
|
id: p.presentation.id,
|
|
|
|
filename: p.presentation.name,
|
2017-05-06 04:17:38 +08:00
|
|
|
uploadedAt: p.upload ? p.upload.date : new Date(),
|
2017-05-04 00:36:16 +08:00
|
|
|
isCurrent: p.presentation.current,
|
|
|
|
isUploaded: true,
|
2017-05-06 04:17:38 +08:00
|
|
|
isProcessed: p.conversion.done,
|
|
|
|
conversion: p.conversion,
|
2017-05-04 00:36:16 +08:00
|
|
|
}));
|
|
|
|
|
|
|
|
const uploadPresentation = (file, meetingID, endpoint) => {
|
|
|
|
var data = new FormData();
|
|
|
|
data.append('Filename', file.filename);
|
|
|
|
data.append('presentation_name', file.filename);
|
|
|
|
data.append('fileUpload', file);
|
|
|
|
data.append('conference', meetingID);
|
|
|
|
data.append('room', meetingID);
|
|
|
|
|
|
|
|
/* TODO: Should we do the request on the html5 server instead of the client? */
|
2017-05-06 04:17:38 +08:00
|
|
|
/* TODO: Upload progress */
|
2017-05-04 00:36:16 +08:00
|
|
|
return fetch(endpoint, {
|
|
|
|
method: 'POST',
|
|
|
|
body: data,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-05-04 04:51:17 +08:00
|
|
|
const uploadPresentations = (presentationsToUpload, meetingID, uploadEndpoint) =>
|
|
|
|
Promise.all(
|
|
|
|
presentationsToUpload
|
|
|
|
.map(p => uploadPresentation(p.file, meetingID, uploadEndpoint))
|
|
|
|
);
|
|
|
|
|
|
|
|
const removePresentation = presentationID => call('removePresentation', presentationID);
|
|
|
|
|
|
|
|
const removePresentations = presentationsToRemove =>
|
|
|
|
Promise.all(presentationsToRemove.map(p => removePresentation(p.id)));
|
2017-05-04 00:36:16 +08:00
|
|
|
|
|
|
|
const persistPresentationChanges = (oldState, newState, uploadEndpoint) => {
|
|
|
|
const presentationsToUpload = newState.filter(_ => !oldState.includes(_));
|
2017-05-04 04:51:17 +08:00
|
|
|
const presentationsToRemove = oldState.filter(_ => !newState.includes(_));
|
|
|
|
const currentPresentation = newState.find(_ => _.isCurrent);
|
|
|
|
|
2017-05-04 00:36:16 +08:00
|
|
|
return new Promise((resolve, reject) =>
|
2017-05-06 04:17:38 +08:00
|
|
|
removePresentations(presentationsToRemove)
|
2017-05-23 22:05:42 +08:00
|
|
|
.then(uploadPresentations.bind(null, presentationsToUpload, Auth.meetingID, uploadEndpoint))
|
|
|
|
.then(call.bind(null, 'sharePresentation', currentPresentation.id, true))
|
|
|
|
.then(resolve)
|
|
|
|
.catch(reject)
|
2017-05-04 00:36:16 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getPresentations,
|
|
|
|
persistPresentationChanges,
|
|
|
|
};
|