1
0
Fork 0
peertube/server/helpers/custom-validators/users.ts
Andréas Livet 7efe153b0b Enh #106 : Add an autoPlayVideo user attribute (#159)
Warning : I was not able to run the tests on my machine. It uses a different approach to handle databse connexion and didn't find where to configure it...

- create a migration file to add a boolean column in user table
- add autoPlayVideo attribute everywhere it is needed (both on client and server side)
- add tests
- add a way to configure this attribute in account-settings
- use the attribute in video-watch component to actually autoplay or not the video
2017-12-19 10:45:49 +01:00

49 lines
1.4 KiB
TypeScript

import * as validator from 'validator'
import 'express-validator'
import { exists } from './misc'
import { CONSTRAINTS_FIELDS } from '../../initializers'
import { UserRole } from '../../../shared'
const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS
function isUserPasswordValid (value: string) {
return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD)
}
function isUserVideoQuotaValid (value: string) {
return exists(value) && validator.isInt(value + '', USERS_CONSTRAINTS_FIELDS.VIDEO_QUOTA)
}
function isUserUsernameValid (value: string) {
const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max
const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min
return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`))
}
function isBoolean (value: any) {
return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
}
function isUserDisplayNSFWValid (value: any) {
return isBoolean(value)
}
function isUserAutoPlayVideoValid (value: any) {
return isBoolean(value)
}
function isUserRoleValid (value: any) {
return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined
}
// ---------------------------------------------------------------------------
export {
isUserPasswordValid,
isUserRoleValid,
isUserVideoQuotaValid,
isUserUsernameValid,
isUserDisplayNSFWValid,
isUserAutoPlayVideoValid
}