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 { UserProfiles, Users } from '@/models/index';
|
||||
import { User } from '@/models/entities/user';
|
||||
@@ -9,32 +8,6 @@ export const meta = {
|
||||
|
||||
requireCredential: false,
|
||||
|
||||
params: {
|
||||
query: {
|
||||
validator: $.str,
|
||||
},
|
||||
|
||||
offset: {
|
||||
validator: $.optional.num.min(0),
|
||||
default: 0,
|
||||
},
|
||||
|
||||
limit: {
|
||||
validator: $.optional.num.range(1, 100),
|
||||
default: 10,
|
||||
},
|
||||
|
||||
origin: {
|
||||
validator: $.optional.str.or(['local', 'remote', 'combined']),
|
||||
default: 'combined',
|
||||
},
|
||||
|
||||
detail: {
|
||||
validator: $.optional.bool,
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
|
||||
res: {
|
||||
type: 'array',
|
||||
optional: false, nullable: false,
|
||||
@@ -46,8 +19,20 @@ export const meta = {
|
||||
},
|
||||
} as const;
|
||||
|
||||
const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
query: { type: 'string' },
|
||||
offset: { type: 'integer', default: 0 },
|
||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
||||
origin: { type: 'string', enum: ['local', 'remote', 'combined'], default: "combined" },
|
||||
detail: { type: 'boolean', default: true },
|
||||
},
|
||||
required: ['query'],
|
||||
} 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日
|
||||
|
||||
const isUsername = ps.query.startsWith('@');
|
||||
@@ -71,7 +56,7 @@ export default define(meta, async (ps, me) => {
|
||||
|
||||
users = await usernameQuery
|
||||
.orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
|
||||
.take(ps.limit!)
|
||||
.take(ps.limit)
|
||||
.skip(ps.offset)
|
||||
.getMany();
|
||||
} else {
|
||||
@@ -91,11 +76,11 @@ export default define(meta, async (ps, me) => {
|
||||
|
||||
users = await nameQuery
|
||||
.orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
|
||||
.take(ps.limit!)
|
||||
.take(ps.limit)
|
||||
.skip(ps.offset)
|
||||
.getMany();
|
||||
|
||||
if (users.length < ps.limit!) {
|
||||
if (users.length < ps.limit) {
|
||||
const profQuery = UserProfiles.createQueryBuilder('prof')
|
||||
.select('prof.userId')
|
||||
.where('prof.description ILIKE :query', { query: '%' + ps.query + '%' });
|
||||
@@ -117,7 +102,7 @@ export default define(meta, async (ps, me) => {
|
||||
|
||||
users = users.concat(await query
|
||||
.orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
|
||||
.take(ps.limit!)
|
||||
.take(ps.limit)
|
||||
.skip(ps.offset)
|
||||
.getMany()
|
||||
);
|
||||
|
Reference in New Issue
Block a user