aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/models/video/video.ts33
-rw-r--r--server/tests/api/multiple-pods.ts10
2 files changed, 25 insertions, 18 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index b4a2b0c95..c376d769e 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -477,19 +477,26 @@ toFormattedJSON = function (this: VideoInstance) {
477 files: [] 477 files: []
478 } 478 }
479 479
480 this.VideoFiles.forEach(videoFile => { 480 // Format and sort video files
481 let resolutionLabel = VIDEO_FILE_RESOLUTIONS[videoFile.resolution] 481 json.files = this.VideoFiles
482 if (!resolutionLabel) resolutionLabel = 'Unknown' 482 .map(videoFile => {
483 483 let resolutionLabel = VIDEO_FILE_RESOLUTIONS[videoFile.resolution]
484 const videoFileJson = { 484 if (!resolutionLabel) resolutionLabel = 'Unknown'
485 resolution: videoFile.resolution, 485
486 resolutionLabel, 486 const videoFileJson = {
487 magnetUri: this.generateMagnetUri(videoFile), 487 resolution: videoFile.resolution,
488 size: videoFile.size 488 resolutionLabel,
489 } 489 magnetUri: this.generateMagnetUri(videoFile),
490 490 size: videoFile.size
491 json.files.push(videoFileJson) 491 }
492 }) 492
493 return videoFileJson
494 })
495 .sort((a, b) => {
496 if (a.resolution < b.resolution) return 1
497 if (a.resolution === b.resolution) return 0
498 return -1
499 })
493 500
494 return json 501 return json
495} 502}
diff --git a/server/tests/api/multiple-pods.ts b/server/tests/api/multiple-pods.ts
index c43793b30..08fa73aa2 100644
--- a/server/tests/api/multiple-pods.ts
+++ b/server/tests/api/multiple-pods.ts
@@ -195,27 +195,27 @@ describe('Test multiple pods', function () {
195 const originalFile = video.files.find(f => f.resolution === 0) 195 const originalFile = video.files.find(f => f.resolution === 0)
196 expect(originalFile).not.to.be.undefined 196 expect(originalFile).not.to.be.undefined
197 expect(originalFile.resolutionLabel).to.equal('original') 197 expect(originalFile.resolutionLabel).to.equal('original')
198 expect(originalFile.size).to.equal(711327) 198 expect(originalFile.size).to.be.above(700000).and.below(720000)
199 199
200 const file240p = video.files.find(f => f.resolution === 240) 200 const file240p = video.files.find(f => f.resolution === 240)
201 expect(file240p).not.to.be.undefined 201 expect(file240p).not.to.be.undefined
202 expect(file240p.resolutionLabel).to.equal('240p') 202 expect(file240p.resolutionLabel).to.equal('240p')
203 expect(file240p.size).to.equal(139953) 203 expect(file240p.size).to.be.above(130000).and.below(150000)
204 204
205 const file360p = video.files.find(f => f.resolution === 360) 205 const file360p = video.files.find(f => f.resolution === 360)
206 expect(file360p).not.to.be.undefined 206 expect(file360p).not.to.be.undefined
207 expect(file360p.resolutionLabel).to.equal('360p') 207 expect(file360p.resolutionLabel).to.equal('360p')
208 expect(file360p.size).to.equal(169926) 208 expect(file360p.size).to.be.above(160000).and.below(180000)
209 209
210 const file480p = video.files.find(f => f.resolution === 480) 210 const file480p = video.files.find(f => f.resolution === 480)
211 expect(file480p).not.to.be.undefined 211 expect(file480p).not.to.be.undefined
212 expect(file480p.resolutionLabel).to.equal('480p') 212 expect(file480p.resolutionLabel).to.equal('480p')
213 expect(file480p.size).to.equal(206758) 213 expect(file480p.size).to.be.above(200000).and.below(220000)
214 214
215 const file720p = video.files.find(f => f.resolution === 720) 215 const file720p = video.files.find(f => f.resolution === 720)
216 expect(file720p).not.to.be.undefined 216 expect(file720p).not.to.be.undefined
217 expect(file720p.resolutionLabel).to.equal('720p') 217 expect(file720p.resolutionLabel).to.equal('720p')
218 expect(file720p.size).to.equal(314913) 218 expect(file720p.size).to.be.above(310000).and.below(320000)
219 219
220 const test = await testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath) 220 const test = await testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath)
221 expect(test).to.equal(true) 221 expect(test).to.equal(true)