From 20494f122186bb1bfd82f4c598c4744acea27b0c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Nov 2017 15:22:39 +0100 Subject: Server shares user videos --- .../custom-validators/activitypub/activity.ts | 6 ++-- .../helpers/custom-validators/activitypub/misc.ts | 2 +- .../custom-validators/activitypub/videos.ts | 42 ++++++++++++++-------- 3 files changed, 31 insertions(+), 19 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts index 08e5ae0aa..8084cf7b0 100644 --- a/server/helpers/custom-validators/activitypub/activity.ts +++ b/server/helpers/custom-validators/activitypub/activity.ts @@ -2,8 +2,7 @@ import * as validator from 'validator' import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' import { isActivityPubUrlValid } from './misc' import { - isVideoAnnounceValid, - isVideoChannelAnnounceValid, + isAnnounceValid, isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid, @@ -37,8 +36,7 @@ function isActivityValid (activity: any) { isAccountFollowActivityValid(activity) || isAccountAcceptActivityValid(activity) || isVideoFlagValid(activity) || - isVideoAnnounceValid(activity) || - isVideoChannelAnnounceValid(activity) + isAnnounceValid(activity) } // --------------------------------------------------------------------------- diff --git a/server/helpers/custom-validators/activitypub/misc.ts b/server/helpers/custom-validators/activitypub/misc.ts index 665a63a73..f09a764b6 100644 --- a/server/helpers/custom-validators/activitypub/misc.ts +++ b/server/helpers/custom-validators/activitypub/misc.ts @@ -21,7 +21,7 @@ function isActivityPubUrlValid (url: string) { } function isBaseActivityValid (activity: any, type: string) { - return Array.isArray(activity['@context']) && + return (activity['@context'] === undefined || Array.isArray(activity['@context'])) && activity.type === type && isActivityPubUrlValid(activity.id) && isActivityPubUrlValid(activity.actor) && diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 89c49b0df..8486297ad 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts @@ -39,6 +39,7 @@ function isActivityPubVideoDurationValid (value: string) { function isVideoTorrentObjectValid (video: any) { return video.type === 'Video' && + isActivityPubUrlValid(video.id) && isVideoNameValid(video.name) && isActivityPubVideoDurationValid(video.duration) && isUUIDValid(video.uuid) && @@ -62,14 +63,12 @@ function isVideoFlagValid (activity: any) { isActivityPubUrlValid(activity.object) } -function isVideoAnnounceValid (activity: any) { +function isAnnounceValid (activity: any) { return isBaseActivityValid(activity, 'Announce') && - isVideoTorrentObjectValid(activity.object) -} - -function isVideoChannelAnnounceValid (activity: any) { - return isBaseActivityValid(activity, 'Announce') && - isVideoChannelObjectValid(activity.object) + ( + isVideoChannelCreateActivityValid(activity.object) || + isVideoTorrentAddActivityValid(activity.object) + ) } function isVideoChannelCreateActivityValid (activity: any) { @@ -88,8 +87,11 @@ function isVideoChannelDeleteActivityValid (activity: any) { function isVideoChannelObjectValid (videoChannel: any) { return videoChannel.type === 'VideoChannel' && + isActivityPubUrlValid(videoChannel.id) && isVideoChannelNameValid(videoChannel.name) && - isVideoChannelDescriptionValid(videoChannel.description) && + isVideoChannelDescriptionValid(videoChannel.content) && + isDateValid(videoChannel.published) && + isDateValid(videoChannel.updated) && isUUIDValid(videoChannel.uuid) } @@ -103,8 +105,8 @@ export { isVideoChannelDeleteActivityValid, isVideoTorrentDeleteActivityValid, isVideoFlagValid, - isVideoAnnounceValid, - isVideoChannelAnnounceValid + isAnnounceValid, + isVideoChannelObjectValid } // --------------------------------------------------------------------------- @@ -148,8 +150,20 @@ function setValidRemoteVideoUrls (video: any) { function isRemoteVideoUrlValid (url: any) { return url.type === 'Link' && - ACTIVITY_PUB.VIDEO_URL_MIME_TYPES.indexOf(url.mimeType) !== -1 && - isVideoUrlValid(url.url) && - validator.isInt(url.width + '', { min: 0 }) && - validator.isInt(url.size + '', { min: 0 }) + ( + ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 && + isVideoUrlValid(url.url) && + validator.isInt(url.width + '', { min: 0 }) && + validator.isInt(url.size + '', { min: 0 }) + ) || + ( + ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 && + isVideoUrlValid(url.url) && + validator.isInt(url.width + '', { min: 0 }) + ) || + ( + ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mimeType) !== -1 && + validator.isLength(url.url, { min: 5 }) && + validator.isInt(url.width + '', { min: 0 }) + ) } -- cgit v1.2.3