diff --git a/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py b/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py index daf7357..9cb3a7a 100644 --- a/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py +++ b/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py @@ -71,11 +71,9 @@ def get_channel(channel_id=None, download_filter=None): videos=videos, ) -@site.route('/refresh_channel', methods=['POST']) -def post_refresh_channel(): - if 'channel_id' not in request.form: - flask.abort(400) - channel_id = request.form['channel_id'] +@site.route('/add_channel', methods=['POST']) +def post_add_channel(): + channel_id = request.form.get('channel_id', '') channel_id = channel_id.strip() if not channel_id: flask.abort(400) @@ -86,11 +84,20 @@ def post_refresh_channel(): except IndexError: flask.abort(404) + channel = common.ycdldb.add_channel(channel_id, get_videos=True) + return jsonify.make_json_response(ycdl.jsonify.channel(channel)) + +@site.route('/channel//refresh', methods=['POST']) +def post_refresh_channel(channel_id): force = request.form.get('force', False) force = ycdl.helpers.truthystring(force) - channel = common.ycdldb.add_channel(channel_id, commit=False) + 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.refresh(force=force) - return jsonify.make_json_response({}) + return jsonify.make_json_response(ycdl.jsonify.channel(channel)) @site.route('/refresh_all_channels', methods=['POST']) def post_refresh_all_channels(): diff --git a/frontends/ycdl_flask/templates/channel.html b/frontends/ycdl_flask/templates/channel.html index cc32a93..464a317 100644 --- a/frontends/ycdl_flask/templates/channel.html +++ b/frontends/ycdl_flask/templates/channel.html @@ -483,16 +483,14 @@ function receive_action_response(response) function refresh_channel(channel_id, force, callback) { - var url = "/refresh_channel"; + var url = `/channel/${channel_id}/refresh`; data = new FormData(); - data.append("channel_id", channel_id); data.append("force", force) return common.post(url, data, callback); } function set_automark_hook(event) { - console.log("What"); var url = "/channel/{{channel.id}}/set_automark"; data = new FormData(); data.append("state", event.target.value); diff --git a/frontends/ycdl_flask/templates/channels.html b/frontends/ycdl_flask/templates/channels.html index 63540e1..e87087e 100644 --- a/frontends/ycdl_flask/templates/channels.html +++ b/frontends/ycdl_flask/templates/channels.html @@ -52,7 +52,7 @@
- +
{% for channel in channels %} {% if channel.has_pending() %} @@ -75,20 +75,27 @@ var box = document.getElementById('new_channel_textbox'); var button = document.getElementById('new_channel_button'); common.bind_box_to_button(box, button); -function _new_channel_submit() +function add_channel_form(event) { if (box.value !== "") { - refresh_channel(box.value, true, function(){location.reload()}); + add_channel(box.value, add_channel_callback); } } -function refresh_channel(channel_id, force, callback) +function add_channel_callback(response) { - var url = "/refresh_channel"; + if (response["meta"]["status"] == 200) + { + window.location.href = "/channel/" + response["data"]["id"]; + } +} + +function add_channel(channel_id, callback) +{ + var url = "/add_channel"; data = new FormData(); data.append("channel_id", channel_id); - data.append("force", force) return common.post(url, data, callback); }