Fix get_file to accept both Path and string arguments
All callers were passing str(path) but the function expected Path objects, causing 'str' object has no attribute 'parent' errors when fetching from IPFS. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ import logging
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
|
||||
import requests
|
||||
|
||||
@@ -132,13 +132,13 @@ def add_string(content: str, pin: bool = True) -> Optional[str]:
|
||||
return add_bytes(content.encode('utf-8'), pin=pin)
|
||||
|
||||
|
||||
def get_file(cid: str, dest_path: Path) -> bool:
|
||||
def get_file(cid: str, dest_path: Union[Path, str]) -> bool:
|
||||
"""
|
||||
Retrieve a file from IPFS and save to destination.
|
||||
|
||||
Args:
|
||||
cid: IPFS CID to retrieve
|
||||
dest_path: Path to save the file
|
||||
dest_path: Path to save the file (Path object or string)
|
||||
|
||||
Returns:
|
||||
True on success, False on failure
|
||||
@@ -148,6 +148,10 @@ def get_file(cid: str, dest_path: Path) -> bool:
|
||||
if data is None:
|
||||
return False
|
||||
|
||||
# Ensure dest_path is a Path object
|
||||
if isinstance(dest_path, str):
|
||||
dest_path = Path(dest_path)
|
||||
|
||||
dest_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
dest_path.write_bytes(data)
|
||||
logger.info(f"Retrieved from IPFS: {cid} -> {dest_path}")
|
||||
|
||||
Reference in New Issue
Block a user