mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 09:49:20 +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:
parent
e6725e6d3a
commit
260447942a
69 changed files with 1322 additions and 518 deletions
|
@ -1,11 +1,13 @@
|
|||
import { FileStorage, MoveStoragePayload, VideoStateType } from '@peertube/peertube-models'
|
||||
import { FileStorage, isMoveCaptionPayload, isMoveVideoStoragePayload, MoveStoragePayload, VideoStateType } from '@peertube/peertube-models'
|
||||
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
|
||||
import { updateTorrentMetadata } from '@server/helpers/webtorrent.js'
|
||||
import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants.js'
|
||||
import {
|
||||
makeCaptionFileAvailable,
|
||||
makeHLSFileAvailable,
|
||||
makeOriginalFileAvailable,
|
||||
makeWebVideoFileAvailable,
|
||||
removeCaptionObjectStorage,
|
||||
removeHLSFileObjectStorageByFilename,
|
||||
removeHLSObjectStorage,
|
||||
removeOriginalFileObjectStorage,
|
||||
|
@ -14,36 +16,54 @@ import {
|
|||
import { getHLSDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths.js'
|
||||
import { VideoPathManager } from '@server/lib/video-path-manager.js'
|
||||
import { moveToFailedMoveToFileSystemState, moveToNextState } from '@server/lib/video-state.js'
|
||||
import { MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoWithAllFiles } from '@server/types/models/index.js'
|
||||
import { MStreamingPlaylistVideo, MVideo, MVideoCaption, MVideoFile, MVideoWithAllFiles } from '@server/types/models/index.js'
|
||||
import { MVideoSource } from '@server/types/models/video/video-source.js'
|
||||
import { Job } from 'bullmq'
|
||||
import { join } from 'path'
|
||||
import { moveToJob, onMoveToStorageFailure } from './shared/move-video.js'
|
||||
import { moveCaptionToStorageJob } from './shared/move-caption.js'
|
||||
import { moveVideoToStorageJob, onMoveVideoToStorageFailure } from './shared/move-video.js'
|
||||
|
||||
const lTagsBase = loggerTagsFactory('move-file-system')
|
||||
|
||||
export async function processMoveToFileSystem (job: Job) {
|
||||
const payload = job.data as MoveStoragePayload
|
||||
logger.info('Moving video %s to file system in job %s.', payload.videoUUID, job.id)
|
||||
|
||||
await moveToJob({
|
||||
jobId: job.id,
|
||||
videoUUID: payload.videoUUID,
|
||||
loggerTags: lTagsBase().tags,
|
||||
if (isMoveVideoStoragePayload(payload)) { // Move all video related files
|
||||
logger.info('Moving video %s to file system in job %s.', payload.videoUUID, job.id)
|
||||
|
||||
moveWebVideoFiles,
|
||||
moveHLSFiles,
|
||||
moveVideoSourceFile,
|
||||
await moveVideoToStorageJob({
|
||||
jobId: job.id,
|
||||
videoUUID: payload.videoUUID,
|
||||
loggerTags: lTagsBase().tags,
|
||||
|
||||
doAfterLastMove: video => doAfterLastMove({ video, previousVideoState: payload.previousVideoState, isNewVideo: payload.isNewVideo }),
|
||||
moveToFailedState: moveToFailedMoveToFileSystemState
|
||||
})
|
||||
moveWebVideoFiles,
|
||||
moveHLSFiles,
|
||||
moveVideoSourceFile,
|
||||
moveCaptionFiles,
|
||||
|
||||
doAfterLastMove: video => doAfterLastMove({ video, previousVideoState: payload.previousVideoState, isNewVideo: payload.isNewVideo }),
|
||||
moveToFailedState: moveToFailedMoveToFileSystemState
|
||||
})
|
||||
} else if (isMoveCaptionPayload(payload)) { // Only caption file
|
||||
logger.info(`Moving video caption ${payload.captionId} to file system in job ${job.id}.`)
|
||||
|
||||
await moveCaptionToStorageJob({
|
||||
jobId: job.id,
|
||||
captionId: payload.captionId,
|
||||
loggerTags: lTagsBase().tags,
|
||||
moveCaptionFiles
|
||||
})
|
||||
} else {
|
||||
throw new Error('Unknown payload type')
|
||||
}
|
||||
}
|
||||
|
||||
export async function onMoveToFileSystemFailure (job: Job, err: any) {
|
||||
const payload = job.data as MoveStoragePayload
|
||||
|
||||
await onMoveToStorageFailure({
|
||||
if (!isMoveVideoStoragePayload(payload)) return
|
||||
|
||||
await onMoveVideoToStorageFailure({
|
||||
videoUUID: payload.videoUUID,
|
||||
err,
|
||||
lTags: lTagsBase(),
|
||||
|
@ -130,6 +150,28 @@ async function onVideoFileMoved (options: {
|
|||
await objetStorageRemover()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function moveCaptionFiles (captions: MVideoCaption[]) {
|
||||
for (const caption of captions) {
|
||||
if (caption.storage === FileStorage.FILE_SYSTEM) continue
|
||||
|
||||
await makeCaptionFileAvailable(caption.filename, caption.getFSPath())
|
||||
|
||||
const oldFileUrl = caption.fileUrl
|
||||
|
||||
caption.fileUrl = null
|
||||
caption.storage = FileStorage.FILE_SYSTEM
|
||||
await caption.save()
|
||||
|
||||
logger.debug('Removing caption file %s because it\'s now on file system', oldFileUrl, lTagsBase())
|
||||
|
||||
await removeCaptionObjectStorage(caption)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function doAfterLastMove (options: {
|
||||
video: MVideoWithAllFiles
|
||||
previousVideoState: VideoStateType
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue