Use proxy for cached fetch

This commit is contained in:
shamoon
2025-03-16 14:37:39 -07:00
parent 5caeba577e
commit 513e3959aa

View File

@@ -1,4 +1,5 @@
import cache from "memory-cache"; import cache from "memory-cache";
import { httpProxy } from "utils/proxy/http";
const defaultDuration = 5; const defaultDuration = 5;
@@ -12,14 +13,13 @@ export default async function cachedFetch(url, duration, ua) {
return cached; return cached;
} }
// wrapping text in JSON.parse to handle utf-8 issues
const options = {}; const options = {};
if (ua) { if (ua) {
options.headers = { options.headers = {
"User-Agent": ua, "User-Agent": ua,
}; };
} }
const data = await fetch(url, options).then((res) => res.json()); const [, , data] = await httpProxy(url, options);
cache.put(url, data, duration * 1000 * 60); cache.put(url, data, duration * 1000 * 60);
return data; return data;
} }