Update app_main.py
Browse files- app_main.py +25 -2
app_main.py
CHANGED
|
@@ -455,8 +455,6 @@ def index():
|
|
| 455 |
return render_template('app_index.html')
|
| 456 |
|
| 457 |
# API endpoint
|
| 458 |
-
|
| 459 |
-
|
| 460 |
@app.route('/process_pdf', methods=['POST'])
|
| 461 |
def process_pdf():
|
| 462 |
try:
|
|
@@ -495,6 +493,31 @@ def process_pdf():
|
|
| 495 |
logger.exception("❌ Failed to process PDF")
|
| 496 |
return jsonify({"error": f"❌ Failed to process PDF: {str(e)}"}), 500
|
| 497 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
|
| 499 |
if __name__ == '__main__':
|
| 500 |
app.run(host='0.0.0.0', port=7860, debug=True)
|
|
|
|
| 455 |
return render_template('app_index.html')
|
| 456 |
|
| 457 |
# API endpoint
|
|
|
|
|
|
|
| 458 |
@app.route('/process_pdf', methods=['POST'])
|
| 459 |
def process_pdf():
|
| 460 |
try:
|
|
|
|
| 493 |
logger.exception("❌ Failed to process PDF")
|
| 494 |
return jsonify({"error": f"❌ Failed to process PDF: {str(e)}"}), 500
|
| 495 |
|
| 496 |
+
# --- New endpoint to download the .sb3 file ---
|
| 497 |
+
@app.route("/download_sb3/<project_id>", methods=["GET"])
|
| 498 |
+
def download_sb3(project_id):
|
| 499 |
+
"""
|
| 500 |
+
Allows users to download the generated .sb3 Scratch project file.
|
| 501 |
+
"""
|
| 502 |
+
sb3_filename = f"{project_id}.sb3"
|
| 503 |
+
sb3_filepath = os.path.join("generated_projects", sb3_filename)
|
| 504 |
+
|
| 505 |
+
try:
|
| 506 |
+
if os.path.exists(sb3_filepath):
|
| 507 |
+
logger.info(f"Serving SB3 file for project ID: {project_id}")
|
| 508 |
+
# send_from_directory serves the file and handles content-disposition for download
|
| 509 |
+
return send_from_directory(
|
| 510 |
+
directory="generated_projects",
|
| 511 |
+
path=sb3_filename,
|
| 512 |
+
as_attachment=True, # This makes the browser download the file
|
| 513 |
+
download_name=sb3_filename # This sets the filename for the download
|
| 514 |
+
)
|
| 515 |
+
else:
|
| 516 |
+
logger.warning(f"SB3 file not found for ID: {project_id}")
|
| 517 |
+
return jsonify({"error": "Scratch project file not found"}), 404
|
| 518 |
+
except Exception as e:
|
| 519 |
+
logger.error(f"Error serving SB3 file for ID {project_id}: {e}")
|
| 520 |
+
return jsonify({"error": "Failed to retrieve Scratch project file"}), 500
|
| 521 |
|
| 522 |
if __name__ == '__main__':
|
| 523 |
app.run(host='0.0.0.0', port=7860, debug=True)
|