aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/dynamic_import.py1
-rw-r--r--api/status.py2
-rw-r--r--api/user/preferences.py27
-rw-r--r--api/user/status.py (renamed from api/user/updateStatus.py)6
-rw-r--r--api/user/updatePreferences.py32
-rw-r--r--components/preferencesContext.tsx2
-rw-r--r--pages/user.tsx2
7 files changed, 32 insertions, 40 deletions
diff --git a/api/dynamic_import.py b/api/dynamic_import.py
index eb8f0c2..3b05764 100644
--- a/api/dynamic_import.py
+++ b/api/dynamic_import.py
@@ -1,4 +1,5 @@
from app import app
+from flask import url_for
import importlib
import os
import log
diff --git a/api/status.py b/api/status.py
index 6404a7f..19a01a1 100644
--- a/api/status.py
+++ b/api/status.py
@@ -1,7 +1,7 @@
from flask import Blueprint
from db import cursor
-status = Blueprint('status', __name__)
+status = Blueprint('server_status', __name__)
@status.route('/status')
def index():
diff --git a/api/user/preferences.py b/api/user/preferences.py
index 5d46f5f..bfbfe66 100644
--- a/api/user/preferences.py
+++ b/api/user/preferences.py
@@ -3,10 +3,13 @@ from db import cursor
from auth.login_token import token_login
import json
+def format_preferences(preferences): #TODO: remove excess properties (create preferences class?)
+ return json.dumps(preferences) or ""
+
preferences = Blueprint('preferences', __name__)
-@preferences.route('/preferences')
-def index():
+@preferences.route('/preferences', methods = ["GET"])
+def get_preferences():
data = request.get_json()
token = request.cookies.get("token") or ""
@@ -19,5 +22,25 @@ def index():
user_prefs = cursor.execute("select preferences from users where user_id = ?", [login]).fetchone()
return { "preferences": json.loads(user_prefs[0]) }, 200
+@preferences.route('/preferences', methods = ["POST"])
+def index():
+ data = request.get_json()
+
+ new_preferences = data.get("newPreferences") or ""
+ token = request.cookies.get("token") or ""
+
+ if not token: return "", 401
+ login = token_login(token) or ""
+
+ if not login: return "", 403
+
+ formatted_json = format_preferences(new_preferences)
+ if not formatted_json: return "", 400
+
+ cursor.execute("update users set preferences = ? where user_id = ?", [formatted_json, login])
+ connection.commit()
+
+ return "", 200
+
dynamic_route = ["/user", preferences]
diff --git a/api/user/updateStatus.py b/api/user/status.py
index de32e95..e2895d5 100644
--- a/api/user/updateStatus.py
+++ b/api/user/status.py
@@ -3,9 +3,9 @@ from db import cursor, connection
from auth.login_token import token_login
import json
-updateStatus = Blueprint('updateStatus', __name__)
+status = Blueprint('user_status', __name__)
-@updateStatus.route('/updateStatus', methods = ['POST'])
+@status.route('/status', methods = ['POST'])
def index():
data = request.get_json()
@@ -23,5 +23,5 @@ def index():
return "", 200
-dynamic_route = ["/user", updateStatus]
+dynamic_route = ["/user", status]
diff --git a/api/user/updatePreferences.py b/api/user/updatePreferences.py
deleted file mode 100644
index 2eb6512..0000000
--- a/api/user/updatePreferences.py
+++ /dev/null
@@ -1,32 +0,0 @@
-from flask import Blueprint, request
-from db import cursor, connection
-from auth.login_token import token_login
-import json
-
-def format_preferences(preferences): #TODO: remove excess properties (create preferences class?)
- return json.dumps(preferences) or ""
-
-updatePreferences = Blueprint('updatePreferences', __name__)
-
-@updatePreferences.route('/updatePreferences', methods = ['POST'])
-def index():
- data = request.get_json()
-
- new_preferences = data.get("newPreferences") or ""
- token = request.cookies.get("token") or ""
-
- if not token: return "", 401
- login = token_login(token) or ""
-
- if not login: return "", 403
-
- formatted_json = format_preferences(new_preferences)
- if not formatted_json: return "", 400
-
- cursor.execute("update users set preferences = ? where user_id = ?", [formatted_json, login])
- connection.commit()
-
- return "", 200
-
-dynamic_route = ["/user", updatePreferences]
-
diff --git a/components/preferencesContext.tsx b/components/preferencesContext.tsx
index f7bc409..3a930af 100644
--- a/components/preferencesContext.tsx
+++ b/components/preferencesContext.tsx
@@ -47,7 +47,7 @@ export function PreferencesContextWrapper(props: { children?: ReactNode }) {
applyPreferences(prefs);
axios.request({
method: "post",
- url: `/api/user/updatePreferences`,
+ url: `/api/user/preferences`,
headers: {"content-type": "application/json"},
data: { "newPreferences": prefs }
});
diff --git a/pages/user.tsx b/pages/user.tsx
index 1b6c2e3..1b0e170 100644
--- a/pages/user.tsx
+++ b/pages/user.tsx
@@ -161,7 +161,7 @@ export default function AccountPage() {
setEditingStatus(false)
axios.request({
method: "post",
- url: `/api/user/updateStatus`,
+ url: `/api/user/status`,
headers: {"content-type": "application/json"},
data: { "status": document.getElementById("status").innerText }
});