X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Factivitypub%2Fvideos.ts;h=fe94bd58a72a10adf599f018a9b5c235bb0ee2c1;hb=7cde3b9c2e84ea20bb0aae4544598483cde9e22c;hp=53ad0588d76a4e75e1d6d1086a3b82a900295234;hpb=b718fd22374d64534bcfe69932cf562894abed6a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 53ad0588d..fe94bd58a 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts @@ -1,5 +1,5 @@ -import * as validator from 'validator' -import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers' +import validator from 'validator' +import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers/constants' import { peertubeTruncate } from '../../core-utils' import { exists, isArray, isBooleanValid, isDateValid, isUUIDValid } from '../misc' import { @@ -12,6 +12,7 @@ import { } from '../videos' import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' import { VideoState } from '../../../../shared/models/videos' +import { logger } from '@server/helpers/logger' function sanitizeAndCheckVideoTorrentUpdateActivity (activity: any) { return isBaseActivityValid(activity, 'Update') && @@ -30,11 +31,26 @@ function isActivityPubVideoDurationValid (value: string) { function sanitizeAndCheckVideoTorrentObject (video: any) { if (!video || video.type !== 'Video') return false - if (!setValidRemoteTags(video)) return false - if (!setValidRemoteVideoUrls(video)) return false - if (!setRemoteVideoTruncatedContent(video)) return false - if (!setValidAttributedTo(video)) return false - if (!setValidRemoteCaptions(video)) return false + if (!setValidRemoteTags(video)) { + logger.debug('Video has invalid tags', { video }) + return false + } + if (!setValidRemoteVideoUrls(video)) { + logger.debug('Video has invalid urls', { video }) + return false + } + if (!setRemoteVideoTruncatedContent(video)) { + logger.debug('Video has invalid content', { video }) + return false + } + if (!setValidAttributedTo(video)) { + logger.debug('Video has invalid attributedTo', { video }) + return false + } + if (!setValidRemoteCaptions(video)) { + logger.debug('Video has invalid captions', { video }) + return false + } // Default attributes if (!isVideoStateValid(video.state)) video.state = VideoState.PUBLISHED @@ -54,6 +70,7 @@ function sanitizeAndCheckVideoTorrentObject (video: any) { isBooleanValid(video.downloadEnabled) && isDateValid(video.published) && isDateValid(video.updated) && + (!video.originallyPublishedAt || isDateValid(video.originallyPublishedAt)) && (!video.content || isRemoteVideoContentValid(video.mediaType, video.content)) && isRemoteVideoIconValid(video.icon) && video.url.length !== 0 && @@ -61,25 +78,21 @@ function sanitizeAndCheckVideoTorrentObject (video: any) { } function isRemoteVideoUrlValid (url: any) { - // FIXME: Old bug, we used the width to represent the resolution. Remove it in a few release (currently beta.11) - if (url.width && !url.height) url.height = url.width - return url.type === 'Link' && ( - // TODO: remove mimeType (backward compatibility, introduced in v1.1.0) - ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mediaType || url.mimeType) !== -1 && + ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mediaType) !== -1 && isActivityPubUrlValid(url.href) && validator.isInt(url.height + '', { min: 0 }) && validator.isInt(url.size + '', { min: 0 }) && (!url.fps || validator.isInt(url.fps + '', { min: -1 })) ) || ( - ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mediaType || url.mimeType) !== -1 && + ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mediaType) !== -1 && isActivityPubUrlValid(url.href) && validator.isInt(url.height + '', { min: 0 }) ) || ( - ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mediaType || url.mimeType) !== -1 && + ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mediaType) !== -1 && validator.isLength(url.href, { min: 5 }) && validator.isInt(url.height + '', { min: 0 }) ) || @@ -154,7 +167,7 @@ function setValidRemoteVideoUrls (video: any) { function setRemoteVideoTruncatedContent (video: any) { if (video.content) { - video.content = peertubeTruncate(video.content, CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max) + video.content = peertubeTruncate(video.content, { length: CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max }) } return true