samwaugh commited on
Commit
07a1661
Β·
1 Parent(s): abb9aca

Try to fix from (previous) working version to load images

Browse files
Files changed (2) hide show
  1. backend/runner/app.py +38 -9
  2. backend/runner/config.py +1 -0
backend/runner/app.py CHANGED
@@ -191,14 +191,33 @@ def list_work_images(work_id: str):
191
  full_work_id = f"W{work_id}"
192
  print(f"πŸ” list_work_images called with work_id: {full_work_id}")
193
  work_dir = get_markdown_dir() / full_work_id
 
 
 
 
 
194
  img_dir = work_dir / "images"
195
  if not img_dir.is_dir():
196
  print(f"❌ Images directory not found: {img_dir}")
197
- return jsonify([])
198
-
199
- files = sorted(
200
- f for f in img_dir.iterdir() if f.suffix.lower() in (".jpg", ".jpeg", ".png")
201
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  host = request.host_url.rstrip("/")
203
  urls = [f"{host}/marker/{full_work_id}/{f.name}" for f in files]
204
  return jsonify(urls)
@@ -608,14 +627,24 @@ def heatmap():
608
  def serve_marker_image(work_id: str, filename: str):
609
  """
610
  Static file server for data/marker_output/<work_id>/images/<filename>
 
611
  """
612
  work_dir = get_markdown_dir() / work_id
613
  img_dir = work_dir / "images"
614
  img_path = img_dir / filename
615
- mime, _ = guess_type(filename)
616
- if not img_path.exists():
617
- return jsonify({"error": "not-found"}), 404
618
- return send_from_directory(img_dir, filename, mimetype=mime)
 
 
 
 
 
 
 
 
 
619
 
620
 
621
  # --------------------------------------------------------------------------- #
 
191
  full_work_id = f"W{work_id}"
192
  print(f"πŸ” list_work_images called with work_id: {full_work_id}")
193
  work_dir = get_markdown_dir() / full_work_id
194
+ print(f"πŸ” Work directory: {work_dir}")
195
+ print(f"πŸ” Work directory exists: {work_dir.exists()}")
196
+ if work_dir.exists():
197
+ work_contents = list(work_dir.iterdir())
198
+ print(f"πŸ” Work directory contents: {[f.name for f in work_contents]}")
199
  img_dir = work_dir / "images"
200
  if not img_dir.is_dir():
201
  print(f"❌ Images directory not found: {img_dir}")
202
+ # Fallback: look for images directly in the work directory
203
+ print(f"πŸ” Checking for images directly in work directory...")
204
+ files = sorted(
205
+ f for f in work_dir.iterdir() if f.suffix.lower() in (".jpg", ".jpeg", ".png")
206
+ )
207
+ if files:
208
+ print(f"βœ… Found {len(files)} images directly in work directory")
209
+ host = request.host_url.rstrip("/")
210
+ urls = [f"{host}/marker/{full_work_id}/{f.name}" for f in files]
211
+ return jsonify(urls)
212
+ else:
213
+ print(f"❌ No images found in work directory either")
214
+ return jsonify([])
215
+ else:
216
+ print(f"βœ… Images directory found: {img_dir}")
217
+ files = sorted(
218
+ f for f in img_dir.iterdir() if f.suffix.lower() in (".jpg", ".jpeg", ".png")
219
+ )
220
+ print(f"πŸ” Found {len(files)} images in images directory")
221
  host = request.host_url.rstrip("/")
222
  urls = [f"{host}/marker/{full_work_id}/{f.name}" for f in files]
223
  return jsonify(urls)
 
627
  def serve_marker_image(work_id: str, filename: str):
628
  """
629
  Static file server for data/marker_output/<work_id>/images/<filename>
630
+ Falls back to work_id/<filename> if images directory doesn't exist
631
  """
632
  work_dir = get_markdown_dir() / work_id
633
  img_dir = work_dir / "images"
634
  img_path = img_dir / filename
635
+
636
+ # Try images directory first
637
+ if img_path.exists():
638
+ mime, _ = guess_type(filename)
639
+ return send_from_directory(img_dir, filename, mimetype=mime)
640
+
641
+ # Fallback: try work directory directly
642
+ work_img_path = work_dir / filename
643
+ if work_img_path.exists():
644
+ mime, _ = guess_type(filename)
645
+ return send_from_directory(work_dir, filename, mimetype=mime)
646
+
647
+ return jsonify({"error": "not-found"}), 404
648
 
649
 
650
  # --------------------------------------------------------------------------- #
backend/runner/config.py CHANGED
@@ -443,6 +443,7 @@ def _download_images_robust(works_dir: Path, work_dirs: set, files: list, progre
443
 
444
  # Get list of image files for this work
445
  work_files = [f for f in files if f.startswith(f"works/{work_id}/images/")]
 
446
 
447
  downloaded = 0
448
  failed = 0
 
443
 
444
  # Get list of image files for this work
445
  work_files = [f for f in files if f.startswith(f"works/{work_id}/images/")]
446
+ print(f"πŸ” Work {work_id}: Found {len(work_files)} image files to download")
447
 
448
  downloaded = 0
449
  failed = 0