summaryrefslogtreecommitdiff
path: root/app/services/images.py
diff options
context:
space:
mode:
authorDylan Bolger <dylan.bolger00@gmail.com>2026-08-18 11:44:36 -0500
committerDylan Bolger <dylan.bolger00@gmail.com>2026-08-18 11:44:36 -0500
commit04892822306bf9a01de19cc70bcfc59d7fca9f8f (patch)
treefcc8bc92c5a15b669a657561dfe2ac7e14c72857 /app/services/images.py
parenteead346519758f45dd587cfd471f90f6a6a8037f (diff)
downloadphotoblog-04892822306bf9a01de19cc70bcfc59d7fca9f8f.tar.xz
photoblog-04892822306bf9a01de19cc70bcfc59d7fca9f8f.zip
move from fastapi to flask, various cleanups involved
Diffstat (limited to 'app/services/images.py')
-rw-r--r--app/services/images.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/app/services/images.py b/app/services/images.py
index 3ce8045..4938014 100644
--- a/app/services/images.py
+++ b/app/services/images.py
@@ -1,21 +1,19 @@
from pathlib import Path
+from flask import Flask, current_app
import random
-print(str(Path.cwd()))
-root_dir = Path.cwd()
-photos_dir = Path(f"{root_dir}photos")
-
image_cache = set()
-def cache_images():
+def cache_images(app: Flask):
+ photos_dir = Path(f"{app.static_folder}/photos")
for file_path in photos_dir.rglob("*"):
if file_path.is_file():
- image_path = file_path.relative_to(root_dir).name
- image_cache.add(str(image_path))
+ img_path = file_path.relative_to(app.static_folder)
+ image_cache.add(str(img_path))
-def get_all_images():
+def get_all_images(current_app: Flask):
# if not image_cache:
- cache_images()
- print(f"returning {len(image_cache)} images")
+ cache_images(current_app)
+ print(f"Returning {len(image_cache)} images")
shuffled = random.sample(list(image_cache), k=len(image_cache))
return shuffled