Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import json
|
|
|
|
| 3 |
import asyncio
|
| 4 |
import traceback
|
| 5 |
|
|
@@ -99,16 +100,18 @@ async def messageAPI():
|
|
| 99 |
if request.method == 'POST':
|
| 100 |
data = json.loads(request.data)
|
| 101 |
msg = data["msg"]
|
| 102 |
-
author =
|
| 103 |
response = (
|
| 104 |
supabase.table("messages")
|
| 105 |
.insert({"author_name": author, "content": msg})
|
| 106 |
.execute()
|
| 107 |
)
|
| 108 |
try:
|
| 109 |
-
|
| 110 |
except:
|
| 111 |
-
return make_response({"message": "something went wrong"})
|
|
|
|
|
|
|
| 112 |
|
| 113 |
|
| 114 |
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
+
import base64
|
| 4 |
import asyncio
|
| 5 |
import traceback
|
| 6 |
|
|
|
|
| 100 |
if request.method == 'POST':
|
| 101 |
data = json.loads(request.data)
|
| 102 |
msg = data["msg"]
|
| 103 |
+
author = base64.b64decode(request.headers.get("Authorization").split(" ")[1].encode("ascii")).decode('utf-8').split(":")[0]
|
| 104 |
response = (
|
| 105 |
supabase.table("messages")
|
| 106 |
.insert({"author_name": author, "content": msg})
|
| 107 |
.execute()
|
| 108 |
)
|
| 109 |
try:
|
| 110 |
+
resp = response.data
|
| 111 |
except:
|
| 112 |
+
return make_response({"message": "something went wrong"}), 401
|
| 113 |
+
return make_response(json.dumps({"author": resp["author_name"], "content": resp["content"], "local": True, "id": resp["id"]})), 201
|
| 114 |
+
|
| 115 |
|
| 116 |
|
| 117 |
|