Server: remote video validators refractoring
This commit is contained in:
parent
62f4ef413c
commit
da691c46df
|
@ -389,11 +389,7 @@ function reportVideoAbuse (req, res, finalCallback) {
|
||||||
|
|
||||||
waterfall([
|
waterfall([
|
||||||
|
|
||||||
function startTransaction (callback) {
|
databaseUtils.startSerializableTransaction,
|
||||||
db.sequelize.transaction().asCallback(function (err, t) {
|
|
||||||
return callback(err, t)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
function createAbuse (t, callback) {
|
function createAbuse (t, callback) {
|
||||||
db.VideoAbuse.create(abuse).asCallback(function (err, abuse) {
|
db.VideoAbuse.create(abuse).asCallback(function (err, abuse) {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const constants = require('../../../initializers/constants')
|
||||||
const videosValidators = require('../videos')
|
const videosValidators = require('../videos')
|
||||||
const miscValidators = require('../misc')
|
const miscValidators = require('../misc')
|
||||||
|
|
||||||
|
const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
|
||||||
|
|
||||||
const remoteVideosValidators = {
|
const remoteVideosValidators = {
|
||||||
isEachRemoteRequestVideosValid
|
isEachRemoteRequestVideosValid
|
||||||
}
|
}
|
||||||
|
@ -13,29 +16,13 @@ function isEachRemoteRequestVideosValid (requests) {
|
||||||
const video = request.data
|
const video = request.data
|
||||||
return (
|
return (
|
||||||
isRequestTypeAddValid(request.type) &&
|
isRequestTypeAddValid(request.type) &&
|
||||||
|
isCommonVideoAttrbiutesValid(video) &&
|
||||||
videosValidators.isVideoAuthorValid(video.author) &&
|
videosValidators.isVideoAuthorValid(video.author) &&
|
||||||
videosValidators.isVideoDateValid(video.createdAt) &&
|
videosValidators.isVideoThumbnailDataValid(video.thumbnailData)
|
||||||
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) &&
|
isRequestTypeUpdateValid(request.type) &&
|
||||||
videosValidators.isVideoDateValid(video.createdAt) &&
|
isCommonVideoAttrbiutesValid(video)
|
||||||
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) &&
|
isRequestTypeRemoveValid(request.type) &&
|
||||||
|
@ -56,18 +43,30 @@ 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)
|
||||||
|
}
|
||||||
|
|
||||||
function isRequestTypeAddValid (value) {
|
function isRequestTypeAddValid (value) {
|
||||||
return value === 'add'
|
return value === ENDPOINT_ACTIONS.ADD
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRequestTypeUpdateValid (value) {
|
function isRequestTypeUpdateValid (value) {
|
||||||
return value === 'update'
|
return value === ENDPOINT_ACTIONS.UPDATE
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRequestTypeRemoveValid (value) {
|
function isRequestTypeRemoveValid (value) {
|
||||||
return value === 'remove'
|
return value === ENDPOINT_ACTIONS.REMOVE
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRequestTypeReportAbuseValid (value) {
|
function isRequestTypeReportAbuseValid (value) {
|
||||||
return value === 'report-abuse'
|
return value === ENDPOINT_ACTIONS.REPORT_ABUSE
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ const db = require('../initializers/database')
|
||||||
const logger = require('../helpers/logger')
|
const logger = require('../helpers/logger')
|
||||||
const requests = require('../helpers/requests')
|
const requests = require('../helpers/requests')
|
||||||
|
|
||||||
|
const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
|
||||||
|
|
||||||
const friends = {
|
const friends = {
|
||||||
addVideoToFriends,
|
addVideoToFriends,
|
||||||
updateVideoToFriends,
|
updateVideoToFriends,
|
||||||
|
@ -26,7 +28,7 @@ const friends = {
|
||||||
|
|
||||||
function addVideoToFriends (videoData, transaction, callback) {
|
function addVideoToFriends (videoData, transaction, callback) {
|
||||||
const options = {
|
const options = {
|
||||||
type: 'add',
|
type: ENDPOINT_ACTIONS.ADD,
|
||||||
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
|
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
|
||||||
data: videoData,
|
data: videoData,
|
||||||
transaction
|
transaction
|
||||||
|
@ -36,7 +38,7 @@ function addVideoToFriends (videoData, transaction, callback) {
|
||||||
|
|
||||||
function updateVideoToFriends (videoData, transaction, callback) {
|
function updateVideoToFriends (videoData, transaction, callback) {
|
||||||
const options = {
|
const options = {
|
||||||
type: 'update',
|
type: ENDPOINT_ACTIONS.UPDATE,
|
||||||
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
|
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
|
||||||
data: videoData,
|
data: videoData,
|
||||||
transaction
|
transaction
|
||||||
|
@ -46,7 +48,7 @@ function updateVideoToFriends (videoData, transaction, callback) {
|
||||||
|
|
||||||
function removeVideoToFriends (videoParams) {
|
function removeVideoToFriends (videoParams) {
|
||||||
const options = {
|
const options = {
|
||||||
type: 'remove',
|
type: ENDPOINT_ACTIONS.REMOVE,
|
||||||
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
|
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
|
||||||
data: videoParams
|
data: videoParams
|
||||||
}
|
}
|
||||||
|
@ -55,7 +57,7 @@ function removeVideoToFriends (videoParams) {
|
||||||
|
|
||||||
function reportAbuseVideoToFriend (reportData, video) {
|
function reportAbuseVideoToFriend (reportData, video) {
|
||||||
const options = {
|
const options = {
|
||||||
type: 'report-abuse',
|
type: ENDPOINT_ACTIONS.REPORT_ABUSE,
|
||||||
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
|
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
|
||||||
data: reportData,
|
data: reportData,
|
||||||
toIds: [ video.Author.podId ]
|
toIds: [ video.Author.podId ]
|
||||||
|
|
Loading…
Reference in New Issue