1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Add ability to put captions in object storage

Deprecate:
 * `path` and `url` of `ActorImage` (used to represent account/channel
   avatars/banners) in favour of `fileUrl`
 * `path` of `AvatarInfo` (used in notifications) in favour of `fileUrl`
 * `captionPath` of `VideoCaption` in favour of `fileUrl`
 * `storyboardPath` of `Storyboard` in favour of `fileUrl`
This commit is contained in:
Chocobozzz 2025-02-07 09:04:20 +01:00
parent e6725e6d3a
commit 260447942a
No known key found for this signature in database
GPG key ID: 583A612D890159BE
69 changed files with 1322 additions and 518 deletions

View file

@ -17,6 +17,10 @@ export function generateOriginalVideoObjectStorageKey (filename: string) {
return filename
}
export function generateCaptionObjectStorageKey (filename: string) {
return filename
}
export function generateUserExportObjectStorageKey (filename: string) {
return filename
}

View file

@ -50,14 +50,16 @@ async function storeObject (options: {
objectStorageKey: string
bucketInfo: BucketInfo
isPrivate: boolean
contentType?: string
}): Promise<string> {
const { inputPath, objectStorageKey, bucketInfo, isPrivate } = options
const { inputPath, objectStorageKey, bucketInfo, isPrivate, contentType } = options
logger.debug('Uploading file %s to %s%s in bucket %s', inputPath, bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME, lTags())
const fileStream = createReadStream(inputPath)
return uploadToStorage({ objectStorageKey, content: fileStream, bucketInfo, isPrivate })
return uploadToStorage({ objectStorageKey, content: fileStream, bucketInfo, isPrivate, contentType })
}
async function storeContent (options: {
@ -65,12 +67,14 @@ async function storeContent (options: {
objectStorageKey: string
bucketInfo: BucketInfo
isPrivate: boolean
contentType?: string
}): Promise<string> {
const { content, objectStorageKey, bucketInfo, isPrivate } = options
const { content, objectStorageKey, bucketInfo, isPrivate, contentType } = options
logger.debug('Uploading %s content to %s%s in bucket %s', content, bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME, lTags())
return uploadToStorage({ objectStorageKey, content, bucketInfo, isPrivate })
return uploadToStorage({ objectStorageKey, content, bucketInfo, isPrivate, contentType })
}
async function storeStream (options: {
@ -78,12 +82,14 @@ async function storeStream (options: {
objectStorageKey: string
bucketInfo: BucketInfo
isPrivate: boolean
contentType?: string
}): Promise<string> {
const { stream, objectStorageKey, bucketInfo, isPrivate } = options
const { stream, objectStorageKey, bucketInfo, isPrivate, contentType } = options
logger.debug('Streaming file to %s%s in bucket %s', bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME, lTags())
return uploadToStorage({ objectStorageKey, content: stream, bucketInfo, isPrivate })
return uploadToStorage({ objectStorageKey, content: stream, bucketInfo, isPrivate, contentType })
}
// ---------------------------------------------------------------------------
@ -296,13 +302,16 @@ async function uploadToStorage (options: {
objectStorageKey: string
bucketInfo: BucketInfo
isPrivate: boolean
contentType?: string
}) {
const { content, objectStorageKey, bucketInfo, isPrivate } = options
const { content, objectStorageKey, bucketInfo, isPrivate, contentType } = options
const input: PutObjectCommandInput = {
Body: content,
Bucket: bucketInfo.BUCKET_NAME,
Key: buildKey(objectStorageKey, bucketInfo)
Key: buildKey(objectStorageKey, bucketInfo),
ContentType: contentType
}
const acl = getACL(isPrivate)

View file

@ -1,11 +1,12 @@
import { logger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/types/models/index.js'
import { MStreamingPlaylistVideo, MVideo, MVideoCaption, MVideoFile } from '@server/types/models/index.js'
import { MVideoSource } from '@server/types/models/video/video-source.js'
import { basename, join } from 'path'
import { getHLSDirectory } from '../paths.js'
import { VideoPathManager } from '../video-path-manager.js'
import {
generateCaptionObjectStorageKey,
generateHLSObjectBaseStorageKey,
generateHLSObjectStorageKey,
generateOriginalVideoObjectStorageKey,
@ -71,6 +72,18 @@ export function storeWebVideoFile (video: MVideo, file: MVideoFile) {
// ---------------------------------------------------------------------------
export function storeVideoCaption (inputPath: string, filename: string) {
return storeObject({
inputPath,
objectStorageKey: generateCaptionObjectStorageKey(filename),
bucketInfo: CONFIG.OBJECT_STORAGE.CAPTIONS,
isPrivate: false,
contentType: 'text/vtt'
})
}
// ---------------------------------------------------------------------------
export function storeOriginalVideoFile (inputPath: string, filename: string) {
return storeObject({
inputPath,
@ -130,6 +143,12 @@ export function removeOriginalFileObjectStorage (videoSource: MVideoSource) {
// ---------------------------------------------------------------------------
export function removeCaptionObjectStorage (videoCaption: MVideoCaption) {
return removeObject(generateCaptionObjectStorageKey(videoCaption.filename), CONFIG.OBJECT_STORAGE.CAPTIONS)
}
// ---------------------------------------------------------------------------
export async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) {
const key = generateHLSObjectStorageKey(playlist, filename)
@ -172,6 +191,20 @@ export async function makeOriginalFileAvailable (keptOriginalFilename: string, d
return destination
}
export async function makeCaptionFileAvailable (filename: string, destination: string) {
const key = generateCaptionObjectStorageKey(filename)
logger.info('Fetching Caption file %s from object storage to %s.', key, destination, lTags())
await makeAvailable({
key,
destination,
bucketInfo: CONFIG.OBJECT_STORAGE.CAPTIONS
})
return destination
}
// ---------------------------------------------------------------------------
export function getWebVideoFileReadStream (options: {