ep_search 0.0.61 → 0.0.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +19 -17
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,32 +2,34 @@
2
2
 
3
3
  // Main job is to check pads periodically for activity and notify owners
4
4
  // when someone begins editing and when someone finishes.
5
- const db = require('ep_etherpad-lite/node/db/DB').db;
6
- const async = require('ep_etherpad-lite/node_modules/async');
5
+ const db = require('ep_etherpad-lite/node/db/DB');
7
6
 
8
7
  // Settings -- EDIT THESE IN settings.json not here..
9
8
  // var pluginSettings = settings.ep_search;
10
9
  // var checkFrequency = pluginSettings.checkFrequency || 60000; // 10 seconds
11
10
 
12
11
  exports.registerRoute = (hookName, args, cb) => {
13
- args.app.get('/search', (req, res) => {
12
+ args.app.get('/search', async (req, res) => {
14
13
  const searchString = req.query.query;
15
14
  const result = {};
16
15
 
17
- db.findKeys('pad:*', '*:*:*', (err, pads) => { // get all pads
18
- async.forEachSeries(pads, (pad, callback) => {
19
- db.get(pad, (err, padData) => { // get the pad contents
20
- const padText = padData.atext.text || '';
21
- // does searchString exist in aText?
22
- if (padText.toLowerCase().indexOf(searchString.toLowerCase()) !== -1) {
23
- result.pad = pad;
24
- }
25
- callback();
26
- });
27
- }, (err) => {
28
- res.send(JSON.stringify(result));
29
- });
30
- });
16
+ try {
17
+ // ueberdb2 v6 is promise-only; the legacy callback-style API silently
18
+ // ignores callbacks and only returns a Promise, so previously this
19
+ // handler hung forever.
20
+ const pads = await db.findKeys('pad:*', '*:*:*');
21
+ for (const pad of pads) {
22
+ const padData = await db.get(pad);
23
+ const padText = (padData && padData.atext && padData.atext.text) || '';
24
+ if (padText.toLowerCase().indexOf(searchString.toLowerCase()) !== -1) {
25
+ result.pad = pad;
26
+ }
27
+ }
28
+ res.send(JSON.stringify(result));
29
+ } catch (err) {
30
+ console.error('ep_search /search failed:', err);
31
+ res.status(500).send(JSON.stringify({error: err.message || String(err)}));
32
+ }
31
33
  });
32
34
  cb(null);
33
35
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ep_search",
3
3
  "description": "Search through all pads for a string",
4
- "version": "0.0.61",
4
+ "version": "0.0.62",
5
5
  "author": {
6
6
  "name": "John McLear",
7
7
  "email": "john@mclear.co.uk",