2018-11-22 17:01:14 -06:00
|
|
|
import $ from 'cafy';
|
2021-08-19 07:55:45 -05:00
|
|
|
import { ID } from '@/misc/cafy-id';
|
|
|
|
import define from '../../define';
|
|
|
|
import { Users } from '@/models/index';
|
2018-11-22 17:01:14 -06:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-22 20:20:58 -06:00
|
|
|
tags: ['admin'],
|
|
|
|
|
2020-02-15 06:33:32 -06:00
|
|
|
requireCredential: true as const,
|
2018-11-22 17:01:14 -06:00
|
|
|
requireModerator: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
userId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
},
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'object' as const,
|
|
|
|
nullable: false as const, optional: false as const,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: 'string' as const,
|
|
|
|
nullable: false as const, optional: false as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
format: 'id',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
type: 'string' as const,
|
|
|
|
nullable: false as const, optional: false as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
format: 'date-time',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
updatedAt: {
|
|
|
|
type: 'string' as const,
|
|
|
|
nullable: true as const, optional: false as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
format: 'date-time',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
lastFetchedAt: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: true as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
username: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
folowersCount: {
|
|
|
|
type: 'number' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
followingCount: {
|
|
|
|
type: 'number' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
notesCount: {
|
|
|
|
type: 'number' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
avatarId: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: true as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
bannerId: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: true as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
tags: {
|
|
|
|
type: 'array' as const,
|
|
|
|
nullable: false as const, optional: false as const,
|
|
|
|
items: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
|
|
|
},
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
avatarUrl: {
|
|
|
|
type: 'string' as const,
|
|
|
|
nullable: true as const, optional: false as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
format: 'url',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
bannerUrl: {
|
|
|
|
type: 'string' as const,
|
|
|
|
nullable: true as const, optional: false as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
format: 'url',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
avatarBlurhash: {
|
|
|
|
type: 'any' as const,
|
|
|
|
nullable: true as const, optional: false as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
default: null,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
bannerBlurhash: {
|
|
|
|
type: 'any' as const,
|
|
|
|
nullable: true as const, optional: false as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
default: null,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isSuspended: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isSilenced: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isLocked: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
nullable: false as const, optional: false as const,
|
|
|
|
},
|
|
|
|
isBot: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isCat: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isAdmin: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isModerator: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
emojis: {
|
|
|
|
type: 'array' as const,
|
|
|
|
nullable: false as const, optional: false as const,
|
|
|
|
items: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: false as const, optional: false as const,
|
|
|
|
},
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
host: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: true as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
inbox: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: true as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
sharedInbox: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: true as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
featured: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: true as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
uri: {
|
|
|
|
type: 'string' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
nullable: true as const, optional: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
token: {
|
|
|
|
type: 'string' as const,
|
|
|
|
nullable: false as const, optional: false as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
default: '<MASKED>',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-11-22 17:01:14 -06:00
|
|
|
};
|
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
export default define(meta, async (ps, me) => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const user = await Users.findOne(ps.userId as string);
|
2018-11-22 17:01:14 -06:00
|
|
|
|
|
|
|
if (user == null) {
|
2019-02-21 20:46:58 -06:00
|
|
|
throw new Error('user not found');
|
2018-11-22 17:01:14 -06:00
|
|
|
}
|
|
|
|
|
2020-02-18 02:53:56 -06:00
|
|
|
if ((me.isModerator && !me.isAdmin) && user.isAdmin) {
|
2019-02-21 20:46:58 -06:00
|
|
|
throw new Error('cannot show info of admin');
|
2018-11-22 17:01:14 -06:00
|
|
|
}
|
|
|
|
|
2020-08-09 11:32:27 -05:00
|
|
|
return {
|
|
|
|
...user,
|
|
|
|
token: user.token != null ? '<MASKED>' : user.token,
|
|
|
|
};
|
2019-02-21 20:46:58 -06:00
|
|
|
});
|