mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Server: implement video views
This commit is contained in:
parent
9e167724f7
commit
e4c87ec269
15 changed files with 612 additions and 48 deletions
|
@ -1,6 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const has = require('lodash/has')
|
||||
const values = require('lodash/values')
|
||||
|
||||
const constants = require('../../../initializers/constants')
|
||||
const videosValidators = require('../videos')
|
||||
|
@ -10,13 +11,17 @@ const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_EN
|
|||
|
||||
const remoteVideosValidators = {
|
||||
isEachRemoteRequestVideosValid,
|
||||
isEachRemoteRequestVideosQaduValid
|
||||
isEachRemoteRequestVideosQaduValid,
|
||||
isEachRemoteRequestVideosEventsValid
|
||||
}
|
||||
|
||||
function isEachRemoteRequestVideosValid (requests) {
|
||||
return miscValidators.isArray(requests) &&
|
||||
requests.every(function (request) {
|
||||
const video = request.data
|
||||
|
||||
if (!video) return false
|
||||
|
||||
return (
|
||||
isRequestTypeAddValid(request.type) &&
|
||||
isCommonVideoAttributesValid(video) &&
|
||||
|
@ -45,6 +50,8 @@ function isEachRemoteRequestVideosQaduValid (requests) {
|
|||
requests.every(function (request) {
|
||||
const video = request.data
|
||||
|
||||
if (!video) return false
|
||||
|
||||
return (
|
||||
videosValidators.isVideoRemoteIdValid(video.remoteId) &&
|
||||
(has(video, 'views') === false || videosValidators.isVideoViewsValid) &&
|
||||
|
@ -54,6 +61,21 @@ function isEachRemoteRequestVideosQaduValid (requests) {
|
|||
})
|
||||
}
|
||||
|
||||
function isEachRemoteRequestVideosEventsValid (requests) {
|
||||
return miscValidators.isArray(requests) &&
|
||||
requests.every(function (request) {
|
||||
const eventData = request.data
|
||||
|
||||
if (!eventData) return false
|
||||
|
||||
return (
|
||||
videosValidators.isVideoRemoteIdValid(eventData.remoteId) &&
|
||||
values(constants.REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 &&
|
||||
videosValidators.isVideoEventCountValid(eventData.count)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
module.exports = remoteVideosValidators
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue