Skip to content

Commit

Permalink
fix: fix wrong cache key when caching json on pin (#184)
Browse files Browse the repository at this point in the history
* fix: fix wrong cache key when caching json on pin

* fix: use cache key pattern from rpc instead of proxy

* fix: use req.params instead of originalUrl

* chore: rename var
  • Loading branch information
wa0x6e authored Sep 18, 2023
1 parent f67e54d commit d2c93ab
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fetch from 'node-fetch';
import { capture } from '@snapshot-labs/snapshot-sentry';
import gateways from './gateways.json';
import { set, get } from './aws';
import { MAX, sha256 } from './utils';
import { MAX } from './utils';
import {
ipfsGatewaysReturnCount,
timeIpfsGatewaysResponse,
Expand All @@ -12,10 +12,10 @@ import {

const router = express.Router();

router.get('/ipfs/*', async (req, res) => {
const key = sha256(req.originalUrl);
router.get('^/ipfs/:cid([0-9a-zA-Z]+)$', async (req, res) => {
const { cid } = req.params;
try {
const cache = await get(`cache/${key}`);
const cache = await get(cid);
if (cache) return res.json(cache);

const result = await Promise.any(
Expand Down Expand Up @@ -56,7 +56,7 @@ router.get('/ipfs/*', async (req, res) => {

try {
const size = Buffer.from(JSON.stringify(result.json)).length;
if (size <= MAX) await set(`cache/${key}`, result.json);
if (size <= MAX) await set(cid, result.json);
} catch (e) {
capture(e);
}
Expand Down

0 comments on commit d2c93ab

Please sign in to comment.