Skip to content

Commit

Permalink
fix: PR reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
negar-abbasi committed Dec 13, 2023
1 parent a1a97cf commit a65f0ae
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/algokit/cli/tasks/ipfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def upload(file_path: Path, name: str | None) -> None:
if total > MAX_FILE_SIZE:
raise click.ClickException("File size exceeds 100MB limit!")

with yaspin(text="Uploading\n", color="yellow") as spinner:
with yaspin(text="Uploading", color="yellow") as spinner:
cid = upload_to_pinata(file_path, pinata_jwt, name)
spinner.ok("✅ ")
logger.info(f"File uploaded successfully!\nCID: {cid}")
Expand Down
19 changes: 8 additions & 11 deletions src/algokit/core/tasks/ipfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
ALGOKIT_PINATA_TOKEN_KEY = "algokit_pinata_access_token"

MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB
MAX_CHUNK_SIZE = 1024 * 1024 # 1MB
DEFAULT_TIMEOUT = 10
DEFAULT_TIMEOUT = 90


class PinataError(Exception):
Expand Down Expand Up @@ -63,14 +62,14 @@ def get_pinata_jwt() -> str | None:
"to create an account and obtain a JWT."
)
keyring.delete_password("algokit_web3_storage", "algokit_web3_storage_access_token")
except KeyError as ex:
logger.debug("Old Web3 Storage API key is already deleted.", exc_info=ex)
except Exception:
pass
return keyring.get_password(ALGOKIT_PINATA_NAMESPACE, ALGOKIT_PINATA_TOKEN_KEY)


def set_pinata_jwt(jwt: str | None) -> None:
"""
Sets or deletes a password in the keyring library based on the provided KWT.
Sets or deletes a password in the keyring library based on the provided JWT.
Args:
jwt (str | None): The JWT to be set in the keyring library. If None, the password will be deleted.
Expand Down Expand Up @@ -117,9 +116,6 @@ def upload_to_pinata(file_path: Path, jwt: str, name: str | None = None) -> str:

with file_path.open("rb") as file:
file_content = file.read()
num_chunks = file_path.stat().st_size // MAX_CHUNK_SIZE | 1
timeout = DEFAULT_TIMEOUT * num_chunks
logger.debug(f"Timeout set to {timeout} seconds based on {num_chunks} chunks.")

headers = {
"accept": "application/json",
Expand All @@ -137,11 +133,12 @@ def upload_to_pinata(file_path: Path, jwt: str, name: str | None = None) -> str:
headers=headers,
timeout=DEFAULT_TIMEOUT,
)

response.raise_for_status()
ipfs_hash = response.json().get("IpfsHash")
if not isinstance(ipfs_hash, str):
cid = response.json().get("IpfsHash")
if not isinstance(cid, str):
raise ValueError("IpfsHash is not a string.")
return ipfs_hash
return cid
except httpx.HTTPStatusError as ex:
if ex.response.status_code == httpx.codes.BAD_REQUEST:
raise PinataBadRequestError(ex.response) from ex
Expand Down
2 changes: 1 addition & 1 deletion src/algokit/core/tasks/mint/mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def mint_token( # noqa: PLR0913
Args:
client (algod.AlgodClient): An instance of the `algod.AlgodClient` class representing the Algorand node.
jwt (str): A string representing the JWT for accessing the Algorand network.
jwt (str): The JWT for accessing the Piñata API.
creator_account (Account): An instance of the `Account` class representing the account that
will create the token.
asset_name (str): A string representing the name of the token.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
DEBUG: Old Web3 Storage API key is already deleted.
WARNING: You are already logged in!
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
DEBUG: Old Web3 Storage API key is already deleted.
Follow the instructions on https://docs.pinata.cloud/docs/getting-started to create an account and obtain a JWT.
Enter pinata JWT:
Repeat for confirmation:
Expand Down
1 change: 0 additions & 1 deletion tests/tasks/TestIpfsLogout.test_ipfs_logout.approved.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
DEBUG: Old Web3 Storage API key is already deleted.
Logout successful
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
DEBUG: Old Web3 Storage API key is already deleted.



⠋ Uploading
DEBUG: Timeout set to 10 seconds based on 1 chunks.
DEBUG: HTTP Request: POST https://api.pinata.cloud/pinning/pinFileToIPFS "HTTP/1.1 500 Internal Server Error"
⠋ UploadingDEBUG: HTTP Request: POST https://api.pinata.cloud/pinning/pinFileToIPFS "HTTP/1.1 500 Internal Server Error"


DEBUG: Pinata error: 500. {"ok": false, "cid": "test"}
Error: PinataInternalServerError('Pinata error: 500')
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
DEBUG: Old Web3 Storage API key is already deleted.



⠋ Uploading
DEBUG: Timeout set to 10 seconds based on 1 chunks.
DEBUG: HTTP Request: POST https://api.pinata.cloud/pinning/pinFileToIPFS "HTTP/1.1 200 OK"
⠋ UploadingDEBUG: HTTP Request: POST https://api.pinata.cloud/pinning/pinFileToIPFS "HTTP/1.1 200 OK"


✅ Uploading

File uploaded successfully!
CID: test
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Enter the mnemonic phrase (25 words separated by whitespace):
Uploading image to pinata...
DEBUG: Timeout set to 10 seconds based on 1 chunks.
DEBUG: HTTP Request: POST https://api.pinata.cloud/pinning/pinFileToIPFS "HTTP/1.1 403 Forbidden"
DEBUG: Pinata error: 403. {"ok": false}
Error: PinataForbiddenError('Pinata error: 403')

0 comments on commit a65f0ae

Please sign in to comment.