Move make_json_response to voussoirkit.flasktools.
This commit is contained in:
parent
d2af56c3f0
commit
f2a81720bd
3 changed files with 16 additions and 20 deletions
|
@ -2,6 +2,8 @@ import flask; from flask import request
|
||||||
import itertools
|
import itertools
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from voussoirkit import flasktools
|
||||||
|
|
||||||
import ycdl
|
import ycdl
|
||||||
|
|
||||||
from .. import common
|
from .. import common
|
||||||
|
@ -13,7 +15,7 @@ site = common.site
|
||||||
def get_all_channel_names():
|
def get_all_channel_names():
|
||||||
all_channels = {channel.id: channel.name for channel in common.ycdldb.get_channels()}
|
all_channels = {channel.id: channel.name for channel in common.ycdldb.get_channels()}
|
||||||
response = {'channels': all_channels}
|
response = {'channels': all_channels}
|
||||||
return jsonify.make_json_response(response)
|
return flasktools.make_json_response(response)
|
||||||
|
|
||||||
@site.route('/channels')
|
@site.route('/channels')
|
||||||
def get_channels():
|
def get_channels():
|
||||||
|
@ -84,20 +86,20 @@ def post_add_channel():
|
||||||
try:
|
try:
|
||||||
channel_id = common.ycdldb.youtube.get_user_id(username=channel_id)
|
channel_id = common.ycdldb.youtube.get_user_id(username=channel_id)
|
||||||
except ycdl.ytapi.ChannelNotFound:
|
except ycdl.ytapi.ChannelNotFound:
|
||||||
return jsonify.make_json_response({}, status=404)
|
return flasktools.make_json_response({}, status=404)
|
||||||
|
|
||||||
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(channel.jsonify())
|
return flasktools.make_json_response(channel.jsonify())
|
||||||
|
|
||||||
@site.route('/channel/<channel_id>/delete', methods=['POST'])
|
@site.route('/channel/<channel_id>/delete', methods=['POST'])
|
||||||
def post_delete_channel(channel_id):
|
def post_delete_channel(channel_id):
|
||||||
try:
|
try:
|
||||||
channel = common.ycdldb.get_channel(channel_id)
|
channel = common.ycdldb.get_channel(channel_id)
|
||||||
except ycdl.exceptions.NoSuchChannel as exc:
|
except ycdl.exceptions.NoSuchChannel as exc:
|
||||||
return jsonify.make_json_response(exc.jsonify(), status=404)
|
return flasktools.make_json_response(exc.jsonify(), status=404)
|
||||||
|
|
||||||
channel.delete()
|
channel.delete()
|
||||||
return jsonify.make_json_response({})
|
return flasktools.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):
|
||||||
|
@ -106,17 +108,17 @@ def post_refresh_channel(channel_id):
|
||||||
try:
|
try:
|
||||||
channel = common.ycdldb.get_channel(channel_id)
|
channel = common.ycdldb.get_channel(channel_id)
|
||||||
except ycdl.exceptions.NoSuchChannel as exc:
|
except ycdl.exceptions.NoSuchChannel as exc:
|
||||||
return jsonify.make_json_response(exc.jsonify(), status=404)
|
return flasktools.make_json_response(exc.jsonify(), status=404)
|
||||||
|
|
||||||
channel.refresh(force=force)
|
channel.refresh(force=force)
|
||||||
return jsonify.make_json_response(channel.jsonify())
|
return flasktools.make_json_response(channel.jsonify())
|
||||||
|
|
||||||
@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)
|
||||||
common.ycdldb.refresh_all_channels(force=force, skip_failures=True)
|
common.ycdldb.refresh_all_channels(force=force, skip_failures=True)
|
||||||
return jsonify.make_json_response({})
|
return flasktools.make_json_response({})
|
||||||
|
|
||||||
@site.route('/channel/<channel_id>/set_automark', methods=['POST'])
|
@site.route('/channel/<channel_id>/set_automark', methods=['POST'])
|
||||||
def post_set_automark(channel_id):
|
def post_set_automark(channel_id):
|
||||||
|
@ -128,7 +130,7 @@ def post_set_automark(channel_id):
|
||||||
except ycdl.exceptions.InvalidVideoState:
|
except ycdl.exceptions.InvalidVideoState:
|
||||||
flask.abort(400)
|
flask.abort(400)
|
||||||
|
|
||||||
return jsonify.make_json_response({})
|
return flasktools.make_json_response({})
|
||||||
|
|
||||||
@site.route('/channel/<channel_id>/set_queuefile_extension', methods=['POST'])
|
@site.route('/channel/<channel_id>/set_queuefile_extension', methods=['POST'])
|
||||||
def post_set_queuefile_extension(channel_id):
|
def post_set_queuefile_extension(channel_id):
|
||||||
|
@ -137,4 +139,4 @@ def post_set_queuefile_extension(channel_id):
|
||||||
|
|
||||||
channel.set_queuefile_extension(extension)
|
channel.set_queuefile_extension(extension)
|
||||||
|
|
||||||
return jsonify.make_json_response({})
|
return flasktools.make_json_response({})
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import flask; from flask import request
|
import flask; from flask import request
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from voussoirkit import flasktools
|
||||||
|
|
||||||
import ycdl
|
import ycdl
|
||||||
|
|
||||||
from .. import common
|
from .. import common
|
||||||
|
@ -29,7 +31,7 @@ def post_mark_video_state():
|
||||||
common.ycdldb.rollback()
|
common.ycdldb.rollback()
|
||||||
flask.abort(400)
|
flask.abort(400)
|
||||||
|
|
||||||
return jsonify.make_json_response({'video_ids': video_ids, 'state': state})
|
return flasktools.make_json_response({'video_ids': video_ids, 'state': state})
|
||||||
|
|
||||||
@site.route('/start_download', methods=['POST'])
|
@site.route('/start_download', methods=['POST'])
|
||||||
def post_start_download():
|
def post_start_download():
|
||||||
|
@ -46,4 +48,4 @@ def post_start_download():
|
||||||
common.ycdldb.rollback()
|
common.ycdldb.rollback()
|
||||||
flask.abort(404)
|
flask.abort(404)
|
||||||
|
|
||||||
return jsonify.make_json_response({'video_ids': video_ids, 'state': 'downloaded'})
|
return flasktools.make_json_response({'video_ids': video_ids, 'state': 'downloaded'})
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
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
|
|
Loading…
Reference in a new issue