Move make_json_response into new jsonify.py.
This commit is contained in:
parent
c7ef2dd41b
commit
d407326392
2 changed files with 13 additions and 10 deletions
8
frontends/ycdl_flask/backend/jsonify.py
Normal file
8
frontends/ycdl_flask/backend/jsonify.py
Normal file
|
@ -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
|
|
@ -20,6 +20,7 @@ import ycdl
|
||||||
from voussoirkit import pathclass
|
from voussoirkit import pathclass
|
||||||
|
|
||||||
from . import jinja_filters
|
from . import jinja_filters
|
||||||
|
from . import jsonify
|
||||||
|
|
||||||
root_dir = pathclass.Path(__file__).parent.parent
|
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):
|
def send_file(filepath):
|
||||||
'''
|
'''
|
||||||
Range-enabled file sending.
|
Range-enabled file sending.
|
||||||
|
@ -218,14 +213,14 @@ def post_mark_video_state():
|
||||||
ycdldb.rollback()
|
ycdldb.rollback()
|
||||||
flask.abort(400)
|
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'])
|
@site.route('/refresh_all_channels', methods=['POST'])
|
||||||
def post_refresh_all_channels():
|
def post_refresh_all_channels():
|
||||||
force = request.form.get('force', False)
|
force = request.form.get('force', False)
|
||||||
force = ycdl.helpers.truthystring(force)
|
force = ycdl.helpers.truthystring(force)
|
||||||
ycdldb.refresh_all_channels(force=force)
|
ycdldb.refresh_all_channels(force=force)
|
||||||
return make_json_response({})
|
return jsonify.make_json_response({})
|
||||||
|
|
||||||
@site.route('/refresh_channel', methods=['POST'])
|
@site.route('/refresh_channel', methods=['POST'])
|
||||||
def post_refresh_channel():
|
def post_refresh_channel():
|
||||||
|
@ -246,7 +241,7 @@ def post_refresh_channel():
|
||||||
force = ycdl.helpers.truthystring(force)
|
force = ycdl.helpers.truthystring(force)
|
||||||
ycdldb.add_channel(channel_id, commit=False)
|
ycdldb.add_channel(channel_id, commit=False)
|
||||||
ycdldb.refresh_channel(channel_id, force=force)
|
ycdldb.refresh_channel(channel_id, force=force)
|
||||||
return make_json_response({})
|
return jsonify.make_json_response({})
|
||||||
|
|
||||||
@site.route('/start_download', methods=['POST'])
|
@site.route('/start_download', methods=['POST'])
|
||||||
def post_start_download():
|
def post_start_download():
|
||||||
|
@ -263,7 +258,7 @@ def post_start_download():
|
||||||
ycdldb.rollback()
|
ycdldb.rollback()
|
||||||
flask.abort(404)
|
flask.abort(404)
|
||||||
|
|
||||||
return make_json_response({'video_ids': video_ids, 'state': 'downloaded'})
|
return jsonify.make_json_response({'video_ids': video_ids, 'state': 'downloaded'})
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
Loading…
Reference in a new issue