1
0
Fork 0

Server: remote video validators refractoring

This commit is contained in:
Chocobozzz 2017-01-17 20:59:16 +01:00
parent 62f4ef413c
commit da691c46df
3 changed files with 29 additions and 32 deletions

View file

@ -389,11 +389,7 @@ function reportVideoAbuse (req, res, finalCallback) {
waterfall([
function startTransaction (callback) {
db.sequelize.transaction().asCallback(function (err, t) {
return callback(err, t)
})
},
databaseUtils.startSerializableTransaction,
function createAbuse (t, callback) {
db.VideoAbuse.create(abuse).asCallback(function (err, abuse) {

View file

@ -1,8 +1,11 @@
'use strict'
const constants = require('../../../initializers/constants')
const videosValidators = require('../videos')
const miscValidators = require('../misc')
const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
const remoteVideosValidators = {
isEachRemoteRequestVideosValid
}
@ -13,29 +16,13 @@ function isEachRemoteRequestVideosValid (requests) {
const video = request.data
return (
isRequestTypeAddValid(request.type) &&
isCommonVideoAttrbiutesValid(video) &&
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)
videosValidators.isVideoThumbnailDataValid(video.thumbnailData)
) ||
(
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)
isCommonVideoAttrbiutesValid(video)
) ||
(
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) {
return value === 'add'
return value === ENDPOINT_ACTIONS.ADD
}
function isRequestTypeUpdateValid (value) {
return value === 'update'
return value === ENDPOINT_ACTIONS.UPDATE
}
function isRequestTypeRemoveValid (value) {
return value === 'remove'
return value === ENDPOINT_ACTIONS.REMOVE
}
function isRequestTypeReportAbuseValid (value) {
return value === 'report-abuse'
return value === ENDPOINT_ACTIONS.REPORT_ABUSE
}

View file

@ -12,6 +12,8 @@ const db = require('../initializers/database')
const logger = require('../helpers/logger')
const requests = require('../helpers/requests')
const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
const friends = {
addVideoToFriends,
updateVideoToFriends,
@ -26,7 +28,7 @@ const friends = {
function addVideoToFriends (videoData, transaction, callback) {
const options = {
type: 'add',
type: ENDPOINT_ACTIONS.ADD,
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
data: videoData,
transaction
@ -36,7 +38,7 @@ function addVideoToFriends (videoData, transaction, callback) {
function updateVideoToFriends (videoData, transaction, callback) {
const options = {
type: 'update',
type: ENDPOINT_ACTIONS.UPDATE,
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
data: videoData,
transaction
@ -46,7 +48,7 @@ function updateVideoToFriends (videoData, transaction, callback) {
function removeVideoToFriends (videoParams) {
const options = {
type: 'remove',
type: ENDPOINT_ACTIONS.REMOVE,
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
data: videoParams
}
@ -55,7 +57,7 @@ function removeVideoToFriends (videoParams) {
function reportAbuseVideoToFriend (reportData, video) {
const options = {
type: 'report-abuse',
type: ENDPOINT_ACTIONS.REPORT_ABUSE,
endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
data: reportData,
toIds: [ video.Author.podId ]