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:
		| @@ -6,13 +6,6 @@ import { Packed } from '@/misc/schema'; | ||||
|  | ||||
| @EntityRepository(DriveFolder) | ||||
| export class DriveFolderRepository extends Repository<DriveFolder> { | ||||
| 	public validateFolderName(name: string): boolean { | ||||
| 		return ( | ||||
| 			(name.trim().length > 0) && | ||||
| 			(name.length <= 200) | ||||
| 		); | ||||
| 	} | ||||
|  | ||||
| 	public async pack( | ||||
| 		src: DriveFolder['id'] | DriveFolder, | ||||
| 		options?: { | ||||
|   | ||||
| @@ -6,10 +6,6 @@ import { User } from '@/models/entities/user'; | ||||
|  | ||||
| @EntityRepository(MessagingMessage) | ||||
| export class MessagingMessageRepository extends Repository<MessagingMessage> { | ||||
| 	public validateText(text: string): boolean { | ||||
| 		return text.trim().length <= 1000 && text.trim() != ''; | ||||
| 	} | ||||
|  | ||||
| 	public async pack( | ||||
| 		src: MessagingMessage['id'] | MessagingMessage, | ||||
| 		me?: { id: User['id'] } | null | undefined, | ||||
|   | ||||
| @@ -12,10 +12,6 @@ import { aggregateNoteEmojis, populateEmojis, prefetchEmojis } from '@/misc/popu | ||||
|  | ||||
| @EntityRepository(Note) | ||||
| export class NoteRepository extends Repository<Note> { | ||||
| 	public validateCw(x: string) { | ||||
| 		return x.trim().length <= 100; | ||||
| 	} | ||||
|  | ||||
| 	public async isVisibleForMe(note: Note, meId: User['id'] | null): Promise<boolean> { | ||||
| 		// visibility が specified かつ自分が指定されていなかったら非表示 | ||||
| 		if (note.visibility === 'specified') { | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| import $ from 'cafy'; | ||||
| import { EntityRepository, Repository, In, Not } from 'typeorm'; | ||||
| import * as Ajv from 'ajv'; | ||||
| import { User, ILocalUser, IRemoteUser } from '@/models/entities/user'; | ||||
| import { Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages, Announcements, AnnouncementReads, Antennas, AntennaNotes, ChannelFollowings, Instances } from '../index'; | ||||
| import config from '@/config/index'; | ||||
| @@ -17,8 +17,26 @@ type IsMeAndIsUserDetailed<ExpectsMe extends boolean | null, Detailed extends bo | ||||
| 		Packed<'UserDetailed'> : | ||||
| 	Packed<'UserLite'>; | ||||
|  | ||||
| const ajv = new Ajv(); | ||||
|  | ||||
| @EntityRepository(User) | ||||
| export class UserRepository extends Repository<User> { | ||||
| 	public localUsernameSchema = { type: 'string', pattern: /^\w{1,20}$/.toString().slice(1, -1) } as const; | ||||
| 	public passwordSchema = { type: 'string', minLength: 1 } as const; | ||||
| 	public nameSchema = { type: 'string', minLength: 1, maxLength: 50 } as const; | ||||
| 	public descriptionSchema = { type: 'string', minLength: 1, maxLength: 500 } as const; | ||||
| 	public locationSchema = { type: 'string', minLength: 1, maxLength: 50 } as const; | ||||
| 	public birthdaySchema = { type: 'string', pattern: /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.toString().slice(1, -1) } as const; | ||||
|  | ||||
| 	//#region Validators | ||||
| 	public validateLocalUsername = ajv.compile(this.localUsernameSchema); | ||||
| 	public validatePassword = ajv.compile(this.passwordSchema); | ||||
| 	public validateName = ajv.compile(this.nameSchema); | ||||
| 	public validateDescription = ajv.compile(this.descriptionSchema); | ||||
| 	public validateLocation = ajv.compile(this.locationSchema); | ||||
| 	public validateBirthday = ajv.compile(this.birthdaySchema); | ||||
| 	//#endregion | ||||
|  | ||||
| 	public async getRelation(me: User['id'], target: User['id']) { | ||||
| 		const [following1, following2, followReq1, followReq2, toBlocking, fromBlocked, mute] = await Promise.all([ | ||||
| 			Followings.findOne({ | ||||
| @@ -351,13 +369,4 @@ export class UserRepository extends Repository<User> { | ||||
| 	public isRemoteUser(user: User | { host: User['host'] }): boolean { | ||||
| 		return !this.isLocalUser(user); | ||||
| 	} | ||||
|  | ||||
| 	//#region Validators | ||||
| 	public validateLocalUsername = $.str.match(/^\w{1,20}$/); | ||||
| 	public validatePassword = $.str.min(1); | ||||
| 	public validateName = $.str.min(1).max(50); | ||||
| 	public validateDescription = $.str.min(1).max(500); | ||||
| 	public validateLocation = $.str.min(1).max(50); | ||||
| 	public validateBirthday = $.str.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/); | ||||
| 	//#endregion | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo