diff --git a/assets/js/handlers.js b/assets/js/handlers.js index 539974fb..67cd9081 100644 --- a/assets/js/handlers.js +++ b/assets/js/handlers.js @@ -91,7 +91,7 @@ var count = document.getElementById('count'); count.textContent--; - var url = '/token_ajax?action_revoke_token=1&redirect=false' + + var url = '/token_ajax?action=revoke_token&redirect=false' + '&referer=' + encodeURIComponent(location.href) + '&session=' + target.getAttribute('data-session'); @@ -111,7 +111,7 @@ var count = document.getElementById('count'); count.textContent--; - var url = '/subscription_ajax?action_remove_subscriptions=1&redirect=false' + + var url = '/subscription_ajax?action=remove_subscriptions&redirect=false' + '&referer=' + encodeURIComponent(location.href) + '&c=' + target.getAttribute('data-ucid'); diff --git a/assets/js/playlist_widget.js b/assets/js/playlist_widget.js index c92592ac..96a51d70 100644 --- a/assets/js/playlist_widget.js +++ b/assets/js/playlist_widget.js @@ -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'); diff --git a/assets/js/subscribe_widget.js b/assets/js/subscribe_widget.js index 7665a00b..d462e848 100644 --- a/assets/js/subscribe_widget.js +++ b/assets/js/subscribe_widget.js @@ -16,7 +16,7 @@ function subscribe() { subscribe_button.onclick = unsubscribe; subscribe_button.innerHTML = '' + subscribe_data.unsubscribe_text + ' | ' + subscribe_data.sub_count_text + ''; - var url = '/subscription_ajax?action_create_subscription_to_channel=1&redirect=false' + + var url = '/subscription_ajax?action=create_subscription_to_channel&redirect=false' + '&c=' + subscribe_data.ucid; helpers.xhr('POST', url, {payload: payload, retries: 5, entity_name: 'subscribe request'}, { @@ -32,7 +32,7 @@ function unsubscribe() { subscribe_button.onclick = subscribe; subscribe_button.innerHTML = '' + subscribe_data.subscribe_text + ' | ' + subscribe_data.sub_count_text + ''; - var url = '/subscription_ajax?action_remove_subscriptions=1&redirect=false' + + var url = '/subscription_ajax?action=remove_subscriptions&redirect=false' + '&c=' + subscribe_data.ucid; helpers.xhr('POST', url, {payload: payload, retries: 5, entity_name: 'unsubscribe request'}, { diff --git a/assets/js/watched_widget.js b/assets/js/watched_widget.js index f1ac9cb4..06af62cc 100644 --- a/assets/js/watched_widget.js +++ b/assets/js/watched_widget.js @@ -6,7 +6,7 @@ function mark_watched(target) { var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode; tile.style.display = 'none'; - var url = '/watch_ajax?action_mark_watched=1&redirect=false' + + var url = '/watch_ajax?action=mark_watched&redirect=false' + '&id=' + target.getAttribute('data-id'); helpers.xhr('POST', url, {payload: payload}, { @@ -22,7 +22,7 @@ function mark_unwatched(target) { var count = document.getElementById('count'); count.textContent--; - var url = '/watch_ajax?action_mark_unwatched=1&redirect=false' + + var url = '/watch_ajax?action=mark_unwatched&redirect=false' + '&id=' + target.getAttribute('data-id'); helpers.xhr('POST', url, {payload: payload}, { diff --git a/src/invidious/routes/account.cr b/src/invidious/routes/account.cr index dd65e7a6..c8db207c 100644 --- a/src/invidious/routes/account.cr +++ b/src/invidious/routes/account.cr @@ -328,17 +328,9 @@ module Invidious::Routes::Account end end - if env.params.query["action_revoke_token"]? - action = "action_revoke_token" - else - return env.redirect referer - end - - session = env.params.query["session"]? - session ||= "" - - case action - when .starts_with? "action_revoke_token" + case action = env.params.query["action"]? + when "revoke_token" + session = env.params.query["session"] Invidious::Database::SessionIDs.delete(sid: session, email: user.email) else return error_json(400, "Unsupported action #{action}") diff --git a/src/invidious/routes/playlists.cr b/src/invidious/routes/playlists.cr index 9c6843e9..f2213da4 100644 --- a/src/invidious/routes/playlists.cr +++ b/src/invidious/routes/playlists.cr @@ -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 diff --git a/src/invidious/routes/subscriptions.cr b/src/invidious/routes/subscriptions.cr index 7f9ec592..1de655d2 100644 --- a/src/invidious/routes/subscriptions.cr +++ b/src/invidious/routes/subscriptions.cr @@ -32,24 +32,16 @@ module Invidious::Routes::Subscriptions end end - if env.params.query["action_create_subscription_to_channel"]?.try &.to_i?.try &.== 1 - action = "action_create_subscription_to_channel" - elsif env.params.query["action_remove_subscriptions"]?.try &.to_i?.try &.== 1 - action = "action_remove_subscriptions" - else - return env.redirect referer - end - channel_id = env.params.query["c"]? channel_id ||= "" - case action - when "action_create_subscription_to_channel" + case action = env.params.query["action"]? + when "create_subscription_to_channel" if !user.subscriptions.includes? channel_id get_channel(channel_id) Invidious::Database::Users.subscribe_channel(user, channel_id) end - when "action_remove_subscriptions" + when "remove_subscriptions" Invidious::Database::Users.unsubscribe_channel(user, channel_id) else return error_json(400, "Unsupported action #{action}") diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index aabe8dfc..27b96730 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -241,18 +241,10 @@ module Invidious::Routes::Watch end end - if env.params.query["action_mark_watched"]? - action = "action_mark_watched" - elsif env.params.query["action_mark_unwatched"]? - action = "action_mark_unwatched" - else - return env.redirect referer - end - - case action - when "action_mark_watched" + case action = env.params.query["action"]? + when "mark_watched" Invidious::Database::Users.mark_watched(user, id) - when "action_mark_unwatched" + when "mark_unwatched" Invidious::Database::Users.mark_unwatched(user, id) else return error_json(400, "Unsupported action #{action}") diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index 6d227cfc..c966a926 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -128,7 +128,7 @@