diff options
Diffstat (limited to 'server/lib/object-storage/videos.ts')
-rw-r--r-- | server/lib/object-storage/videos.ts | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/server/lib/object-storage/videos.ts b/server/lib/object-storage/videos.ts index 66e738200..62aae248b 100644 --- a/server/lib/object-storage/videos.ts +++ b/server/lib/object-storage/videos.ts | |||
@@ -1,19 +1,35 @@ | |||
1 | import { join } from 'path' | 1 | import { basename, join } from 'path' |
2 | import { logger } from '@server/helpers/logger' | 2 | import { logger } from '@server/helpers/logger' |
3 | import { CONFIG } from '@server/initializers/config' | 3 | import { CONFIG } from '@server/initializers/config' |
4 | import { MStreamingPlaylistVideo, MVideoFile } from '@server/types/models' | 4 | import { MStreamingPlaylistVideo, MVideoFile } from '@server/types/models' |
5 | import { getHLSDirectory } from '../paths' | 5 | import { getHLSDirectory } from '../paths' |
6 | import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys' | 6 | import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys' |
7 | import { lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared' | 7 | import { listKeysOfPrefix, lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared' |
8 | 8 | ||
9 | function storeHLSFile (playlist: MStreamingPlaylistVideo, filename: string, path?: string) { | 9 | function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) { |
10 | return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | ||
11 | } | ||
12 | |||
13 | // --------------------------------------------------------------------------- | ||
14 | |||
15 | function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: string) { | ||
10 | return storeObject({ | 16 | return storeObject({ |
11 | inputPath: path ?? join(getHLSDirectory(playlist.Video), filename), | 17 | inputPath: join(getHLSDirectory(playlist.Video), filename), |
12 | objectStorageKey: generateHLSObjectStorageKey(playlist, filename), | 18 | objectStorageKey: generateHLSObjectStorageKey(playlist, filename), |
13 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS | 19 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS |
14 | }) | 20 | }) |
15 | } | 21 | } |
16 | 22 | ||
23 | function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) { | ||
24 | return storeObject({ | ||
25 | inputPath: path, | ||
26 | objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)), | ||
27 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS | ||
28 | }) | ||
29 | } | ||
30 | |||
31 | // --------------------------------------------------------------------------- | ||
32 | |||
17 | function storeWebTorrentFile (filename: string) { | 33 | function storeWebTorrentFile (filename: string) { |
18 | return storeObject({ | 34 | return storeObject({ |
19 | inputPath: join(CONFIG.STORAGE.VIDEOS_DIR, filename), | 35 | inputPath: join(CONFIG.STORAGE.VIDEOS_DIR, filename), |
@@ -22,6 +38,8 @@ function storeWebTorrentFile (filename: string) { | |||
22 | }) | 38 | }) |
23 | } | 39 | } |
24 | 40 | ||
41 | // --------------------------------------------------------------------------- | ||
42 | |||
25 | function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) { | 43 | function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) { |
26 | return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | 44 | return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) |
27 | } | 45 | } |
@@ -30,10 +48,14 @@ function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename | |||
30 | return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | 48 | return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) |
31 | } | 49 | } |
32 | 50 | ||
51 | // --------------------------------------------------------------------------- | ||
52 | |||
33 | function removeWebTorrentObjectStorage (videoFile: MVideoFile) { | 53 | function removeWebTorrentObjectStorage (videoFile: MVideoFile) { |
34 | return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS) | 54 | return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS) |
35 | } | 55 | } |
36 | 56 | ||
57 | // --------------------------------------------------------------------------- | ||
58 | |||
37 | async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) { | 59 | async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) { |
38 | const key = generateHLSObjectStorageKey(playlist, filename) | 60 | const key = generateHLSObjectStorageKey(playlist, filename) |
39 | 61 | ||
@@ -62,9 +84,14 @@ async function makeWebTorrentFileAvailable (filename: string, destination: strin | |||
62 | return destination | 84 | return destination |
63 | } | 85 | } |
64 | 86 | ||
87 | // --------------------------------------------------------------------------- | ||
88 | |||
65 | export { | 89 | export { |
90 | listHLSFileKeysOf, | ||
91 | |||
66 | storeWebTorrentFile, | 92 | storeWebTorrentFile, |
67 | storeHLSFile, | 93 | storeHLSFileFromFilename, |
94 | storeHLSFileFromPath, | ||
68 | 95 | ||
69 | removeHLSObjectStorage, | 96 | removeHLSObjectStorage, |
70 | removeHLSFileObjectStorage, | 97 | removeHLSFileObjectStorage, |