2017-01-04 13:59:23 -06:00
|
|
|
'use strict'
|
|
|
|
|
2017-01-17 13:59:16 -06:00
|
|
|
const constants = require('../../../initializers/constants')
|
2017-01-04 13:59:23 -06:00
|
|
|
const videosValidators = require('../videos')
|
|
|
|
const miscValidators = require('../misc')
|
|
|
|
|
2017-01-17 13:59:16 -06:00
|
|
|
const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
|
|
|
|
|
2017-01-04 13:59:23 -06:00
|
|
|
const remoteVideosValidators = {
|
|
|
|
isEachRemoteRequestVideosValid
|
|
|
|
}
|
|
|
|
|
|
|
|
function isEachRemoteRequestVideosValid (requests) {
|
|
|
|
return miscValidators.isArray(requests) &&
|
|
|
|
requests.every(function (request) {
|
|
|
|
const video = request.data
|
|
|
|
return (
|
|
|
|
isRequestTypeAddValid(request.type) &&
|
2017-01-17 13:59:16 -06:00
|
|
|
isCommonVideoAttrbiutesValid(video) &&
|
2017-01-04 13:59:23 -06:00
|
|
|
videosValidators.isVideoAuthorValid(video.author) &&
|
2017-01-17 13:59:16 -06:00
|
|
|
videosValidators.isVideoThumbnailDataValid(video.thumbnailData)
|
2017-01-04 13:59:23 -06:00
|
|
|
) ||
|
|
|
|
(
|
|
|
|
isRequestTypeUpdateValid(request.type) &&
|
2017-01-17 13:59:16 -06:00
|
|
|
isCommonVideoAttrbiutesValid(video)
|
2017-01-04 13:59:23 -06:00
|
|
|
) ||
|
|
|
|
(
|
|
|
|
isRequestTypeRemoveValid(request.type) &&
|
|
|
|
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
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-01-17 13:59:16 -06:00
|
|
|
function isCommonVideoAttrbiutesValid (video) {
|
|
|
|
return 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)
|
|
|
|
}
|
|
|
|
|
2017-01-04 13:59:23 -06:00
|
|
|
function isRequestTypeAddValid (value) {
|
2017-01-17 13:59:16 -06:00
|
|
|
return value === ENDPOINT_ACTIONS.ADD
|
2017-01-04 13:59:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function isRequestTypeUpdateValid (value) {
|
2017-01-17 13:59:16 -06:00
|
|
|
return value === ENDPOINT_ACTIONS.UPDATE
|
2017-01-04 13:59:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function isRequestTypeRemoveValid (value) {
|
2017-01-17 13:59:16 -06:00
|
|
|
return value === ENDPOINT_ACTIONS.REMOVE
|
2017-01-04 13:59:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function isRequestTypeReportAbuseValid (value) {
|
2017-01-17 13:59:16 -06:00
|
|
|
return value === ENDPOINT_ACTIONS.REPORT_ABUSE
|
2017-01-04 13:59:23 -06:00
|
|
|
}
|