Skip to content

Commit

Permalink
support download resource (#23)
Browse files Browse the repository at this point in the history
* support download resource

* add return type
  • Loading branch information
findmyway authored Nov 13, 2024
1 parent 22f2284 commit e0c5873
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,30 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
Expand Down
8 changes: 8 additions & 0 deletions client/py/yidong/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ def list_resource_iter(self, **kwargs) -> PaginationIter[Resource]:
def get_resource(self, id: str) -> Resource:
return self._request(Resource, "get", f"/resource/{id}")

def download_resource(self, id: str, path: str | None = None) -> str:
r = self.get_resource(id)
path = path or r.name or f"{r.id}.{r.mime.split('/')[1]}"
with open(path, "wb") as f:
resp = httpx.get(r.url)
f.write(resp.content)
return path

def delete_resource(self, id: str) -> None:
self._request(bool, "delete", f"/resource/{id}")

Expand Down

0 comments on commit e0c5873

Please sign in to comment.