Fixed download sizes and directory highlighting

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
sarahandClaude Opus 5.5 committed 2026-10-13 14:46:47 +02:00
1 parent 843ad1986e
commit d4c018a402
8 files changed
+113 -37

No files matched your search

+9 -2
View File
@@ -435,8 +435,10 @@ class ServerSource(Source):
Done = {**Params, "UploadId": UploadId, "TotalChunks": TotalChunks, "FileName": LocalFile.name}
return self._Json("POST", "/upload/complete", params=Done)["Saved"]
def Download(self, Root: str, RelativePath: str, Destination: Path) -> None:
"""A file as-is, a directory as a .zip (the server builds it)."""
def Download(self, Root: str, RelativePath: str, Destination: Path,
OnProgress: Optional[Callable[[int, int], None]] = None) -> None:
"""A file as-is, a directory as a .zip (the server builds it).
OnProgress(BytesReceived, TotalBytes) as it arrives (Total 0 if unknown)."""
if not self.Url:
raise SourceError("No server address yet.")
Partial = Destination.with_name(Destination.name + ".part")
@@ -445,9 +447,14 @@ class ServerSource(Source):
if not Response.is_success:
Response.read()
raise SourceError(f"Download failed: {Response.status_code} {Response.reason_phrase}", Response.status_code)
Total = int(Response.headers.get("Content-Length") or 0)
Received = 0
with Partial.open("wb") as Handle:
for Chunk in Response.iter_bytes(1024 * 1024):
Handle.write(Chunk)
Received += len(Chunk)
if OnProgress:
OnProgress(Received, Total)
Partial.replace(Destination)
except httpx.HTTPError as Error:
Partial.unlink(missing_ok=True)