mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Server: add video abuse support
This commit is contained in:
parent
a6fd2b30bf
commit
55fa55a9be
32 changed files with 921 additions and 175 deletions
|
@ -2,12 +2,14 @@
|
|||
|
||||
const miscValidators = require('./misc')
|
||||
const podsValidators = require('./pods')
|
||||
const remoteValidators = require('./remote')
|
||||
const usersValidators = require('./users')
|
||||
const videosValidators = require('./videos')
|
||||
|
||||
const validators = {
|
||||
misc: miscValidators,
|
||||
pods: podsValidators,
|
||||
remote: remoteValidators,
|
||||
users: usersValidators,
|
||||
videos: videosValidators
|
||||
}
|
||||
|
|
11
server/helpers/custom-validators/remote/index.js
Normal file
11
server/helpers/custom-validators/remote/index.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict'
|
||||
|
||||
const remoteVideosValidators = require('./videos')
|
||||
|
||||
const validators = {
|
||||
videos: remoteVideosValidators
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
module.exports = validators
|
74
server/helpers/custom-validators/remote/videos.js
Normal file
74
server/helpers/custom-validators/remote/videos.js
Normal file
|
@ -0,0 +1,74 @@
|
|||
'use strict'
|
||||
|
||||
const videosValidators = require('../videos')
|
||||
const miscValidators = require('../misc')
|
||||
|
||||
const remoteVideosValidators = {
|
||||
isEachRemoteRequestVideosValid
|
||||
}
|
||||
|
||||
function isEachRemoteRequestVideosValid (requests) {
|
||||
return miscValidators.isArray(requests) &&
|
||||
requests.every(function (request) {
|
||||
const video = request.data
|
||||
return (
|
||||
isRequestTypeAddValid(request.type) &&
|
||||
videosValidators.isVideoAuthorValid(video.author) &&
|
||||
videosValidators.isVideoDateValid(video.createdAt) &&
|
||||
videosValidators.isVideoDateValid(video.updatedAt) &&
|
||||
videosValidators.isVideoDescriptionValid(video.description) &&
|
||||
videosValidators.isVideoDurationValid(video.duration) &&
|
||||
videosValidators.isVideoInfoHashValid(video.infoHash) &&
|
||||
videosValidators.isVideoNameValid(video.name) &&
|
||||
videosValidators.isVideoTagsValid(video.tags) &&
|
||||
videosValidators.isVideoThumbnailDataValid(video.thumbnailData) &&
|
||||
videosValidators.isVideoRemoteIdValid(video.remoteId) &&
|
||||
videosValidators.isVideoExtnameValid(video.extname)
|
||||
) ||
|
||||
(
|
||||
isRequestTypeUpdateValid(request.type) &&
|
||||
videosValidators.isVideoDateValid(video.createdAt) &&
|
||||
videosValidators.isVideoDateValid(video.updatedAt) &&
|
||||
videosValidators.isVideoDescriptionValid(video.description) &&
|
||||
videosValidators.isVideoDurationValid(video.duration) &&
|
||||
videosValidators.isVideoInfoHashValid(video.infoHash) &&
|
||||
videosValidators.isVideoNameValid(video.name) &&
|
||||
videosValidators.isVideoTagsValid(video.tags) &&
|
||||
videosValidators.isVideoRemoteIdValid(video.remoteId) &&
|
||||
videosValidators.isVideoExtnameValid(video.extname)
|
||||
) ||
|
||||
(
|
||||
isRequestTypeRemoveValid(request.type) &&
|
||||
videosValidators.isVideoNameValid(video.name) &&
|
||||
videosValidators.isVideoRemoteIdValid(video.remoteId)
|
||||
) ||
|
||||
(
|
||||
isRequestTypeReportAbuseValid(request.type) &&
|
||||
videosValidators.isVideoRemoteIdValid(request.data.videoRemoteId) &&
|
||||
videosValidators.isVideoAbuseReasonValid(request.data.reportReason) &&
|
||||
videosValidators.isVideoAbuseReporterUsernameValid(request.data.reporterUsername)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
module.exports = remoteVideosValidators
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isRequestTypeAddValid (value) {
|
||||
return value === 'add'
|
||||
}
|
||||
|
||||
function isRequestTypeUpdateValid (value) {
|
||||
return value === 'update'
|
||||
}
|
||||
|
||||
function isRequestTypeRemoveValid (value) {
|
||||
return value === 'remove'
|
||||
}
|
||||
|
||||
function isRequestTypeReportAbuseValid (value) {
|
||||
return value === 'report-abuse'
|
||||
}
|
|
@ -6,9 +6,9 @@ const constants = require('../../initializers/constants')
|
|||
const usersValidators = require('./users')
|
||||
const miscValidators = require('./misc')
|
||||
const VIDEOS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEOS
|
||||
const VIDEO_ABUSES_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_ABUSES
|
||||
|
||||
const videosValidators = {
|
||||
isEachRemoteVideosValid,
|
||||
isVideoAuthorValid,
|
||||
isVideoDateValid,
|
||||
isVideoDescriptionValid,
|
||||
|
@ -17,45 +17,11 @@ const videosValidators = {
|
|||
isVideoNameValid,
|
||||
isVideoTagsValid,
|
||||
isVideoThumbnailValid,
|
||||
isVideoThumbnailDataValid
|
||||
}
|
||||
|
||||
function isEachRemoteVideosValid (requests) {
|
||||
return miscValidators.isArray(requests) &&
|
||||
requests.every(function (request) {
|
||||
const video = request.data
|
||||
return (
|
||||
isRequestTypeAddValid(request.type) &&
|
||||
isVideoAuthorValid(video.author) &&
|
||||
isVideoDateValid(video.createdAt) &&
|
||||
isVideoDateValid(video.updatedAt) &&
|
||||
isVideoDescriptionValid(video.description) &&
|
||||
isVideoDurationValid(video.duration) &&
|
||||
isVideoInfoHashValid(video.infoHash) &&
|
||||
isVideoNameValid(video.name) &&
|
||||
isVideoTagsValid(video.tags) &&
|
||||
isVideoThumbnailDataValid(video.thumbnailData) &&
|
||||
isVideoRemoteIdValid(video.remoteId) &&
|
||||
isVideoExtnameValid(video.extname)
|
||||
) ||
|
||||
(
|
||||
isRequestTypeUpdateValid(request.type) &&
|
||||
isVideoDateValid(video.createdAt) &&
|
||||
isVideoDateValid(video.updatedAt) &&
|
||||
isVideoDescriptionValid(video.description) &&
|
||||
isVideoDurationValid(video.duration) &&
|
||||
isVideoInfoHashValid(video.infoHash) &&
|
||||
isVideoNameValid(video.name) &&
|
||||
isVideoTagsValid(video.tags) &&
|
||||
isVideoRemoteIdValid(video.remoteId) &&
|
||||
isVideoExtnameValid(video.extname)
|
||||
) ||
|
||||
(
|
||||
isRequestTypeRemoveValid(request.type) &&
|
||||
isVideoNameValid(video.name) &&
|
||||
isVideoRemoteIdValid(video.remoteId)
|
||||
)
|
||||
})
|
||||
isVideoThumbnailDataValid,
|
||||
isVideoExtnameValid,
|
||||
isVideoRemoteIdValid,
|
||||
isVideoAbuseReasonValid,
|
||||
isVideoAbuseReporterUsernameValid
|
||||
}
|
||||
|
||||
function isVideoAuthorValid (value) {
|
||||
|
@ -107,20 +73,14 @@ function isVideoRemoteIdValid (value) {
|
|||
return validator.isUUID(value, 4)
|
||||
}
|
||||
|
||||
function isVideoAbuseReasonValid (value) {
|
||||
return validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
|
||||
}
|
||||
|
||||
function isVideoAbuseReporterUsernameValid (value) {
|
||||
return usersValidators.isUserUsernameValid(value)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
module.exports = videosValidators
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isRequestTypeAddValid (value) {
|
||||
return value === 'add'
|
||||
}
|
||||
|
||||
function isRequestTypeUpdateValid (value) {
|
||||
return value === 'update'
|
||||
}
|
||||
|
||||
function isRequestTypeRemoveValid (value) {
|
||||
return value === 'remove'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue