diff options
| author | Zephyrrus <[email protected]> | 2020-07-22 02:11:05 +0300 |
|---|---|---|
| committer | Zephyrrus <[email protected]> | 2020-07-22 02:11:05 +0300 |
| commit | 78c6fa14e61f518906521b8cd7c6f81da67dbb8d (patch) | |
| tree | aabde0ab33cefdb7b023244a7ac3394e72793674 /src/api/routes/search | |
| parent | fix: make modal use full height on mobile (diff) | |
| download | host.fuwn.me-78c6fa14e61f518906521b8cd7c6f81da67dbb8d.tar.xz host.fuwn.me-78c6fa14e61f518906521b8cd7c6f81da67dbb8d.zip | |
feat: add experimental search parser
Diffstat (limited to 'src/api/routes/search')
| -rw-r--r-- | src/api/routes/search/searchGET.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/api/routes/search/searchGET.js b/src/api/routes/search/searchGET.js new file mode 100644 index 0000000..ae73d27 --- /dev/null +++ b/src/api/routes/search/searchGET.js @@ -0,0 +1,25 @@ +const searchQuery = require('search-query-parser'); +const chrono = require('chrono-node'); +const Route = require('../../structures/Route'); + +const options = { keywords: ['album', 'tag', 'user', 'before', 'after'], offsets: false }; +class configGET extends Route { + constructor() { + super('/search/:q', 'get', { bypassAuth: true }); + } + + run(req, res) { + const { q } = req.params; + const parsed = searchQuery.parse(q, options); + + if (parsed.before) { + parsed.before = chrono.parse(parsed.before); + } + if (parsed.after) { + parsed.after = chrono.parse(parsed.after); + } + return res.json(parsed); + } +} + +module.exports = configGET; |