Improve hashtag API

This commit is contained in:
syuilo
2019-04-25 13:25:10 +09:00
parent da9dd7c423
commit 6721d27e3f
5 changed files with 124 additions and 47 deletions

View File

@ -92,5 +92,5 @@ export default define(meta, async (ps, me) => {
const tags = await query.take(ps.limit!).getMany();
return tags;
return Hashtags.packMany(tags);
});

View File

@ -0,0 +1,48 @@
import $ from 'cafy';
import define from '../../define';
import { ApiError } from '../../error';
import { Hashtags } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
'ja-JP': '指定したハッシュタグの情報を取得します。',
},
tags: ['hashtags'],
requireCredential: false,
params: {
tag: {
validator: $.str,
desc: {
'ja-JP': '対象のハッシュタグ(#なし)',
'en-US': 'Target hashtag. (no # prefixed)'
}
}
},
res: {
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Hashtag',
},
errors: {
noSuchHashtag: {
message: 'No such hashtag.',
code: 'NO_SUCH_HASHTAG',
id: '110ee688-193e-4a3a-9ecf-c167b2e6981e'
}
}
};
export default define(meta, async (ps, user) => {
const hashtag = await Hashtags.findOne({ name: ps.tag.toLowerCase() });
if (hashtag == null) {
throw new ApiError(meta.errors.noSuchHashtag);
}
return await Hashtags.pack(hashtag);
});