mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-09 17:58:23 +00:00
API: Fix out of bound error on empty playlists (#4696)
Before this PR, Invidious assumed that every playlist had at least one video. When a playlist had no videos, Invidious was throwing an "Index out of bounds" exception. The following API endpoints were impacted: * api/v1/playlists/:plid * api/v1/auth/playlists/:plid Fixes issue 4679
This commit is contained in:
commit
4f60feee17
@ -74,7 +74,9 @@ module Invidious::Routes::API::V1::Misc
|
|||||||
response = playlist.to_json(offset, video_id: video_id)
|
response = playlist.to_json(offset, video_id: video_id)
|
||||||
json_response = JSON.parse(response)
|
json_response = JSON.parse(response)
|
||||||
|
|
||||||
if json_response["videos"].as_a[0]["index"] != offset
|
if json_response["videos"].as_a.empty?
|
||||||
|
json_response = JSON.parse(response)
|
||||||
|
elsif json_response["videos"].as_a[0]["index"] != offset
|
||||||
offset = json_response["videos"].as_a[0]["index"].as_i
|
offset = json_response["videos"].as_a[0]["index"].as_i
|
||||||
lookback = offset < 50 ? offset : 50
|
lookback = offset < 50 ? offset : 50
|
||||||
response = playlist.to_json(offset - lookback)
|
response = playlist.to_json(offset - lookback)
|
||||||
|
Loading…
Reference in New Issue
Block a user