Add endpoint and gui button for deleting channels.

This commit is contained in:
voussoir 2020-08-10 18:30:56 -07:00
parent e42e4cac55
commit b660d700b9
3 changed files with 42 additions and 0 deletions

View file

@ -90,6 +90,16 @@ def post_add_channel():
channel = common.ycdldb.add_channel(channel_id, get_videos=True) channel = common.ycdldb.add_channel(channel_id, get_videos=True)
return jsonify.make_json_response(ycdl.jsonify.channel(channel)) return jsonify.make_json_response(ycdl.jsonify.channel(channel))
@site.route('/channel/<channel_id>/delete', methods=['POST'])
def post_delete_channel(channel_id):
try:
channel = common.ycdldb.get_channel(channel_id)
except ycdl.exceptions.NoSuchChannel as exc:
return jsonify.make_json_response(ycdl.jsonify.exception(exc), status=404)
channel.delete()
return jsonify.make_json_response({})
@site.route('/channel/<channel_id>/refresh', methods=['POST']) @site.route('/channel/<channel_id>/refresh', methods=['POST'])
def post_refresh_channel(channel_id): def post_refresh_channel(channel_id):
force = request.form.get('force', False) force = request.form.get('force', False)

View file

@ -12,6 +12,14 @@ function add_channel(channel_id, callback)
return common.post(url, data, callback); return common.post(url, data, callback);
} }
api.channels.delete_channel =
function delete_channel(channel_id, callback)
{
var url = `/channel/${channel_id}/delete`;
data = new FormData();
return common.post(url, data, callback);
}
api.channels.refresh_channel = api.channels.refresh_channel =
function refresh_channel(channel_id, force, callback) function refresh_channel(channel_id, force, callback)
{ {
@ -39,6 +47,19 @@ function set_automark(channel_id, state, callback)
return common.post(url, data, callback); return common.post(url, data, callback);
} }
api.channels.callback_go_to_channels =
function callback_go_to_channels(response)
{
if (response.meta.status === 200)
{
window.location.href = "/channels";
}
else
{
console.log(response);
}
}
/**************************************************************************************************/ /**************************************************************************************************/
api.videos = {}; api.videos = {};

View file

@ -226,6 +226,12 @@ https://stackoverflow.com/a/35153397
</div> </div>
<div id="toolbox_right"> <div id="toolbox_right">
{% if channel is not none %}
<button class="red_button button_with_confirm"
data-prompt="Delete channel and all videos?"
data-onclick="delete_channel_form();"
>Delete Channel</button>
{% endif %}
</div> </div>
@ -298,6 +304,11 @@ var DOWNLOAD_FILTER = "{{download_filter if download_filter else ""}}";
var video_card_first_selected = null; var video_card_first_selected = null;
var video_card_selections = []; var video_card_selections = [];
function delete_channel_form()
{
api.channels.delete_channel(CHANNEL_ID, api.channels.callback_go_to_channels);
}
function refresh_channel_form(force) function refresh_channel_form(force)
{ {
console.log(`Refreshing channel ${CHANNEL_ID}, force=${force}.`); console.log(`Refreshing channel ${CHANNEL_ID}, force=${force}.`);