hippius 0.2.9__tar.gz → 0.2.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hippius-0.2.9 → hippius-0.2.10}/PKG-INFO +1 -1
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/__init__.py +1 -1
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/cli_handlers.py +1 -2
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/client.py +1 -1
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/ipfs.py +32 -113
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/ipfs_core.py +1 -1
- {hippius-0.2.9 → hippius-0.2.10}/pyproject.toml +1 -1
- {hippius-0.2.9 → hippius-0.2.10}/README.md +0 -0
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/cli.py +0 -0
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/cli_assets.py +0 -0
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/cli_parser.py +0 -0
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/cli_rich.py +0 -0
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/config.py +0 -0
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/errors.py +0 -0
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/substrate.py +0 -0
- {hippius-0.2.9 → hippius-0.2.10}/hippius_sdk/utils.py +0 -0
@@ -1032,8 +1032,7 @@ async def handle_ec_files(
|
|
1032
1032
|
with tempfile.NamedTemporaryFile() as temp:
|
1033
1033
|
temp_path = temp.name
|
1034
1034
|
|
1035
|
-
|
1036
|
-
await client.ipfs_client.download_file(metadata_cid, temp_path)
|
1035
|
+
await client.download_file(metadata_cid, temp_path)
|
1037
1036
|
|
1038
1037
|
# Open and parse the metadata file
|
1039
1038
|
with open(temp_path, "r") as f:
|
@@ -169,7 +169,7 @@ class HippiusClient:
|
|
169
169
|
requests.RequestException: If the download fails
|
170
170
|
ValueError: If decryption is requested but fails
|
171
171
|
"""
|
172
|
-
return await self.ipfs_client.download_file(cid, output_path,
|
172
|
+
return await self.ipfs_client.download_file(cid, output_path, _=decrypt)
|
173
173
|
|
174
174
|
async def cat(
|
175
175
|
self,
|
@@ -441,20 +441,17 @@ class IPFSClient:
|
|
441
441
|
self,
|
442
442
|
cid: str,
|
443
443
|
output_path: str,
|
444
|
-
|
444
|
+
_: Optional[bool] = None,
|
445
445
|
max_retries: int = 3,
|
446
|
-
skip_directory_check: bool = False,
|
447
446
|
) -> Dict[str, Any]:
|
448
447
|
"""
|
449
448
|
Download a file from IPFS with optional decryption.
|
450
|
-
Supports downloading directories - in that case, a directory structure will be created.
|
451
449
|
|
452
450
|
Args:
|
453
451
|
cid: Content Identifier (CID) of the file to download
|
454
|
-
output_path: Path where the downloaded file
|
455
|
-
|
452
|
+
output_path: Path where the downloaded file will be saved
|
453
|
+
_: Whether to decrypt the file (overrides default)
|
456
454
|
max_retries: Maximum number of retry attempts (default: 3)
|
457
|
-
skip_directory_check: If True, skips directory check (treats as file)
|
458
455
|
|
459
456
|
Returns:
|
460
457
|
Dict[str, Any]: Dictionary containing download results:
|
@@ -464,7 +461,6 @@ class IPFSClient:
|
|
464
461
|
- size_formatted: Human-readable file size
|
465
462
|
- elapsed_seconds: Time taken for the download in seconds
|
466
463
|
- decrypted: Whether the file was decrypted
|
467
|
-
- is_directory: Whether the download was a directory
|
468
464
|
|
469
465
|
Raises:
|
470
466
|
requests.RequestException: If the download fails
|
@@ -472,117 +468,40 @@ class IPFSClient:
|
|
472
468
|
"""
|
473
469
|
start_time = time.time()
|
474
470
|
|
475
|
-
|
476
|
-
|
477
|
-
if not skip_directory_check:
|
478
|
-
# Use the improved ls function to properly detect directories
|
479
|
-
try:
|
480
|
-
# The ls function now properly detects directories
|
481
|
-
ls_result = await self.client.ls(cid)
|
482
|
-
is_directory = ls_result.get("is_directory", False)
|
483
|
-
except Exception:
|
484
|
-
# If ls fails, we'll proceed as if it's a file
|
485
|
-
pass
|
486
|
-
|
487
|
-
# If it's a directory, handle it differently
|
488
|
-
if is_directory:
|
489
|
-
# For directories, we don't need to decrypt each file during the initial download
|
490
|
-
# We'll use the AsyncIPFSClient's download_directory method directly
|
471
|
+
retries = 0
|
472
|
+
while retries < max_retries:
|
491
473
|
try:
|
492
|
-
|
474
|
+
url = f"{self.gateway}/ipfs/{cid}"
|
475
|
+
async with self.client.client.stream(url=url, method="GET") as response:
|
476
|
+
response.raise_for_status()
|
493
477
|
|
494
|
-
# Calculate the total size of the directory
|
495
|
-
total_size = 0
|
496
|
-
for root, _, files in os.walk(output_path):
|
497
|
-
for file in files:
|
498
|
-
file_path = os.path.join(root, file)
|
499
|
-
total_size += os.path.getsize(file_path)
|
500
|
-
|
501
|
-
elapsed_time = time.time() - start_time
|
502
|
-
|
503
|
-
return {
|
504
|
-
"success": True,
|
505
|
-
"output_path": output_path,
|
506
|
-
"size_bytes": total_size,
|
507
|
-
"size_formatted": self.format_size(total_size),
|
508
|
-
"elapsed_seconds": round(elapsed_time, 2),
|
509
|
-
"decrypted": False, # Directories aren't decrypted as a whole
|
510
|
-
"is_directory": True,
|
511
|
-
}
|
512
|
-
except Exception as e:
|
513
|
-
raise RuntimeError(f"Failed to download directory: {str(e)}")
|
514
|
-
|
515
|
-
# For regular files, use the existing logic
|
516
|
-
# Determine if we should decrypt
|
517
|
-
should_decrypt = self.encrypt_by_default if decrypt is None else decrypt
|
518
|
-
|
519
|
-
# Check if decryption is available if requested
|
520
|
-
if should_decrypt and not self.encryption_available:
|
521
|
-
raise ValueError(
|
522
|
-
"Decryption requested but not available. Check that PyNaCl is installed and a valid encryption key is provided."
|
523
|
-
)
|
524
|
-
|
525
|
-
# Create a temporary file if we'll be decrypting
|
526
|
-
temp_file_path = None
|
527
|
-
try:
|
528
|
-
if should_decrypt:
|
529
|
-
# Create a temporary file for the encrypted data
|
530
|
-
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
531
|
-
temp_file_path = temp_file.name
|
532
|
-
temp_file.close()
|
533
|
-
download_path = temp_file_path
|
534
|
-
else:
|
535
|
-
download_path = output_path
|
536
|
-
|
537
|
-
# Pass the skip_directory_check parameter to the core client
|
538
|
-
await self.client.download_file(
|
539
|
-
cid, download_path, skip_directory_check=skip_directory_check
|
540
|
-
)
|
541
|
-
download_success = True
|
542
|
-
|
543
|
-
if not download_success:
|
544
|
-
raise RuntimeError("Failed to download file after multiple attempts")
|
545
|
-
|
546
|
-
# Decrypt if needed
|
547
|
-
if should_decrypt:
|
548
|
-
try:
|
549
|
-
# Read the encrypted data
|
550
|
-
with open(temp_file_path, "rb") as f:
|
551
|
-
encrypted_data = f.read()
|
552
|
-
|
553
|
-
# Decrypt the data
|
554
|
-
decrypted_data = self.decrypt_data(encrypted_data)
|
555
|
-
|
556
|
-
# Write the decrypted data to the output path
|
557
|
-
os.makedirs(
|
558
|
-
os.path.dirname(os.path.abspath(output_path)), exist_ok=True
|
559
|
-
)
|
560
478
|
with open(output_path, "wb") as f:
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
479
|
+
async for chunk in response.aiter_bytes(chunk_size=8192):
|
480
|
+
f.write(chunk)
|
481
|
+
break
|
482
|
+
|
483
|
+
except (httpx.HTTPError, IOError) as e:
|
484
|
+
retries += 1
|
485
|
+
|
486
|
+
if retries < max_retries:
|
487
|
+
wait_time = 2**retries
|
488
|
+
print(f"Download attempt {retries} failed: {str(e)}")
|
489
|
+
print(f"Retrying in {wait_time} seconds...")
|
490
|
+
time.sleep(wait_time)
|
491
|
+
else:
|
492
|
+
raise
|
569
493
|
|
570
|
-
|
494
|
+
file_size_bytes = os.path.getsize(output_path)
|
495
|
+
elapsed_time = time.time() - start_time
|
571
496
|
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
}
|
581
|
-
|
582
|
-
finally:
|
583
|
-
# Clean up temporary file if created
|
584
|
-
if temp_file_path and os.path.exists(temp_file_path):
|
585
|
-
os.unlink(temp_file_path)
|
497
|
+
return {
|
498
|
+
"success": True,
|
499
|
+
"output_path": output_path,
|
500
|
+
"size_bytes": file_size_bytes,
|
501
|
+
"size_formatted": self.format_size(file_size_bytes),
|
502
|
+
"elapsed_seconds": round(elapsed_time, 2),
|
503
|
+
"decrypted": _,
|
504
|
+
}
|
586
505
|
|
587
506
|
async def cat(
|
588
507
|
self,
|
@@ -36,7 +36,7 @@ class AsyncIPFSClient:
|
|
36
36
|
api_url = "http://localhost:5001"
|
37
37
|
self.api_url = api_url
|
38
38
|
self.gateway = gateway
|
39
|
-
self.client = httpx.AsyncClient(timeout=
|
39
|
+
self.client = httpx.AsyncClient(timeout=300, follow_redirects=True)
|
40
40
|
|
41
41
|
async def close(self):
|
42
42
|
"""Close the httpx client."""
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|