mirror of
https://github.com/paricafe/misskey.git
synced 2025-01-11 03:10:50 -06:00
484e023c0c
* remove empty file If the endpoint is to be implemented later, the file can be added back, but for now it is confusing to have an empty file. * enhance(doc): document defaults Default for `isPublic` is based on the database schema default value. Defaults for `local` and `withFiles` are based on the behaviour of the endpoint. * enhance(doc): explain nullable emoji category * fix: make nullable if default is null * enhance(doc): explain mute attribute expiresAt * fix: define required fields - `notes/create`: the default for `text` has been removed because ajv can not handle `default` inside of `anyOf`, see https://ajv.js.org/guide/modifying-data.html#assigning-defaults and the default value cannot be `null` if text is `nullable: false` in the `anyOf` first alternative. - `notes/create`: The `mediaIds` property has been marked as deprecated because it has the same behaviour as using `fileIds`, but the implementation tries to handlè `fileIds` first. - The result schema for `admin/emoji/list` has been altered because the `host` property will always be `null` as it is filtered this way in the database query. See packages/backend/src/server/api/endpoints/admin/emoji/list.ts line 67. * enhance(doc): explain nullable hostname * update changelog Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
128 lines
2.8 KiB
TypeScript
128 lines
2.8 KiB
TypeScript
import { resolveUser } from '@/remote/resolve-user.js';
|
|
import define from '../../define.js';
|
|
import { apiLogger } from '../../logger.js';
|
|
import { ApiError } from '../../error.js';
|
|
import { Users } from '@/models/index.js';
|
|
import { FindOptionsWhere, In, IsNull } from 'typeorm';
|
|
import { User } from '@/models/entities/user.js';
|
|
|
|
export const meta = {
|
|
tags: ['users'],
|
|
|
|
requireCredential: false,
|
|
|
|
res: {
|
|
optional: false, nullable: false,
|
|
oneOf: [
|
|
{
|
|
type: 'object',
|
|
ref: 'UserDetailed',
|
|
},
|
|
{
|
|
type: 'array',
|
|
items: {
|
|
type: 'object',
|
|
ref: 'UserDetailed',
|
|
}
|
|
},
|
|
]
|
|
},
|
|
|
|
errors: {
|
|
failedToResolveRemoteUser: {
|
|
message: 'Failed to resolve remote user.',
|
|
code: 'FAILED_TO_RESOLVE_REMOTE_USER',
|
|
id: 'ef7b9be4-9cba-4e6f-ab41-90ed171c7d3c',
|
|
kind: 'server',
|
|
},
|
|
|
|
noSuchUser: {
|
|
message: 'No such user.',
|
|
code: 'NO_SUCH_USER',
|
|
id: '4362f8dc-731f-4ad8-a694-be5a88922a24',
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
anyOf: [
|
|
{
|
|
properties: {
|
|
userId: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
required: ['userId'],
|
|
},
|
|
{
|
|
properties: {
|
|
userIds: { type: 'array', uniqueItems: true, items: {
|
|
type: 'string', format: 'misskey:id',
|
|
} },
|
|
},
|
|
required: ['userIds'],
|
|
},
|
|
{
|
|
properties: {
|
|
username: { type: 'string' },
|
|
host: {
|
|
type: 'string',
|
|
nullable: true,
|
|
description: 'The local host is represented with `null`.',
|
|
},
|
|
},
|
|
required: ['username', 'host'],
|
|
},
|
|
],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
export default define(meta, paramDef, async (ps, me) => {
|
|
let user;
|
|
|
|
const isAdminOrModerator = me && (me.isAdmin || me.isModerator);
|
|
|
|
if (ps.userIds) {
|
|
if (ps.userIds.length === 0) {
|
|
return [];
|
|
}
|
|
|
|
const users = await Users.findBy(isAdminOrModerator ? {
|
|
id: In(ps.userIds),
|
|
} : {
|
|
id: In(ps.userIds),
|
|
isSuspended: false,
|
|
});
|
|
|
|
// リクエストされた通りに並べ替え
|
|
const _users: User[] = [];
|
|
for (const id of ps.userIds) {
|
|
_users.push(users.find(x => x.id === id)!);
|
|
}
|
|
|
|
return await Promise.all(_users.map(u => Users.pack(u, me, {
|
|
detail: true,
|
|
})));
|
|
} else {
|
|
// Lookup user
|
|
if (typeof ps.host === 'string' && typeof ps.username === 'string') {
|
|
user = await resolveUser(ps.username, ps.host).catch(e => {
|
|
apiLogger.warn(`failed to resolve remote user: ${e}`);
|
|
throw new ApiError(meta.errors.failedToResolveRemoteUser);
|
|
});
|
|
} else {
|
|
const q: FindOptionsWhere<User> = ps.userId != null
|
|
? { id: ps.userId }
|
|
: { usernameLower: ps.username!.toLowerCase(), host: IsNull() };
|
|
|
|
user = await Users.findOneBy(q);
|
|
}
|
|
|
|
if (user == null || (!isAdminOrModerator && user.isSuspended)) {
|
|
throw new ApiError(meta.errors.noSuchUser);
|
|
}
|
|
|
|
return await Users.pack(user, me, {
|
|
detail: true,
|
|
});
|
|
}
|
|
});
|