diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-03-03 06:48:26 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-03-03 06:48:26 +0900 |
| commit | 6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a (patch) | |
| tree | d9319e37433f57c70cdf9e66b57b525fd7bfc881 /src/api/endpoints/posts/search.ts | |
| parent | wip (diff) | |
| download | misskey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.tar.gz misskey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.tar.bz2 misskey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.zip | |
wip
Diffstat (limited to '')
| -rw-r--r-- | src/api/endpoints/posts/search.ts (renamed from src/api/endpoints/posts/search.js) | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/api/endpoints/posts/search.js b/src/api/endpoints/posts/search.ts index bc06340fda..1d02f6775d 100644 --- a/src/api/endpoints/posts/search.js +++ b/src/api/endpoints/posts/search.ts @@ -4,6 +4,7 @@ * Module dependencies */ import * as mongo from 'mongodb'; +import it from '../../it'; const escapeRegexp = require('escape-regexp'); import Post from '../../models/post'; import serialize from '../../serializers/post'; @@ -20,31 +21,16 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Get 'query' parameter - let query = params.query; - if (query === undefined || query === null || query.trim() === '') { - return rej('query is required'); - } + const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').qed(); + if (queryError) return rej('invalid query param'); // Get 'offset' parameter - let offset = params.offset; - if (offset !== undefined && offset !== null) { - offset = parseInt(offset, 10); - } else { - offset = 0; - } + const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed(); + if (offsetErr) return rej('invalid offset param'); // Get 'max' parameter - let max = params.max; - if (max !== undefined && max !== null) { - max = parseInt(max, 10); - - // From 1 to 30 - if (!(1 <= max && max <= 30)) { - return rej('invalid max range'); - } - } else { - max = 10; - } + const [max, maxErr] = it(params.max).expect.number().range(1, 30).default(10).qed(); + if (maxErr) return rej('invalid max param'); // If Elasticsearch is available, search by it // If not, search by MongoDB |