mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Implement user import/export in server
This commit is contained in:
parent
4d63e6f577
commit
8573e5a80a
196 changed files with 5661 additions and 722 deletions
|
@ -1,6 +1,6 @@
|
|||
import { CONFIG } from '@server/initializers/config.js'
|
||||
import { MStreamingPlaylistVideo, MVideoFile } from '@server/types/models/index.js'
|
||||
import { generateHLSObjectStorageKey, generateWebVideoObjectStorageKey } from './keys.js'
|
||||
import { MStreamingPlaylistVideo, MUserExport, MVideoFile } from '@server/types/models/index.js'
|
||||
import { generateHLSObjectStorageKey, generateUserExportObjectStorageKey, generateWebVideoObjectStorageKey } from './keys.js'
|
||||
import { buildKey, getClient } from './shared/index.js'
|
||||
import { getHLSPublicFileUrl, getWebVideoPublicFileUrl } from './urls.js'
|
||||
|
||||
|
@ -10,19 +10,12 @@ export async function generateWebVideoPresignedUrl (options: {
|
|||
}) {
|
||||
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="${encodeURI(downloadFilename)}"`
|
||||
const url = await generatePresignedUrl({
|
||||
bucket: CONFIG.OBJECT_STORAGE.WEB_VIDEOS.BUCKET_NAME,
|
||||
key: buildKey(generateWebVideoObjectStorageKey(file.filename), CONFIG.OBJECT_STORAGE.WEB_VIDEOS),
|
||||
downloadFilename
|
||||
})
|
||||
|
||||
const url = await getSignedUrl(await getClient(), command, { expiresIn: 3600 * 24 })
|
||||
|
||||
return getWebVideoPublicFileUrl(url)
|
||||
}
|
||||
|
||||
|
@ -33,18 +26,49 @@ export async function generateHLSFilePresignedUrl (options: {
|
|||
}) {
|
||||
const { streamingPlaylist, file, downloadFilename } = options
|
||||
|
||||
const key = generateHLSObjectStorageKey(streamingPlaylist, file.filename)
|
||||
const url = await generatePresignedUrl({
|
||||
bucket: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME,
|
||||
key: buildKey(generateHLSObjectStorageKey(streamingPlaylist, file.filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS),
|
||||
downloadFilename
|
||||
})
|
||||
|
||||
return getHLSPublicFileUrl(url)
|
||||
}
|
||||
|
||||
export async function generateUserExportPresignedUrl (options: {
|
||||
userExport: MUserExport
|
||||
downloadFilename: string
|
||||
}) {
|
||||
const { userExport, downloadFilename } = options
|
||||
|
||||
const url = await generatePresignedUrl({
|
||||
bucket: CONFIG.OBJECT_STORAGE.USER_EXPORTS.BUCKET_NAME,
|
||||
key: buildKey(generateUserExportObjectStorageKey(userExport.filename), CONFIG.OBJECT_STORAGE.USER_EXPORTS),
|
||||
downloadFilename
|
||||
})
|
||||
|
||||
return getHLSPublicFileUrl(url)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Private
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function generatePresignedUrl (options: {
|
||||
bucket: string
|
||||
key: string
|
||||
downloadFilename: string
|
||||
}) {
|
||||
const { bucket, downloadFilename, key } = options
|
||||
|
||||
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),
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
ResponseContentDisposition: `attachment; filename="${encodeURI(downloadFilename)}"`
|
||||
})
|
||||
|
||||
const url = await getSignedUrl(await getClient(), command, { expiresIn: 3600 * 24 })
|
||||
|
||||
return getHLSPublicFileUrl(url)
|
||||
return getSignedUrl(await getClient(), command, { expiresIn: 3600 * 24 })
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue