ep_search 0.0.61 → 0.0.63
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.
- package/.github/workflows/backend-tests.yml +1 -1
- package/index.js +19 -17
- 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')
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
};
|