Add read-only NAS and WebDAV photo sources with random scheduling
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user