1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +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

@ -1,12 +1,15 @@
import { program } from 'commander'
import { FileStorage, VideoState } from '@peertube/peertube-models'
import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
import { CONFIG } from '@server/initializers/config.js'
import { initDatabaseModels } from '@server/initializers/database.js'
import { JobQueue } from '@server/lib/job-queue/index.js'
import { moveToExternalStorageState, moveToFileSystemState } from '@server/lib/video-state.js'
import { VideoCaptionModel } from '@server/models/video/video-caption.js'
import { VideoSourceModel } from '@server/models/video/video-source.js'
import { VideoModel } from '@server/models/video/video.js'
import { VideoState, FileStorage } from '@peertube/peertube-models'
import { MStreamingPlaylist, MVideoFile, MVideoFullLight } from '@server/types/models/index.js'
import { MStreamingPlaylist, MVideoCaption, MVideoFile, MVideoFullLight } from '@server/types/models/index.js'
import { MVideoSource } from '@server/types/models/video/video-source.js'
import { program } from 'commander'
program
.description('Move videos to another storage.')
@ -83,8 +86,13 @@ async function run () {
await createMoveJobIfNeeded({
video: videoFull,
type: 'to object storage',
canProcessVideo: (files, hls) => {
return files.some(f => f.storage === FileStorage.FILE_SYSTEM) || hls?.storage === FileStorage.FILE_SYSTEM
canProcessVideo: (options) => {
const { files, hls, source, captions } = options
return files.some(f => f.storage === FileStorage.FILE_SYSTEM) ||
hls?.storage === FileStorage.FILE_SYSTEM ||
source?.storage === FileStorage.FILE_SYSTEM ||
captions.some(c => c.storage === FileStorage.FILE_SYSTEM)
},
handler: () => moveToExternalStorageState({ video: videoFull, isNewVideo: false, transaction: undefined })
})
@ -97,9 +105,15 @@ async function run () {
video: videoFull,
type: 'to file system',
canProcessVideo: (files, hls) => {
return files.some(f => f.storage === FileStorage.OBJECT_STORAGE) || hls?.storage === FileStorage.OBJECT_STORAGE
canProcessVideo: options => {
const { files, hls, source, captions } = options
return files.some(f => f.storage === FileStorage.OBJECT_STORAGE) ||
hls?.storage === FileStorage.OBJECT_STORAGE ||
source?.storage === FileStorage.OBJECT_STORAGE ||
captions.some(c => c.storage === FileStorage.OBJECT_STORAGE)
},
handler: () => moveToFileSystemState({ video: videoFull, isNewVideo: false, transaction: undefined })
})
}
@ -110,7 +124,13 @@ async function createMoveJobIfNeeded (options: {
video: MVideoFullLight
type: 'to object storage' | 'to file system'
canProcessVideo: (files: MVideoFile[], hls: MStreamingPlaylist) => boolean
canProcessVideo: (options: {
files: MVideoFile[]
hls: MStreamingPlaylist
source: MVideoSource
captions: MVideoCaption[]
}) => boolean
handler: () => Promise<any>
}) {
const { video, type, canProcessVideo, handler } = options
@ -118,7 +138,10 @@ async function createMoveJobIfNeeded (options: {
const files = video.VideoFiles || []
const hls = video.getHLSPlaylist()
if (canProcessVideo(files, hls)) {
const source = await VideoSourceModel.loadLatest(video.id)
const captions = await VideoCaptionModel.listVideoCaptions(video.id)
if (canProcessVideo({ files, hls, source, captions })) {
console.log(`Moving ${type} video ${video.name}`)
const success = await handler()