Add read-only NAS and WebDAV photo sources with random scheduling

This commit is contained in:
Pigway
2026-10-05 00:52:39 +08:00
parent b530e32c65
commit f5ab1ade77
18 changed files with 5578 additions and 84 deletions
+9 -5
View File
@@ -114,7 +114,10 @@ class Assets:
raise FlowError(E.INVALID_REQUEST, "Image exceeds 20 MiB")
return data
def fetch_url(self, url):
def fetch_url(
self, url, *, method="GET", headers=None, limit=None, accepted_status=(200,)
):
limit = limit or self.settings.max_bytes
parsed = urlsplit(url)
if (
parsed.scheme != "https"
@@ -153,16 +156,17 @@ class Assets:
connection = PinnedHTTPS(parsed.hostname, timeout=10)
try:
connection.request(
"GET",
method,
(parsed.path or "/") + ("?" + parsed.query if parsed.query else ""),
headers=headers or {},
)
response = connection.getresponse()
if response.status != 200:
if response.status not in accepted_status:
raise FlowError(
E.INVALID_REQUEST, "Image URL returned an invalid response"
)
data = response.read(self.settings.max_bytes + 1)
if len(data) > self.settings.max_bytes:
data = response.read(limit + 1)
if len(data) > limit:
raise FlowError(E.INVALID_REQUEST, "Image exceeds 20 MiB")
return data
finally: