feat: add experimental search parser
This commit is contained in:
parent
93478a334b
commit
78c6fa14e6
|
@ -38,6 +38,7 @@
|
|||
"buefy": "^0.8.20",
|
||||
"busboy": "^0.2.14",
|
||||
"chalk": "^2.4.1",
|
||||
"chrono-node": "^2.1.4",
|
||||
"compression": "^1.7.2",
|
||||
"cookie-universal-nuxt": "^2.0.14",
|
||||
"cors": "^2.8.5",
|
||||
|
@ -68,6 +69,7 @@
|
|||
"pg": "^7.8.1",
|
||||
"qoa": "^0.2.0",
|
||||
"randomstring": "^1.1.5",
|
||||
"search-query-parser": "^1.5.5",
|
||||
"serve-static": "^1.13.2",
|
||||
"sharp": "^0.25.2",
|
||||
"sqlite3": "^4.0.6",
|
||||
|
|
|
@ -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;
|
17
yarn.lock
17
yarn.lock
|
@ -2588,6 +2588,13 @@ chrome-trace-event@^1.0.2:
|
|||
dependencies:
|
||||
tslib "^1.9.0"
|
||||
|
||||
chrono-node@^2.1.4:
|
||||
version "2.1.4"
|
||||
resolved "https://registry.yarnpkg.com/chrono-node/-/chrono-node-2.1.4.tgz#0c172adbb0a90366a938ec479920d813141bb624"
|
||||
integrity sha512-bfU6CvHO3j2yB9X+OxF8QmrYrUqdxfw5uoHmb9sTOffM2ev6ZM3xD01pJz4HejZyQVbrcylT1lEURDbponTqXA==
|
||||
dependencies:
|
||||
dayjs "^1.8.29"
|
||||
|
||||
ci-info@^1.5.0, ci-info@^1.6.0:
|
||||
version "1.6.0"
|
||||
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.6.0.tgz#2ca20dbb9ceb32d4524a683303313f0304b1e497"
|
||||
|
@ -3361,6 +3368,11 @@ dashify@2.0.0:
|
|||
resolved "https://registry.yarnpkg.com/dashify/-/dashify-2.0.0.tgz#fff270ca2868ca427fee571de35691d6e437a648"
|
||||
integrity sha512-hpA5C/YrPjucXypHPPc0oJ1l9Hf6wWbiOL7Ik42cxnsUOhWiCB/fylKbKqqJalW9FgkNQCw16YO8uW9Hs0Iy1A==
|
||||
|
||||
dayjs@^1.8.29:
|
||||
version "1.8.29"
|
||||
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.29.tgz#5d23e341de6bfbd206c01136d2fb0f01877820f5"
|
||||
integrity sha512-Vm6teig8ZWK7rH/lxzVGxZJCljPdmUr6q/3f4fr5F0VWNGVkZEjZOQJsAN8hUHUqn+NK4XHNEpJZS1MwLyDcLw==
|
||||
|
||||
de-indent@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"
|
||||
|
@ -9632,6 +9644,11 @@ scss-tokenizer@^0.2.3:
|
|||
js-base64 "^2.1.8"
|
||||
source-map "^0.4.2"
|
||||
|
||||
search-query-parser@^1.5.5:
|
||||
version "1.5.5"
|
||||
resolved "https://registry.yarnpkg.com/search-query-parser/-/search-query-parser-1.5.5.tgz#dfd829f4fb567a9a3a5b70327576dff4d5be071d"
|
||||
integrity sha512-8hKmRbHShAc+LJtUu7mu4L/oWVgICG1GCzWZtlR11Vl3T/v4aTGv+Ie2bPg+8ueJn+l8zMHCQhzrBNMoV/t2qw==
|
||||
|
||||
semver-compare@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
|
||||
|
|
Loading…
Reference in New Issue