mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 09:49:20 +02:00
Type functions
This commit is contained in:
parent
4d4e5cd4dc
commit
69818c9394
96 changed files with 990 additions and 544 deletions
|
@ -1,25 +1,26 @@
|
|||
import { values } from 'lodash'
|
||||
import * as validator from 'validator'
|
||||
|
||||
import { exists } from './misc'
|
||||
import { CONSTRAINTS_FIELDS, USER_ROLES } from '../../initializers'
|
||||
const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS
|
||||
|
||||
function isUserPasswordValid (value) {
|
||||
function isUserPasswordValid (value: string) {
|
||||
return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD)
|
||||
}
|
||||
|
||||
function isUserRoleValid (value) {
|
||||
function isUserRoleValid (value: string) {
|
||||
return values(USER_ROLES).indexOf(value) !== -1
|
||||
}
|
||||
|
||||
function isUserUsernameValid (value) {
|
||||
function isUserUsernameValid (value: string) {
|
||||
const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max
|
||||
const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min
|
||||
return validator.matches(value, new RegExp(`^[a-zA-Z0-9._]{${min},${max}}$`))
|
||||
return exists(value) && validator.matches(value, new RegExp(`^[a-zA-Z0-9._]{${min},${max}}$`))
|
||||
}
|
||||
|
||||
function isUserDisplayNSFWValid (value) {
|
||||
return validator.isBoolean(value)
|
||||
function isUserDisplayNSFWValid (value: any) {
|
||||
return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -30,3 +31,14 @@ export {
|
|||
isUserUsernameValid,
|
||||
isUserDisplayNSFWValid
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace ExpressValidator {
|
||||
export interface Validator {
|
||||
isUserPasswordValid,
|
||||
isUserRoleValid,
|
||||
isUserUsernameValid,
|
||||
isUserDisplayNSFWValid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue