bigbluebutton-Github/bigbluebutton-html5/imports/api/note/server/helpers.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

import { Meteor } from 'meteor/meteor';
import { hashFNV32a } 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}`;
2019-06-01 04:02:33 +08:00
const TOKEN = '_';
2019-05-29 22:31:27 +08:00
const createPadURL = padId => `${BASE_URL}/createPad?apikey=${ETHERPAD.apikey}&padID=${padId}`;
2019-05-29 22:31:27 +08:00
const getReadOnlyIdURL = padId => `${BASE_URL}/getReadOnlyID?apikey=${ETHERPAD.apikey}&padID=${padId}`;
2019-06-22 01:56:12 +08:00
const appendTextURL = (padId, text) => `${BASE_URL}/appendText?apikey=${ETHERPAD.apikey}&padID=${padId}&text=${encodeURIComponent(text)}`;
2019-05-29 22:31:27 +08:00
const generateNoteId = (meetingId) => {
const noteId = hashFNV32a(meetingId, true);
return noteId;
};
2019-05-29 22:31:27 +08:00
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);
2019-06-01 04:02:33 +08:00
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,
2019-06-01 04:02:33 +08:00
processForNotePadOnly,
};