bigbluebutton-Github/bigbluebutton-html5/imports/api/note/server/helpers.js
Pedro Beschorner Marin c0a7f9cd92 Replace FNV32a pad's id generator with salted SHA1
When managing Etherpad's pads, Meteor makes API calls to initiate the closed captions
and shared notes modules. The pad id was being mapped to a shorter id than the meeting
id because of a Etherpad lenght limitation.

Changed to something less guessable.
2021-02-09 12:59:59 -03:00

51 lines
1.4 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { hashSHA1 } from '/imports/api/common/server/helpers';
const ETHERPAD = Meteor.settings.private.etherpad;
const NOTE_CONFIG = Meteor.settings.public.note;
const BASE_URL = `http://${ETHERPAD.host}:${ETHERPAD.port}/api/${ETHERPAD.version}`;
const TOKEN = '_';
const createPadURL = padId => `${BASE_URL}/createPad?apikey=${ETHERPAD.apikey}&padID=${padId}`;
const getReadOnlyIdURL = padId => `${BASE_URL}/getReadOnlyID?apikey=${ETHERPAD.apikey}&padID=${padId}`;
const appendTextURL = (padId, text) => `${BASE_URL}/appendText?apikey=${ETHERPAD.apikey}&padID=${padId}&text=${encodeURIComponent(text)}`;
const generateNoteId = (meetingId) => hashSHA1(meetingId+ETHERPAD.apikey);
const isEnabled = () => NOTE_CONFIG.enabled;
const getDataFromResponse = (data, key) => {
if (data) {
const innerData = data.data;
if (innerData && innerData[key]) {
return innerData[key];
}
}
return null;
};
const isNotePad = padId => padId.search(TOKEN);
const processForNotePadOnly = fn => (message, ...args) => {
const { body } = message;
const { pad } = body;
const { id } = pad;
check(id, String);
if (isNotePad(id)) return fn(message, ...args);
return () => {};
};
export {
generateNoteId,
createPadURL,
getReadOnlyIdURL,
isEnabled,
getDataFromResponse,
appendTextURL,
processForNotePadOnly,
};