2017-01-04 13:59:23 -06:00
|
|
|
'use strict'
|
|
|
|
|
2017-02-21 14:35:59 -06:00
|
|
|
const has = require('lodash/has')
|
|
|
|
|
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 = {
|
2017-02-21 14:35:59 -06:00
|
|
|
isEachRemoteRequestVideosValid,
|
|
|
|
isEachRemoteRequestVideosQaduValid
|
2017-01-04 13:59:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function isEachRemoteRequestVideosValid (requests) {
|
|
|
|
return miscValidators.isArray(requests) &&
|
|
|
|
requests.every(function (request) {
|
|
|
|
const video = request.data
|
|
|
|
return (
|
|
|
|
isRequestTypeAddValid(request.type) &&
|
2017-02-21 14:35:59 -06:00
|
|
|
isCommonVideoAttributesValid(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-02-21 14:35:59 -06:00
|
|
|
isCommonVideoAttributesValid(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)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-21 14:35:59 -06:00
|
|
|
function isEachRemoteRequestVideosQaduValid (requests) {
|
|
|
|
return miscValidators.isArray(requests) &&
|
|
|
|
requests.every(function (request) {
|
|
|
|
const video = request.data
|
|
|
|
|
|
|
|
return (
|
|
|
|
videosValidators.isVideoRemoteIdValid(video.remoteId) &&
|
|
|
|
(has(video, 'views') === false || videosValidators.isVideoViewsValid) &&
|
|
|
|
(has(video, 'likes') === false || videosValidators.isVideoLikesValid) &&
|
|
|
|
(has(video, 'dislikes') === false || videosValidators.isVideoDislikesValid)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-04 13:59:23 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
module.exports = remoteVideosValidators
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-02-21 14:35:59 -06:00
|
|
|
function isCommonVideoAttributesValid (video) {
|
2017-01-17 13:59:16 -06:00
|
|
|
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
|
|
|
}
|