From c37e305342c8655325f9606aa1f4b29abc471b39 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jun 2023 11:14:13 +0200 Subject: Fix CI tests --- server/lib/object-storage/pre-signed-urls.ts | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 server/lib/object-storage/pre-signed-urls.ts (limited to 'server/lib/object-storage') diff --git a/server/lib/object-storage/pre-signed-urls.ts b/server/lib/object-storage/pre-signed-urls.ts new file mode 100644 index 000000000..46a0750a1 --- /dev/null +++ b/server/lib/object-storage/pre-signed-urls.ts @@ -0,0 +1,41 @@ +import { GetObjectCommand } from '@aws-sdk/client-s3' +import { getSignedUrl } from '@aws-sdk/s3-request-presigner' +import { CONFIG } from '@server/initializers/config' +import { MStreamingPlaylistVideo, MVideoFile } from '@server/types/models' +import { generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys' +import { buildKey, getClient } from './shared' + +export function generateWebVideoPresignedUrl (options: { + file: MVideoFile + downloadFilename: string +}) { + const { file, downloadFilename } = options + + const key = generateWebTorrentObjectStorageKey(file.filename) + + const command = new GetObjectCommand({ + Bucket: CONFIG.OBJECT_STORAGE.VIDEOS.BUCKET_NAME, + Key: buildKey(key, CONFIG.OBJECT_STORAGE.VIDEOS), + ResponseContentDisposition: `attachment; filename=${downloadFilename}` + }) + + return getSignedUrl(getClient(), command, { expiresIn: 3600 * 24 }) +} + +export function generateHLSFilePresignedUrl (options: { + streamingPlaylist: MStreamingPlaylistVideo + file: MVideoFile + downloadFilename: string +}) { + const { streamingPlaylist, file, downloadFilename } = options + + const key = generateHLSObjectStorageKey(streamingPlaylist, file.filename) + + const command = new GetObjectCommand({ + Bucket: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME, + Key: buildKey(key, CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS), + ResponseContentDisposition: `attachment; filename=${downloadFilename}` + }) + + return getSignedUrl(getClient(), command, { expiresIn: 3600 * 24 }) +} -- cgit v1.2.3