mirror of
https://github.com/iv-org/invidious.git
synced 2026-03-31 15:18:30 -05:00
fix(playlists): prevent duplicate videos in the same playlist
Check if the video already exists in the playlist before inserting. Uses the existing select_index() query. Returns 409 via the API and silently redirects back on the web UI. Applied to both the web route (playlist_ajax) and the API v1 route (POST /api/v1/auth/playlists/:plid/videos).
This commit is contained in:
parent
0eb941f498
commit
58ced289d3
@ -313,6 +313,11 @@ module Invidious::Routes::API::V1::Authenticated
|
|||||||
return error_json(403, "Invalid videoId")
|
return error_json(403, "Invalid videoId")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Prevent duplicate videos in the same playlist
|
||||||
|
if Invidious::Database::PlaylistVideos.select_index(plid, video_id)
|
||||||
|
return error_json(409, "Video already exists in this playlist")
|
||||||
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(video_id)
|
video = get_video(video_id)
|
||||||
rescue ex : NotFoundException
|
rescue ex : NotFoundException
|
||||||
|
|||||||
@ -330,6 +330,15 @@ module Invidious::Routes::Playlists
|
|||||||
|
|
||||||
video_id = env.params.query["video_id"]
|
video_id = env.params.query["video_id"]
|
||||||
|
|
||||||
|
# Prevent duplicate videos in the same playlist
|
||||||
|
if Invidious::Database::PlaylistVideos.select_index(playlist_id, video_id)
|
||||||
|
if redirect
|
||||||
|
return env.redirect referer
|
||||||
|
else
|
||||||
|
return error_json(409, "Video already exists in this playlist")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(video_id)
|
video = get_video(video_id)
|
||||||
rescue ex : NotFoundException
|
rescue ex : NotFoundException
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user