diff --git a/test.py b/test.py new file mode 100644 index 0000000..be0b1eb --- /dev/null +++ b/test.py @@ -0,0 +1,47 @@ +import sqlite3 +from flask import Flask, request, abort +import os + +app = Flask(__name__) + +UPLOAD_DIR = os.path.abspath("uploads") + +@app.route("/user_profile") +def get_user(): + user_id = request.args.get("id") + if not user_id: + abort(400, description="Missing id parameter") + + with sqlite3.connect("database.db") as conn: + cursor = conn.cursor() + cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,)) + user = cursor.fetchone() + + if user is None: + abort(404, description="User not found") + + return str(list(user)) + + +@app.route("/read_file") +def read_data(): + filename = request.args.get("file") + if not filename: + abort(400, description="Missing file parameter") + + filepath = os.path.abspath(os.path.join(UPLOAD_DIR, filename)) + if not filepath.startswith(UPLOAD_DIR + os.sep): + abort(400, description="Invalid file path") + + if not os.path.isfile(filepath): + abort(404, description="File not found") + + with open(filepath, "r") as f: + return f.read() + + +if __name__ == "__main__": + debug = os.environ.get("FLASK_DEBUG", "false").lower() == "true" + host = os.environ.get("FLASK_HOST", "127.0.0.1") + port = int(os.environ.get("FLASK_PORT", "5000")) + app.run(debug=debug, host=host, port=port) \ No newline at end of file