make .txt work again
This commit is contained in:
parent
d2e77b9ae5
commit
3d8cdca5cd
2 changed files with 23 additions and 4 deletions
|
@ -50,7 +50,7 @@ class WebDAVSettings(DAVSettings):
|
||||||
username: str = "ovd_user"
|
username: str = "ovd_user"
|
||||||
password: str = "password"
|
password: str = "password"
|
||||||
|
|
||||||
config_filename: str = "config.toml"
|
config_filename: str = "config.txt"
|
||||||
|
|
||||||
disable_check: bool = False
|
disable_check: bool = False
|
||||||
retries: int = 20
|
retries: int = 20
|
||||||
|
|
|
@ -5,6 +5,7 @@ from io import BytesIO
|
||||||
from asyncify import asyncify
|
from asyncify import asyncify
|
||||||
from cache import AsyncTTL
|
from cache import AsyncTTL
|
||||||
from cache.key import KEY
|
from cache.key import KEY
|
||||||
|
from requests import Response
|
||||||
from webdav3.client import Client as WebDAVclient
|
from webdav3.client import Client as WebDAVclient
|
||||||
|
|
||||||
from .settings import SETTINGS
|
from .settings import SETTINGS
|
||||||
|
@ -13,7 +14,24 @@ _logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class WebDAV:
|
class WebDAV:
|
||||||
_webdav_client = WebDAVclient(
|
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_hostname": SETTINGS.webdav.url,
|
"webdav_hostname": SETTINGS.webdav.url,
|
||||||
"webdav_login": SETTINGS.webdav.username,
|
"webdav_login": SETTINGS.webdav.username,
|
||||||
|
@ -72,7 +90,8 @@ class WebDAV:
|
||||||
|
|
||||||
_logger.debug(f"read_bytes {path!r}")
|
_logger.debug(f"read_bytes {path!r}")
|
||||||
buffer = BytesIO()
|
buffer = BytesIO()
|
||||||
await asyncify(cls._webdav_client.resource(path).write_to)(buffer)
|
await asyncify(cls._webdav_client.download_from)(buffer, path)
|
||||||
|
buffer.seek(0)
|
||||||
|
|
||||||
return buffer.read()
|
return buffer.read()
|
||||||
|
|
||||||
|
@ -92,7 +111,7 @@ class WebDAV:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_logger.debug(f"write_bytes {path!r}")
|
_logger.debug(f"write_bytes {path!r}")
|
||||||
await asyncify(cls._webdav_client.resource(path).read_from)(buffer)
|
await asyncify(cls._webdav_client.upload_to)(buffer, path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# hack: zugehörigen Cache-Eintrag entfernen
|
# hack: zugehörigen Cache-Eintrag entfernen
|
||||||
|
|
Loading…
Reference in a new issue