From b3d9dedcc36a333bae0bafe92eeede1a11796ce7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 2 May 2022 14:57:37 +0200 Subject: Allow oembed to fetch unlisted videos --- server/middlewares/validators/oembed.ts | 36 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'server/middlewares/validators') diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index 32dd05271..fc1a294e0 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts @@ -6,7 +6,7 @@ import { VideoPlaylistModel } from '@server/models/video/video-playlist' import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isTestInstance } from '../../helpers/core-utils' -import { isIdOrUUIDValid, toCompleteUUID } from '../../helpers/custom-validators/misc' +import { isIdOrUUIDValid, isUUIDValid, toCompleteUUID } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' import { WEBSERVER } from '../../initializers/constants' import { areValidationErrors } from './shared' @@ -107,15 +107,18 @@ const oembedValidator = [ }) } - if (video.privacy !== VideoPrivacy.PUBLIC) { - return res.fail({ - status: HttpStatusCode.FORBIDDEN_403, - message: 'Video is not public' - }) + if ( + video.privacy === VideoPrivacy.PUBLIC || + (video.privacy === VideoPrivacy.UNLISTED && isUUIDValid(elementId) === true) + ) { + res.locals.videoAll = video + return next() } - res.locals.videoAll = video - return next() + return res.fail({ + status: HttpStatusCode.FORBIDDEN_403, + message: 'Video is not publicly available' + }) } // Is playlist @@ -128,15 +131,18 @@ const oembedValidator = [ }) } - if (videoPlaylist.privacy !== VideoPlaylistPrivacy.PUBLIC) { - return res.fail({ - status: HttpStatusCode.FORBIDDEN_403, - message: 'Playlist is not public' - }) + if ( + videoPlaylist.privacy === VideoPlaylistPrivacy.PUBLIC || + (videoPlaylist.privacy === VideoPlaylistPrivacy.UNLISTED && isUUIDValid(elementId)) + ) { + res.locals.videoPlaylistSummary = videoPlaylist + return next() } - res.locals.videoPlaylistSummary = videoPlaylist - return next() + return res.fail({ + status: HttpStatusCode.FORBIDDEN_403, + message: 'Playlist is not public' + }) } ] -- cgit v1.2.3