import { copy, stat } from 'fs-extra'
import { VideoFileModel } from '../../../models/video/video-file'
import { extname } from 'path'
-
-export type VideoFileImportPayload = {
- videoUUID: string,
- filePath: string
-}
+import { MVideoFile, MVideoWithFile } from '@server/types/models'
+import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
+import { getVideoFilePath } from '@server/lib/video-paths'
+import { VideoFileImportPayload } from '@shared/models'
async function processVideoFileImport (job: Bull.Job) {
const payload = job.data as VideoFileImportPayload
// ---------------------------------------------------------------------------
-async function updateVideoFile (video: VideoModel, inputFilePath: string) {
+async function updateVideoFile (video: MVideoWithFile, inputFilePath: string) {
const { videoFileResolution } = await getVideoFileResolution(inputFilePath)
const { size } = await stat(inputFilePath)
const fps = await getVideoFileFPS(inputFilePath)
size,
fps,
videoId: video.id
- })
+ }) as MVideoFile
const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution)
video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile)
// Update the database
- currentVideoFile.set('extname', updatedVideoFile.extname)
- currentVideoFile.set('size', updatedVideoFile.size)
- currentVideoFile.set('fps', updatedVideoFile.fps)
+ currentVideoFile.extname = updatedVideoFile.extname
+ currentVideoFile.size = updatedVideoFile.size
+ currentVideoFile.fps = updatedVideoFile.fps
updatedVideoFile = currentVideoFile
}
- const outputPath = video.getVideoFilePath(updatedVideoFile)
+ const outputPath = getVideoFilePath(video, updatedVideoFile)
await copy(inputFilePath, outputPath)
- await video.createTorrentAndSetInfoHash(updatedVideoFile)
+ await createTorrentAndSetInfoHash(video, updatedVideoFile)
await updatedVideoFile.save()