Live editing (server)
This commit is contained in:
parent
5cc188ae58
commit
819d3cbade
46
main
46
main
|
@ -107,6 +107,9 @@ async def add_cors_headers(response):
|
||||||
response.headers.add("Access-Control-Allow-Methods", "*")
|
response.headers.add("Access-Control-Allow-Methods", "*")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
# Live editing store
|
||||||
|
messages = {}
|
||||||
|
|
||||||
@app.route("/api/version", methods=("GET", "POST"))
|
@app.route("/api/version", methods=("GET", "POST"))
|
||||||
async def apiversion():
|
async def apiversion():
|
||||||
return "Burgernotes Version 1.2"
|
return "Burgernotes Version 1.2"
|
||||||
|
@ -268,27 +271,6 @@ async def apiexportnotes():
|
||||||
|
|
||||||
return datatemplate, 200
|
return datatemplate, 200
|
||||||
|
|
||||||
@app.route("/api/importnotes", methods=("GET", "POST"))
|
|
||||||
async def apiimportnotes():
|
|
||||||
if request.method == "POST":
|
|
||||||
data = await request.get_json()
|
|
||||||
notesData = data["notesData"]
|
|
||||||
secretKey = data["secretKey"]
|
|
||||||
|
|
||||||
userCookie = get_session(secretKey)
|
|
||||||
user = get_user(userCookie["id"])
|
|
||||||
|
|
||||||
if(user):
|
|
||||||
for note in notesData:
|
|
||||||
conn = get_db_connection()
|
|
||||||
conn.execute("INSERT INTO notes (title, content, creator, created, edited) VALUES (?, ?, ?, ?, ?)",
|
|
||||||
(note["title"], note["content"], user["id"], str(note["created"]), str(str(note["edited"]))))
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
return {}, 200
|
|
||||||
else:
|
|
||||||
return {}, 403
|
|
||||||
|
|
||||||
@app.route("/api/newnote", methods=("GET", "POST"))
|
@app.route("/api/newnote", methods=("GET", "POST"))
|
||||||
async def apinewnote():
|
async def apinewnote():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
@ -331,6 +313,24 @@ async def apireadnote():
|
||||||
else:
|
else:
|
||||||
return {}, 422
|
return {}, 422
|
||||||
|
|
||||||
|
@app.route("/api/waitforedit", methods=("GET", "POST"))
|
||||||
|
async def waitforedit():
|
||||||
|
if request.method == "POST":
|
||||||
|
data = await request.get_json()
|
||||||
|
secretKey = data["secretKey"]
|
||||||
|
userCookie = get_session(secretKey)
|
||||||
|
user = get_user(userCookie["id"])
|
||||||
|
|
||||||
|
while user["id"] not in messages or not messages[user["id"]]:
|
||||||
|
await asyncio.sleep(0)
|
||||||
|
|
||||||
|
message = messages[user["id"]].pop(0)
|
||||||
|
del messages[user["id"]]
|
||||||
|
|
||||||
|
return {
|
||||||
|
"note": message
|
||||||
|
}, 200
|
||||||
|
|
||||||
@app.route("/api/editnote", methods=("GET", "POST"))
|
@app.route("/api/editnote", methods=("GET", "POST"))
|
||||||
async def apieditnote():
|
async def apieditnote():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
@ -355,6 +355,10 @@ async def apieditnote():
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
if user["id"] not in messages:
|
||||||
|
messages[user["id"]] = []
|
||||||
|
messages[user["id"]].append(noteId)
|
||||||
|
|
||||||
return {}, 200
|
return {}, 200
|
||||||
else:
|
else:
|
||||||
return {}, 403
|
return {}, 403
|
||||||
|
|
Loading…
Reference in New Issue