2022-02-27 00:52:05 +08:00
|
|
|
const Logger = require('../lib/utils/logger');
|
|
|
|
const config = require('../config');
|
|
|
|
const fs = require('fs');
|
|
|
|
const FormData = require('form-data');
|
2022-03-01 18:01:50 +08:00
|
|
|
const redis = require('redis');
|
2022-02-27 00:52:05 +08:00
|
|
|
const axios = require('axios').default;
|
2022-04-29 19:50:42 +08:00
|
|
|
const path = require('path');
|
2022-02-27 00:52:05 +08:00
|
|
|
|
|
|
|
const { workerData, parentPort } = require('worker_threads')
|
|
|
|
|
2022-04-29 19:50:42 +08:00
|
|
|
const [jobType, jobId, filename] = workerData;
|
2022-02-27 00:52:05 +08:00
|
|
|
|
|
|
|
const logger = new Logger('presAnn Notifier Worker');
|
|
|
|
|
|
|
|
const dropbox = `${config.shared.presAnnDropboxDir}/${jobId}`
|
2022-04-29 19:50:42 +08:00
|
|
|
let job = fs.readFileSync(path.join(dropbox, 'job'));
|
2022-02-27 00:52:05 +08:00
|
|
|
let exportJob = JSON.parse(job);
|
|
|
|
|
2022-04-12 23:40:17 +08:00
|
|
|
async function notifyMeetingActor() {
|
2022-03-01 18:01:50 +08:00
|
|
|
const client = redis.createClient({
|
|
|
|
host: config.redis.host,
|
|
|
|
port: config.redis.port,
|
|
|
|
password: config.redis.password
|
|
|
|
});
|
|
|
|
|
|
|
|
await client.connect();
|
|
|
|
client.on('error', (err) => logger.info('Redis Client Error', err));
|
|
|
|
|
2022-05-01 05:28:11 +08:00
|
|
|
let link = `${config.notifier.protocol}://${config.notifier.host}/bigbluebutton/presentation/${exportJob.parentMeetingId}/${exportJob.parentMeetingId}/${exportJob.presId}/pdf/${jobId}/${filename}.pdf`;
|
2022-03-01 18:01:50 +08:00
|
|
|
// Notify Meeting Actor of file availability by sending a message through Redis PubSub
|
|
|
|
const notification = {
|
|
|
|
envelope: {
|
|
|
|
name: config.notifier.msgName,
|
|
|
|
routing: {
|
|
|
|
sender: exportJob.module
|
|
|
|
},
|
|
|
|
timestamp: (new Date()).getTime(),
|
|
|
|
},
|
|
|
|
core: {
|
|
|
|
header: {
|
|
|
|
name: config.notifier.msgName,
|
|
|
|
meetingId: exportJob.parentMeetingId,
|
|
|
|
userId: ""
|
|
|
|
},
|
|
|
|
body: {
|
2022-03-03 00:02:08 +08:00
|
|
|
fileURI: link
|
2022-03-01 18:01:50 +08:00
|
|
|
},
|
2022-03-03 00:02:08 +08:00
|
|
|
}
|
2022-03-01 18:01:50 +08:00
|
|
|
}
|
|
|
|
|
2022-03-03 00:02:08 +08:00
|
|
|
logger.info(`Annotated PDF available at ${link}`);
|
2022-03-01 18:01:50 +08:00
|
|
|
await client.publish(config.redis.channels.publish, JSON.stringify(notification));
|
2022-04-12 23:40:17 +08:00
|
|
|
client.disconnect();
|
2022-03-01 18:01:50 +08:00
|
|
|
}
|
|
|
|
|
2022-02-27 00:52:05 +08:00
|
|
|
async function upload(exportJob) {
|
|
|
|
let callbackUrl = `http://${config.bbbWeb.host}:${config.bbbWeb.port}/bigbluebutton/presentation/${exportJob.presentationUploadToken}/upload`
|
|
|
|
let formData = new FormData();
|
|
|
|
|
|
|
|
formData.append('conference', exportJob.parentMeetingId);
|
|
|
|
formData.append('pod_id', config.notifier.pod_id);
|
|
|
|
formData.append('is_downloadable', config.notifier.is_downloadable);
|
2022-05-24 16:59:03 +08:00
|
|
|
formData.append('temporaryPresentationId', jobId);
|
2022-04-29 19:50:42 +08:00
|
|
|
formData.append('fileUpload', fs.createReadStream(`${exportJob.presLocation}/pdfs/${jobId}/${filename}.pdf`));
|
2022-02-27 00:52:05 +08:00
|
|
|
|
|
|
|
let res = await axios.post(callbackUrl, formData, { headers: formData.getHeaders() });
|
|
|
|
logger.info(`Upload of job ${exportJob.jobId} returned ${res.data}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jobType == 'PresentationWithAnnotationDownloadJob') {
|
2022-04-12 23:40:17 +08:00
|
|
|
notifyMeetingActor();
|
2022-02-27 00:52:05 +08:00
|
|
|
|
|
|
|
} else if (jobType == 'PresentationWithAnnotationExportJob') {
|
2022-03-01 18:01:50 +08:00
|
|
|
upload(exportJob);
|
2022-02-27 00:52:05 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
logger.error(`Notifier received unknown job type ${jobType}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
parentPort.postMessage({ message: workerData })
|