diff options
Diffstat (limited to 'server/lib/object-storage')
-rw-r--r-- | server/lib/object-storage/shared/object-storage-helpers.ts | 25 | ||||
-rw-r--r-- | server/lib/object-storage/videos.ts | 37 |
2 files changed, 56 insertions, 6 deletions
diff --git a/server/lib/object-storage/shared/object-storage-helpers.ts b/server/lib/object-storage/shared/object-storage-helpers.ts index 16161362c..c131977e8 100644 --- a/server/lib/object-storage/shared/object-storage-helpers.ts +++ b/server/lib/object-storage/shared/object-storage-helpers.ts | |||
@@ -22,6 +22,24 @@ type BucketInfo = { | |||
22 | PREFIX?: string | 22 | PREFIX?: string |
23 | } | 23 | } |
24 | 24 | ||
25 | async function listKeysOfPrefix (prefix: string, bucketInfo: BucketInfo) { | ||
26 | const s3Client = getClient() | ||
27 | |||
28 | const commandPrefix = bucketInfo.PREFIX + prefix | ||
29 | const listCommand = new ListObjectsV2Command({ | ||
30 | Bucket: bucketInfo.BUCKET_NAME, | ||
31 | Prefix: commandPrefix | ||
32 | }) | ||
33 | |||
34 | const listedObjects = await s3Client.send(listCommand) | ||
35 | |||
36 | if (isArray(listedObjects.Contents) !== true) return [] | ||
37 | |||
38 | return listedObjects.Contents.map(c => c.Key) | ||
39 | } | ||
40 | |||
41 | // --------------------------------------------------------------------------- | ||
42 | |||
25 | async function storeObject (options: { | 43 | async function storeObject (options: { |
26 | inputPath: string | 44 | inputPath: string |
27 | objectStorageKey: string | 45 | objectStorageKey: string |
@@ -36,6 +54,8 @@ async function storeObject (options: { | |||
36 | return uploadToStorage({ objectStorageKey, content: fileStream, bucketInfo }) | 54 | return uploadToStorage({ objectStorageKey, content: fileStream, bucketInfo }) |
37 | } | 55 | } |
38 | 56 | ||
57 | // --------------------------------------------------------------------------- | ||
58 | |||
39 | async function removeObject (filename: string, bucketInfo: BucketInfo) { | 59 | async function removeObject (filename: string, bucketInfo: BucketInfo) { |
40 | const command = new DeleteObjectCommand({ | 60 | const command = new DeleteObjectCommand({ |
41 | Bucket: bucketInfo.BUCKET_NAME, | 61 | Bucket: bucketInfo.BUCKET_NAME, |
@@ -89,6 +109,8 @@ async function removePrefix (prefix: string, bucketInfo: BucketInfo) { | |||
89 | if (listedObjects.IsTruncated) await removePrefix(prefix, bucketInfo) | 109 | if (listedObjects.IsTruncated) await removePrefix(prefix, bucketInfo) |
90 | } | 110 | } |
91 | 111 | ||
112 | // --------------------------------------------------------------------------- | ||
113 | |||
92 | async function makeAvailable (options: { | 114 | async function makeAvailable (options: { |
93 | key: string | 115 | key: string |
94 | destination: string | 116 | destination: string |
@@ -122,7 +144,8 @@ export { | |||
122 | storeObject, | 144 | storeObject, |
123 | removeObject, | 145 | removeObject, |
124 | removePrefix, | 146 | removePrefix, |
125 | makeAvailable | 147 | makeAvailable, |
148 | listKeysOfPrefix | ||
126 | } | 149 | } |
127 | 150 | ||
128 | // --------------------------------------------------------------------------- | 151 | // --------------------------------------------------------------------------- |
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, |