Fix add_file to accept both Path and string
This commit is contained in:
@@ -45,18 +45,22 @@ def _multiaddr_to_url(multiaddr: str) -> str:
|
|||||||
IPFS_BASE_URL = _multiaddr_to_url(IPFS_API)
|
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.
|
Add a file to IPFS and optionally pin it.
|
||||||
|
|
||||||
Args:
|
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)
|
pin: Whether to pin the file (default: True)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
IPFS CID (content identifier) or None on failure
|
IPFS CID (content identifier) or None on failure
|
||||||
"""
|
"""
|
||||||
try:
|
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"
|
url = f"{IPFS_BASE_URL}/api/v0/add"
|
||||||
params = {"pin": str(pin).lower()}
|
params = {"pin": str(pin).lower()}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user