aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/object-storage/pre-signed-urls.ts
blob: 46a0750a1e287754d4b52b77899ea3f74738101c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 })
}