diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video.ts | 27 |
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' | |||
2 | import { map, maxBy } from 'lodash' | 2 | import { map, maxBy } from 'lodash' |
3 | import * as magnetUtil from 'magnet-uri' | 3 | import * as magnetUtil from 'magnet-uri' |
4 | import * as parseTorrent from 'parse-torrent' | 4 | import * as parseTorrent from 'parse-torrent' |
5 | import { join, extname } from 'path' | 5 | import { extname, join } from 'path' |
6 | import * as Sequelize from 'sequelize' | 6 | import * as Sequelize from 'sequelize' |
7 | import { | 7 | import { |
8 | AllowNull, | 8 | AllowNull, |
@@ -30,9 +30,9 @@ import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | |||
30 | import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' | 30 | import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' |
31 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' | 31 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' |
32 | import { | 32 | import { |
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 () { |