Improve hashtag API
This commit is contained in:
@ -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);
|
||||
});
|
||||
|
48
src/server/api/endpoints/hashtags/show.ts
Normal file
48
src/server/api/endpoints/hashtags/show.ts
Normal 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);
|
||||
});
|
@ -11,6 +11,7 @@ import { packedFollowingSchema } from '../../../models/repositories/following';
|
||||
import { packedMutingSchema } from '../../../models/repositories/muting';
|
||||
import { packedBlockingSchema } from '../../../models/repositories/blocking';
|
||||
import { packedNoteReactionSchema } from '../../../models/repositories/note-reaction';
|
||||
import { packedHashtagSchema } from '../../../models/repositories/hashtag';
|
||||
|
||||
export function convertSchemaToOpenApiSchema(schema: Schema) {
|
||||
const res: any = schema;
|
||||
@ -74,48 +75,5 @@ export const schemas = {
|
||||
Muting: convertSchemaToOpenApiSchema(packedMutingSchema),
|
||||
Blocking: convertSchemaToOpenApiSchema(packedBlockingSchema),
|
||||
NoteReaction: convertSchemaToOpenApiSchema(packedNoteReactionSchema),
|
||||
|
||||
Hashtag: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
tag: {
|
||||
type: 'string',
|
||||
description: 'The hashtag name. No # prefixed.',
|
||||
example: 'misskey',
|
||||
},
|
||||
mentionedUsersCount: {
|
||||
type: 'number',
|
||||
description: 'Number of all users using this hashtag.'
|
||||
},
|
||||
mentionedLocalUsersCount: {
|
||||
type: 'number',
|
||||
description: 'Number of local users using this hashtag.'
|
||||
},
|
||||
mentionedRemoteUsersCount: {
|
||||
type: 'number',
|
||||
description: 'Number of remote users using this hashtag.'
|
||||
},
|
||||
attachedUsersCount: {
|
||||
type: 'number',
|
||||
description: 'Number of all users who attached this hashtag to profile.'
|
||||
},
|
||||
attachedLocalUsersCount: {
|
||||
type: 'number',
|
||||
description: 'Number of local users who attached this hashtag to profile.'
|
||||
},
|
||||
attachedRemoteUsersCount: {
|
||||
type: 'number',
|
||||
description: 'Number of remote users who attached this hashtag to profile.'
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'tag',
|
||||
'mentionedUsersCount',
|
||||
'mentionedLocalUsersCount',
|
||||
'mentionedRemoteUsersCount',
|
||||
'attachedUsersCount',
|
||||
'attachedLocalUsersCount',
|
||||
'attachedRemoteUsersCount',
|
||||
]
|
||||
},
|
||||
Hashtag: convertSchemaToOpenApiSchema(packedHashtagSchema),
|
||||
};
|
||||
|
Reference in New Issue
Block a user