diff options
Diffstat (limited to 'fbin/api.py')
-rw-r--r-- | fbin/api.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/fbin/api.py b/fbin/api.py index 8f3f86c..5659b3a 100644 --- a/fbin/api.py +++ b/fbin/api.py @@ -11,6 +11,7 @@ from .fbin import upload as fbin_upload, get_file app = Blueprint('api', __name__) + def makejson(f): @functools.wraps(f) def wrapper(*args, **kwargs): @@ -20,16 +21,17 @@ def makejson(f): return r return wrapper + @app.before_request def authenticate(): g.user = None - if not 'Authorization' in request.headers: + if 'Authorization' not in request.headers: abort(403) scheme, token = request.headers['Authorization'].split(None, 1) if scheme != 'Bearer': abort(400) try: - token = jwt.decode(token, current_app.config['SECRET_KEY'], issuer = request.url_root) + token = jwt.decode(token, current_app.config['SECRET_KEY'], issuer=request.url_root) except jwt.InvalidTokenError: abort(403) try: @@ -43,6 +45,7 @@ def authenticate(): except NoResultFound: abort(403) + def api_login_required(f): def wrapper(*args, **kwargs): if not current_user.is_authenticated: @@ -53,15 +56,17 @@ def api_login_required(f): return f(*args, **kwargs) return wrapper -@app.route('/upload', methods = ['POST']) + +@app.route('/upload', methods=['POST']) def upload(): - return fbin_upload(api = True, user = g.user) + return fbin_upload(api=True, user=g.user) + class FileAPI(MethodView): decorators = [api_login_required, makejson] def put(self, hash): - f = get_file(hash, user_id = current_user.get_id()) + f = get_file(hash, user_id=current_user.get_id()) if not f: return { 'status': False, @@ -83,8 +88,9 @@ class FileAPI(MethodView): pass # TODO: Add back FileAPI when ready. -#file_api_view = FileAPI.as_view('file_api') -#app.add_url_rule('/file/<hash>', view_func = file_api_view, methods = ['PUT', 'DELETE']) +# file_api_view = FileAPI.as_view('file_api') +# app.add_url_rule('/file/<hash>', view_func=file_api_view, methods=['PUT', 'DELETE']) + @app.route('/test') def test(): |