Skip to content

Commit

Permalink
Removes nft.storage and adds Pinata upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kgrofelnik committed Apr 3, 2024
1 parent b94df77 commit fd790ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion oracles/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

GCS_BUCKET_NAME = os.getenv("GCS_BUCKET_NAME", "galadriel-assets")
SERVE_METRICS = os.getenv("SERVE_METRICS", "False").lower() == "true"
NFT_STORAGE_API_KEY = os.getenv("NFT_STORAGE_API_KEY")
BEARLY_API_KEY = os.getenv("BEARLY_API_KEY")
PINATA_API_JWT = os.getenv("PINATA_API_JWT")
PINATA_GATEWAY_TOKEN = os.getenv("PINATA_GATEWAY_TOKEN")

KNOWLEDGE_BASE_MAX_SIZE_BYTES = int(
Expand Down
14 changes: 9 additions & 5 deletions oracles/src/repositories/ipfs_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@ async def write_file(self, data: Union[str, bytes]) -> str:
mime_type = (
"text/plain" if isinstance(data, str) else "application/octet-stream"
)
form_data = aiohttp.FormData()
form_data.add_field("file",
data,
filename="file",
content_type=mime_type)
async with aiohttp.ClientSession() as session:
async with session.post(
"https://api.nft.storage/upload",
"https://api.pinata.cloud/pinning/pinFileToIPFS",
headers={
"Authorization": f"Bearer {settings.NFT_STORAGE_API_KEY}",
"Content-Type": mime_type,
"Authorization": f"Bearer {settings.PINATA_API_JWT}",
},
data=data,
data=form_data,
) as response:
response.raise_for_status()
json_response = await response.json()
return json_response.get("value").get("cid")
return json_response.get("IpfsHash")


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions oracles/template.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ GCS_BUCKET_NAME="galadriel-assets"
BEARLY_API_KEY=""
SERVE_METRICS="False"
NFT_STORAGE_API_KEY=""
PINATA_GATEWAY_TOKEN=""
PINATA_API_JWT=""

# serialized knowledge base max size in bytes
# 10 megabytes * 1024 * 1024
Expand Down

0 comments on commit fd790ea

Please sign in to comment.