From b42c2c7e89a64ed730d8140840fe74a13c31f2a4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 9 Aug 2022 09:09:31 +0200 Subject: Avoid concurrency issue on transcoding --- server/models/video/video.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'server/models') 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>> { } getQualityFileBy (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) { - // We first transcode to WebTorrent format, so try this array first - if (Array.isArray(this.VideoFiles) && this.VideoFiles.length !== 0) { - const file = fun(this.VideoFiles, file => file.resolution) + const files = this.getAllFiles() + const file = fun(files, file => file.resolution) + if (!file) return undefined + if (file.videoId) { return Object.assign(file, { Video: this }) } - // No webtorrent files, try with streaming playlist files - if (Array.isArray(this.VideoStreamingPlaylists) && this.VideoStreamingPlaylists.length !== 0) { + if (file.videoStreamingPlaylistId) { const streamingPlaylistWithVideo = Object.assign(this.VideoStreamingPlaylists[0], { Video: this }) - const file = fun(streamingPlaylistWithVideo.VideoFiles, file => file.resolution) return Object.assign(file, { VideoStreamingPlaylist: streamingPlaylistWithVideo }) } - return undefined + throw new Error('File is not associated to a video of a playlist') } getMaxQualityFile (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo { -- cgit v1.2.3