2019-06-14 10:18:36 +08:00
|
|
|
import axios from 'axios';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2021-05-16 21:45:17 +08:00
|
|
|
import Captions from '/imports/api/captions';
|
|
|
|
import { CAPTIONS_TOKEN } from '/imports/api/captions/server/helpers';
|
2021-03-30 05:35:33 +08:00
|
|
|
import { appendTextURL } from '/imports/api/common/server/etherpad';
|
2020-04-30 21:46:30 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2019-06-14 10:18:36 +08:00
|
|
|
|
2020-04-30 21:46:30 +08:00
|
|
|
export default function appendText(text, locale) {
|
2021-05-05 01:34:31 +08:00
|
|
|
try {
|
|
|
|
const { meetingId } = extractCredentials(this.userId);
|
2021-05-16 21:45:17 +08:00
|
|
|
|
2021-05-05 01:34:31 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(text, String);
|
|
|
|
check(locale, String);
|
2019-06-14 10:18:36 +08:00
|
|
|
|
2021-05-16 21:45:17 +08:00
|
|
|
const captions = Captions.findOne({
|
|
|
|
meetingId,
|
|
|
|
padId: { $regex: `${CAPTIONS_TOKEN}${locale}$` },
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!captions) {
|
|
|
|
Logger.error(`Could not find captions' pad for meetingId=${meetingId} locale=${locale}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { padId } = captions;
|
2019-06-14 10:18:36 +08:00
|
|
|
|
2021-05-05 01:34:31 +08:00
|
|
|
axios({
|
|
|
|
method: 'get',
|
|
|
|
url: appendTextURL(padId, text),
|
|
|
|
responseType: 'json',
|
|
|
|
}).then((response) => {
|
|
|
|
const { status } = response;
|
|
|
|
if (status !== 200) {
|
|
|
|
Logger.error(`Could not append captions for padId=${padId}`);
|
|
|
|
}
|
|
|
|
}).catch((error) => Logger.error(`Could not append captions for padId=${padId}: ${error}`));
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method appendText ${err.stack}`);
|
|
|
|
}
|
2019-06-14 10:18:36 +08:00
|
|
|
}
|