From d407326392379c124399a7b0692ff8f4a0a6b020 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 28 Mar 2020 16:51:40 -0700 Subject: [PATCH] Move make_json_response into new jsonify.py. --- frontends/ycdl_flask/backend/jsonify.py | 8 ++++++++ frontends/ycdl_flask/backend/ycdl_flask.py | 15 +++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 frontends/ycdl_flask/backend/jsonify.py diff --git a/frontends/ycdl_flask/backend/jsonify.py b/frontends/ycdl_flask/backend/jsonify.py new file mode 100644 index 0000000..6faaaf9 --- /dev/null +++ b/frontends/ycdl_flask/backend/jsonify.py @@ -0,0 +1,8 @@ +import flask +import json + +def make_json_response(j, *args, **kwargs): + dumped = json.dumps(j) + response = flask.Response(dumped, *args, **kwargs) + response.headers['Content-Type'] = 'application/json;charset=utf-8' + return response diff --git a/frontends/ycdl_flask/backend/ycdl_flask.py b/frontends/ycdl_flask/backend/ycdl_flask.py index 61e1fe0..96ad0bb 100644 --- a/frontends/ycdl_flask/backend/ycdl_flask.py +++ b/frontends/ycdl_flask/backend/ycdl_flask.py @@ -20,6 +20,7 @@ import ycdl from voussoirkit import pathclass from . import jinja_filters +from . import jsonify root_dir = pathclass.Path(__file__).parent.parent @@ -48,12 +49,6 @@ site.debug = True #################################################################################################### #################################################################################################### -def make_json_response(j, *args, **kwargs): - dumped = json.dumps(j) - response = flask.Response(dumped, *args, **kwargs) - response.headers['Content-Type'] = 'application/json;charset=utf-8' - return response - def send_file(filepath): ''' Range-enabled file sending. @@ -218,14 +213,14 @@ def post_mark_video_state(): ycdldb.rollback() flask.abort(400) - return make_json_response({'video_ids': video_ids, 'state': state}) + return jsonify.make_json_response({'video_ids': video_ids, 'state': state}) @site.route('/refresh_all_channels', methods=['POST']) def post_refresh_all_channels(): force = request.form.get('force', False) force = ycdl.helpers.truthystring(force) ycdldb.refresh_all_channels(force=force) - return make_json_response({}) + return jsonify.make_json_response({}) @site.route('/refresh_channel', methods=['POST']) def post_refresh_channel(): @@ -246,7 +241,7 @@ def post_refresh_channel(): force = ycdl.helpers.truthystring(force) ycdldb.add_channel(channel_id, commit=False) ycdldb.refresh_channel(channel_id, force=force) - return make_json_response({}) + return jsonify.make_json_response({}) @site.route('/start_download', methods=['POST']) def post_start_download(): @@ -263,7 +258,7 @@ def post_start_download(): ycdldb.rollback() flask.abort(404) - return make_json_response({'video_ids': video_ids, 'state': 'downloaded'}) + return jsonify.make_json_response({'video_ids': video_ids, 'state': 'downloaded'}) #################################################################################################### ####################################################################################################