diff --git a/oracles/settings.py b/oracles/settings.py index b130be9..fc6f4b4 100644 --- a/oracles/settings.py +++ b/oracles/settings.py @@ -20,6 +20,7 @@ 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_GATEWAY_TOKEN = os.getenv("PINATA_GATEWAY_TOKEN") KNOWLEDGE_BASE_MAX_SIZE_BYTES = int( os.getenv("KNOWLEDGE_BASE_MAX_SIZE_BYTES", 10485760) diff --git a/oracles/src/repositories/ipfs_repository.py b/oracles/src/repositories/ipfs_repository.py index 5c88354..7b37395 100644 --- a/oracles/src/repositories/ipfs_repository.py +++ b/oracles/src/repositories/ipfs_repository.py @@ -2,13 +2,16 @@ import settings from typing import Union -NFT_STORAGE_LINK_BASE = "https://ipfs.io/ipfs/{}" +PINATA_LINK_BASE = "https://galadriel.mypinata.cloud/ipfs/{}" class IpfsRepository: async def read_file(self, cid: str, max_bytes: int = 0) -> bytes: async with aiohttp.ClientSession() as session: - async with session.get(NFT_STORAGE_LINK_BASE.format(cid)) as response: + headers = { + "x-pinata-gateway-token": settings.PINATA_GATEWAY_TOKEN + } + async with session.get(PINATA_LINK_BASE.format(cid)) as response: response.raise_for_status() data = bytearray() while True: @@ -45,6 +48,9 @@ async def write_file(self, data: Union[str, bytes]) -> str: async def main(): ipfs = IpfsRepository() - print(await ipfs.write_file(bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))) + cid = await ipfs.write_file(bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) + assert cid is not None + data = await ipfs.read_file(cid) + assert data == bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) asyncio.run(main())