From 9ab330b90decf4edf152ff8e1d2948c065766b2c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Oct 2022 10:43:53 +0200 Subject: Use private ACL for private videos in s3 --- server/lib/object-storage/videos.ts | 80 ++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 5 deletions(-) (limited to 'server/lib/object-storage/videos.ts') diff --git a/server/lib/object-storage/videos.ts b/server/lib/object-storage/videos.ts index e323baaa2..003807826 100644 --- a/server/lib/object-storage/videos.ts +++ b/server/lib/object-storage/videos.ts @@ -5,7 +5,17 @@ import { MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/types/model import { getHLSDirectory } from '../paths' import { VideoPathManager } from '../video-path-manager' import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys' -import { listKeysOfPrefix, lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared' +import { + createObjectReadStream, + listKeysOfPrefix, + lTags, + makeAvailable, + removeObject, + removePrefix, + storeObject, + updateObjectACL, + updatePrefixACL +} from './shared' function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) { return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) @@ -17,7 +27,8 @@ function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: return storeObject({ inputPath: join(getHLSDirectory(playlist.Video), filename), objectStorageKey: generateHLSObjectStorageKey(playlist, filename), - bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS + bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, + isPrivate: playlist.Video.hasPrivateStaticPath() }) } @@ -25,7 +36,8 @@ function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) return storeObject({ inputPath: path, objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)), - bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS + bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, + isPrivate: playlist.Video.hasPrivateStaticPath() }) } @@ -35,7 +47,26 @@ function storeWebTorrentFile (video: MVideo, file: MVideoFile) { return storeObject({ inputPath: VideoPathManager.Instance.getFSVideoFileOutputPath(video, file), objectStorageKey: generateWebTorrentObjectStorageKey(file.filename), - bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS + bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS, + isPrivate: video.hasPrivateStaticPath() + }) +} + +// --------------------------------------------------------------------------- + +function updateWebTorrentFileACL (video: MVideo, file: MVideoFile) { + return updateObjectACL({ + objectStorageKey: generateWebTorrentObjectStorageKey(file.filename), + bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS, + isPrivate: video.hasPrivateStaticPath() + }) +} + +function updateHLSFilesACL (playlist: MStreamingPlaylistVideo) { + return updatePrefixACL({ + prefix: generateHLSObjectBaseStorageKey(playlist), + bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, + isPrivate: playlist.Video.hasPrivateStaticPath() }) } @@ -87,6 +118,39 @@ async function makeWebTorrentFileAvailable (filename: string, destination: strin // --------------------------------------------------------------------------- +function getWebTorrentFileReadStream (options: { + filename: string + rangeHeader: string +}) { + const { filename, rangeHeader } = options + + const key = generateWebTorrentObjectStorageKey(filename) + + return createObjectReadStream({ + key, + bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS, + rangeHeader + }) +} + +function getHLSFileReadStream (options: { + playlist: MStreamingPlaylistVideo + filename: string + rangeHeader: string +}) { + const { playlist, filename, rangeHeader } = options + + const key = generateHLSObjectStorageKey(playlist, filename) + + return createObjectReadStream({ + key, + bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, + rangeHeader + }) +} + +// --------------------------------------------------------------------------- + export { listHLSFileKeysOf, @@ -94,10 +158,16 @@ export { storeHLSFileFromFilename, storeHLSFileFromPath, + updateWebTorrentFileACL, + updateHLSFilesACL, + removeHLSObjectStorage, removeHLSFileObjectStorage, removeWebTorrentObjectStorage, makeWebTorrentFileAvailable, - makeHLSFileAvailable + makeHLSFileAvailable, + + getWebTorrentFileReadStream, + getHLSFileReadStream } -- cgit v1.2.3