diff options
author | Chocobozzz <me@florianbigard.com> | 2023-06-06 11:14:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-06-29 10:19:05 +0200 |
commit | c37e305342c8655325f9606aa1f4b29abc471b39 (patch) | |
tree | 7d0529c0895c0522de9e77c8ab4d48e502599d2c /server/lib/object-storage | |
parent | 881958d17902b1efbb184400d7e5030cfc5b7224 (diff) | |
download | PeerTube-c37e305342c8655325f9606aa1f4b29abc471b39.tar.gz PeerTube-c37e305342c8655325f9606aa1f4b29abc471b39.tar.zst PeerTube-c37e305342c8655325f9606aa1f4b29abc471b39.zip |
Fix CI tests
Diffstat (limited to 'server/lib/object-storage')
-rw-r--r-- | server/lib/object-storage/pre-signed-urls.ts | 41 |
1 files changed, 41 insertions, 0 deletions
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 @@ | |||
1 | import { GetObjectCommand } from '@aws-sdk/client-s3' | ||
2 | import { getSignedUrl } from '@aws-sdk/s3-request-presigner' | ||
3 | import { CONFIG } from '@server/initializers/config' | ||
4 | import { MStreamingPlaylistVideo, MVideoFile } from '@server/types/models' | ||
5 | import { generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys' | ||
6 | import { buildKey, getClient } from './shared' | ||
7 | |||
8 | export function generateWebVideoPresignedUrl (options: { | ||
9 | file: MVideoFile | ||
10 | downloadFilename: string | ||
11 | }) { | ||
12 | const { file, downloadFilename } = options | ||
13 | |||
14 | const key = generateWebTorrentObjectStorageKey(file.filename) | ||
15 | |||
16 | const command = new GetObjectCommand({ | ||
17 | Bucket: CONFIG.OBJECT_STORAGE.VIDEOS.BUCKET_NAME, | ||
18 | Key: buildKey(key, CONFIG.OBJECT_STORAGE.VIDEOS), | ||
19 | ResponseContentDisposition: `attachment; filename=${downloadFilename}` | ||
20 | }) | ||
21 | |||
22 | return getSignedUrl(getClient(), command, { expiresIn: 3600 * 24 }) | ||
23 | } | ||
24 | |||
25 | export function generateHLSFilePresignedUrl (options: { | ||
26 | streamingPlaylist: MStreamingPlaylistVideo | ||
27 | file: MVideoFile | ||
28 | downloadFilename: string | ||
29 | }) { | ||
30 | const { streamingPlaylist, file, downloadFilename } = options | ||
31 | |||
32 | const key = generateHLSObjectStorageKey(streamingPlaylist, file.filename) | ||
33 | |||
34 | const command = new GetObjectCommand({ | ||
35 | Bucket: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME, | ||
36 | Key: buildKey(key, CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS), | ||
37 | ResponseContentDisposition: `attachment; filename=${downloadFilename}` | ||
38 | }) | ||
39 | |||
40 | return getSignedUrl(getClient(), command, { expiresIn: 3600 * 24 }) | ||
41 | } | ||