mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Be tolerant with remote requests
Just remove videos we don't want
This commit is contained in:
parent
faab3a8453
commit
51c443dbe0
4 changed files with 90 additions and 51 deletions
|
@ -15,9 +15,9 @@ import {
|
|||
isVideoLikesValid,
|
||||
isVideoDislikesValid,
|
||||
isVideoEventCountValid,
|
||||
isVideoCategoryValid,
|
||||
isVideoLicenceValid,
|
||||
isVideoLanguageValid,
|
||||
isRemoteVideoCategoryValid,
|
||||
isRemoteVideoLicenceValid,
|
||||
isRemoteVideoLanguageValid,
|
||||
isVideoNSFWValid,
|
||||
isVideoDescriptionValid,
|
||||
isVideoDurationValid,
|
||||
|
@ -43,58 +43,64 @@ checkers[ENDPOINT_ACTIONS.REMOVE_CHANNEL] = checkRemoveVideoChannel
|
|||
checkers[ENDPOINT_ACTIONS.ADD_AUTHOR] = checkAddAuthor
|
||||
checkers[ENDPOINT_ACTIONS.REMOVE_AUTHOR] = checkRemoveAuthor
|
||||
|
||||
function isEachRemoteRequestVideosValid (requests: any[]) {
|
||||
return isArray(requests) &&
|
||||
requests.every(request => {
|
||||
const video = request.data
|
||||
function removeBadRequestVideos (requests: any[]) {
|
||||
for (let i = requests.length - 1; i >= 0 ; i--) {
|
||||
const request = requests[i]
|
||||
const video = request.data
|
||||
|
||||
if (!video) return false
|
||||
|
||||
const checker = checkers[request.type]
|
||||
// We don't know the request type
|
||||
if (checker === undefined) return false
|
||||
|
||||
return checker(video)
|
||||
})
|
||||
if (
|
||||
!video ||
|
||||
checkers[request.type] === undefined ||
|
||||
checkers[request.type](video) === false
|
||||
) {
|
||||
requests.splice(i, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isEachRemoteRequestVideosQaduValid (requests: any[]) {
|
||||
return isArray(requests) &&
|
||||
requests.every(request => {
|
||||
const video = request.data
|
||||
function removeBadRequestVideosQadu (requests: any[]) {
|
||||
for (let i = requests.length - 1; i >= 0 ; i--) {
|
||||
const request = requests[i]
|
||||
const video = request.data
|
||||
|
||||
if (!video) return false
|
||||
|
||||
return (
|
||||
if (
|
||||
!video ||
|
||||
(
|
||||
isUUIDValid(video.uuid) &&
|
||||
(has(video, 'views') === false || isVideoViewsValid(video.views)) &&
|
||||
(has(video, 'likes') === false || isVideoLikesValid(video.likes)) &&
|
||||
(has(video, 'dislikes') === false || isVideoDislikesValid(video.dislikes))
|
||||
)
|
||||
})
|
||||
) === false
|
||||
) {
|
||||
requests.splice(i, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isEachRemoteRequestVideosEventsValid (requests: any[]) {
|
||||
return isArray(requests) &&
|
||||
requests.every(request => {
|
||||
const eventData = request.data
|
||||
function removeBadRequestVideosEvents (requests: any[]) {
|
||||
for (let i = requests.length - 1; i >= 0 ; i--) {
|
||||
const request = requests[i]
|
||||
const eventData = request.data
|
||||
|
||||
if (!eventData) return false
|
||||
|
||||
return (
|
||||
if (
|
||||
!eventData ||
|
||||
(
|
||||
isUUIDValid(eventData.uuid) &&
|
||||
values(REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 &&
|
||||
isVideoEventCountValid(eventData.count)
|
||||
)
|
||||
})
|
||||
) === false
|
||||
) {
|
||||
requests.splice(i, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
isEachRemoteRequestVideosValid,
|
||||
isEachRemoteRequestVideosQaduValid,
|
||||
isEachRemoteRequestVideosEventsValid
|
||||
removeBadRequestVideos,
|
||||
removeBadRequestVideosQadu,
|
||||
removeBadRequestVideosEvents
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -102,9 +108,9 @@ export {
|
|||
function isCommonVideoAttributesValid (video: any) {
|
||||
return isDateValid(video.createdAt) &&
|
||||
isDateValid(video.updatedAt) &&
|
||||
isVideoCategoryValid(video.category) &&
|
||||
isVideoLicenceValid(video.licence) &&
|
||||
isVideoLanguageValid(video.language) &&
|
||||
isRemoteVideoCategoryValid(video.category) &&
|
||||
isRemoteVideoLicenceValid(video.licence) &&
|
||||
isRemoteVideoLanguageValid(video.language) &&
|
||||
isVideoNSFWValid(video.nsfw) &&
|
||||
isVideoDescriptionValid(video.description) &&
|
||||
isVideoDurationValid(video.duration) &&
|
||||
|
|
|
@ -27,14 +27,29 @@ function isVideoCategoryValid (value: number) {
|
|||
return VIDEO_CATEGORIES[value] !== undefined
|
||||
}
|
||||
|
||||
// Maybe we don't know the remote category, but that doesn't matter
|
||||
function isRemoteVideoCategoryValid (value: string) {
|
||||
return validator.isInt('' + value)
|
||||
}
|
||||
|
||||
function isVideoLicenceValid (value: number) {
|
||||
return VIDEO_LICENCES[value] !== undefined
|
||||
}
|
||||
|
||||
// Maybe we don't know the remote licence, but that doesn't matter
|
||||
function isRemoteVideoLicenceValid (value: string) {
|
||||
return validator.isInt('' + value)
|
||||
}
|
||||
|
||||
function isVideoLanguageValid (value: number) {
|
||||
return value === null || VIDEO_LANGUAGES[value] !== undefined
|
||||
}
|
||||
|
||||
// Maybe we don't know the remote language, but that doesn't matter
|
||||
function isRemoteVideoLanguageValid (value: string) {
|
||||
return validator.isInt('' + value)
|
||||
}
|
||||
|
||||
function isVideoNSFWValid (value: any) {
|
||||
return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
|
||||
}
|
||||
|
@ -176,5 +191,8 @@ export {
|
|||
isVideoEventCountValid,
|
||||
isVideoFileSizeValid,
|
||||
isVideoFileResolutionValid,
|
||||
checkVideoExists
|
||||
checkVideoExists,
|
||||
isRemoteVideoCategoryValid,
|
||||
isRemoteVideoLicenceValid,
|
||||
isRemoteVideoLanguageValid
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue