diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-22 14:28:03 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-07-26 11:29:31 +0200 |
commit | 83903cb65d531a6b6b91715387493ba8312b264d (patch) | |
tree | fd172e26a483331e74f15a062743a9d40d4016d3 /server/lib/video-paths.ts | |
parent | c4fa01f7c45b66b112ebd08abce744b7c4041feb (diff) | |
download | PeerTube-83903cb65d531a6b6b91715387493ba8312b264d.tar.gz PeerTube-83903cb65d531a6b6b91715387493ba8312b264d.tar.zst PeerTube-83903cb65d531a6b6b91715387493ba8312b264d.zip |
Generate random uuid for video files
Diffstat (limited to 'server/lib/video-paths.ts')
-rw-r--r-- | server/lib/video-paths.ts | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/server/lib/video-paths.ts b/server/lib/video-paths.ts index 1708c479a..b7068190c 100644 --- a/server/lib/video-paths.ts +++ b/server/lib/video-paths.ts | |||
@@ -3,29 +3,20 @@ import { extractVideo } from '@server/helpers/video' | |||
3 | import { CONFIG } from '@server/initializers/config' | 3 | import { CONFIG } from '@server/initializers/config' |
4 | import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_PATHS, WEBSERVER } from '@server/initializers/constants' | 4 | import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_PATHS, WEBSERVER } from '@server/initializers/constants' |
5 | import { isStreamingPlaylist, MStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models' | 5 | import { isStreamingPlaylist, MStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models' |
6 | import { buildUUID } from '@server/helpers/uuid' | ||
6 | 7 | ||
7 | // ################## Video file name ################## | 8 | // ################## Video file name ################## |
8 | 9 | ||
9 | function generateVideoFilename (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, isHls: boolean, resolution: number, extname: string) { | 10 | function generateWebTorrentVideoFilename (resolution: number, extname: string) { |
10 | const video = extractVideo(videoOrPlaylist) | 11 | const uuid = buildUUID() |
11 | 12 | ||
12 | // FIXME: use a generated uuid instead, that will break compatibility with PeerTube < 3.1 | 13 | return uuid + '-' + resolution + extname |
13 | // const uuid = uuidv4() | ||
14 | const uuid = video.uuid | ||
15 | |||
16 | if (isHls) { | ||
17 | return generateVideoStreamingPlaylistName(uuid, resolution) | ||
18 | } | ||
19 | |||
20 | return generateWebTorrentVideoName(uuid, resolution, extname) | ||
21 | } | 14 | } |
22 | 15 | ||
23 | function generateVideoStreamingPlaylistName (uuid: string, resolution: number) { | 16 | function generateHLSVideoFilename (resolution: number) { |
24 | return `${uuid}-${resolution}-fragmented.mp4` | 17 | const uuid = buildUUID() |
25 | } | ||
26 | 18 | ||
27 | function generateWebTorrentVideoName (uuid: string, resolution: number, extname: string) { | 19 | return `${uuid}-${resolution}-fragmented.mp4` |
28 | return uuid + '-' + resolution + extname | ||
29 | } | 20 | } |
30 | 21 | ||
31 | function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { | 22 | function getVideoFilePath (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile, isRedundancy = false) { |
@@ -66,12 +57,8 @@ function getHLSDirectory (video: MVideoUUID, isRedundancy = false) { | |||
66 | // ################## Torrents ################## | 57 | // ################## Torrents ################## |
67 | 58 | ||
68 | function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) { | 59 | function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) { |
69 | const video = extractVideo(videoOrPlaylist) | ||
70 | const extension = '.torrent' | 60 | const extension = '.torrent' |
71 | 61 | const uuid = buildUUID() | |
72 | // FIXME: use a generated uuid instead, that will break compatibility with PeerTube < 3.1 | ||
73 | // const uuid = uuidv4() | ||
74 | const uuid = video.uuid | ||
75 | 62 | ||
76 | if (isStreamingPlaylist(videoOrPlaylist)) { | 63 | if (isStreamingPlaylist(videoOrPlaylist)) { |
77 | return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}` | 64 | return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}` |
@@ -95,9 +82,9 @@ function getLocalVideoFileMetadataUrl (video: MVideoUUID, videoFile: MVideoFile) | |||
95 | // --------------------------------------------------------------------------- | 82 | // --------------------------------------------------------------------------- |
96 | 83 | ||
97 | export { | 84 | export { |
98 | generateVideoStreamingPlaylistName, | 85 | generateHLSVideoFilename, |
99 | generateWebTorrentVideoName, | 86 | generateWebTorrentVideoFilename, |
100 | generateVideoFilename, | 87 | |
101 | getVideoFilePath, | 88 | getVideoFilePath, |
102 | 89 | ||
103 | generateTorrentFileName, | 90 | generateTorrentFileName, |