aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-07 09:43:18 +0200
committerChocobozzz <me@florianbigard.com>2018-06-07 09:43:18 +0200
commit28be89161aab245526d64f6fb7dd29391a97fe0a (patch)
tree1ee8bece60eea295f218cb5936141848f3a470fc /server/models/video/video.ts
parent0138af9237b77dd7d3a49260d164193b4048de84 (diff)
downloadPeerTube-28be89161aab245526d64f6fb7dd29391a97fe0a.tar.gz
PeerTube-28be89161aab245526d64f6fb7dd29391a97fe0a.tar.zst
PeerTube-28be89161aab245526d64f6fb7dd29391a97fe0a.zip
Improve create import file job
Fix federation of .ogv videos
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts27
1 files changed, 15 insertions, 12 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 2875e6685..faa6f3f9b 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -2,7 +2,7 @@ import * as Bluebird from 'bluebird'
2import { map, maxBy } from 'lodash' 2import { map, maxBy } from 'lodash'
3import * as magnetUtil from 'magnet-uri' 3import * as magnetUtil from 'magnet-uri'
4import * as parseTorrent from 'parse-torrent' 4import * as parseTorrent from 'parse-torrent'
5import { join, extname } from 'path' 5import { extname, join } from 'path'
6import * as Sequelize from 'sequelize' 6import * as Sequelize from 'sequelize'
7import { 7import {
8 AllowNull, 8 AllowNull,
@@ -30,9 +30,9 @@ import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
30import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' 30import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
31import { VideoFilter } from '../../../shared/models/videos/video-query.type' 31import { VideoFilter } from '../../../shared/models/videos/video-query.type'
32import { 32import {
33 copyFilePromise,
33 createTorrentPromise, 34 createTorrentPromise,
34 peertubeTruncate, 35 peertubeTruncate,
35 copyFilePromise,
36 renamePromise, 36 renamePromise,
37 statPromise, 37 statPromise,
38 unlinkPromise, 38 unlinkPromise,
@@ -63,6 +63,7 @@ import {
63 STATIC_PATHS, 63 STATIC_PATHS,
64 THUMBNAILS_SIZE, 64 THUMBNAILS_SIZE,
65 VIDEO_CATEGORIES, 65 VIDEO_CATEGORIES,
66 VIDEO_EXT_MIMETYPE,
66 VIDEO_LANGUAGES, 67 VIDEO_LANGUAGES,
67 VIDEO_LICENCES, 68 VIDEO_LICENCES,
68 VIDEO_PRIVACIES 69 VIDEO_PRIVACIES
@@ -1166,7 +1167,7 @@ export class VideoModel extends Model<VideoModel> {
1166 for (const file of this.VideoFiles) { 1167 for (const file of this.VideoFiles) {
1167 url.push({ 1168 url.push({
1168 type: 'Link', 1169 type: 'Link',
1169 mimeType: 'video/' + file.extname.replace('.', ''), 1170 mimeType: VIDEO_EXT_MIMETYPE[file.extname],
1170 href: this.getVideoFileUrl(file, baseUrlHttp), 1171 href: this.getVideoFileUrl(file, baseUrlHttp),
1171 width: file.resolution, 1172 width: file.resolution,
1172 size: file.size 1173 size: file.size
@@ -1328,14 +1329,18 @@ export class VideoModel extends Model<VideoModel> {
1328 await copyFilePromise(inputFilePath, outputPath) 1329 await copyFilePromise(inputFilePath, outputPath)
1329 1330
1330 const currentVideoFile = this.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution) 1331 const currentVideoFile = this.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution)
1331 const isNewVideoFile = !currentVideoFile
1332 1332
1333 if (!isNewVideoFile) { 1333 if (currentVideoFile) {
1334 if (currentVideoFile.extname !== updatedVideoFile.extname) { 1334 // Remove old file and old torrent
1335 await this.removeFile(currentVideoFile) 1335 await this.removeFile(currentVideoFile)
1336 currentVideoFile.set('extname', updatedVideoFile.extname) 1336 await this.removeTorrent(currentVideoFile)
1337 } 1337 // Remove the old video file from the array
1338 this.VideoFiles = this.VideoFiles.filter(f => f !== currentVideoFile)
1339
1340 // Update the database
1341 currentVideoFile.set('extname', updatedVideoFile.extname)
1338 currentVideoFile.set('size', updatedVideoFile.size) 1342 currentVideoFile.set('size', updatedVideoFile.size)
1343
1339 updatedVideoFile = currentVideoFile 1344 updatedVideoFile = currentVideoFile
1340 } 1345 }
1341 1346
@@ -1343,9 +1348,7 @@ export class VideoModel extends Model<VideoModel> {
1343 1348
1344 await updatedVideoFile.save() 1349 await updatedVideoFile.save()
1345 1350
1346 if (isNewVideoFile) { 1351 this.VideoFiles.push(updatedVideoFile)
1347 this.VideoFiles.push(updatedVideoFile)
1348 }
1349 } 1352 }
1350 1353
1351 getOriginalFileResolution () { 1354 getOriginalFileResolution () {