]>
Commit | Line | Data |
---|---|---|
0305db28 JB |
1 | import { join } from 'path' |
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' | |
7 | import { lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared' | |
8 | ||
ad5db104 C |
9 | function storeHLSFile (playlist: MStreamingPlaylistVideo, filename: string) { |
10 | const baseHlsDirectory = getHLSDirectory(playlist.Video) | |
0305db28 JB |
11 | |
12 | return storeObject({ | |
13 | inputPath: join(baseHlsDirectory, filename), | |
ad5db104 | 14 | objectStorageKey: generateHLSObjectStorageKey(playlist, filename), |
0305db28 JB |
15 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS |
16 | }) | |
17 | } | |
18 | ||
19 | function storeWebTorrentFile (filename: string) { | |
20 | return storeObject({ | |
21 | inputPath: join(CONFIG.STORAGE.VIDEOS_DIR, filename), | |
22 | objectStorageKey: generateWebTorrentObjectStorageKey(filename), | |
23 | bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS | |
24 | }) | |
25 | } | |
26 | ||
ad5db104 C |
27 | function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) { |
28 | return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | |
0305db28 JB |
29 | } |
30 | ||
31 | function removeWebTorrentObjectStorage (videoFile: MVideoFile) { | |
32 | return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS) | |
33 | } | |
34 | ||
ad5db104 C |
35 | async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) { |
36 | const key = generateHLSObjectStorageKey(playlist, filename) | |
0305db28 JB |
37 | |
38 | logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags()) | |
39 | ||
40 | await makeAvailable({ | |
41 | key, | |
42 | destination, | |
43 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS | |
44 | }) | |
45 | ||
46 | return destination | |
47 | } | |
48 | ||
49 | async function makeWebTorrentFileAvailable (filename: string, destination: string) { | |
50 | const key = generateWebTorrentObjectStorageKey(filename) | |
51 | ||
52 | logger.info('Fetching WebTorrent file %s from object storage to %s.', key, destination, lTags()) | |
53 | ||
54 | await makeAvailable({ | |
55 | key, | |
56 | destination, | |
57 | bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS | |
58 | }) | |
59 | ||
60 | return destination | |
61 | } | |
62 | ||
63 | export { | |
64 | storeWebTorrentFile, | |
65 | storeHLSFile, | |
66 | ||
67 | removeHLSObjectStorage, | |
68 | removeWebTorrentObjectStorage, | |
69 | ||
70 | makeWebTorrentFileAvailable, | |
71 | makeHLSFileAvailable | |
72 | } |