2019-05-17 04:11:10 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import {
|
|
|
|
generatePadId,
|
|
|
|
isEnabled,
|
|
|
|
getLocalesURL,
|
|
|
|
} from '/imports/api/captions/server/helpers';
|
|
|
|
import addCaption from '/imports/api/captions/server/modifiers/addCaption';
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
export default function createCaptions(meetingId) {
|
|
|
|
// Avoid captions creation if this feature is disabled
|
|
|
|
if (!isEnabled()) {
|
|
|
|
Logger.warn(`Captions are disabled for ${meetingId}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
|
|
|
|
axios({
|
|
|
|
method: 'get',
|
|
|
|
url: getLocalesURL(),
|
|
|
|
responseType: 'json',
|
|
|
|
}).then((response) => {
|
|
|
|
const { status } = response;
|
|
|
|
if (status !== 200) {
|
|
|
|
Logger.error(`Could not get locales info for ${meetingId} ${status}`);
|
|
|
|
}
|
|
|
|
const locales = response.data;
|
2019-05-29 22:31:27 +08:00
|
|
|
locales.forEach((locale) => {
|
2019-05-23 22:51:01 +08:00
|
|
|
const padId = generatePadId(meetingId, locale.locale);
|
|
|
|
addCaption(meetingId, padId, locale);
|
|
|
|
});
|
2019-05-17 04:11:10 +08:00
|
|
|
}).catch(error => Logger.error(`Could not create captions for ${meetingId}: ${error}`));
|
|
|
|
}
|