diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 5324b52..c7f8598 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -14,7 +14,7 @@ ], "env": { "PYDEVD_DISABLE_FILE_VALIDATION": "1", - "CACHE_TTL": "30", + "WEBDAV__CACHE_TTL": "30", }, "justMyCode": true, } diff --git a/api/advent22_api/core/config.py b/api/advent22_api/core/config.py index 002cff2..d737860 100644 --- a/api/advent22_api/core/config.py +++ b/api/advent22_api/core/config.py @@ -50,5 +50,5 @@ async def get_config() -> "Config": Globale Konfiguration lesen """ - txt = await WebDAV.read_str(path=SETTINGS.config_filename) + txt = await WebDAV.read_str(path=SETTINGS.webdav.config_filename) return Config.model_validate(tomllib.loads(txt)) diff --git a/api/advent22_api/core/settings.py b/api/advent22_api/core/settings.py index 6b79a60..7a1fe75 100644 --- a/api/advent22_api/core/settings.py +++ b/api/advent22_api/core/settings.py @@ -9,13 +9,14 @@ class DavSettings(BaseModel): protocol: str = "https" host: str = "example.com" - username: str = "advent22_user" - password: str = "password" path: str = "/remote.php/webdav" prefix: str = "/advent22" - disable_check: bool = False - retries: int = 20 + username: str = "advent22_user" + password: str = "password" + + cache_ttl: int = 60 * 30 + config_filename: str = "config.toml" @property def url(self) -> str: @@ -58,8 +59,5 @@ class Settings(BaseSettings): webdav: DavSettings = DavSettings() - cache_ttl: int = 60 * 30 - config_filename: str = "config.toml" - SETTINGS = Settings() diff --git a/api/advent22_api/core/webdav.py b/api/advent22_api/core/webdav.py index 034fadb..78daf60 100644 --- a/api/advent22_api/core/webdav.py +++ b/api/advent22_api/core/webdav.py @@ -13,12 +13,11 @@ class WebDAV: "webdav_hostname": SETTINGS.webdav.url, "webdav_login": SETTINGS.webdav.username, "webdav_password": SETTINGS.webdav.password, - "disable_check": SETTINGS.webdav.disable_check, } ) @classmethod - @AsyncTTL(time_to_live=SETTINGS.cache_ttl) + @AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl) async def list_files( cls, directory: str = "", @@ -34,7 +33,7 @@ class WebDAV: return [f"{directory}/{path}" for path in ls if regex.search(path)] @classmethod - @AsyncTTL(time_to_live=SETTINGS.cache_ttl) + @AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl) async def file_exists(cls, path: str) -> bool: """ `True`, wenn an Pfad `path` eine Datei existiert @@ -43,7 +42,7 @@ class WebDAV: return cls._webdav_client.check(path) @classmethod - @AsyncTTL(time_to_live=SETTINGS.cache_ttl) + @AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl) async def read_bytes(cls, path: str) -> bytes: """ Datei aus Pfad `path` als bytes laden @@ -56,7 +55,7 @@ class WebDAV: return buffer.read() @classmethod - @AsyncTTL(time_to_live=SETTINGS.cache_ttl) + @AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl) async def read_str(cls, path: str, encoding="utf-8") -> str: """ Datei aus Pfad `path` als string laden