forked from ether/ep_search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (29 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
// Main job is to check pads periodically for activity and notify owners
// when someone begins editing and when someone finishes.
const db = require('ep_etherpad-lite/node/db/DB').db;
const async = require('ep_etherpad-lite/node_modules/async');
// Settings -- EDIT THESE IN settings.json not here..
// var pluginSettings = settings.ep_search;
// var checkFrequency = pluginSettings.checkFrequency || 60000; // 10 seconds
exports.registerRoute = (hookName, args, cb) => {
args.app.get('/search', (req, res) => {
const searchString = req.query.query;
const result = {};
db.findKeys('pad:*', '*:*:*', (err, pads) => { // get all pads
async.forEachSeries(pads, (pad, callback) => {
db.get(pad, (err, padData) => { // get the pad contents
const padText = padData.atext.text || '';
// does searchString exist in aText?
if (padText.toLowerCase().indexOf(searchString.toLowerCase()) !== -1) {
result.pad = pad;
}
callback();
});
}, (err) => {
res.send(JSON.stringify(result));
});
});
});
cb(null);
};