]>
Commit | Line | Data |
---|---|---|
cfd57d2c | 1 | import { basename, join } from 'path' |
0305db28 JB |
2 | import { logger } from '@server/helpers/logger' |
3 | import { CONFIG } from '@server/initializers/config' | |
ad5db104 | 4 | import { MStreamingPlaylistVideo, MVideoFile } from '@server/types/models' |
0305db28 JB |
5 | import { getHLSDirectory } from '../paths' |
6 | import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys' | |
cfd57d2c | 7 | import { listKeysOfPrefix, lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared' |
0305db28 | 8 | |
cfd57d2c C |
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) { | |
0305db28 | 16 | return storeObject({ |
cfd57d2c | 17 | inputPath: join(getHLSDirectory(playlist.Video), filename), |
ad5db104 | 18 | objectStorageKey: generateHLSObjectStorageKey(playlist, filename), |
0305db28 JB |
19 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS |
20 | }) | |
21 | } | |
22 | ||
cfd57d2c C |
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 | ||
0305db28 JB |
33 | function storeWebTorrentFile (filename: string) { |
34 | return storeObject({ | |
35 | inputPath: join(CONFIG.STORAGE.VIDEOS_DIR, filename), | |
36 | objectStorageKey: generateWebTorrentObjectStorageKey(filename), | |
37 | bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS | |
38 | }) | |
39 | } | |
40 | ||
cfd57d2c C |
41 | // --------------------------------------------------------------------------- |
42 | ||
ad5db104 C |
43 | function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) { |
44 | return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | |
0305db28 JB |
45 | } |
46 | ||
7b6b445d C |
47 | function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) { |
48 | return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | |
49 | } | |
50 | ||
cfd57d2c C |
51 | // --------------------------------------------------------------------------- |
52 | ||
0305db28 JB |
53 | function removeWebTorrentObjectStorage (videoFile: MVideoFile) { |
54 | return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS) | |
55 | } | |
56 | ||
cfd57d2c C |
57 | // --------------------------------------------------------------------------- |
58 | ||
ad5db104 C |
59 | async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) { |
60 | const key = generateHLSObjectStorageKey(playlist, filename) | |
0305db28 JB |
61 | |
62 | logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags()) | |
63 | ||
64 | await makeAvailable({ | |
65 | key, | |
66 | destination, | |
67 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS | |
68 | }) | |
69 | ||
70 | return destination | |
71 | } | |
72 | ||
73 | async function makeWebTorrentFileAvailable (filename: string, destination: string) { | |
74 | const key = generateWebTorrentObjectStorageKey(filename) | |
75 | ||
76 | logger.info('Fetching WebTorrent file %s from object storage to %s.', key, destination, lTags()) | |
77 | ||
78 | await makeAvailable({ | |
79 | key, | |
80 | destination, | |
81 | bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS | |
82 | }) | |
83 | ||
84 | return destination | |
85 | } | |
86 | ||
cfd57d2c C |
87 | // --------------------------------------------------------------------------- |
88 | ||
0305db28 | 89 | export { |
cfd57d2c C |
90 | listHLSFileKeysOf, |
91 | ||
0305db28 | 92 | storeWebTorrentFile, |
cfd57d2c C |
93 | storeHLSFileFromFilename, |
94 | storeHLSFileFromPath, | |
0305db28 JB |
95 | |
96 | removeHLSObjectStorage, | |
7b6b445d | 97 | removeHLSFileObjectStorage, |
0305db28 JB |
98 | removeWebTorrentObjectStorage, |
99 | ||
100 | makeWebTorrentFileAvailable, | |
101 | makeHLSFileAvailable | |
102 | } |