From cfd57d2ca0bb058087f7dc90fcc3e8442b0288e1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 4 Oct 2022 10:03:17 +0200 Subject: Live supports object storage * Sync live files (segments, master playlist, resolution playlist, segment sha file) into object storage * Automatically delete them when the live ends * Segment sha file is now a file on disk, and not stored in memory anymore --- .../shared/object-storage-helpers.ts | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'server/lib/object-storage/shared') 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 = { PREFIX?: string } +async function listKeysOfPrefix (prefix: string, bucketInfo: BucketInfo) { + const s3Client = getClient() + + const commandPrefix = bucketInfo.PREFIX + prefix + const listCommand = new ListObjectsV2Command({ + Bucket: bucketInfo.BUCKET_NAME, + Prefix: commandPrefix + }) + + const listedObjects = await s3Client.send(listCommand) + + if (isArray(listedObjects.Contents) !== true) return [] + + return listedObjects.Contents.map(c => c.Key) +} + +// --------------------------------------------------------------------------- + async function storeObject (options: { inputPath: string objectStorageKey: string @@ -36,6 +54,8 @@ async function storeObject (options: { return uploadToStorage({ objectStorageKey, content: fileStream, bucketInfo }) } +// --------------------------------------------------------------------------- + async function removeObject (filename: string, bucketInfo: BucketInfo) { const command = new DeleteObjectCommand({ Bucket: bucketInfo.BUCKET_NAME, @@ -89,6 +109,8 @@ async function removePrefix (prefix: string, bucketInfo: BucketInfo) { if (listedObjects.IsTruncated) await removePrefix(prefix, bucketInfo) } +// --------------------------------------------------------------------------- + async function makeAvailable (options: { key: string destination: string @@ -122,7 +144,8 @@ export { storeObject, removeObject, removePrefix, - makeAvailable + makeAvailable, + listKeysOfPrefix } // --------------------------------------------------------------------------- -- cgit v1.2.3