diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-07-18 07:19:24 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-07-18 07:19:24 +0900 |
| commit | df20f5063dd5f93235307e5fca6fc7b17625bea9 (patch) | |
| tree | 4adfc17a5ea5794e4d70fe1fe6fbc40812277e3d /src/server | |
| parent | :v: (diff) | |
| download | sharkey-df20f5063dd5f93235307e5fca6fc7b17625bea9.tar.gz sharkey-df20f5063dd5f93235307e5fca6fc7b17625bea9.tar.bz2 sharkey-df20f5063dd5f93235307e5fca6fc7b17625bea9.zip | |
#1720 #59
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/api/endpoints/hashtags/search.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/server/api/endpoints/hashtags/search.ts b/src/server/api/endpoints/hashtags/search.ts new file mode 100644 index 0000000000..988a786a08 --- /dev/null +++ b/src/server/api/endpoints/hashtags/search.ts @@ -0,0 +1,51 @@ +import $ from 'cafy'; +import Hashtag from '../../../../models/hashtag'; +import getParams from '../../get-params'; + +export const meta = { + desc: { + ja: 'ハッシュタグを検索します。' + }, + + requireCredential: false, + + params: { + limit: $.num.optional.range(1, 100).note({ + default: 10, + desc: { + ja: '最大数' + } + }), + + query: $.str.note({ + desc: { + ja: 'クエリ' + } + }), + + offset: $.num.optional.min(0).note({ + default: 0, + desc: { + ja: 'オフセット' + } + }) + } +}; + +export default (params: any) => new Promise(async (res, rej) => { + const [ps, psErr] = getParams(meta, params); + if (psErr) throw psErr; + + const hashtags = await Hashtag + .find({ + tag: new RegExp(ps.query.toLowerCase()) + }, { + sort: { + count: -1 + }, + limit: ps.limit, + skip: ps.offset + }); + + res(hashtags.map(tag => tag.tag)); +}); |