mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 17:59:37 +02:00
server/server -> server/core
This commit is contained in:
parent
114327d4ce
commit
5a3d0650c9
838 changed files with 111 additions and 111 deletions
50
server/core/lib/object-storage/pre-signed-urls.ts
Normal file
50
server/core/lib/object-storage/pre-signed-urls.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
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'
|
||||
|
||||
export async function generateWebVideoPresignedUrl (options: {
|
||||
file: MVideoFile
|
||||
downloadFilename: string
|
||||
}) {
|
||||
const { file, downloadFilename } = options
|
||||
|
||||
const key = generateWebVideoObjectStorageKey(file.filename)
|
||||
|
||||
const { GetObjectCommand } = await import('@aws-sdk/client-s3')
|
||||
const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner')
|
||||
|
||||
const command = new GetObjectCommand({
|
||||
Bucket: CONFIG.OBJECT_STORAGE.WEB_VIDEOS.BUCKET_NAME,
|
||||
Key: buildKey(key, CONFIG.OBJECT_STORAGE.WEB_VIDEOS),
|
||||
ResponseContentDisposition: `attachment; filename=${downloadFilename}`
|
||||
})
|
||||
|
||||
const url = await getSignedUrl(await getClient(), command, { expiresIn: 3600 * 24 })
|
||||
|
||||
return getWebVideoPublicFileUrl(url)
|
||||
}
|
||||
|
||||
export async function generateHLSFilePresignedUrl (options: {
|
||||
streamingPlaylist: MStreamingPlaylistVideo
|
||||
file: MVideoFile
|
||||
downloadFilename: string
|
||||
}) {
|
||||
const { streamingPlaylist, file, downloadFilename } = options
|
||||
|
||||
const key = generateHLSObjectStorageKey(streamingPlaylist, file.filename)
|
||||
|
||||
const { GetObjectCommand } = await import('@aws-sdk/client-s3')
|
||||
const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner')
|
||||
|
||||
const command = new GetObjectCommand({
|
||||
Bucket: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME,
|
||||
Key: buildKey(key, CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS),
|
||||
ResponseContentDisposition: `attachment; filename=${downloadFilename}`
|
||||
})
|
||||
|
||||
const url = await getSignedUrl(await getClient(), command, { expiresIn: 3600 * 24 })
|
||||
|
||||
return getHLSPublicFileUrl(url)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue