Spaces:
Sleeping
Sleeping
Essi
commited on
Commit
·
f38ac36
1
Parent(s):
7cfdefc
feat: add `fetch_task_file` function to retrieve task files from API
Browse files- helpers.py +18 -0
helpers.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
|
4 |
+
def fetch_task_file(api_url: str, task_id: str) -> tuple[bytes, str]:
|
5 |
+
"""
|
6 |
+
Returns (file_bytes, content_type) or (b'', '') if no attachment found.
|
7 |
+
Follows any redirect the endpoint issues.
|
8 |
+
"""
|
9 |
+
url = f"{api_url}/files/{task_id}"
|
10 |
+
try:
|
11 |
+
r = requests.get(url, timeout=15, allow_redirects=True)
|
12 |
+
except requests.RequestException as e:
|
13 |
+
print(f"[DEBUG] GET {url} failed → {e}")
|
14 |
+
return b"", ""
|
15 |
+
if r.status_code != 200:
|
16 |
+
print(f"[DEBUG] GET {url} → {r.status_code}")
|
17 |
+
return b"", ""
|
18 |
+
return r.content, r.headers.get("content-type", "").lower()
|