From c074bac3c889e2115f2d6039077198e6d983d8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Mon, 5 Sep 2022 20:17:27 +0000 Subject: [PATCH] webdav_prefix setting --- api/ovdashboard_api/config.py | 2 +- api/ovdashboard_api/dav_common.py | 8 ++++++-- api/ovdashboard_api/routers/image.py | 4 ++-- api/ovdashboard_api/routers/text.py | 6 +++--- api/ovdashboard_api/settings.py | 1 + 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/api/ovdashboard_api/config.py b/api/ovdashboard_api/config.py index f50d807..c072eaf 100644 --- a/api/ovdashboard_api/config.py +++ b/api/ovdashboard_api/config.py @@ -48,7 +48,7 @@ class Config(BaseModel): Load the configuration instance from the server using `TOML`. """ - dav_file = DavFile("ovdashboard/config.txt") + dav_file = DavFile("config.txt") try: return cls.parse_obj( diff --git a/api/ovdashboard_api/dav_common.py b/api/ovdashboard_api/dav_common.py index 81faab5..edfa14e 100644 --- a/api/ovdashboard_api/dav_common.py +++ b/api/ovdashboard_api/dav_common.py @@ -26,7 +26,9 @@ def webdav_resource(remote_path: Any) -> WebDAVResource: Gets a resource using the main WebDAV client. """ - return _WEBDAV_CLIENT.resource(remote_path) + return _WEBDAV_CLIENT.resource( + f"{SETTINGS.webdav_prefix}/{remote_path}" + ) @run_in_executor @@ -35,7 +37,9 @@ def webdav_list(remote_path: str) -> list[str]: Asynchroneously lists a WebDAV path using the main WebDAV client. """ - return _WEBDAV_CLIENT.list(remote_path) + return _WEBDAV_CLIENT.list( + f"{SETTINGS.webdav_prefix}/{remote_path}" + ) _CALDAV_CLIENT = CalDAVclient( diff --git a/api/ovdashboard_api/routers/image.py b/api/ovdashboard_api/routers/image.py index bbb403a..3e28cdf 100644 --- a/api/ovdashboard_api/routers/image.py +++ b/api/ovdashboard_api/routers/image.py @@ -62,11 +62,11 @@ async def get_image( prefix: str, name: str = Depends(_unique), ) -> str: - dav_file = DavFile(f"ovdashboard/{_lister.remote_path}/{name}") + dav_file = DavFile(f"{_lister.remote_path}/{name}") img = Image.open(BytesIO(await dav_file.bytes)).convert("RGB") img_buffer = BytesIO() - img.save(img_buffer, format='JPEG', quality=85) + img.save(img_buffer, format="JPEG", quality=85) img_buffer.seek(0) return StreamingResponse( diff --git a/api/ovdashboard_api/routers/text.py b/api/ovdashboard_api/routers/text.py index acad336..a32f5c3 100644 --- a/api/ovdashboard_api/routers/text.py +++ b/api/ovdashboard_api/routers/text.py @@ -22,7 +22,7 @@ from ._common import FileNameLister, PrefixFinder, PrefixUnique router = APIRouter(prefix="/text", tags=["text"]) _lister = FileNameLister( - remote_path="ovdashboard/text", + remote_path="text", re=re.compile( r"\.(txt|md)$", flags=re.IGNORECASE, @@ -34,7 +34,7 @@ _unique = PrefixUnique(_finder) async def get_ticker_lines() -> Iterator[str]: - ticker = await DavFile("ovdashboard/text/ticker.txt").string + ticker = await DavFile("text/ticker.txt").string return ( line.strip() @@ -104,7 +104,7 @@ async def find_texts( async def get_text_content( name: str = Depends(_unique), ) -> str: - return await DavFile(f"ovdashboard/{_lister.remote_path}/{name}").string + return await DavFile(f"{_lister.remote_path}/{name}").string @router.get( diff --git a/api/ovdashboard_api/settings.py b/api/ovdashboard_api/settings.py index 2e26052..3b07198 100644 --- a/api/ovdashboard_api/settings.py +++ b/api/ovdashboard_api/settings.py @@ -54,6 +54,7 @@ class Settings(BaseSettings): redoc_url: Optional[str] = "/redoc" webdav: DavSettings = DavSettings() + webdav_prefix: str = "/ovdashboard" caldav: DavSettings = DavSettings() cache_seconds: int = 30