sync: auto-sync from HOWARD-HOME at 2026-07-05 20:23:39
Author: Howard Enos Machine: HOWARD-HOME Timestamp: 2026-07-05 20:23:39
This commit is contained in:
@@ -181,34 +181,22 @@ class SeafileClient:
|
||||
|
||||
The Seafile admin endpoints read from request.data; the share endpoints
|
||||
use QueryDict.getlist('share_to'), which only works for form-encoded
|
||||
bodies (not JSON) -- so all writes go out as
|
||||
application/x-www-form-urlencoded. `form` values that are lists are
|
||||
expanded (doseq) into repeated fields.
|
||||
bodies (not JSON) -- so all writes go out as form-urlencoded via the
|
||||
shared transport (bc.http_json form=). Any 2xx is success; on error we
|
||||
surface the server's message.
|
||||
"""
|
||||
url = f"{self.base}{path}"
|
||||
data = urllib.parse.urlencode(form or {}, doseq=True).encode()
|
||||
req = bc.urllib.request.Request(
|
||||
url, data=data, method=method,
|
||||
headers={"Authorization": f"Token {self._tok()}",
|
||||
"Content-Type": "application/x-www-form-urlencoded"})
|
||||
try:
|
||||
with bc.urllib.request.urlopen(req, timeout=bc.HTTP_TIMEOUT) as resp:
|
||||
status = resp.getcode()
|
||||
raw = resp.read().decode("utf-8", errors="replace")
|
||||
except bc.urllib.error.HTTPError as exc:
|
||||
status = exc.code
|
||||
raw = exc.read().decode("utf-8", errors="replace")
|
||||
except bc.urllib.error.URLError as exc:
|
||||
raise bc.BackupError(f"Seafile {method} {path} failed: {exc}")
|
||||
status, parsed = bc.http_json(
|
||||
method, f"{self.base}{path}", form=form or {},
|
||||
headers={"Authorization": f"Token {self._tok()}"})
|
||||
if status in (401, 403) and retry_auth:
|
||||
self._token = self._authorize()
|
||||
return self._write(method, path, form, retry_auth=False)
|
||||
try:
|
||||
parsed = json.loads(raw) if raw.strip() else {}
|
||||
except json.JSONDecodeError:
|
||||
parsed = {"_raw": raw[:600]}
|
||||
if status not in (200, 201):
|
||||
msg = parsed.get("error_msg") or parsed.get("detail") or raw[:400]
|
||||
if not (200 <= status < 300):
|
||||
msg = ""
|
||||
if isinstance(parsed, dict):
|
||||
msg = parsed.get("error_msg") or parsed.get("detail") or ""
|
||||
if not msg:
|
||||
msg = json.dumps(parsed)[:400] if parsed else ""
|
||||
raise bc.BackupError(f"Seafile {method} {path} failed (HTTP {status}): {msg}",
|
||||
status=status)
|
||||
return parsed
|
||||
|
||||
Reference in New Issue
Block a user