From b36f9c05071ea549ed59e703270fcf223b60df03 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 9 Apr 2017 09:02:09 +0200 Subject: Major rewrite to use jab/oauth. Highlights: - Uses the oauth branch of jab. - Changed design to use bootstrap. - Some minor changes to functionality in file uploading and listing. - API is currently disabled and incomplete. --- fbin/api.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 fbin/api.py (limited to 'fbin/api.py') diff --git a/fbin/api.py b/fbin/api.py new file mode 100644 index 0000000..e652019 --- /dev/null +++ b/fbin/api.py @@ -0,0 +1,62 @@ +import functools + +from flask import Blueprint, current_app, request, jsonify +from flask.views import MethodView +from flask_login import current_user + +from . import db +# FIXME +from .fbin import get_file + +app = Blueprint('api', __name__) + +# TODO: Implement this stuff. + +def makejson(f): + @functools.wraps(f) + def wrapper(*args, **kwargs): + r = f(*args, **kwargs) + if isinstance(r, dict): + r = jsonify(r) + return r + return wrapper + +def api_login_required(f): + def wrapper(*args, **kwargs): + if not current_user.is_authenticated: + return { + 'status': False, + 'message': 'Not authenticated' + } + return f(*args, **kwargs) + return wrapper + +class FileAPI(MethodView): + decorators = [api_login_required, makejson] + + def put(self, hash): + f = get_file(hash, user_id = current_user.get_id()) + if not f: + return { + 'status': False, + 'message': 'File not found' + } + filename = request.form.get('filename') + if not filename: + return { + 'status': False, + 'message': 'Empty or missing filename', + } + with db.session_scope() as sess: + f.filename = filename + sess.add(f) + return { + 'status': True, + } + + def delete(self, hash): + pass + +file_api_view = FileAPI.as_view('file_api') +app.add_url_rule('/file/', view_func = file_api_view, methods = ['PUT', 'DELETE']) + -- cgit v1.2.3