Compare commits
No commits in common. "2ca63776346fac69d0de70044ada35c4721c9389" and "d2e77b9ae51d543845cc5623cea63b4e0fe35206" have entirely different histories.
2ca6377634
...
d2e77b9ae5
2 changed files with 5 additions and 24 deletions
|
|
@ -50,7 +50,7 @@ class WebDAVSettings(DAVSettings):
|
|||
username: str = "ovd_user"
|
||||
password: str = "password"
|
||||
|
||||
config_filename: str = "config.txt"
|
||||
config_filename: str = "config.toml"
|
||||
|
||||
disable_check: bool = False
|
||||
retries: int = 20
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ from io import BytesIO
|
|||
from asyncify import asyncify
|
||||
from cache import AsyncTTL
|
||||
from cache.key import KEY
|
||||
from requests import Response
|
||||
from webdav3.client import Client as WebDAVclient
|
||||
|
||||
from .settings import SETTINGS
|
||||
|
|
@ -14,24 +13,7 @@ _logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class WebDAV:
|
||||
class __WebDAVclient(WebDAVclient):
|
||||
def execute_request(
|
||||
self,
|
||||
action,
|
||||
path,
|
||||
data=None,
|
||||
headers_ext=None,
|
||||
) -> Response:
|
||||
res = super().execute_request(action, path, data, headers_ext)
|
||||
|
||||
# the "Content-Length" header can randomly be missing on txt files,
|
||||
# this should fix that (probably serverside bug)
|
||||
if action == "download" and "Content-Length" not in res.headers:
|
||||
res.headers["Content-Length"] = str(len(res.text))
|
||||
|
||||
return res
|
||||
|
||||
_webdav_client = __WebDAVclient(
|
||||
_webdav_client = WebDAVclient(
|
||||
{
|
||||
"webdav_hostname": SETTINGS.webdav.url,
|
||||
"webdav_login": SETTINGS.webdav.username,
|
||||
|
|
@ -59,7 +41,7 @@ class WebDAV:
|
|||
_logger.debug(f"list_files {directory!r}")
|
||||
ls = await asyncify(cls._webdav_client.list)(directory)
|
||||
|
||||
return [path for path in ls if regex.search(path)]
|
||||
return [f"{directory}/{path}" for path in ls if regex.search(path)]
|
||||
|
||||
@classmethod
|
||||
@AsyncTTL(
|
||||
|
|
@ -90,8 +72,7 @@ class WebDAV:
|
|||
|
||||
_logger.debug(f"read_bytes {path!r}")
|
||||
buffer = BytesIO()
|
||||
await asyncify(cls._webdav_client.download_from)(buffer, path)
|
||||
buffer.seek(0)
|
||||
await asyncify(cls._webdav_client.resource(path).write_to)(buffer)
|
||||
|
||||
return buffer.read()
|
||||
|
||||
|
|
@ -111,7 +92,7 @@ class WebDAV:
|
|||
"""
|
||||
|
||||
_logger.debug(f"write_bytes {path!r}")
|
||||
await asyncify(cls._webdav_client.upload_to)(buffer, path)
|
||||
await asyncify(cls._webdav_client.resource(path).read_from)(buffer)
|
||||
|
||||
try:
|
||||
# hack: zugehörigen Cache-Eintrag entfernen
|
||||
|
|
|
|||
Loading…
Reference in a new issue