mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 00:03:07 +00:00
api: minor cfg/settings adjustment
This commit is contained in:
parent
c4181dc5f8
commit
8389ceb14a
4 changed files with 11 additions and 14 deletions
2
api/.vscode/launch.json
vendored
2
api/.vscode/launch.json
vendored
|
@ -14,7 +14,7 @@
|
|||
],
|
||||
"env": {
|
||||
"PYDEVD_DISABLE_FILE_VALIDATION": "1",
|
||||
"CACHE_TTL": "30",
|
||||
"WEBDAV__CACHE_TTL": "30",
|
||||
},
|
||||
"justMyCode": true,
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue