2022-03-15 23:02:54 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import PresentationUploaderService from '/imports/ui/components/presentation/presentation-uploader/service';
|
|
|
|
import PadsService from '/imports/ui/components/pads/service';
|
|
|
|
import NotesService from '/imports/ui/components/notes/service';
|
2022-09-22 04:41:31 +08:00
|
|
|
import { UploadingPresentations } from '/imports/api/presentations';
|
2022-10-05 03:25:54 +08:00
|
|
|
import _ from 'lodash';
|
2022-03-15 23:02:54 +08:00
|
|
|
|
|
|
|
const PADS_CONFIG = Meteor.settings.public.pads;
|
|
|
|
const PRESENTATION_CONFIG = Meteor.settings.public.presentation;
|
|
|
|
|
|
|
|
async function convertAndUpload() {
|
2022-09-22 04:41:31 +08:00
|
|
|
|
|
|
|
let filename = 'Shared_Notes';
|
|
|
|
const presentations = PresentationUploaderService.getPresentations();
|
2022-09-27 21:05:27 +08:00
|
|
|
const duplicates = presentations.filter((pres) => pres.filename?.startsWith(filename) || pres.name?.startsWith(filename)).length;
|
2022-09-22 04:41:31 +08:00
|
|
|
|
|
|
|
if (duplicates !== 0) { filename = `${filename}(${duplicates})`; }
|
|
|
|
|
2022-03-15 23:02:54 +08:00
|
|
|
const params = PadsService.getParams();
|
|
|
|
const padId = await PadsService.getPadId(NotesService.ID);
|
2022-05-07 05:49:06 +08:00
|
|
|
const extension = 'pdf';
|
2022-09-22 04:41:31 +08:00
|
|
|
filename = `${filename}.${extension}`;
|
|
|
|
|
|
|
|
UploadingPresentations.insert({
|
2022-10-05 03:25:54 +08:00
|
|
|
id: _.uniqueId(filename),
|
2022-09-22 04:41:31 +08:00
|
|
|
progress: 0,
|
|
|
|
filename,
|
|
|
|
lastModifiedUploader: false,
|
|
|
|
upload: {
|
|
|
|
done: false,
|
|
|
|
error: false
|
|
|
|
},
|
|
|
|
uploadTimestamp: new Date()
|
|
|
|
})
|
2022-05-07 05:49:06 +08:00
|
|
|
|
|
|
|
const exportUrl = Auth.authenticateURL(`${PADS_CONFIG.url}/p/${padId}/export/${extension}?${params}`);
|
|
|
|
const sharedNotesAsFile = await fetch(exportUrl, { credentials: 'include' });
|
|
|
|
|
|
|
|
const data = await sharedNotesAsFile.blob();
|
2022-03-15 23:02:54 +08:00
|
|
|
|
2022-09-22 04:41:31 +08:00
|
|
|
const sharedNotesData = new File([data], filename, {
|
2022-03-15 23:02:54 +08:00
|
|
|
type: data.type,
|
|
|
|
});
|
|
|
|
|
2022-08-08 19:50:52 +08:00
|
|
|
PresentationUploaderService.handleSavePresentation([], isFromPresentationUploaderInterface = false, {
|
|
|
|
file: sharedNotesData,
|
|
|
|
isDownloadable: false, // by default new presentations are set not to be downloadable
|
|
|
|
isRemovable: true,
|
|
|
|
filename: sharedNotesData.name,
|
|
|
|
isCurrent: true,
|
|
|
|
conversion: { done: false, error: false },
|
|
|
|
upload: { done: false, error: false, progress: 0 },
|
|
|
|
exportation: { isRunning: false, error: false },
|
|
|
|
onConversion: () => {},
|
|
|
|
onUpload: () => {},
|
|
|
|
onProgress: () => {},
|
|
|
|
onDone: () => {},
|
2022-08-12 02:07:42 +08:00
|
|
|
})
|
2022-03-15 23:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
convertAndUpload,
|
|
|
|
};
|