bigbluebutton-Github/bigbluebutton-html5/imports/api/captions/server/methods/fetchReadOnlyPadId.js
2021-05-04 14:34:31 -03:00

33 lines
1.2 KiB
JavaScript

import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import { getReadOnlyIdURL } from '/imports/api/common/server/etherpad';
import { getDataFromResponse } from '/imports/api/note/server/helpers';
import updateReadOnlyPadId from '/imports/api/captions/server/modifiers/updateReadOnlyPadId';
import axios from 'axios';
export default function fetchReadOnlyPadId(padId) {
try {
check(padId, String);
axios({
method: 'get',
url: getReadOnlyIdURL(padId),
responseType: 'json',
}).then((response) => {
const { status } = response;
if (status !== 200) {
Logger.error(`Could not get closed captions readOnlyID for ${padId} ${status}`);
return;
}
const readOnlyPadId = getDataFromResponse(response.data, 'readOnlyID');
if (readOnlyPadId) {
updateReadOnlyPadId(padId, readOnlyPadId);
} else {
Logger.error(`Could not get pad readOnlyID for ${padId}`);
}
}).catch((error) => Logger.error(`Could not get pad readOnlyID for ${padId}: ${error}`));
} catch (err) {
Logger.error(`Exception while invoking method fetchReadOnlyPadId ${err.stack}`);
}
}