Moved debug endpoint. Fixed debug Mirrors not returning a error code but allways 200 and made the ElIf mess better...

This commit is contained in:
ZKWolf
2023-09-11 17:59:33 +02:00
parent 6dbcfb5d87
commit d7c011e68f

View File

@@ -28,6 +28,20 @@ def dnt():
return send_from_directory(app.static_folder, request.path[1:])
@app.route("/debug/", methods=["Get"])
def debug_root():
check_for_game_client("soft")
endpoint_descriptions = {
'/debug/user': 'Endpoint to debug user information'}
endpoint_list = []
for endpoint, description in endpoint_descriptions.items():
endpoint_list.append(f'<li>{endpoint}: {description}</li>')
endpoints_html = '<ul>' + ''.join(endpoint_list) + '</ul>'
return f'<h1>Debug Endpoints:</h1>{endpoints_html}'
@app.route('/debug/user/', methods=['GET'], defaults={'steamid': None})
@app.route('/debug/user/<steamid>', methods=['GET'])
def debug_user(steamid):
@@ -72,24 +86,28 @@ def debug_mirrors_write():
api_token = request.cookies.get("api_token")
if api_token is None:
return jsonify({"status": "error", "message": "No api token found"}, 401)
else:
if api_token in allowed_tokens:
if api_token not in allowed_tokens:
return jsonify({"status": "error", "message": "Invalid api token"}), 401
steam_user_id = request.json.get("steamid")
data_b = request.json.get("data")
steam_user_id = request.json.get("steamid")
data_b = request.json.get("data")
if not data_b:
return jsonify({"status": "error", "message": "No data found."}), 400
if data_b or steam_user_id:
return_val = mongo.write_data_with_list(steamid=steam_user_id, items_dict=data_b, server=mongo_host, db=mongo_db,
collection=mongo_collection)
if return_val is None:
return jsonify({"status": "error", "message": "There was a error on our End. "
"Please try again later."}, 400)
else:
return jsonify({"status": "success", "message": "Data written."}, 200)
else:
return jsonify({"status": "error", "message": "No data or Steamid found."}, 400)
else:
return jsonify({"status": "error", "message": "Invalid api token"}, 401)
if not steam_user_id:
return jsonify({"status": "error", "message": "No Steamid found."}), 400
logger.graylog_logger(level="info", handler="logging_debug_mirror_write",
message={"IP": check_for_game_client("remote"), "steamid": steam_user_id, "data": data_b})
return_val = mongo.write_data_with_list(steamid=steam_user_id, items_dict=data_b, server=mongo_host, db=mongo_db,
collection=mongo_collection)
if return_val is None:
return jsonify({"status": "error", "message": "There was a error on our End. "
"Please try again later."}), 400
return jsonify({"status": "success", "message": "Data written."}), 200
except TimeoutError:
return jsonify({"status": "error"})
@@ -108,7 +126,7 @@ def updater_root():
@app.route("/updater/version/", methods=["GET"])
def updater_version():
return jsonify({"Error": "Please read the Docs about this Endpoint."})
return jsonify({"Error": "Please read the Docs about this Endpoint."}), 400
@app.route("/updater/version/script/", methods=["GET"])
@@ -128,7 +146,7 @@ def updater_version_sig():
@app.route("/updater/files/", methods=["GET"])
def updater_files():
return jsonify({"Error": "Please read the Docs about this Endpoint."})
return jsonify({"Error": "Please read the Docs about this Endpoint."}), 400
@app.route("/updater/files/pak/", methods=["GET"])