diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-28 11:36:33 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-28 11:38:08 +0200 |
commit | a1eda903a497857017495f37a1fd3593ba7ab23c (patch) | |
tree | a109f34af8b18c087caf6d5a7264267550f0416d /server/middlewares/validators/oembed.ts | |
parent | 012580d98f489e599d44a9a2a0bdc892b9455a90 (diff) | |
download | PeerTube-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/oembed.ts')
-rw-r--r-- | server/middlewares/validators/oembed.ts | 24 |
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' | |||
4 | import { fetchVideo } from '@server/helpers/video' | 4 | import { fetchVideo } from '@server/helpers/video' |
5 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' | 5 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' |
6 | import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' | 6 | import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
7 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
7 | import { isTestInstance } from '../../helpers/core-utils' | 8 | import { isTestInstance } from '../../helpers/core-utils' |
8 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 9 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
9 | import { logger } from '../../helpers/logger' | 10 | import { logger } from '../../helpers/logger' |
10 | import { WEBSERVER } from '../../initializers/constants' | 11 | import { WEBSERVER } from '../../initializers/constants' |
11 | import { areValidationErrors } from './utils' | 12 | import { areValidationErrors } from './utils' |
12 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
13 | 13 | ||
14 | const startVideoPlaylistsURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch', 'playlist') + '/' | 14 | const playlistPaths = [ |
15 | const startVideosURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/' | 15 | join('videos', 'watch', 'playlist'), |
16 | join('w', 'p') | ||
17 | ] | ||
18 | |||
19 | const videoPaths = [ | ||
20 | join('videos', 'watch'), | ||
21 | 'w' | ||
22 | ] | ||
23 | |||
24 | function buildUrls (paths: string[]) { | ||
25 | return paths.map(p => WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, p) + '/') | ||
26 | } | ||
27 | |||
28 | const startPlaylistURLs = buildUrls(playlistPaths) | ||
29 | const startVideoURLs = buildUrls(videoPaths) | ||
16 | 30 | ||
17 | const watchRegex = /([^/]+)$/ | 31 | const watchRegex = /([^/]+)$/ |
18 | const isURLOptions = { | 32 | const 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 | ||