Update app.py
Browse files
app.py
CHANGED
|
@@ -2265,13 +2265,16 @@ def save_pdf_to_generated_dir(pdf_path: str, project_id: str) -> str:
|
|
| 2265 |
# 1) Build the destination directory and base filename
|
| 2266 |
output_dir = GEN_PROJECT_DIR / project_id
|
| 2267 |
output_dir.mkdir(parents=True, exist_ok=True)
|
| 2268 |
-
|
|
|
|
| 2269 |
# 2) Define the target PDF path
|
| 2270 |
target_pdf = output_dir / f"{project_id}.pdf"
|
| 2271 |
-
|
| 2272 |
# 3) Copy the PDF
|
| 2273 |
shutil.copy2(pdf_path, target_pdf)
|
|
|
|
| 2274 |
logger.info(f"Copied PDF from {pdf_path} → {target_pdf}")
|
|
|
|
| 2275 |
|
| 2276 |
return str(target_pdf)
|
| 2277 |
|
|
@@ -2298,8 +2301,8 @@ def download_sb3(project_id):
|
|
| 2298 |
@app.route("/download_pdf/<project_id>", methods=["GET"])
|
| 2299 |
def download_pdf(project_id):
|
| 2300 |
pdf_path = GEN_PROJECT_DIR / f"{project_id}.pdf"
|
| 2301 |
-
if not pdf_path.exists():
|
| 2302 |
-
|
| 2303 |
|
| 2304 |
return send_file(
|
| 2305 |
pdf_path,
|
|
@@ -2401,8 +2404,10 @@ def process_pdf():
|
|
| 2401 |
if sb3_file_path:
|
| 2402 |
logger.info(f"Successfully created SB3 file: {sb3_file_path}")
|
| 2403 |
# Instead of returning the local path, return a URL to the download endpoint
|
| 2404 |
-
download_url = f"https://prthm11-scratch-vision-game.hf.space/download_sb3/{project_id}"
|
|
|
|
| 2405 |
print(f"DOWNLOAD_URL: {download_url}")
|
|
|
|
| 2406 |
# return jsonify({"message": "Procesed PDF and Game sb3 generated successfully", "project_id": project_id, "download_url": download_url})
|
| 2407 |
return jsonify({
|
| 2408 |
"message": "✅ PDF processed successfully",
|
|
|
|
| 2265 |
# 1) Build the destination directory and base filename
|
| 2266 |
output_dir = GEN_PROJECT_DIR / project_id
|
| 2267 |
output_dir.mkdir(parents=True, exist_ok=True)
|
| 2268 |
+
print(f"\n--------------------------------output_dir {output_dir}")
|
| 2269 |
+
|
| 2270 |
# 2) Define the target PDF path
|
| 2271 |
target_pdf = output_dir / f"{project_id}.pdf"
|
| 2272 |
+
print(f"\n--------------------------------target_pdf {target_pdf}")
|
| 2273 |
# 3) Copy the PDF
|
| 2274 |
shutil.copy2(pdf_path, target_pdf)
|
| 2275 |
+
print(f"Copied PDF from {pdf_path} → {target_pdf}")
|
| 2276 |
logger.info(f"Copied PDF from {pdf_path} → {target_pdf}")
|
| 2277 |
+
|
| 2278 |
|
| 2279 |
return str(target_pdf)
|
| 2280 |
|
|
|
|
| 2301 |
@app.route("/download_pdf/<project_id>", methods=["GET"])
|
| 2302 |
def download_pdf(project_id):
|
| 2303 |
pdf_path = GEN_PROJECT_DIR / f"{project_id}.pdf"
|
| 2304 |
+
# if not pdf_path.exists():
|
| 2305 |
+
# return jsonify({"error": "Scratch project file not found"}), 404
|
| 2306 |
|
| 2307 |
return send_file(
|
| 2308 |
pdf_path,
|
|
|
|
| 2404 |
if sb3_file_path:
|
| 2405 |
logger.info(f"Successfully created SB3 file: {sb3_file_path}")
|
| 2406 |
# Instead of returning the local path, return a URL to the download endpoint
|
| 2407 |
+
download_url = f"https://prthm11-scratch-vision-game.hf.space/download_sb3/{project_id}"
|
| 2408 |
+
pdf_url = f"https://prthm11-scratch-vision-game.hf.space/download_pdf/{project_id}"
|
| 2409 |
print(f"DOWNLOAD_URL: {download_url}")
|
| 2410 |
+
print(f"PDF_URL: {pdf_url}")
|
| 2411 |
# return jsonify({"message": "Procesed PDF and Game sb3 generated successfully", "project_id": project_id, "download_url": download_url})
|
| 2412 |
return jsonify({
|
| 2413 |
"message": "✅ PDF processed successfully",
|