mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-30 10:42:33 +05:30
Routes: Simplify actions in playlist_ajax
This commit is contained in:
parent
d8b893e9ad
commit
7e4b3b182a
@ -6,7 +6,7 @@ function add_playlist_video(target) {
|
||||
var select = target.parentNode.children[0].children[1];
|
||||
var option = select.children[select.selectedIndex];
|
||||
|
||||
var url = '/playlist_ajax?action_add_video=1&redirect=false' +
|
||||
var url = '/playlist_ajax?action=add_video&redirect=false' +
|
||||
'&video_id=' + target.getAttribute('data-id') +
|
||||
'&playlist_id=' + option.getAttribute('data-plid');
|
||||
|
||||
@ -21,7 +21,7 @@ function add_playlist_item(target) {
|
||||
var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode;
|
||||
tile.style.display = 'none';
|
||||
|
||||
var url = '/playlist_ajax?action_add_video=1&redirect=false' +
|
||||
var url = '/playlist_ajax?action=add_video&redirect=false' +
|
||||
'&video_id=' + target.getAttribute('data-id') +
|
||||
'&playlist_id=' + target.getAttribute('data-plid');
|
||||
|
||||
@ -36,7 +36,7 @@ function remove_playlist_item(target) {
|
||||
var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode;
|
||||
tile.style.display = 'none';
|
||||
|
||||
var url = '/playlist_ajax?action_remove_video=1&redirect=false' +
|
||||
var url = '/playlist_ajax?action=remove_video&redirect=false' +
|
||||
'&set_video_id=' + target.getAttribute('data-index') +
|
||||
'&playlist_id=' + target.getAttribute('data-plid');
|
||||
|
||||
|
@ -304,23 +304,6 @@ module Invidious::Routes::Playlists
|
||||
end
|
||||
end
|
||||
|
||||
if env.params.query["action_create_playlist"]?
|
||||
action = "action_create_playlist"
|
||||
elsif env.params.query["action_delete_playlist"]?
|
||||
action = "action_delete_playlist"
|
||||
elsif env.params.query["action_edit_playlist"]?
|
||||
action = "action_edit_playlist"
|
||||
elsif env.params.query["action_add_video"]?
|
||||
action = "action_add_video"
|
||||
video_id = env.params.query["video_id"]
|
||||
elsif env.params.query["action_remove_video"]?
|
||||
action = "action_remove_video"
|
||||
elsif env.params.query["action_move_video_before"]?
|
||||
action = "action_move_video_before"
|
||||
else
|
||||
return env.redirect referer
|
||||
end
|
||||
|
||||
begin
|
||||
playlist_id = env.params.query["playlist_id"]
|
||||
playlist = get_playlist(playlist_id).as(InvidiousPlaylist)
|
||||
@ -335,12 +318,8 @@ module Invidious::Routes::Playlists
|
||||
end
|
||||
end
|
||||
|
||||
email = user.email
|
||||
|
||||
case action
|
||||
when "action_edit_playlist"
|
||||
# TODO: Playlist stub
|
||||
when "action_add_video"
|
||||
case action = env.params.query["action"]?
|
||||
when "add_video"
|
||||
if playlist.index.size >= CONFIG.playlist_length_limit
|
||||
if redirect
|
||||
return error_template(400, "Playlist cannot have more than #{CONFIG.playlist_length_limit} videos")
|
||||
@ -377,12 +356,14 @@ module Invidious::Routes::Playlists
|
||||
|
||||
Invidious::Database::PlaylistVideos.insert(playlist_video)
|
||||
Invidious::Database::Playlists.update_video_added(playlist_id, playlist_video.index)
|
||||
when "action_remove_video"
|
||||
when "remove_video"
|
||||
index = env.params.query["set_video_id"]
|
||||
Invidious::Database::PlaylistVideos.delete(index)
|
||||
Invidious::Database::Playlists.update_video_removed(playlist_id, index)
|
||||
when "action_move_video_before"
|
||||
when "move_video_before"
|
||||
# TODO: Playlist stub
|
||||
when nil
|
||||
return error_json(400, "Missing action")
|
||||
else
|
||||
return error_json(400, "Unsupported action #{action}")
|
||||
end
|
||||
|
@ -138,14 +138,14 @@
|
||||
<%- end -%>
|
||||
|
||||
<%- if plid_form = env.get?("add_playlist_items") -%>
|
||||
<%- form_parameters = "action_add_video=1&video_id=#{item.id}&playlist_id=#{plid_form}&referer=#{env.get("current_page")}" -%>
|
||||
<%- form_parameters = "action=add_video&video_id=#{item.id}&playlist_id=#{plid_form}&referer=#{env.get("current_page")}" -%>
|
||||
<form data-onsubmit="return_false" action="/playlist_ajax?<%= form_parameters %>" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<%= HTML.escape(env.get?("csrf_token").try &.as(String) || "") %>">
|
||||
<button type="submit" class="pure-button pure-button-secondary low-profile"
|
||||
data-onclick="add_playlist_item" data-id="<%= item.id %>" data-plid="<%= plid_form %>"><i class="icon ion-md-add"></i></button>
|
||||
</form>
|
||||
<%- elsif item.is_a?(PlaylistVideo) && (plid_form = env.get?("remove_playlist_items")) -%>
|
||||
<%- form_parameters = "action_remove_video=1&set_video_id=#{item.index}&playlist_id=#{plid_form}&referer=#{env.get("current_page")}" -%>
|
||||
<%- form_parameters = "action=remove_video&set_video_id=#{item.index}&playlist_id=#{plid_form}&referer=#{env.get("current_page")}" -%>
|
||||
<form data-onsubmit="return_false" action="/playlist_ajax?<%= form_parameters %>" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<%= HTML.escape(env.get?("csrf_token").try &.as(String) || "") %>">
|
||||
<button type="submit" class="pure-button pure-button-secondary low-profile"
|
||||
|
@ -169,7 +169,7 @@ we're going to need to do it here in order to allow for translations.
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="csrf_token" value="<%= URI.encode_www_form(env.get?("csrf_token").try &.as(String) || "") %>">
|
||||
<input type="hidden" name="action_add_video" value="1">
|
||||
<input type="hidden" name="action" value="add_video">
|
||||
<input type="hidden" name="video_id" value="<%= video.id %>">
|
||||
<button data-onclick="add_playlist_video" data-id="<%= video.id %>" type="submit" class="pure-button pure-button-primary">
|
||||
<b><%= translate(locale, "Add to playlist") %></b>
|
||||
|
Loading…
Reference in New Issue
Block a user