aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-paths.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-16 16:25:53 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-18 13:38:09 +0100
commit90a8bd305de4153ec21137a73ff482dcc2e3e19b (patch)
tree2e35b5504ec11bc51579c92a70c77ed3d5ace816 /server/lib/video-paths.ts
parent684cdacbbd775b5f404dd7b373e02dd21baf5ff0 (diff)
downloadPeerTube-90a8bd305de4153ec21137a73ff482dcc2e3e19b.tar.gz
PeerTube-90a8bd305de4153ec21137a73ff482dcc2e3e19b.tar.zst
PeerTube-90a8bd305de4153ec21137a73ff482dcc2e3e19b.zip
Dissociate video file names and video uuid
Diffstat (limited to 'server/lib/video-paths.ts')
-rw-r--r--server/lib/video-paths.ts75
1 files changed, 56 insertions, 19 deletions
diff --git a/server/lib/video-paths.ts b/server/lib/video-paths.ts
index 53fc8e81d..0385e89cc 100644
--- a/server/lib/video-paths.ts
+++ b/server/lib/video-paths.ts
@@ -1,19 +1,23 @@
1import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models'
2import { join } from 'path' 1import { join } from 'path'
3import { CONFIG } from '@server/initializers/config'
4import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
5import { extractVideo } from '@server/helpers/video' 2import { extractVideo } from '@server/helpers/video'
3import { CONFIG } from '@server/initializers/config'
4import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_PATHS, WEBSERVER } from '@server/initializers/constants'
5import { isStreamingPlaylist, MStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models'
6 6
7// ################## Video file name ################## 7// ################## Video file name ##################
8 8
9function getVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { 9function generateVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, isHls: boolean, resolution: number, extname: string) {
10 const video = extractVideo(videoOrPlaylist) 10 const video = extractVideo(videoOrPlaylist)
11 11
12 if (videoFile.isHLS()) { 12 // FIXME: use a generated uuid instead, that will break compatibility with PeerTube < 3.2
13 return generateVideoStreamingPlaylistName(video.uuid, videoFile.resolution) 13 // const uuid = uuidv4()
14 const uuid = video.uuid
15
16 if (isHls) {
17 return generateVideoStreamingPlaylistName(uuid, resolution)
14 } 18 }
15 19
16 return generateWebTorrentVideoName(video.uuid, videoFile.resolution, videoFile.extname) 20 return generateWebTorrentVideoName(uuid, resolution, extname)
17} 21}
18 22
19function generateVideoStreamingPlaylistName (uuid: string, resolution: number) { 23function generateVideoStreamingPlaylistName (uuid: string, resolution: number) {
@@ -28,36 +32,64 @@ function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, vi
28 if (videoFile.isHLS()) { 32 if (videoFile.isHLS()) {
29 const video = extractVideo(videoOrPlaylist) 33 const video = extractVideo(videoOrPlaylist)
30 34
31 return join(getHLSDirectory(video), getVideoFilename(videoOrPlaylist, videoFile)) 35 return join(getHLSDirectory(video), videoFile.filename)
32 } 36 }
33 37
34 const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR 38 const baseDir = isRedundancy
35 return join(baseDir, getVideoFilename(videoOrPlaylist, videoFile)) 39 ? CONFIG.STORAGE.REDUNDANCY_DIR
40 : CONFIG.STORAGE.VIDEOS_DIR
41
42 return join(baseDir, videoFile.filename)
43}
44
45// ################## Redundancy ##################
46
47function generateHLSRedundancyUrl (video: MVideo, playlist: MStreamingPlaylist) {
48 // Base URL used by our HLS player
49 return WEBSERVER.URL + STATIC_PATHS.REDUNDANCY + playlist.getStringType() + '/' + video.uuid
50}
51
52function generateWebTorrentRedundancyUrl (file: MVideoFile) {
53 return WEBSERVER.URL + STATIC_PATHS.REDUNDANCY + file.filename
36} 54}
37 55
38// ################## Streaming playlist ################## 56// ################## Streaming playlist ##################
39 57
40function getHLSDirectory (video: MVideoUUID, isRedundancy = false) { 58function getHLSDirectory (video: MVideoUUID, isRedundancy = false) {
41 const baseDir = isRedundancy ? HLS_REDUNDANCY_DIRECTORY : HLS_STREAMING_PLAYLIST_DIRECTORY 59 const baseDir = isRedundancy
60 ? HLS_REDUNDANCY_DIRECTORY
61 : HLS_STREAMING_PLAYLIST_DIRECTORY
42 62
43 return join(baseDir, video.uuid) 63 return join(baseDir, video.uuid)
44} 64}
45 65
46// ################## Torrents ################## 66// ################## Torrents ##################
47 67
48function getTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { 68function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) {
49 const video = extractVideo(videoOrPlaylist) 69 const video = extractVideo(videoOrPlaylist)
50 const extension = '.torrent' 70 const extension = '.torrent'
51 71
72 // FIXME: use a generated uuid instead, that will break compatibility with PeerTube < 3.2
73 // const uuid = uuidv4()
74 const uuid = video.uuid
75
52 if (isStreamingPlaylist(videoOrPlaylist)) { 76 if (isStreamingPlaylist(videoOrPlaylist)) {
53 return `${video.uuid}-${videoFile.resolution}-${videoOrPlaylist.getStringType()}${extension}` 77 return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}`
54 } 78 }
55 79
56 return video.uuid + '-' + videoFile.resolution + extension 80 return uuid + '-' + resolution + extension
81}
82
83function getTorrentFilePath (videoFile: MVideoFile) {
84 return join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
57} 85}
58 86
59function getTorrentFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { 87// ################## Meta data ##################
60 return join(CONFIG.STORAGE.TORRENTS_DIR, getTorrentFileName(videoOrPlaylist, videoFile)) 88
89function getLocalVideoFileMetadataUrl (video: MVideoUUID, videoFile: MVideoFile) {
90 const path = '/api/v1/videos/'
91
92 return WEBSERVER.URL + path + video.uuid + '/metadata/' + videoFile.id
61} 93}
62 94
63// --------------------------------------------------------------------------- 95// ---------------------------------------------------------------------------
@@ -65,11 +97,16 @@ function getTorrentFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo,
65export { 97export {
66 generateVideoStreamingPlaylistName, 98 generateVideoStreamingPlaylistName,
67 generateWebTorrentVideoName, 99 generateWebTorrentVideoName,
68 getVideoFilename, 100 generateVideoFilename,
69 getVideoFilePath, 101 getVideoFilePath,
70 102
71 getTorrentFileName, 103 generateTorrentFileName,
72 getTorrentFilePath, 104 getTorrentFilePath,
73 105
74 getHLSDirectory 106 getHLSDirectory,
107
108 getLocalVideoFileMetadataUrl,
109
110 generateWebTorrentRedundancyUrl,
111 generateHLSRedundancyUrl
75} 112}