Fix add_file to accept both Path and string

This commit is contained in:
gilesb
2026-01-13 04:44:11 +00:00
parent ca2d4a17a4
commit cf83952a19

View File

@@ -45,18 +45,22 @@ def _multiaddr_to_url(multiaddr: str) -> str:
IPFS_BASE_URL = _multiaddr_to_url(IPFS_API)
def add_file(file_path: Path, pin: bool = True) -> Optional[str]:
def add_file(file_path: Union[Path, str], pin: bool = True) -> Optional[str]:
"""
Add a file to IPFS and optionally pin it.
Args:
file_path: Path to the file to add
file_path: Path to the file to add (Path object or string)
pin: Whether to pin the file (default: True)
Returns:
IPFS CID (content identifier) or None on failure
"""
try:
# Ensure file_path is a Path object
if isinstance(file_path, str):
file_path = Path(file_path)
url = f"{IPFS_BASE_URL}/api/v0/add"
params = {"pin": str(pin).lower()}