2019-03-29 02:47:11 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2019-05-17 04:11:10 +08:00
|
|
|
import { hashFNV32a } from '/imports/api/common/server/helpers';
|
2019-03-29 02:47:11 +08:00
|
|
|
|
|
|
|
const ETHERPAD = Meteor.settings.private.etherpad;
|
2019-03-30 02:22:52 +08:00
|
|
|
const NOTE_CONFIG = Meteor.settings.public.note;
|
2019-03-29 02:47:11 +08:00
|
|
|
const BASE_URL = `http://${ETHERPAD.host}:${ETHERPAD.port}/api/${ETHERPAD.version}`;
|
2019-06-01 04:02:33 +08:00
|
|
|
const TOKEN = '_';
|
2019-03-29 02:47:11 +08:00
|
|
|
|
2019-05-29 22:31:27 +08:00
|
|
|
const createPadURL = padId => `${BASE_URL}/createPad?apikey=${ETHERPAD.apikey}&padID=${padId}`;
|
2019-03-29 02:47:11 +08:00
|
|
|
|
2019-05-29 22:31:27 +08:00
|
|
|
const getReadOnlyIdURL = padId => `${BASE_URL}/getReadOnlyID?apikey=${ETHERPAD.apikey}&padID=${padId}`;
|
2019-03-29 02:47:11 +08:00
|
|
|
|
2019-06-22 01:56:12 +08:00
|
|
|
const appendTextURL = (padId, text) => `${BASE_URL}/appendText?apikey=${ETHERPAD.apikey}&padID=${padId}&text=${encodeURIComponent(text)}`;
|
2019-06-14 10:18:36 +08:00
|
|
|
|
2019-05-29 22:31:27 +08:00
|
|
|
const generateNoteId = (meetingId) => {
|
2019-03-29 02:47:11 +08:00
|
|
|
const noteId = hashFNV32a(meetingId, true);
|
|
|
|
return noteId;
|
|
|
|
};
|
|
|
|
|
2019-05-29 22:31:27 +08:00
|
|
|
const isEnabled = () => NOTE_CONFIG.enabled;
|
2019-03-30 02:22:52 +08:00
|
|
|
|
2019-05-17 04:11:10 +08:00
|
|
|
const getDataFromResponse = (data, key) => {
|
|
|
|
if (data) {
|
|
|
|
const innerData = data.data;
|
|
|
|
if (innerData && innerData[key]) {
|
|
|
|
return innerData[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2019-07-26 07:29:52 +08:00
|
|
|
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 () => {};
|
|
|
|
};
|
|
|
|
|
2019-03-29 02:47:11 +08:00
|
|
|
export {
|
|
|
|
generateNoteId,
|
|
|
|
createPadURL,
|
|
|
|
getReadOnlyIdURL,
|
2019-03-30 02:22:52 +08:00
|
|
|
isEnabled,
|
2019-05-17 04:11:10 +08:00
|
|
|
getDataFromResponse,
|
2019-06-14 10:18:36 +08:00
|
|
|
appendTextURL,
|
2019-06-01 04:02:33 +08:00
|
|
|
processForNotePadOnly,
|
2019-03-29 02:47:11 +08:00
|
|
|
};
|