2024-01-16 03:49:09 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import PresentationUploaderService from '/imports/ui/components/presentation/presentation-uploader/service';
|
2024-02-14 03:39:45 +08:00
|
|
|
import PadsService from '/imports/ui/components/pads/pads-graphql/service';
|
2024-01-16 03:49:09 +08:00
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2024-06-15 04:57:40 +08:00
|
|
|
async function convertAndUpload(presentations: any, padId: string, presentationEnabled = true) {
|
2024-01-16 03:49:09 +08:00
|
|
|
let filename = 'Shared_Notes';
|
|
|
|
const duplicates = presentations.filter(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
(pres: any) => pres.filename?.startsWith(filename) || pres.name?.startsWith(filename),
|
|
|
|
).length;
|
|
|
|
|
|
|
|
if (duplicates !== 0) { filename = `${filename}(${duplicates})`; }
|
|
|
|
|
|
|
|
const params = PadsService.getParams();
|
|
|
|
const extension = 'pdf';
|
|
|
|
filename = `${filename}.${extension}`;
|
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
const PADS_CONFIG = window.meetingClientSettings.public.pads;
|
|
|
|
|
2024-01-16 03:49:09 +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();
|
|
|
|
|
|
|
|
const sharedNotesData = new File([data], filename, {
|
|
|
|
type: data.type,
|
|
|
|
});
|
|
|
|
|
|
|
|
PresentationUploaderService.handleSavePresentation([], 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: () => { },
|
2024-06-15 04:57:40 +08:00
|
|
|
}, undefined, undefined, undefined, presentationEnabled);
|
2024-01-16 03:49:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
convertAndUpload,
|
|
|
|
};
|