diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-26 14:12:39 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-26 14:12:50 +0200 |
commit | 9162fdd36300d2478f13d6ad346ec2c323f40faa (patch) | |
tree | dea0ca43f3ea2fb72a73ca77338f5b7c990acdd7 /client/src/assets/player/utils.ts | |
parent | 764b1a14fc494f2cfd7ea590d2f07b01df65c7ad (diff) | |
download | PeerTube-9162fdd36300d2478f13d6ad346ec2c323f40faa.tar.gz PeerTube-9162fdd36300d2478f13d6ad346ec2c323f40faa.tar.zst PeerTube-9162fdd36300d2478f13d6ad346ec2c323f40faa.zip |
Refactor video links building
Diffstat (limited to 'client/src/assets/player/utils.ts')
-rw-r--r-- | client/src/assets/player/utils.ts | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index 2bb70d1fa..eb9302493 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { VideoFile } from '@shared/models' | 1 | import { Video, VideoFile, VideoPlaylist } from '@shared/models' |
2 | import { escapeHTML } from '@shared/core-utils/renderer' | 2 | import { escapeHTML } from '@shared/core-utils/renderer' |
3 | 3 | ||
4 | function toTitleCase (str: string) { | 4 | function toTitleCase (str: string) { |
@@ -43,8 +43,24 @@ function isMobile () { | |||
43 | return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) | 43 | return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) |
44 | } | 44 | } |
45 | 45 | ||
46 | function buildVideoLink (options: { | 46 | function buildPlaylistLink (playlist: Pick<VideoPlaylist, 'shortUUID'>, base?: string) { |
47 | baseUrl?: string | 47 | return (base ?? window.location.origin) + '/w/p/' + playlist.shortUUID |
48 | } | ||
49 | |||
50 | function buildVideoLink (video: Pick<Video, 'shortUUID'>, base?: string) { | ||
51 | return (base ?? window.location.origin) + '/w/' + video.shortUUID | ||
52 | } | ||
53 | |||
54 | function buildPlaylistEmbedLink (playlist: Pick<VideoPlaylist, 'uuid'>, base?: string) { | ||
55 | return (base ?? window.location.origin) + '/video-playlists/embed/' + playlist.uuid | ||
56 | } | ||
57 | |||
58 | function buildVideoEmbedLink (video: Pick<Video, 'uuid'>, base?: string) { | ||
59 | return (base ?? window.location.origin) + '/videos/embed/' + video.uuid | ||
60 | } | ||
61 | |||
62 | function decorateVideoLink (options: { | ||
63 | url: string | ||
48 | 64 | ||
49 | startTime?: number | 65 | startTime?: number |
50 | stopTime?: number | 66 | stopTime?: number |
@@ -60,12 +76,8 @@ function buildVideoLink (options: { | |||
60 | warningTitle?: boolean | 76 | warningTitle?: boolean |
61 | controls?: boolean | 77 | controls?: boolean |
62 | peertubeLink?: boolean | 78 | peertubeLink?: boolean |
63 | } = {}) { | 79 | }) { |
64 | const { baseUrl } = options | 80 | const { url } = options |
65 | |||
66 | const url = baseUrl | ||
67 | ? baseUrl | ||
68 | : window.location.origin + window.location.pathname.replace('/embed/', '/w/') | ||
69 | 81 | ||
70 | const params = generateParams(window.location.search) | 82 | const params = generateParams(window.location.search) |
71 | 83 | ||
@@ -92,16 +104,12 @@ function buildVideoLink (options: { | |||
92 | return buildUrl(url, params) | 104 | return buildUrl(url, params) |
93 | } | 105 | } |
94 | 106 | ||
95 | function buildPlaylistLink (options: { | 107 | function decoratePlaylistLink (options: { |
96 | baseUrl?: string | 108 | url: string |
97 | 109 | ||
98 | playlistPosition?: number | 110 | playlistPosition?: number |
99 | }) { | 111 | }) { |
100 | const { baseUrl } = options | 112 | const { url } = options |
101 | |||
102 | const url = baseUrl | ||
103 | ? baseUrl | ||
104 | : window.location.origin + window.location.pathname.replace('/video-playlists/embed/', '/w/p/') | ||
105 | 113 | ||
106 | const params = generateParams(window.location.search) | 114 | const params = generateParams(window.location.search) |
107 | 115 | ||
@@ -224,8 +232,14 @@ export { | |||
224 | timeToInt, | 232 | timeToInt, |
225 | secondsToTime, | 233 | secondsToTime, |
226 | isWebRTCDisabled, | 234 | isWebRTCDisabled, |
235 | |||
227 | buildPlaylistLink, | 236 | buildPlaylistLink, |
228 | buildVideoLink, | 237 | buildVideoLink, |
238 | decorateVideoLink, | ||
239 | decoratePlaylistLink, | ||
240 | buildPlaylistEmbedLink, | ||
241 | buildVideoEmbedLink, | ||
242 | |||
229 | buildVideoOrPlaylistEmbed, | 243 | buildVideoOrPlaylistEmbed, |
230 | videoFileMaxByResolution, | 244 | videoFileMaxByResolution, |
231 | videoFileMinByResolution, | 245 | videoFileMinByResolution, |