2019-05-17 04:11:10 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2021-03-30 05:35:33 +08:00
|
|
|
import { hashSHA1 } from '/imports/api/common/server/etherpad';
|
2019-05-17 04:11:10 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
|
2021-02-09 23:59:59 +08:00
|
|
|
const ETHERPAD = Meteor.settings.private.etherpad;
|
2019-05-17 04:11:10 +08:00
|
|
|
const CAPTIONS_CONFIG = Meteor.settings.public.captions;
|
2019-05-23 22:51:01 +08:00
|
|
|
const BASENAME = Meteor.settings.public.app.basename;
|
|
|
|
const APP = Meteor.settings.private.app;
|
2020-12-01 00:09:35 +08:00
|
|
|
const INSTANCE_ID = Meteor.settings.public.app.instanceId;
|
2021-03-05 05:25:47 +08:00
|
|
|
const LOCALES_URL = `http://${APP.host}:${process.env.PORT}${BASENAME}${INSTANCE_ID}${APP.localesUrl}`;
|
2021-02-09 23:59:59 +08:00
|
|
|
const CAPTIONS_TOKEN = '_cc_';
|
2019-05-17 04:11:10 +08:00
|
|
|
const TOKEN = '$';
|
|
|
|
|
2021-02-09 23:59:59 +08:00
|
|
|
// Captions padId should look like: {prefix}_cc_{locale}
|
2021-03-05 05:25:47 +08:00
|
|
|
const generatePadId = (meetingId, locale) => `${hashSHA1(meetingId + locale + ETHERPAD.apikey)}${CAPTIONS_TOKEN}${locale}`;
|
2019-05-17 04:11:10 +08:00
|
|
|
|
2019-05-29 22:31:27 +08:00
|
|
|
const isCaptionsPad = (padId) => {
|
2021-02-09 23:59:59 +08:00
|
|
|
const splitPadId = padId.split(CAPTIONS_TOKEN);
|
2019-05-29 22:31:27 +08:00
|
|
|
return splitPadId.length === 2;
|
2019-05-23 22:51:01 +08:00
|
|
|
};
|
2019-05-17 04:11:10 +08:00
|
|
|
|
2019-05-29 22:31:27 +08:00
|
|
|
const getDataFromChangeset = (changeset) => {
|
2019-05-17 04:11:10 +08:00
|
|
|
const splitChangeset = changeset.split(TOKEN);
|
|
|
|
if (splitChangeset.length > 1) {
|
|
|
|
splitChangeset.shift();
|
|
|
|
return splitChangeset.join(TOKEN);
|
|
|
|
}
|
2019-05-29 22:31:27 +08:00
|
|
|
return '';
|
2019-05-23 22:51:01 +08:00
|
|
|
};
|
2019-05-17 04:11:10 +08:00
|
|
|
|
2019-05-29 22:31:27 +08:00
|
|
|
const isEnabled = () => CAPTIONS_CONFIG.enabled;
|
2019-05-17 04:11:10 +08:00
|
|
|
|
|
|
|
const getLocalesURL = () => LOCALES_URL;
|
|
|
|
|
|
|
|
const processForCaptionsPadOnly = fn => (message, ...args) => {
|
|
|
|
const { body } = message;
|
|
|
|
const { pad } = body;
|
|
|
|
const { id } = pad;
|
|
|
|
|
|
|
|
check(id, String);
|
|
|
|
|
|
|
|
if (isCaptionsPad(id)) return fn(message, ...args);
|
2021-03-05 05:25:47 +08:00
|
|
|
return () => { };
|
2019-05-17 04:11:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export {
|
2021-02-09 23:59:59 +08:00
|
|
|
CAPTIONS_TOKEN,
|
2019-05-17 04:11:10 +08:00
|
|
|
generatePadId,
|
|
|
|
processForCaptionsPadOnly,
|
|
|
|
isEnabled,
|
|
|
|
getLocalesURL,
|
|
|
|
getDataFromChangeset,
|
|
|
|
};
|