feat: Organize public uploads into daily directories based on timezone

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-11-23 10:43:16 -07:00
parent 979354f87b
commit be5c8dec26
2 changed files with 23 additions and 2 deletions

View File

@@ -33,6 +33,11 @@ try:
except Exception:
qrcode = None
try:
import pytz
except ImportError:
pytz = None
from app.config import Settings, load_settings
# ---- App & static ----
@@ -256,8 +261,21 @@ def get_or_create_album_dir(album_name: str) -> str:
"""Get or create a directory for an album. Returns the path."""
if not album_name or not isinstance(album_name, str):
album_name = "public"
safe_album_name = sanitize_filename(album_name)
save_dir = os.path.join("./data/uploads", safe_album_name)
if album_name == "public":
try:
if not pytz:
raise ImportError("pytz is not installed")
tz = pytz.timezone(SETTINGS.timezone)
today = datetime.now(tz).strftime('%Y-%m-%d')
save_dir = os.path.join("./data/uploads", "public", today)
except Exception as e:
logger.warning("Timezone logic failed, falling back to 'public' album. Timezone: %s. Error: %s", SETTINGS.timezone, e)
save_dir = os.path.join("./data/uploads", "public")
else:
safe_album_name = sanitize_filename(album_name)
save_dir = os.path.join("./data/uploads", safe_album_name)
os.makedirs(save_dir, exist_ok=True)
return save_dir