From a1eda903a497857017495f37a1fd3593ba7ab23c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 28 May 2021 11:36:33 +0200 Subject: Support '/w/' and '/w/p/' for watch page And use them as default in client --- server/middlewares/validators/oembed.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index 2a7dc257b..165eda6d5 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts @@ -4,15 +4,29 @@ import { join } from 'path' import { fetchVideo } from '@server/helpers/video' import { VideoPlaylistModel } from '@server/models/video/video-playlist' import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' import { isTestInstance } from '../../helpers/core-utils' import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' import { WEBSERVER } from '../../initializers/constants' import { areValidationErrors } from './utils' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -const startVideoPlaylistsURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch', 'playlist') + '/' -const startVideosURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/' +const playlistPaths = [ + join('videos', 'watch', 'playlist'), + join('w', 'p') +] + +const videoPaths = [ + join('videos', 'watch'), + 'w' +] + +function buildUrls (paths: string[]) { + return paths.map(p => WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, p) + '/') +} + +const startPlaylistURLs = buildUrls(playlistPaths) +const startVideoURLs = buildUrls(videoPaths) const watchRegex = /([^/]+)$/ const isURLOptions = { @@ -43,8 +57,8 @@ const oembedValidator = [ const url = req.query.url as string - const isPlaylist = url.startsWith(startVideoPlaylistsURL) - const isVideo = isPlaylist ? false : url.startsWith(startVideosURL) + const isPlaylist = startPlaylistURLs.some(u => url.startsWith(u)) + const isVideo = isPlaylist ? false : startVideoURLs.some(u => url.startsWith(u)) const startIsOk = isVideo || isPlaylist -- cgit v1.2.3