2018-08-10 10:54:01 -04:00
|
|
|
import { Response } from 'express'
|
|
|
|
import * as validator from 'validator'
|
2019-04-11 08:26:41 -04:00
|
|
|
import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
|
2018-08-10 10:54:01 -04:00
|
|
|
import { exists } from './misc'
|
|
|
|
import { VideoAbuseModel } from '../../models/video/video-abuse'
|
|
|
|
|
|
|
|
const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
|
|
|
|
|
|
|
|
function isVideoAbuseReasonValid (value: string) {
|
|
|
|
return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoAbuseModerationCommentValid (value: string) {
|
|
|
|
return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.MODERATION_COMMENT)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoAbuseStateValid (value: string) {
|
|
|
|
return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined
|
|
|
|
}
|
|
|
|
|
2019-03-19 04:26:50 -04:00
|
|
|
async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) {
|
2018-08-10 10:54:01 -04:00
|
|
|
const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId)
|
|
|
|
|
|
|
|
if (videoAbuse === null) {
|
|
|
|
res.status(404)
|
|
|
|
.json({ error: 'Video abuse not found' })
|
|
|
|
.end()
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.videoAbuse = videoAbuse
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2019-03-19 04:26:50 -04:00
|
|
|
doesVideoAbuseExist,
|
2018-08-10 10:54:01 -04:00
|
|
|
isVideoAbuseStateValid,
|
|
|
|
isVideoAbuseReasonValid,
|
|
|
|
isVideoAbuseModerationCommentValid
|
|
|
|
}
|