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,5 +1,3 @@ | ||||
| import $ from 'cafy'; | ||||
| import { ID } from '@/misc/cafy-id'; | ||||
| import ms from 'ms'; | ||||
| import create from '@/services/blocking/create'; | ||||
| import define from '../../define'; | ||||
| @@ -19,12 +17,6 @@ export const meta = { | ||||
|  | ||||
| 	kind: 'write:blocks', | ||||
|  | ||||
| 	params: { | ||||
| 		userId: { | ||||
| 			validator: $.type(ID), | ||||
| 		}, | ||||
| 	}, | ||||
|  | ||||
| 	errors: { | ||||
| 		noSuchUser: { | ||||
| 			message: 'No such user.', | ||||
| @@ -52,8 +44,16 @@ export const meta = { | ||||
| 	}, | ||||
| } as const; | ||||
|  | ||||
| const paramDef = { | ||||
| 	type: 'object', | ||||
| 	properties: { | ||||
| 		userId: { type: 'string', format: 'misskey:id' }, | ||||
| 	}, | ||||
| 	required: ['userId'], | ||||
| } as const; | ||||
|  | ||||
| // eslint-disable-next-line import/no-default-export | ||||
| export default define(meta, async (ps, user) => { | ||||
| export default define(meta, paramDef, async (ps, user) => { | ||||
| 	const blocker = await Users.findOneOrFail(user.id); | ||||
|  | ||||
| 	// 自分自身 | ||||
|   | ||||
| @@ -1,5 +1,3 @@ | ||||
| import $ from 'cafy'; | ||||
| import { ID } from '@/misc/cafy-id'; | ||||
| import ms from 'ms'; | ||||
| import deleteBlocking from '@/services/blocking/delete'; | ||||
| import define from '../../define'; | ||||
| @@ -19,12 +17,6 @@ export const meta = { | ||||
|  | ||||
| 	kind: 'write:blocks', | ||||
|  | ||||
| 	params: { | ||||
| 		userId: { | ||||
| 			validator: $.type(ID), | ||||
| 		}, | ||||
| 	}, | ||||
|  | ||||
| 	errors: { | ||||
| 		noSuchUser: { | ||||
| 			message: 'No such user.', | ||||
| @@ -52,8 +44,16 @@ export const meta = { | ||||
| 	}, | ||||
| } as const; | ||||
|  | ||||
| const paramDef = { | ||||
| 	type: 'object', | ||||
| 	properties: { | ||||
| 		userId: { type: 'string', format: 'misskey:id' }, | ||||
| 	}, | ||||
| 	required: ['userId'], | ||||
| } as const; | ||||
|  | ||||
| // eslint-disable-next-line import/no-default-export | ||||
| export default define(meta, async (ps, user) => { | ||||
| export default define(meta, paramDef, async (ps, user) => { | ||||
| 	const blocker = await Users.findOneOrFail(user.id); | ||||
|  | ||||
| 	// Check if the blockee is yourself | ||||
|   | ||||
| @@ -1,5 +1,3 @@ | ||||
| import $ from 'cafy'; | ||||
| import { ID } from '@/misc/cafy-id'; | ||||
| import define from '../../define'; | ||||
| import { Blockings } from '@/models/index'; | ||||
| import { makePaginationQuery } from '../../common/make-pagination-query'; | ||||
| @@ -11,21 +9,6 @@ export const meta = { | ||||
|  | ||||
| 	kind: 'read:blocks', | ||||
|  | ||||
| 	params: { | ||||
| 		limit: { | ||||
| 			validator: $.optional.num.range(1, 100), | ||||
| 			default: 30, | ||||
| 		}, | ||||
|  | ||||
| 		sinceId: { | ||||
| 			validator: $.optional.type(ID), | ||||
| 		}, | ||||
|  | ||||
| 		untilId: { | ||||
| 			validator: $.optional.type(ID), | ||||
| 		}, | ||||
| 	}, | ||||
|  | ||||
| 	res: { | ||||
| 		type: 'array', | ||||
| 		optional: false, nullable: false, | ||||
| @@ -37,13 +20,23 @@ export const meta = { | ||||
| 	}, | ||||
| } as const; | ||||
|  | ||||
| const paramDef = { | ||||
| 	type: 'object', | ||||
| 	properties: { | ||||
| 		limit: { type: 'integer', minimum: 1, maximum: 100, default: 30 }, | ||||
| 		sinceId: { type: 'string', format: 'misskey:id' }, | ||||
| 		untilId: { type: 'string', format: 'misskey:id' }, | ||||
| 	}, | ||||
| 	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 query = makePaginationQuery(Blockings.createQueryBuilder('blocking'), ps.sinceId, ps.untilId) | ||||
| 		.andWhere(`blocking.blockerId = :meId`, { meId: me.id }); | ||||
|  | ||||
| 	const blockings = await query | ||||
| 		.take(ps.limit!) | ||||
| 		.take(ps.limit) | ||||
| 		.getMany(); | ||||
|  | ||||
| 	return await Blockings.packMany(blockings, me); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo