aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-09 09:09:31 +0200
committerChocobozzz <me@florianbigard.com>2022-08-09 09:32:17 +0200
commitb42c2c7e89a64ed730d8140840fe74a13c31f2a4 (patch)
tree715e7ad31d03881e3f3530dba1fe3d172251249b /server/models/video
parentbd911b54b555b11df7e9849cf92d358bccfecf6e (diff)
downloadPeerTube-b42c2c7e89a64ed730d8140840fe74a13c31f2a4.tar.gz
PeerTube-b42c2c7e89a64ed730d8140840fe74a13c31f2a4.tar.zst
PeerTube-b42c2c7e89a64ed730d8140840fe74a13c31f2a4.zip
Avoid concurrency issue on transcoding
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video.ts13
1 files changed, 6 insertions, 7 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index b8e383502..a8ea67c39 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1592,22 +1592,21 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
1592 } 1592 }
1593 1593
1594 getQualityFileBy<T extends MVideoWithFile> (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) { 1594 getQualityFileBy<T extends MVideoWithFile> (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) {
1595 // We first transcode to WebTorrent format, so try this array first 1595 const files = this.getAllFiles()
1596 if (Array.isArray(this.VideoFiles) && this.VideoFiles.length !== 0) { 1596 const file = fun(files, file => file.resolution)
1597 const file = fun(this.VideoFiles, file => file.resolution) 1597 if (!file) return undefined
1598 1598
1599 if (file.videoId) {
1599 return Object.assign(file, { Video: this }) 1600 return Object.assign(file, { Video: this })
1600 } 1601 }
1601 1602
1602 // No webtorrent files, try with streaming playlist files 1603 if (file.videoStreamingPlaylistId) {
1603 if (Array.isArray(this.VideoStreamingPlaylists) && this.VideoStreamingPlaylists.length !== 0) {
1604 const streamingPlaylistWithVideo = Object.assign(this.VideoStreamingPlaylists[0], { Video: this }) 1604 const streamingPlaylistWithVideo = Object.assign(this.VideoStreamingPlaylists[0], { Video: this })
1605 1605
1606 const file = fun(streamingPlaylistWithVideo.VideoFiles, file => file.resolution)
1607 return Object.assign(file, { VideoStreamingPlaylist: streamingPlaylistWithVideo }) 1606 return Object.assign(file, { VideoStreamingPlaylist: streamingPlaylistWithVideo })
1608 } 1607 }
1609 1608
1610 return undefined 1609 throw new Error('File is not associated to a video of a playlist')
1611 } 1610 }
1612 1611
1613 getMaxQualityFile<T extends MVideoWithFile> (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo { 1612 getMaxQualityFile<T extends MVideoWithFile> (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo {