2017-10-12 10:00:28 +08:00
|
|
|
import Presentations from '/imports/api/presentations';
|
2018-09-05 00:56:10 +08:00
|
|
|
import PresentationUploadToken from '/imports/api/presentation-upload-token';
|
2017-05-04 00:36:16 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2019-03-09 04:46:25 +08:00
|
|
|
import Poll from '/imports/api/polls/';
|
2022-07-22 02:56:44 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2017-09-27 03:45:33 +08:00
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
2020-04-30 00:34:37 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2017-11-28 20:26:00 +08:00
|
|
|
import _ from 'lodash';
|
2022-08-03 04:25:15 +08:00
|
|
|
import update from 'immutability-helper';
|
|
|
|
import { Random } from 'meteor/random';
|
|
|
|
import { UploadingPresentations } from '/imports/api/presentations';
|
2022-06-25 00:47:17 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
2017-05-04 00:36:16 +08:00
|
|
|
|
2017-09-27 03:45:33 +08:00
|
|
|
const CONVERSION_TIMEOUT = 300000;
|
2018-09-05 00:56:10 +08:00
|
|
|
const TOKEN_TIMEOUT = 5000;
|
2022-07-22 02:56:44 +08:00
|
|
|
const PRESENTATION_CONFIG = Meteor.settings.public.presentation;
|
2017-09-27 03:45:33 +08:00
|
|
|
|
2019-02-21 06:20:04 +08:00
|
|
|
// fetch doesn't support progress. So we use xhr which support progress.
|
2017-09-08 02:18:14 +08:00
|
|
|
const futch = (url, opts = {}, onProgress) => new Promise((res, rej) => {
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
xhr.open(opts.method || 'get', url);
|
|
|
|
|
|
|
|
Object.keys(opts.headers || {})
|
|
|
|
.forEach(k => xhr.setRequestHeader(k, opts.headers[k]));
|
|
|
|
|
|
|
|
xhr.onload = (e) => {
|
|
|
|
if (e.target.status !== 200) {
|
|
|
|
return rej({ code: e.target.status, message: e.target.statusText });
|
|
|
|
}
|
|
|
|
|
|
|
|
return res(e.target.responseText);
|
|
|
|
};
|
|
|
|
xhr.onerror = rej;
|
|
|
|
if (xhr.upload && onProgress) {
|
|
|
|
xhr.upload.addEventListener('progress', onProgress, false);
|
|
|
|
}
|
|
|
|
xhr.send(opts.body);
|
|
|
|
});
|
|
|
|
|
2019-03-19 02:13:15 +08:00
|
|
|
const getPresentations = () => Presentations
|
|
|
|
.find({
|
|
|
|
'conversion.error': false,
|
|
|
|
})
|
|
|
|
.fetch()
|
|
|
|
.map((presentation) => {
|
|
|
|
const {
|
|
|
|
conversion,
|
|
|
|
current,
|
|
|
|
downloadable,
|
2022-02-03 22:37:14 +08:00
|
|
|
removable,
|
2022-09-27 21:05:27 +08:00
|
|
|
renderedInToast,
|
|
|
|
temporaryPresentationId,
|
2019-03-19 02:13:15 +08:00
|
|
|
id,
|
|
|
|
name,
|
2022-07-20 03:36:00 +08:00
|
|
|
exportation,
|
2019-03-19 02:13:15 +08:00
|
|
|
} = presentation;
|
|
|
|
|
|
|
|
const uploadTimestamp = id.split('-').pop();
|
|
|
|
|
2022-12-08 22:20:17 +08:00
|
|
|
|
2019-03-19 02:13:15 +08:00
|
|
|
return {
|
|
|
|
id,
|
|
|
|
filename: name,
|
2022-09-27 21:05:27 +08:00
|
|
|
renderedInToast,
|
|
|
|
temporaryPresentationId,
|
2019-03-19 02:13:15 +08:00
|
|
|
isCurrent: current || false,
|
2017-09-08 02:18:14 +08:00
|
|
|
upload: { done: true, error: false },
|
2019-03-19 02:13:15 +08:00
|
|
|
isDownloadable: downloadable,
|
2022-02-03 22:37:14 +08:00
|
|
|
isRemovable: removable,
|
2019-03-19 02:13:15 +08:00
|
|
|
conversion: conversion || { done: true, error: false },
|
|
|
|
uploadTimestamp,
|
2022-08-24 21:31:20 +08:00
|
|
|
exportation: exportation || { error: false },
|
2019-03-19 02:13:15 +08:00
|
|
|
};
|
|
|
|
});
|
2017-05-04 00:36:16 +08:00
|
|
|
|
2019-02-21 06:20:04 +08:00
|
|
|
const dispatchTogglePresentationDownloadable = (presentation, newState) => {
|
|
|
|
makeCall('setPresentationDownloadable', presentation.id, newState);
|
|
|
|
};
|
|
|
|
|
2019-07-12 01:46:44 +08:00
|
|
|
const observePresentationConversion = (
|
|
|
|
meetingId,
|
2022-08-22 20:21:33 +08:00
|
|
|
temporaryPresentationId,
|
2019-07-12 01:46:44 +08:00
|
|
|
onConversion,
|
|
|
|
) => new Promise((resolve) => {
|
2022-09-16 23:52:41 +08:00
|
|
|
// The token is placed as an id before the original one is generated
|
2022-10-06 20:58:42 +08:00
|
|
|
// in the back-end;
|
2022-09-22 04:41:31 +08:00
|
|
|
const tokenId = PresentationUploadToken.findOne({temporaryPresentationId})?.authzToken;
|
2022-08-08 19:50:52 +08:00
|
|
|
|
2019-07-12 01:46:44 +08:00
|
|
|
const conversionTimeout = setTimeout(() => {
|
|
|
|
onConversion({
|
|
|
|
done: true,
|
|
|
|
error: true,
|
|
|
|
status: 'TIMEOUT',
|
|
|
|
});
|
|
|
|
}, CONVERSION_TIMEOUT);
|
|
|
|
|
|
|
|
const didValidate = (doc) => {
|
|
|
|
clearTimeout(conversionTimeout);
|
|
|
|
resolve(doc);
|
|
|
|
};
|
2017-11-28 01:44:45 +08:00
|
|
|
|
2019-07-12 01:46:44 +08:00
|
|
|
Tracker.autorun((c) => {
|
|
|
|
const query = Presentations.find({ meetingId });
|
2017-09-27 03:45:33 +08:00
|
|
|
|
2019-07-12 01:46:44 +08:00
|
|
|
query.observe({
|
2021-04-21 01:21:12 +08:00
|
|
|
added: (doc) => {
|
|
|
|
|
2022-09-16 23:52:41 +08:00
|
|
|
if (doc.temporaryPresentationId !== temporaryPresentationId && doc.id !== tokenId) return;
|
2021-04-21 01:21:12 +08:00
|
|
|
|
2022-11-25 22:02:51 +08:00
|
|
|
if (doc.conversion.status === 'FILE_TOO_LARGE' || doc.conversion.status === 'UNSUPPORTED_DOCUMENT'
|
|
|
|
|| doc.conversion.status === 'CONVERSION_TIMEOUT' || doc.conversion.status === "IVALID_MIME_TYPE") {
|
2022-09-17 04:36:23 +08:00
|
|
|
Presentations.update({id: tokenId}, {$set: {temporaryPresentationId, renderedInToast: false}})
|
2021-04-21 01:21:12 +08:00
|
|
|
onConversion(doc.conversion);
|
|
|
|
c.stop();
|
|
|
|
clearTimeout(conversionTimeout);
|
|
|
|
}
|
|
|
|
},
|
2019-07-12 01:46:44 +08:00
|
|
|
changed: (newDoc) => {
|
2022-08-22 20:21:33 +08:00
|
|
|
if (newDoc.temporaryPresentationId !== temporaryPresentationId) return;
|
2017-09-27 03:45:33 +08:00
|
|
|
|
2019-07-12 01:46:44 +08:00
|
|
|
onConversion(newDoc.conversion);
|
2017-11-28 01:44:45 +08:00
|
|
|
|
2021-04-21 01:21:12 +08:00
|
|
|
if (newDoc.conversion.error) {
|
|
|
|
c.stop();
|
|
|
|
clearTimeout(conversionTimeout);
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:46:44 +08:00
|
|
|
if (newDoc.conversion.done) {
|
|
|
|
c.stop();
|
|
|
|
didValidate(newDoc);
|
|
|
|
}
|
|
|
|
},
|
2017-09-27 03:45:33 +08:00
|
|
|
});
|
|
|
|
});
|
2019-07-12 01:46:44 +08:00
|
|
|
});
|
2017-09-27 03:45:33 +08:00
|
|
|
|
2019-07-12 01:46:44 +08:00
|
|
|
const requestPresentationUploadToken = (
|
2022-08-22 20:21:33 +08:00
|
|
|
temporaryPresentationId,
|
2019-07-12 01:46:44 +08:00
|
|
|
podId,
|
|
|
|
meetingId,
|
|
|
|
filename,
|
|
|
|
) => new Promise((resolve, reject) => {
|
2022-08-22 20:21:33 +08:00
|
|
|
makeCall('requestPresentationUploadToken', podId, filename, temporaryPresentationId);
|
2019-07-12 01:46:44 +08:00
|
|
|
|
|
|
|
let computation = null;
|
|
|
|
const timeout = setTimeout(() => {
|
|
|
|
computation.stop();
|
|
|
|
reject({ code: 408, message: 'requestPresentationUploadToken timeout' });
|
|
|
|
}, TOKEN_TIMEOUT);
|
|
|
|
|
|
|
|
Tracker.autorun((c) => {
|
|
|
|
computation = c;
|
2022-08-22 20:21:33 +08:00
|
|
|
const sub = Meteor.subscribe('presentation-upload-token', podId, filename, temporaryPresentationId);
|
2019-07-12 01:46:44 +08:00
|
|
|
if (!sub.ready()) return;
|
|
|
|
|
|
|
|
const PresentationToken = PresentationUploadToken.findOne({
|
|
|
|
podId,
|
|
|
|
meetingId,
|
2022-08-22 20:21:33 +08:00
|
|
|
temporaryPresentationId,
|
2019-07-12 01:46:44 +08:00
|
|
|
used: false,
|
2018-09-05 00:56:10 +08:00
|
|
|
});
|
2019-07-12 01:46:44 +08:00
|
|
|
|
|
|
|
if (!PresentationToken || !('failed' in PresentationToken)) return;
|
|
|
|
|
|
|
|
if (!PresentationToken.failed) {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
resolve(PresentationToken.authzToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PresentationToken.failed) {
|
2019-07-19 02:45:11 +08:00
|
|
|
reject({ code: 401, message: `requestPresentationUploadToken token ${PresentationToken.authzToken} failed` });
|
2019-07-12 01:46:44 +08:00
|
|
|
}
|
2018-09-05 00:56:10 +08:00
|
|
|
});
|
2019-07-12 01:46:44 +08:00
|
|
|
});
|
2018-09-05 00:56:10 +08:00
|
|
|
|
2019-07-12 01:46:44 +08:00
|
|
|
const uploadAndConvertPresentation = (
|
|
|
|
file,
|
|
|
|
downloadable,
|
|
|
|
podId,
|
|
|
|
meetingId,
|
|
|
|
endpoint,
|
|
|
|
onUpload,
|
|
|
|
onProgress,
|
|
|
|
onConversion,
|
|
|
|
) => {
|
2022-08-22 20:21:33 +08:00
|
|
|
const temporaryPresentationId = _.uniqueId(Random.id(20))
|
2022-04-08 22:28:47 +08:00
|
|
|
|
2017-06-07 20:28:41 +08:00
|
|
|
const data = new FormData();
|
2017-05-04 00:36:16 +08:00
|
|
|
data.append('fileUpload', file);
|
2018-09-05 00:56:10 +08:00
|
|
|
data.append('conference', meetingId);
|
|
|
|
data.append('room', meetingId);
|
2022-08-22 20:21:33 +08:00
|
|
|
data.append('temporaryPresentationId', temporaryPresentationId);
|
2018-09-05 00:56:10 +08:00
|
|
|
|
|
|
|
// TODO: Currently the uploader is not related to a POD so the id is fixed to the default
|
|
|
|
data.append('pod_id', podId);
|
|
|
|
|
2019-02-23 05:04:35 +08:00
|
|
|
data.append('is_downloadable', downloadable);
|
2017-05-04 00:36:16 +08:00
|
|
|
|
2017-09-08 02:18:14 +08:00
|
|
|
const opts = {
|
2017-05-04 00:36:16 +08:00
|
|
|
method: 'POST',
|
|
|
|
body: data,
|
2017-09-08 02:18:14 +08:00
|
|
|
};
|
|
|
|
|
2022-10-06 20:58:42 +08:00
|
|
|
// If the presentation is from sharedNotes I don't want to
|
2022-09-22 04:41:31 +08:00
|
|
|
// insert another one, I just need to update it.
|
|
|
|
UploadingPresentations.upsert({
|
|
|
|
filename: file.name,
|
|
|
|
lastModifiedUploader: false,
|
|
|
|
}, {
|
|
|
|
$set: {
|
|
|
|
temporaryPresentationId,
|
|
|
|
progress: 0,
|
|
|
|
filename: file.name,
|
|
|
|
lastModifiedUploader: true,
|
|
|
|
upload: {
|
|
|
|
done: false,
|
|
|
|
error: false
|
|
|
|
},
|
|
|
|
uploadTimestamp: new Date()
|
|
|
|
}
|
2022-08-03 04:25:15 +08:00
|
|
|
})
|
|
|
|
|
2022-08-22 20:21:33 +08:00
|
|
|
return requestPresentationUploadToken(temporaryPresentationId, podId, meetingId, file.name)
|
2019-07-12 01:46:44 +08:00
|
|
|
.then((token) => {
|
|
|
|
makeCall('setUsedToken', token);
|
2022-10-05 03:25:54 +08:00
|
|
|
UploadingPresentations.upsert({
|
|
|
|
temporaryPresentationId
|
|
|
|
}, {
|
|
|
|
$set: {
|
|
|
|
id: token,
|
|
|
|
}
|
|
|
|
})
|
2022-08-03 04:25:15 +08:00
|
|
|
return futch(endpoint.replace('upload', `${token}/upload`), opts, (e) => {
|
2022-08-08 19:50:52 +08:00
|
|
|
onProgress(e);
|
2022-12-08 22:20:17 +08:00
|
|
|
let pr = (e.loaded / e.total) * 100;
|
|
|
|
if (pr != 100) UploadingPresentations.upsert({ temporaryPresentationId }, {$set: {progress: pr}});
|
|
|
|
else UploadingPresentations.upsert({ temporaryPresentationId }, {$set: {
|
|
|
|
progress: pr,
|
|
|
|
upload: {
|
|
|
|
done: true,
|
|
|
|
error: false,
|
|
|
|
}
|
|
|
|
}});
|
2022-08-03 04:25:15 +08:00
|
|
|
});
|
2019-07-12 01:46:44 +08:00
|
|
|
})
|
2022-08-22 20:21:33 +08:00
|
|
|
.then(() => observePresentationConversion(meetingId, temporaryPresentationId, onConversion))
|
2017-09-27 03:45:33 +08:00
|
|
|
// Trap the error so we can have parallel upload
|
|
|
|
.catch((error) => {
|
2020-04-30 00:34:37 +08:00
|
|
|
logger.debug({
|
|
|
|
logCode: 'presentation_uploader_service',
|
|
|
|
extraInfo: {
|
|
|
|
error,
|
|
|
|
},
|
|
|
|
}, 'Generic presentation upload exception catcher');
|
2022-08-22 20:21:33 +08:00
|
|
|
observePresentationConversion(meetingId, temporaryPresentationId, onConversion);
|
2017-11-28 01:44:45 +08:00
|
|
|
onUpload({ error: true, done: true, status: error.code });
|
|
|
|
return Promise.resolve();
|
2017-09-27 03:45:33 +08:00
|
|
|
});
|
2017-05-04 00:36:16 +08:00
|
|
|
};
|
|
|
|
|
2019-07-12 01:46:44 +08:00
|
|
|
const uploadAndConvertPresentations = (
|
|
|
|
presentationsToUpload,
|
|
|
|
meetingId,
|
|
|
|
podId,
|
|
|
|
uploadEndpoint,
|
2021-04-21 01:21:12 +08:00
|
|
|
) => Promise.all(presentationsToUpload.map((p) => uploadAndConvertPresentation(
|
2022-04-08 22:28:47 +08:00
|
|
|
p.file, p.isDownloadable, podId, meetingId, uploadEndpoint,
|
2019-07-12 01:46:44 +08:00
|
|
|
p.onUpload, p.onProgress, p.onConversion,
|
|
|
|
)));
|
2017-05-04 04:51:17 +08:00
|
|
|
|
2020-01-25 09:02:36 +08:00
|
|
|
const setPresentation = (presentationId, podId) => {
|
|
|
|
makeCall('setPresentation', presentationId, podId);
|
|
|
|
};
|
2017-09-30 01:44:18 +08:00
|
|
|
|
2019-03-09 04:46:25 +08:00
|
|
|
const removePresentation = (presentationId, podId) => {
|
2019-08-22 20:05:06 +08:00
|
|
|
const hasPoll = Poll.find({}, { fields: {} }).count();
|
2019-03-09 04:46:25 +08:00
|
|
|
if (hasPoll) makeCall('stopPoll');
|
|
|
|
makeCall('removePresentation', presentationId, podId);
|
|
|
|
};
|
2017-05-04 04:51:17 +08:00
|
|
|
|
2019-07-12 01:46:44 +08:00
|
|
|
const removePresentations = (
|
|
|
|
presentationsToRemove,
|
|
|
|
podId,
|
2021-04-21 01:21:12 +08:00
|
|
|
) => Promise.all(presentationsToRemove.map((p) => removePresentation(p.id, podId)));
|
2017-05-04 00:36:16 +08:00
|
|
|
|
2018-09-05 00:56:10 +08:00
|
|
|
const persistPresentationChanges = (oldState, newState, uploadEndpoint, podId) => {
|
2021-04-21 01:21:12 +08:00
|
|
|
const presentationsToUpload = newState.filter((p) => !p.upload.done);
|
|
|
|
const presentationsToRemove = oldState.filter((p) => !_.find(newState, ['id', p.id]));
|
2017-11-28 20:26:00 +08:00
|
|
|
|
2021-04-21 01:21:12 +08:00
|
|
|
let currentPresentation = newState.find((p) => p.isCurrent);
|
2017-11-28 01:44:45 +08:00
|
|
|
|
2018-09-05 00:56:10 +08:00
|
|
|
return uploadAndConvertPresentations(presentationsToUpload, Auth.meetingID, podId, uploadEndpoint)
|
2017-11-28 01:44:45 +08:00
|
|
|
.then((presentations) => {
|
|
|
|
if (!presentations.length && !currentPresentation) return Promise.resolve();
|
|
|
|
|
|
|
|
// Update the presentation with their new ids
|
|
|
|
presentations.forEach((p, i) => {
|
|
|
|
if (p === undefined) return;
|
|
|
|
presentationsToUpload[i].onDone(p.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
return Promise.resolve(presentations);
|
|
|
|
})
|
|
|
|
.then((presentations) => {
|
2017-12-16 02:49:47 +08:00
|
|
|
if (currentPresentation === undefined) {
|
2021-08-27 04:13:05 +08:00
|
|
|
setPresentation('', podId);
|
2017-12-16 02:49:47 +08:00
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2017-11-28 01:44:45 +08:00
|
|
|
// If its a newly uploaded presentation we need to get it from promise result
|
|
|
|
if (!currentPresentation.conversion.done) {
|
2021-04-21 01:21:12 +08:00
|
|
|
const currentIndex = presentationsToUpload.findIndex((p) => p === currentPresentation);
|
2017-11-28 01:44:45 +08:00
|
|
|
currentPresentation = presentations[currentIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip setting as current if error happened
|
2017-12-16 02:49:47 +08:00
|
|
|
if (currentPresentation.conversion.error) {
|
2017-11-28 01:44:45 +08:00
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2018-09-05 00:56:10 +08:00
|
|
|
return setPresentation(currentPresentation.id, podId);
|
2017-11-28 01:44:45 +08:00
|
|
|
})
|
2018-09-05 00:56:10 +08:00
|
|
|
.then(removePresentations.bind(null, presentationsToRemove, podId));
|
2017-05-04 00:36:16 +08:00
|
|
|
};
|
|
|
|
|
2022-08-08 19:50:52 +08:00
|
|
|
const handleSavePresentation = (presentations = [], isFromPresentationUploaderInterface = true, newPres = {}) => {
|
|
|
|
const currentPresentations = getPresentations();
|
|
|
|
if (!isFromPresentationUploaderInterface) {
|
|
|
|
|
|
|
|
if (presentations.length === 0) {
|
|
|
|
presentations = [...currentPresentations];
|
|
|
|
}
|
|
|
|
presentations = presentations.map(p => update(p, {
|
|
|
|
isCurrent: {
|
|
|
|
$set: false
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
newPres.isCurrent = true;
|
|
|
|
presentations.push(newPres);
|
|
|
|
}
|
|
|
|
return persistPresentationChanges(
|
|
|
|
currentPresentations,
|
|
|
|
presentations,
|
|
|
|
PRESENTATION_CONFIG.uploadEndpoint,
|
|
|
|
'DEFAULT_PRESENTATION_POD'
|
|
|
|
)}
|
|
|
|
|
2022-06-25 00:47:17 +08:00
|
|
|
const getExternalUploadData = () => {
|
|
|
|
const { meetingProp } = Meetings.findOne(
|
|
|
|
{ meetingId: Auth.meetingID },
|
|
|
|
{
|
|
|
|
fields: {
|
2022-09-12 22:04:13 +08:00
|
|
|
'meetingProp.presentationUploadExternalDescription': 1,
|
|
|
|
'meetingProp.presentationUploadExternalUrl': 1
|
2022-06-25 00:47:17 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2022-09-12 22:04:13 +08:00
|
|
|
const { presentationUploadExternalDescription, presentationUploadExternalUrl } = meetingProp;
|
2022-06-25 00:47:17 +08:00
|
|
|
|
|
|
|
return {
|
2022-09-12 22:04:13 +08:00
|
|
|
presentationUploadExternalDescription,
|
|
|
|
presentationUploadExternalUrl,
|
2022-06-25 00:47:17 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-20 03:36:00 +08:00
|
|
|
const exportPresentationToChat = (presentationId, observer) => {
|
|
|
|
let lastStatus = {};
|
|
|
|
|
|
|
|
Tracker.autorun((c) => {
|
|
|
|
const cursor = Presentations.find({ id: presentationId });
|
|
|
|
|
|
|
|
const checkStatus = (exportation) => {
|
2022-08-24 21:31:20 +08:00
|
|
|
const shouldStop = lastStatus.status === 'PROCESSING' && exportation.status === 'EXPORTED';
|
2022-07-20 03:36:00 +08:00
|
|
|
|
|
|
|
if (shouldStop) {
|
|
|
|
observer(exportation, true);
|
|
|
|
return c.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
observer(exportation, false);
|
|
|
|
lastStatus = exportation;
|
|
|
|
};
|
|
|
|
|
|
|
|
cursor.observe({
|
|
|
|
added: (doc) => {
|
|
|
|
checkStatus(doc.exportation);
|
|
|
|
},
|
|
|
|
changed: (doc) => {
|
|
|
|
checkStatus(doc.exportation);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
makeCall('exportPresentationToChat', presentationId);
|
|
|
|
};
|
|
|
|
|
2022-12-08 22:20:17 +08:00
|
|
|
function handleFiledrop(files, files2, that) {
|
|
|
|
if(that){
|
|
|
|
const { fileValidMimeTypes, intl } = that.props;
|
|
|
|
const { toUploadCount } = that.state;
|
|
|
|
const validMimes = fileValidMimeTypes.map((fileValid) => fileValid.mime);
|
|
|
|
const validExtentions = fileValidMimeTypes.map((fileValid) => fileValid.extension);
|
|
|
|
const [accepted, rejected] = _.partition(files
|
|
|
|
.concat(files2), (f) => (
|
|
|
|
validMimes.includes(f.type) || validExtentions.includes(`.${f.name.split('.').pop()}`)
|
|
|
|
));
|
|
|
|
|
|
|
|
const presentationsToUpload = accepted.map((file) => {
|
|
|
|
const id = _.uniqueId(file.name);
|
|
|
|
|
|
|
|
return {
|
|
|
|
file,
|
|
|
|
isDownloadable: false, // by default new presentations are set not to be downloadable
|
|
|
|
isRemovable: true,
|
|
|
|
id,
|
|
|
|
filename: file.name,
|
|
|
|
isCurrent: false,
|
|
|
|
conversion: { done: false, error: false },
|
|
|
|
upload: { done: false, error: false, progress: 0 },
|
|
|
|
exportation: { error: false },
|
|
|
|
onProgress: (event) => {
|
|
|
|
if (!event.lengthComputable) {
|
|
|
|
that.deepMergeUpdateFileKey(id, 'upload', {
|
|
|
|
progress: 100,
|
|
|
|
done: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let pt = (event.loaded === event.total);
|
|
|
|
that.deepMergeUpdateFileKey(id, 'upload', {
|
|
|
|
progress: (event.loaded / event.total) * 100,
|
|
|
|
done: event.loaded === event.total,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onConversion: (conversion) => {
|
|
|
|
that.deepMergeUpdateFileKey(id, 'conversion', conversion);
|
|
|
|
},
|
|
|
|
onUpload: (upload) => {
|
|
|
|
that.deepMergeUpdateFileKey(id, 'upload', upload);
|
|
|
|
},
|
|
|
|
onDone: (newId) => {
|
|
|
|
that.updateFileKey(id, 'id', newId);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
that.setState(({ presentations }) => ({
|
|
|
|
presentations: presentations.concat(presentationsToUpload),
|
|
|
|
toUploadCount: (toUploadCount + presentationsToUpload.length),
|
|
|
|
}), () => {
|
|
|
|
// after the state is set (files have been dropped),
|
|
|
|
// make the first of the new presentations current
|
|
|
|
if (presentationsToUpload && presentationsToUpload.length) {
|
|
|
|
that.handleCurrentChange(presentationsToUpload[0].id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (rejected.length > 0) {
|
|
|
|
notify(intl.formatMessage(intlMessages.rejectedError), 'error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-04 00:36:16 +08:00
|
|
|
export default {
|
2022-08-08 19:50:52 +08:00
|
|
|
handleSavePresentation,
|
2017-05-04 00:36:16 +08:00
|
|
|
getPresentations,
|
|
|
|
persistPresentationChanges,
|
2019-02-21 06:20:04 +08:00
|
|
|
dispatchTogglePresentationDownloadable,
|
2020-01-25 09:02:36 +08:00
|
|
|
setPresentation,
|
2022-03-08 23:29:11 +08:00
|
|
|
requestPresentationUploadToken,
|
2022-06-25 00:47:17 +08:00
|
|
|
getExternalUploadData,
|
2022-07-20 03:36:00 +08:00
|
|
|
exportPresentationToChat,
|
2022-08-08 19:50:52 +08:00
|
|
|
uploadAndConvertPresentation,
|
2022-12-08 22:20:17 +08:00
|
|
|
handleFiledrop,
|
2017-05-04 00:36:16 +08:00
|
|
|
};
|