2020-01-07 07:56:07 -06:00
|
|
|
import validator from 'validator'
|
2020-05-06 10:39:07 -05:00
|
|
|
|
2019-04-11 07:26:41 -05:00
|
|
|
import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
|
2020-06-22 06:00:39 -05:00
|
|
|
import { exists, isArray } from './misc'
|
2020-05-06 10:39:07 -05:00
|
|
|
import { VideoAbuseVideoIs } from '@shared/models/videos/abuse/video-abuse-video-is.type'
|
2020-06-22 06:00:39 -05:00
|
|
|
import { VideoAbusePredefinedReasonsString, videoAbusePredefinedReasonsMap } from '@shared/models/videos/abuse/video-abuse-reason.model'
|
2018-08-10 09:54:01 -05:00
|
|
|
|
|
|
|
const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
|
|
|
|
|
|
|
|
function isVideoAbuseReasonValid (value: string) {
|
|
|
|
return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
|
|
|
|
}
|
|
|
|
|
2020-06-22 06:00:39 -05:00
|
|
|
function isVideoAbusePredefinedReasonValid (value: VideoAbusePredefinedReasonsString) {
|
|
|
|
return exists(value) && value in videoAbusePredefinedReasonsMap
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoAbusePredefinedReasonsValid (value: VideoAbusePredefinedReasonsString[]) {
|
|
|
|
return exists(value) && isArray(value) && value.every(v => v in videoAbusePredefinedReasonsMap)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoAbuseTimestampValid (value: number) {
|
|
|
|
return value === null || (exists(value) && validator.isInt('' + value, { min: 0 }))
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoAbuseTimestampCoherent (endAt: number, { req }) {
|
|
|
|
return exists(req.body.startAt) && endAt > req.body.startAt
|
|
|
|
}
|
|
|
|
|
2018-08-10 09:54:01 -05:00
|
|
|
function isVideoAbuseModerationCommentValid (value: string) {
|
|
|
|
return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.MODERATION_COMMENT)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoAbuseStateValid (value: string) {
|
2020-01-31 09:56:52 -06:00
|
|
|
return exists(value) && VIDEO_ABUSE_STATES[value] !== undefined
|
2018-08-10 09:54:01 -05:00
|
|
|
}
|
|
|
|
|
2020-05-06 10:39:07 -05:00
|
|
|
function isAbuseVideoIsValid (value: VideoAbuseVideoIs) {
|
|
|
|
return exists(value) && (
|
|
|
|
value === 'deleted' ||
|
|
|
|
value === 'blacklisted'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-08-10 09:54:01 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
isVideoAbuseReasonValid,
|
2020-06-22 06:00:39 -05:00
|
|
|
isVideoAbusePredefinedReasonValid,
|
|
|
|
isVideoAbusePredefinedReasonsValid,
|
|
|
|
isVideoAbuseTimestampValid,
|
|
|
|
isVideoAbuseTimestampCoherent,
|
|
|
|
isVideoAbuseModerationCommentValid,
|
|
|
|
isVideoAbuseStateValid,
|
|
|
|
isAbuseVideoIsValid
|
2018-08-10 09:54:01 -05:00
|
|
|
}
|