aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-28 11:36:33 +0200
committerChocobozzz <me@florianbigard.com>2021-05-28 11:38:08 +0200
commita1eda903a497857017495f37a1fd3593ba7ab23c (patch)
treea109f34af8b18c087caf6d5a7264267550f0416d /server/middlewares/validators
parent012580d98f489e599d44a9a2a0bdc892b9455a90 (diff)
downloadPeerTube-a1eda903a497857017495f37a1fd3593ba7ab23c.tar.gz
PeerTube-a1eda903a497857017495f37a1fd3593ba7ab23c.tar.zst
PeerTube-a1eda903a497857017495f37a1fd3593ba7ab23c.zip
Support '/w/' and '/w/p/' for watch page
And use them as default in client
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/oembed.ts24
1 files changed, 19 insertions, 5 deletions
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'
4import { fetchVideo } from '@server/helpers/video' 4import { fetchVideo } from '@server/helpers/video'
5import { VideoPlaylistModel } from '@server/models/video/video-playlist' 5import { VideoPlaylistModel } from '@server/models/video/video-playlist'
6import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' 6import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
7import { isTestInstance } from '../../helpers/core-utils' 8import { isTestInstance } from '../../helpers/core-utils'
8import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 9import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
9import { logger } from '../../helpers/logger' 10import { logger } from '../../helpers/logger'
10import { WEBSERVER } from '../../initializers/constants' 11import { WEBSERVER } from '../../initializers/constants'
11import { areValidationErrors } from './utils' 12import { areValidationErrors } from './utils'
12import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
13 13
14const startVideoPlaylistsURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch', 'playlist') + '/' 14const playlistPaths = [
15const startVideosURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/' 15 join('videos', 'watch', 'playlist'),
16 join('w', 'p')
17]
18
19const videoPaths = [
20 join('videos', 'watch'),
21 'w'
22]
23
24function buildUrls (paths: string[]) {
25 return paths.map(p => WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, p) + '/')
26}
27
28const startPlaylistURLs = buildUrls(playlistPaths)
29const startVideoURLs = buildUrls(videoPaths)
16 30
17const watchRegex = /([^/]+)$/ 31const watchRegex = /([^/]+)$/
18const isURLOptions = { 32const isURLOptions = {
@@ -43,8 +57,8 @@ const oembedValidator = [
43 57
44 const url = req.query.url as string 58 const url = req.query.url as string
45 59
46 const isPlaylist = url.startsWith(startVideoPlaylistsURL) 60 const isPlaylist = startPlaylistURLs.some(u => url.startsWith(u))
47 const isVideo = isPlaylist ? false : url.startsWith(startVideosURL) 61 const isVideo = isPlaylist ? false : startVideoURLs.some(u => url.startsWith(u))
48 62
49 const startIsOk = isVideo || isPlaylist 63 const startIsOk = isVideo || isPlaylist
50 64