Fix caption in object storage export

This commit is contained in:
Chocobozzz 2025-02-10 08:10:05 +01:00
parent b6b6922006
commit 0184aa9be7
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 29 additions and 4 deletions

View File

@ -252,3 +252,18 @@ export function getOriginalFileReadStream (options: {
rangeHeader
})
}
export function getCaptionReadStream (options: {
filename: string
rangeHeader: string
}) {
const { filename, rangeHeader } = options
const key = generateCaptionObjectStorageKey(filename)
return createObjectReadStream({
key,
bucketInfo: CONFIG.OBJECT_STORAGE.CAPTIONS,
rangeHeader
})
}

View File

@ -5,7 +5,7 @@ import { USER_EXPORT_MAX_ITEMS } from '@server/initializers/constants.js'
import { audiencify, getAudience } from '@server/lib/activitypub/audience.js'
import { buildCreateActivity } from '@server/lib/activitypub/send/send-create.js'
import { buildChaptersAPHasPart } from '@server/lib/activitypub/video-chapters.js'
import { getHLSFileReadStream, getOriginalFileReadStream, getWebVideoFileReadStream } from '@server/lib/object-storage/videos.js'
import { getCaptionReadStream, getHLSFileReadStream, getOriginalFileReadStream, getWebVideoFileReadStream } from '@server/lib/object-storage/videos.js'
import { muxToMergeVideoFiles } from '@server/lib/video-file.js'
import { VideoPathManager } from '@server/lib/video-path-manager.js'
import { VideoCaptionModel } from '@server/models/video/video-caption.js'
@ -344,7 +344,7 @@ export class VideosExporter extends AbstractUserExporter <VideoExportJSON> {
for (const caption of captions) {
staticFiles.push({
archivePath: this.getArchiveCaptionFilePath(video, caption),
readStreamFactory: () => Promise.resolve(createReadStream(caption.getFSPath()))
readStreamFactory: () => this.generateCaptionReadStream(caption)
})
relativePathsFromJSON.captions[caption.language] = join(this.relativeStaticDirPath, this.getArchiveCaptionFilePath(video, caption))
@ -400,6 +400,18 @@ export class VideosExporter extends AbstractUserExporter <VideoExportJSON> {
return stream
}
private async generateCaptionReadStream (caption: MVideoCaption): Promise<Readable> {
if (caption.storage === FileStorage.FILE_SYSTEM) {
return createReadStream(caption.getFSPath())
}
const { stream } = await getCaptionReadStream({ filename: caption.filename, rangeHeader: undefined })
return stream
}
// ---------------------------------------------------------------------------
private async getArchiveVideo (video: MVideoFullLight) {
const source = await VideoSourceModel.loadLatest(video.id)

View File

@ -291,8 +291,6 @@ export class UserExporter {
stream.once('readable', () => {
if (errored) return
logger.error('Readable stream ' + archivePath)
this.archive.append(stream, { name: archivePath })
})
})