aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-17 09:36:09 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-18 13:38:09 +0100
commit2451916e45420fedf556913ce121f3964c4b57d6 (patch)
treec8a0e35285cac08acc0a2f3fefb33a27006e9df5 /server/lib/job-queue
parent90a8bd305de4153ec21137a73ff482dcc2e3e19b (diff)
downloadPeerTube-2451916e45420fedf556913ce121f3964c4b57d6.tar.gz
PeerTube-2451916e45420fedf556913ce121f3964c4b57d6.tar.zst
PeerTube-2451916e45420fedf556913ce121f3964c4b57d6.zip
Add video files migration
Diffstat (limited to 'server/lib/job-queue')
-rw-r--r--server/lib/job-queue/handlers/video-file-import.ts37
1 files changed, 16 insertions, 21 deletions
diff --git a/server/lib/job-queue/handlers/video-file-import.ts b/server/lib/job-queue/handlers/video-file-import.ts
index 86c9b5c29..839916306 100644
--- a/server/lib/job-queue/handlers/video-file-import.ts
+++ b/server/lib/job-queue/handlers/video-file-import.ts
@@ -4,7 +4,7 @@ import { extname } from 'path'
4import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 4import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
5import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' 5import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
6import { UserModel } from '@server/models/account/user' 6import { UserModel } from '@server/models/account/user'
7import { MVideoFile, MVideoFullLight } from '@server/types/models' 7import { MVideoFullLight } from '@server/types/models'
8import { VideoFileImportPayload } from '@shared/models' 8import { VideoFileImportPayload } from '@shared/models'
9import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' 9import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils'
10import { logger } from '../../../helpers/logger' 10import { logger } from '../../../helpers/logger'
@@ -56,16 +56,8 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
56 const fps = await getVideoFileFPS(inputFilePath) 56 const fps = await getVideoFileFPS(inputFilePath)
57 57
58 const fileExt = extname(inputFilePath) 58 const fileExt = extname(inputFilePath)
59 let updatedVideoFile = new VideoFileModel({
60 resolution: videoFileResolution,
61 extname: fileExt,
62 filename: generateVideoFilename(video, false, videoFileResolution, fileExt),
63 size,
64 fps,
65 videoId: video.id
66 }) as MVideoFile
67 59
68 const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution) 60 const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === videoFileResolution)
69 61
70 if (currentVideoFile) { 62 if (currentVideoFile) {
71 // Remove old file and old torrent 63 // Remove old file and old torrent
@@ -74,20 +66,23 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
74 // Remove the old video file from the array 66 // Remove the old video file from the array
75 video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile) 67 video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile)
76 68
77 // Update the database 69 await currentVideoFile.destroy()
78 currentVideoFile.extname = updatedVideoFile.extname
79 currentVideoFile.size = updatedVideoFile.size
80 currentVideoFile.fps = updatedVideoFile.fps
81
82 updatedVideoFile = currentVideoFile
83 } 70 }
84 71
85 const outputPath = getVideoFilePath(video, updatedVideoFile) 72 const newVideoFile = new VideoFileModel({
86 await copy(inputFilePath, outputPath) 73 resolution: videoFileResolution,
74 extname: fileExt,
75 filename: generateVideoFilename(video, false, videoFileResolution, fileExt),
76 size,
77 fps,
78 videoId: video.id
79 })
87 80
88 await createTorrentAndSetInfoHash(video, video, updatedVideoFile) 81 const outputPath = getVideoFilePath(video, newVideoFile)
82 await copy(inputFilePath, outputPath)
89 83
90 await updatedVideoFile.save() 84 video.VideoFiles.push(newVideoFile)
85 await createTorrentAndSetInfoHash(video, video, newVideoFile)
91 86
92 video.VideoFiles.push(updatedVideoFile) 87 await newVideoFile.save()
93} 88}