Skip to content

Commit 28d2455

Browse files
committed
Moving to react checkpoint
1 parent dc23c1a commit 28d2455

10 files changed

Lines changed: 908 additions & 44 deletions

File tree

viewer_react/backend.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,34 @@ def api_readme():
625625
return jsonify({"success": True, "message": "Readme saved successfully"})
626626

627627

628+
@app.route("/api/download")
629+
def api_download():
630+
"""Download a file from a game folder"""
631+
from flask import send_file
632+
633+
folder_path = request.args.get("folder")
634+
relative_path = request.args.get("path")
635+
636+
if not folder_path or not relative_path:
637+
return jsonify({"success": False, "error": "Missing folder or path parameter"}), 400
638+
639+
folder = LOG_BASE_DIR / folder_path
640+
if not folder.exists() or not folder.is_dir():
641+
return jsonify({"success": False, "error": "Invalid folder"}), 404
642+
643+
file_path = folder / relative_path
644+
if not file_path.exists() or not file_path.is_file():
645+
return jsonify({"success": False, "error": "File not found"}), 404
646+
647+
# Security check: ensure file is within the game folder
648+
try:
649+
file_path.resolve().relative_to(folder.resolve())
650+
except ValueError:
651+
return jsonify({"success": False, "error": "Invalid file path"}), 403
652+
653+
return send_file(file_path, as_attachment=True, download_name=file_path.name)
654+
655+
628656
# Catch-all route for React Router (must be last)
629657
@app.errorhandler(404)
630658
def not_found(e):

viewer_react/frontend/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>CodeClash Trajectory Viewer</title>
8+
<!-- Bootstrap Icons -->
9+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.2/font/bootstrap-icons.css">
810
</head>
911
<body>
1012
<div id="root"></div>

0 commit comments

Comments
 (0)