|
|
|
|
@ -16,8 +16,22 @@ cur = con.cursor() # NB! single is enough for now, we might require multiple la
|
|
|
|
|
async def new_session():
|
|
|
|
|
"""Start a new session"""
|
|
|
|
|
# add session to the database
|
|
|
|
|
try:
|
|
|
|
|
# generate a cookie
|
|
|
|
|
cookie = uuid4().hex
|
|
|
|
|
cur.execute(
|
|
|
|
|
"""INSERT INTO sessions(cookie)
|
|
|
|
|
VALUES(:cookie)
|
|
|
|
|
""",
|
|
|
|
|
{"cookie": cookie},
|
|
|
|
|
)
|
|
|
|
|
con.commit()
|
|
|
|
|
except sqlite3.IntegrityError as e:
|
|
|
|
|
if str(e) == "UNIQUE constraint failed: sessions.cookie":
|
|
|
|
|
return {"cookie": "error"}
|
|
|
|
|
|
|
|
|
|
# return new session cookie
|
|
|
|
|
return {"session_id": 42}
|
|
|
|
|
return {"cookie": cookie}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/next_picture/{cookie}")
|
|
|
|
|
|