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

Add video files migration

This commit is contained in:
Chocobozzz 2021-02-17 09:36:09 +01:00 committed by Chocobozzz
parent 90a8bd305d
commit 2451916e45
5 changed files with 74 additions and 23 deletions

View file

@ -4,7 +4,7 @@ import { extname } from 'path'
import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
import { UserModel } from '@server/models/account/user'
import { MVideoFile, MVideoFullLight } from '@server/types/models'
import { MVideoFullLight } from '@server/types/models'
import { VideoFileImportPayload } from '@shared/models'
import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils'
import { logger } from '../../../helpers/logger'
@ -56,16 +56,8 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
const fps = await getVideoFileFPS(inputFilePath)
const fileExt = extname(inputFilePath)
let updatedVideoFile = new VideoFileModel({
resolution: videoFileResolution,
extname: fileExt,
filename: generateVideoFilename(video, false, videoFileResolution, fileExt),
size,
fps,
videoId: video.id
}) as MVideoFile
const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution)
const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === videoFileResolution)
if (currentVideoFile) {
// Remove old file and old torrent
@ -74,20 +66,23 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
// Remove the old video file from the array
video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile)
// Update the database
currentVideoFile.extname = updatedVideoFile.extname
currentVideoFile.size = updatedVideoFile.size
currentVideoFile.fps = updatedVideoFile.fps
updatedVideoFile = currentVideoFile
await currentVideoFile.destroy()
}
const outputPath = getVideoFilePath(video, updatedVideoFile)
const newVideoFile = new VideoFileModel({
resolution: videoFileResolution,
extname: fileExt,
filename: generateVideoFilename(video, false, videoFileResolution, fileExt),
size,
fps,
videoId: video.id
})
const outputPath = getVideoFilePath(video, newVideoFile)
await copy(inputFilePath, outputPath)
await createTorrentAndSetInfoHash(video, video, updatedVideoFile)
video.VideoFiles.push(newVideoFile)
await createTorrentAndSetInfoHash(video, video, newVideoFile)
await updatedVideoFile.save()
video.VideoFiles.push(updatedVideoFile)
await newVideoFile.save()
}