forked from bton/matekasse
Error codes website + Doc
This commit is contained in:
parent
2e328167e8
commit
d3fe363776
2 changed files with 22 additions and 32 deletions
45
main.py
45
main.py
|
@ -89,7 +89,7 @@ def user_info():
|
|||
</html>
|
||||
"""
|
||||
else:
|
||||
return "User does not exists"
|
||||
return "Error: 043"
|
||||
|
||||
@app.route("/adduser")
|
||||
def new_user():
|
||||
|
@ -121,7 +121,7 @@ def adduser():
|
|||
socketio.emit("update", "update")
|
||||
return 'Added user <a href="/list">user and tag list</a> <p>The creator of this website accepts no liability for any linguistic or technical errors!</p>'
|
||||
else:
|
||||
return '<p>User already exists</p> <a href="/list">user and tag list</a>'
|
||||
return '<p>Error: 170</p> <a href="/list">user and tag list</a>'
|
||||
|
||||
|
||||
@app.route("/change", methods=['GET'])
|
||||
|
@ -130,7 +130,7 @@ def change():
|
|||
try:
|
||||
change = int(request.args.get("change"))
|
||||
except ValueError:
|
||||
return '<p>Please enter a number!</p><a href="/list">tags and user list</a>'
|
||||
return '<p>Error: 095</p><a href="/list">tags and user list</a>'
|
||||
c.execute(f"UPDATE users SET balance = balance + {change} WHERE id={user_id}")
|
||||
socketio.emit("update", "update")
|
||||
return """<html>
|
||||
|
@ -160,7 +160,7 @@ def get_addtag_request():
|
|||
try:
|
||||
user_id = int(request.args.get("id"))
|
||||
except: #except im Normalen Code!
|
||||
return "Wrong user id!"
|
||||
return "Error: 095"
|
||||
session_id = uuid.uuid4()
|
||||
session[id] = session_id
|
||||
users.put([user_id, "add", session_id])
|
||||
|
@ -180,21 +180,17 @@ def request_addtag(data):
|
|||
time.sleep(1)
|
||||
i += 1
|
||||
if i > 20:
|
||||
socketio.emit("error", "timeout", to=session[id])
|
||||
socketio.emit("error", "352", to=session[id])
|
||||
notimportant = users.get()
|
||||
break
|
||||
else:
|
||||
finished = None
|
||||
c.execute(f"SELECT * FROM users WHERE id ={user[0]}")
|
||||
username = c.fetchall()[0][1]
|
||||
if message == "Error: 170":
|
||||
socketio.emit("finished", f"{message}")
|
||||
else:
|
||||
socketio.emit("finished", f"Added {message} to {username}", to=session[id])
|
||||
socketio.emit("finished", f"{message}", to=session[id])
|
||||
|
||||
else:
|
||||
socketio.emit("busy", "busy", to=session[id])
|
||||
else:
|
||||
socketio.emit("error", "error", to=session[id])
|
||||
socketio.emit("error", "418", to=session[id])
|
||||
leave_room(session[id])
|
||||
|
||||
@app.route("/removetag", methods=['GET'])
|
||||
|
@ -224,21 +220,16 @@ def request_removetag(data):
|
|||
time.sleep(1)
|
||||
i += 1
|
||||
if i > 20:
|
||||
socketio.emit("error", "timeout", to=session[id])
|
||||
socketio.emit("error", "352", to=session[id])
|
||||
notimportant = users.get()
|
||||
break
|
||||
else:
|
||||
finished = None
|
||||
c.execute(f"SELECT * FROM users WHERE id ={user}")
|
||||
username = c.fetchall()[0][1]
|
||||
if message == "Tag does not exist":
|
||||
socketio.emit("finished", f"{message}")
|
||||
else:
|
||||
socketio.emit("finished", f"removed {message} from {username}")
|
||||
socketio.emit("finished", f"{message}", to=session[id])
|
||||
else:
|
||||
socketio.emit("busy", "busy", to=session[id])
|
||||
else:
|
||||
socketio.emit("error", "error", to=session[id])
|
||||
socketio.emit("error", "418", to=session[id])
|
||||
leave_room(session[id])
|
||||
|
||||
#api
|
||||
|
@ -254,30 +245,26 @@ def get_id():
|
|||
queue_item = users.get()
|
||||
user = queue_item[0]
|
||||
state = queue_item[1]
|
||||
c.execute(f"SELECT * FROM users WHERE id={user}")
|
||||
username = c.fetchall()[0][1]
|
||||
if state == "add":
|
||||
c.execute(f"SELECT * FROM tags WHERE tagid={tag_id}")
|
||||
if c.fetchall() != []:
|
||||
message = "Tag already exists"
|
||||
message = "Error: 170"
|
||||
finished = queue_item
|
||||
return make_response(json.dumps({"mode":"0","error":"170"}))
|
||||
else:
|
||||
c.execute(f"INSERT OR IGNORE INTO tags (tagid, userid) VALUES ({tag_id}, {user})")
|
||||
message = tag_id
|
||||
message = f"Added {tag_id} to {username}"
|
||||
finished = queue_item
|
||||
c.execute(f"SELECT * FROM users WHERE id={user}")
|
||||
username = c.fetchall()[0][1]
|
||||
conn.commit()
|
||||
return make_response(json.dumps({"mode":"2","username":username,"code":"1"}))
|
||||
elif state == "remove":
|
||||
c.execute(f"SELECT * FROM tags WHERE (tagid = {tag_id} AND userid = {user})")
|
||||
tags = c.fetchall()
|
||||
if tags != []:
|
||||
c.execute(f"DELETE FROM tags WHERE (tagid = {tag_id} AND userid = {user}) ")
|
||||
message = tag_id
|
||||
message = f"Removed {tag_id} from {username}"
|
||||
finished = queue_item
|
||||
c.execute(f"SELECT * FROM users WHERE id={user}")
|
||||
username = c.fetchall()[0][1]
|
||||
conn.commit()
|
||||
return make_response(json.dumps({"mode":"2","username":username,"code":"2"}))
|
||||
else:
|
||||
message = "Tag does not exist"
|
||||
|
|
|
@ -14,10 +14,13 @@
|
|||
<p> </p>
|
||||
<div id="text">
|
||||
<h2>API:</h2>
|
||||
<p>API Documentation:</p>
|
||||
<br></br>
|
||||
<h2>Error Codes:</h2>
|
||||
<p>Error Codes Documentation</p>
|
||||
<p>170: Tag already exists</p>
|
||||
<p>054: Tag does not exists</p>
|
||||
<p>757: Usere already exists</p>
|
||||
<p>043: User does not exists</p>
|
||||
<p>352: Timeout</p>
|
||||
<p>095: Input is not a Number</p>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
|
|
Loading…
Reference in a new issue