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": {
|
"env": {
|
||||||
"PYDEVD_DISABLE_FILE_VALIDATION": "1",
|
"PYDEVD_DISABLE_FILE_VALIDATION": "1",
|
||||||
"CACHE_TTL": "30",
|
"WEBDAV__CACHE_TTL": "30",
|
||||||
},
|
},
|
||||||
"justMyCode": true,
|
"justMyCode": true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,5 +50,5 @@ async def get_config() -> "Config":
|
||||||
Globale Konfiguration lesen
|
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))
|
return Config.model_validate(tomllib.loads(txt))
|
||||||
|
|
|
@ -9,13 +9,14 @@ class DavSettings(BaseModel):
|
||||||
|
|
||||||
protocol: str = "https"
|
protocol: str = "https"
|
||||||
host: str = "example.com"
|
host: str = "example.com"
|
||||||
username: str = "advent22_user"
|
|
||||||
password: str = "password"
|
|
||||||
path: str = "/remote.php/webdav"
|
path: str = "/remote.php/webdav"
|
||||||
prefix: str = "/advent22"
|
prefix: str = "/advent22"
|
||||||
|
|
||||||
disable_check: bool = False
|
username: str = "advent22_user"
|
||||||
retries: int = 20
|
password: str = "password"
|
||||||
|
|
||||||
|
cache_ttl: int = 60 * 30
|
||||||
|
config_filename: str = "config.toml"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self) -> str:
|
def url(self) -> str:
|
||||||
|
@ -58,8 +59,5 @@ class Settings(BaseSettings):
|
||||||
|
|
||||||
webdav: DavSettings = DavSettings()
|
webdav: DavSettings = DavSettings()
|
||||||
|
|
||||||
cache_ttl: int = 60 * 30
|
|
||||||
config_filename: str = "config.toml"
|
|
||||||
|
|
||||||
|
|
||||||
SETTINGS = Settings()
|
SETTINGS = Settings()
|
||||||
|
|
|
@ -13,12 +13,11 @@ class WebDAV:
|
||||||
"webdav_hostname": SETTINGS.webdav.url,
|
"webdav_hostname": SETTINGS.webdav.url,
|
||||||
"webdav_login": SETTINGS.webdav.username,
|
"webdav_login": SETTINGS.webdav.username,
|
||||||
"webdav_password": SETTINGS.webdav.password,
|
"webdav_password": SETTINGS.webdav.password,
|
||||||
"disable_check": SETTINGS.webdav.disable_check,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@AsyncTTL(time_to_live=SETTINGS.cache_ttl)
|
@AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl)
|
||||||
async def list_files(
|
async def list_files(
|
||||||
cls,
|
cls,
|
||||||
directory: str = "",
|
directory: str = "",
|
||||||
|
@ -34,7 +33,7 @@ class WebDAV:
|
||||||
return [f"{directory}/{path}" for path in ls if regex.search(path)]
|
return [f"{directory}/{path}" for path in ls if regex.search(path)]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@AsyncTTL(time_to_live=SETTINGS.cache_ttl)
|
@AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl)
|
||||||
async def file_exists(cls, path: str) -> bool:
|
async def file_exists(cls, path: str) -> bool:
|
||||||
"""
|
"""
|
||||||
`True`, wenn an Pfad `path` eine Datei existiert
|
`True`, wenn an Pfad `path` eine Datei existiert
|
||||||
|
@ -43,7 +42,7 @@ class WebDAV:
|
||||||
return cls._webdav_client.check(path)
|
return cls._webdav_client.check(path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@AsyncTTL(time_to_live=SETTINGS.cache_ttl)
|
@AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl)
|
||||||
async def read_bytes(cls, path: str) -> bytes:
|
async def read_bytes(cls, path: str) -> bytes:
|
||||||
"""
|
"""
|
||||||
Datei aus Pfad `path` als bytes laden
|
Datei aus Pfad `path` als bytes laden
|
||||||
|
@ -56,7 +55,7 @@ class WebDAV:
|
||||||
return buffer.read()
|
return buffer.read()
|
||||||
|
|
||||||
@classmethod
|
@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:
|
async def read_str(cls, path: str, encoding="utf-8") -> str:
|
||||||
"""
|
"""
|
||||||
Datei aus Pfad `path` als string laden
|
Datei aus Pfad `path` als string laden
|
||||||
|
|
Loading…
Reference in a new issue