PeerTube/server/helpers/custom-validators/remote/videos.js

73 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-01-04 13:59:23 -06:00
'use strict'
const constants = require('../../../initializers/constants')
2017-01-04 13:59:23 -06:00
const videosValidators = require('../videos')
const miscValidators = require('../misc')
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) &&
isCommonVideoAttrbiutesValid(video) &&
2017-01-04 13:59:23 -06:00
videosValidators.isVideoAuthorValid(video.author) &&
videosValidators.isVideoThumbnailDataValid(video.thumbnailData)
2017-01-04 13:59:23 -06:00
) ||
(
isRequestTypeUpdateValid(request.type) &&
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
// ---------------------------------------------------------------------------
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) {
return value === ENDPOINT_ACTIONS.ADD
2017-01-04 13:59:23 -06:00
}
function isRequestTypeUpdateValid (value) {
return value === ENDPOINT_ACTIONS.UPDATE
2017-01-04 13:59:23 -06:00
}
function isRequestTypeRemoveValid (value) {
return value === ENDPOINT_ACTIONS.REMOVE
2017-01-04 13:59:23 -06:00
}
function isRequestTypeReportAbuseValid (value) {
return value === ENDPOINT_ACTIONS.REPORT_ABUSE
2017-01-04 13:59:23 -06:00
}