2023-07-31 07:34:36 -05:00
|
|
|
import { CONFIG } from '@server/initializers/config.js'
|
|
|
|
import { MStreamingPlaylistVideo, MVideoFile } from '@server/types/models/index.js'
|
|
|
|
import { generateHLSObjectStorageKey, generateWebVideoObjectStorageKey } from './keys.js'
|
|
|
|
import { buildKey, getClient } from './shared/index.js'
|
|
|
|
import { getHLSPublicFileUrl, getWebVideoPublicFileUrl } from './urls.js'
|
2023-06-06 04:14:13 -05:00
|
|
|
|
2023-06-06 04:59:00 -05:00
|
|
|
export async function generateWebVideoPresignedUrl (options: {
|
2023-06-06 04:14:13 -05:00
|
|
|
file: MVideoFile
|
|
|
|
downloadFilename: string
|
|
|
|
}) {
|
|
|
|
const { file, downloadFilename } = options
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
const key = generateWebVideoObjectStorageKey(file.filename)
|
2023-06-06 04:14:13 -05:00
|
|
|
|
2023-07-31 07:34:36 -05:00
|
|
|
const { GetObjectCommand } = await import('@aws-sdk/client-s3')
|
|
|
|
const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner')
|
|
|
|
|
2023-06-06 04:14:13 -05:00
|
|
|
const command = new GetObjectCommand({
|
2023-07-11 04:23:51 -05:00
|
|
|
Bucket: CONFIG.OBJECT_STORAGE.WEB_VIDEOS.BUCKET_NAME,
|
|
|
|
Key: buildKey(key, CONFIG.OBJECT_STORAGE.WEB_VIDEOS),
|
2023-12-19 00:26:09 -06:00
|
|
|
ResponseContentDisposition: `attachment; filename=${encodeURI(downloadFilename)}`
|
2023-06-06 04:14:13 -05:00
|
|
|
})
|
|
|
|
|
2023-07-31 07:34:36 -05:00
|
|
|
const url = await getSignedUrl(await getClient(), command, { expiresIn: 3600 * 24 })
|
2023-06-06 04:59:00 -05:00
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
return getWebVideoPublicFileUrl(url)
|
2023-06-06 04:14:13 -05:00
|
|
|
}
|
|
|
|
|
2023-06-06 04:59:00 -05:00
|
|
|
export async function generateHLSFilePresignedUrl (options: {
|
2023-06-06 04:14:13 -05:00
|
|
|
streamingPlaylist: MStreamingPlaylistVideo
|
|
|
|
file: MVideoFile
|
|
|
|
downloadFilename: string
|
|
|
|
}) {
|
|
|
|
const { streamingPlaylist, file, downloadFilename } = options
|
|
|
|
|
|
|
|
const key = generateHLSObjectStorageKey(streamingPlaylist, file.filename)
|
|
|
|
|
2023-07-31 07:34:36 -05:00
|
|
|
const { GetObjectCommand } = await import('@aws-sdk/client-s3')
|
|
|
|
const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner')
|
|
|
|
|
2023-06-06 04:14:13 -05:00
|
|
|
const command = new GetObjectCommand({
|
|
|
|
Bucket: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME,
|
|
|
|
Key: buildKey(key, CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS),
|
2023-12-19 00:26:09 -06:00
|
|
|
ResponseContentDisposition: `attachment; filename=${encodeURI(downloadFilename)}`
|
2023-06-06 04:14:13 -05:00
|
|
|
})
|
|
|
|
|
2023-07-31 07:34:36 -05:00
|
|
|
const url = await getSignedUrl(await getClient(), command, { expiresIn: 3600 * 24 })
|
2023-06-06 04:59:00 -05:00
|
|
|
|
|
|
|
return getHLSPublicFileUrl(url)
|
2023-06-06 04:14:13 -05:00
|
|
|
}
|