Commit 8a48e4c

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-10-28 09:36:08
feat(cleanup): add configurable cleanup duration for old files
1 parent ce5f48e
Changed files (2)
src/config.py
@@ -33,6 +33,7 @@ TELEGRAM_UA = os.getenv("TELEGRAM_UA", "TelegramBot (like TwitterBot)")
 NUM_YOUTUBE_SEARCH_RESULTS = int(os.getenv("NUM_YOUTUBE_SEARCH_RESULTS", "10"))  # Number of youtube search results
 NUM_GOOGLE_SEARCH_RESULTS = int(os.getenv("NUM_GOOGLE_SEARCH_RESULTS", "10"))  # Number of google search results
 GOOGLE_SEARCH_GL = os.getenv("GOOGLE_SEARCH_GL", "cn")  # "gl" parameter (Geolocation)
+CLEAN_OLD_FILES_OLDER_THAN_SECONDS = int(os.getenv("CLEAN_OLD_FILES_OLDER_THAN_SECONDS", "7200"))
 
 
 class ENABLE:  # see fine-grained permission in `src/permission.py`
src/utils.py
@@ -25,7 +25,7 @@ from pyrogram.client import Client
 from pyrogram.types import User
 from yt_dlp.extractor import gen_extractors
 
-from config import DOWNLOAD_DIR, TZ, cache
+from config import CLEAN_OLD_FILES_OLDER_THAN_SECONDS, DOWNLOAD_DIR, TZ, cache
 
 # ruff: noqa: RUF001
 
@@ -566,7 +566,7 @@ def check_data(text: str, check_keys: list[str] | None = None, check_kv: dict |
                 raise ValueError
 
 
-def cleanup_old_files(root: Path | str | None = None, duration: int = 7200) -> None:
+def cleanup_old_files(root: Path | str | None = None, duration: int = CLEAN_OLD_FILES_OLDER_THAN_SECONDS) -> None:
     """Clean up files older than duration seconds."""
     if root is None:
         root = DOWNLOAD_DIR