Conversation
Signed-off-by: d4v1d03 <amit08072005@gmail.com>
Signed-off-by: Amit Pandey <amit08072005@gmail.com>
Signed-off-by: Amit Pandey <amit08072005@gmail.com>
Signed-off-by: Amit Pandey <amit08072005@gmail.com>
| print("\n⚠️ Some dependencies could not be installed automatically.") | ||
| print("Please install them manually before using the package.") | ||
| print("- ipfs-car: npm install -g ipfs-car") | ||
| print("- w3cli: npm install -g @web3-storage/w3") |
There was a problem hiding this comment.
| print("- w3cli: npm install -g @web3-storage/w3") | |
| print("- w3cli: npm install -g @web3-storage/w3cli") |
| @@ -0,0 +1,154 @@ | |||
| """import os | |||
There was a problem hiding this comment.
Is this meant to be commented?
There was a problem hiding this comment.
my bad, i forgot to remove this file
|
|
||
| auth_secret = os.getenv("X-AUTH-SECRET-HEADER") | ||
| authorization = os.getenv("AUTHORIZATION-HEADER") | ||
| endpoint = os.getenv("HTTPS-ENDPOINT", "https://up.storacha.network/bridge") |
There was a problem hiding this comment.
Env vars should use underscore (_) not dash (-) to be a valid bash variable.
| return response.json() | ||
| else: | ||
| print(f"❌ Upload failed with status code {response.status_code}: {response.text}") | ||
| return None |
| json.dump(payload, temp, indent=2) | ||
| temp_json_path = temp.name | ||
|
|
||
| return temp_json_path |
There was a problem hiding this comment.
Why does it store these and not return them?
|
|
||
| def upload_to_storacha(json_file): | ||
| """Upload to Storacha using the HTTP Bridge.""" | ||
| load_dotenv() |
There was a problem hiding this comment.
I would pass these dotenv vars to the function as parameters, and load them in main(). This allows the script to be used as a library where the values could come from places oter than environment vars.
|
|
||
| cid, car_file = create_dag_and_car(file_path) | ||
|
|
||
| json_file = create_all_instructions_json(cid, space_did) |
There was a problem hiding this comment.
Why all "instructions"? We only want to do store/add next...
There was a problem hiding this comment.
Fixed this, I've put other instructions that the user can use in the README.md
| return cid, car_file | ||
| except subprocess.CalledProcessError as e: | ||
| print(f"❌ ipfs-car failed: {e.stderr.decode('utf-8')}") | ||
| sys.exit(1) |
There was a problem hiding this comment.
I'd avoid printing and sys.exit in methods that could be used as library code. Instead catch the error here, and re-throw it with the constructed error message. It can be caught in main() if you like but I assume a raised error is going to be printed to the console and the exit code set to non-zero anyways.
| return None | ||
|
|
||
| def create_dag_and_car(file_path): | ||
| if not os.path.exists(file_path): |
There was a problem hiding this comment.
ipfs-car will do this - I think this is redundant.
There was a problem hiding this comment.
It is? I still see the conditional here.
There was a problem hiding this comment.
can you review again pls , ive used ipfs-car directly this time
Signed-off-by: Amit Pandey <amit08072005@gmail.com>
Signed-off-by: Amit Pandey <amit08072005@gmail.com>
|
|
||
| ## Instructions to be used over the http bridge | ||
|
|
||
| Below instructions can be used over the http bridge by adidng them to the list.json file. |
There was a problem hiding this comment.
| Below instructions can be used over the http bridge by adidng them to the list.json file. | |
| Below instructions can be used over the http bridge by adding them to the list.json file. |
| ] | ||
| */ | ||
| ] | ||
| } |
There was a problem hiding this comment.
I think this is a bit confusing, why not expose these as separate methods on the client?
| return None | ||
|
|
||
| def create_dag_and_car(file_path): | ||
| if not os.path.exists(file_path): |
There was a problem hiding this comment.
It is? I still see the conditional here.
| raise FileNotFoundError(f"File '{file_path}' not found.") | ||
|
|
||
| car_file = f"{file_path}.car" | ||
| ipfs_car_cmd = f"npx ipfs-car pack {file_path} --output {car_file}" if platform.system() == "Windows" else f"ipfs-car pack {file_path} --output {car_file}" |
There was a problem hiding this comment.
Why npx only on windows?
Why not install ipfs-car as part of the setup?
There was a problem hiding this comment.
fixed this and added it to package.json
| print("❌ w3cli not found.") | ||
| print("📦 Installing w3cli globally...") | ||
| try: | ||
| subprocess.run("npm install -g @web3-storage/w3cli", shell=True, check=True) |
There was a problem hiding this comment.
Does it need to be global - can you just add it to the package.json here and install and use it locally?
| payload = f.read() | ||
| return payload | ||
|
|
||
| def upload_to_storacha(json_payload, auth_secret, authorization, endpoint): |
There was a problem hiding this comment.
I'd perhaps rename - this is "send request to the bridge".
| try: | ||
| cid, car_file = create_dag_and_car(file_path) | ||
| json_payload = read_list_json() | ||
| result = upload_to_storacha(json_payload, auth_secret, authorization, endpoint) |
There was a problem hiding this comment.
I think we're missing a step here. The response from the bridge will have the URL for where you should HTTP PUT the data. Have a read through https://docs.storacha.network/how-to/http-bridge/#storing-files
There was a problem hiding this comment.
My bad, i checked this right now. Fixed it now
Signed-off-by: Amit Pandey <amit08072005@gmail.com>
Signed-off-by: Amit Pandey <amit08072005@gmail.com>
Draft PR on the issue #1621