summaryrefslogtreecommitdiff
path: root/fbin/api.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2017-04-09 09:02:09 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2017-04-09 09:02:09 +0200
commitb36f9c05071ea549ed59e703270fcf223b60df03 (patch)
tree8992c6bcaa5b0d64cbd589588b2539523125548c /fbin/api.py
parentaf750a6598d53b8a5cb58092dd5b523ea7e967ca (diff)
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.
Diffstat (limited to 'fbin/api.py')
-rw-r--r--fbin/api.py62
1 files changed, 62 insertions, 0 deletions
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/<hash>', view_func = file_api_view, methods = ['PUT', 'DELETE'])
+