Skip to content

Commit e0c5873

Browse files
authored
support download resource (#23)
* support download resource * add return type
1 parent 22f2284 commit e0c5873

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,30 @@ cython_debug/
162162
# and can be added to the global gitignore or merged into this file. For a more nuclear
163163
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
164164
#.idea/
165+
166+
# General
167+
.DS_Store
168+
.AppleDouble
169+
.LSOverride
170+
171+
# Icon must end with two \r
172+
Icon
173+
174+
# Thumbnails
175+
._*
176+
177+
# Files that might appear in the root of a volume
178+
.DocumentRevisions-V100
179+
.fseventsd
180+
.Spotlight-V100
181+
.TemporaryItems
182+
.Trashes
183+
.VolumeIcon.icns
184+
.com.apple.timemachine.donotpresent
185+
186+
# Directories potentially created on remote AFP share
187+
.AppleDB
188+
.AppleDesktop
189+
Network Trash Folder
190+
Temporary Items
191+
.apdisk

client/py/yidong/client.py

+8
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ def list_resource_iter(self, **kwargs) -> PaginationIter[Resource]:
194194
def get_resource(self, id: str) -> Resource:
195195
return self._request(Resource, "get", f"/resource/{id}")
196196

197+
def download_resource(self, id: str, path: str | None = None) -> str:
198+
r = self.get_resource(id)
199+
path = path or r.name or f"{r.id}.{r.mime.split('/')[1]}"
200+
with open(path, "wb") as f:
201+
resp = httpx.get(r.url)
202+
f.write(resp.content)
203+
return path
204+
197205
def delete_resource(self, id: str) -> None:
198206
self._request(bool, "delete", f"/resource/{id}")
199207

0 commit comments

Comments
 (0)