mirror of
https://github.com/sim1222/misskey.git
synced 2025-08-03 23:16:28 +09:00
refactor: use ajv instead of cafy (#8324)
* wip * wip * Update abuse-user-reports.ts * Update files.ts * Update list-remote.ts * Update list.ts * Update show-users.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * Update search.ts * Update reactions.ts * Update search.ts * wip * wip * wip * wip * Update update.ts * Update relation.ts * Update available.ts * wip * wip * wip * Update packages/backend/src/server/api/define.ts Co-authored-by: Johann150 <johann.galle@protonmail.com> * Update define.ts * Update define.ts * typo * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * wip * Update signup.ts * Update call.ts * minimum for limit * type * remove needless annotation * wip * Update signup.ts * wip * wip * fix * Update create.ts Co-authored-by: Johann150 <johann.galle@protonmail.com>
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
import $ from 'cafy';
|
||||
import define from '../../define';
|
||||
import { Followings, Users } from '@/models/index';
|
||||
import { Brackets } from 'typeorm';
|
||||
@ -10,26 +9,6 @@ export const meta = {
|
||||
|
||||
requireCredential: false,
|
||||
|
||||
params: {
|
||||
username: {
|
||||
validator: $.optional.nullable.str,
|
||||
},
|
||||
|
||||
host: {
|
||||
validator: $.optional.nullable.str,
|
||||
},
|
||||
|
||||
limit: {
|
||||
validator: $.optional.num.range(1, 100),
|
||||
default: 10,
|
||||
},
|
||||
|
||||
detail: {
|
||||
validator: $.optional.bool,
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
|
||||
res: {
|
||||
type: 'array',
|
||||
optional: false, nullable: false,
|
||||
@ -41,8 +20,19 @@ export const meta = {
|
||||
},
|
||||
} as const;
|
||||
|
||||
const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
username: { type: 'string', nullable: true },
|
||||
host: { type: 'string', nullable: true },
|
||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
||||
detail: { type: 'boolean', default: true },
|
||||
},
|
||||
required: [],
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, async (ps, me) => {
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const activeThreshold = new Date(Date.now() - (1000 * 60 * 60 * 24 * 30)); // 30日
|
||||
|
||||
if (ps.host) {
|
||||
@ -57,7 +47,7 @@ export default define(meta, async (ps, me) => {
|
||||
q.andWhere('user.updatedAt IS NOT NULL');
|
||||
q.orderBy('user.updatedAt', 'DESC');
|
||||
|
||||
const users = await q.take(ps.limit!).getMany();
|
||||
const users = await q.take(ps.limit).getMany();
|
||||
|
||||
return await Users.packMany(users, me, { detail: ps.detail });
|
||||
} else if (ps.username) {
|
||||
@ -82,10 +72,10 @@ export default define(meta, async (ps, me) => {
|
||||
|
||||
users = await query
|
||||
.orderBy('user.usernameLower', 'ASC')
|
||||
.take(ps.limit!)
|
||||
.take(ps.limit)
|
||||
.getMany();
|
||||
|
||||
if (users.length < ps.limit!) {
|
||||
if (users.length < ps.limit) {
|
||||
const otherQuery = await Users.createQueryBuilder('user')
|
||||
.where(`user.id NOT IN (${ followingQuery.getQuery() })`)
|
||||
.andWhere(`user.id != :meId`, { meId: me.id })
|
||||
@ -97,7 +87,7 @@ export default define(meta, async (ps, me) => {
|
||||
|
||||
const otherUsers = await otherQuery
|
||||
.orderBy('user.updatedAt', 'DESC')
|
||||
.take(ps.limit! - users.length)
|
||||
.take(ps.limit - users.length)
|
||||
.getMany();
|
||||
|
||||
users = users.concat(otherUsers);
|
||||
@ -108,7 +98,7 @@ export default define(meta, async (ps, me) => {
|
||||
.andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' })
|
||||
.andWhere('user.updatedAt IS NOT NULL')
|
||||
.orderBy('user.updatedAt', 'DESC')
|
||||
.take(ps.limit! - users.length)
|
||||
.take(ps.limit - users.length)
|
||||
.getMany();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user