mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-15 05:42:08 +08:00
Buffer parsing
This commit is contained in:
@@ -14,14 +14,21 @@ export default async function cachedFetch(url, duration, ua) {
|
|||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = {};
|
const options = {
|
||||||
if (ua) {
|
headers: {
|
||||||
options.headers = {
|
"User-Agent": ua ?? "homepage",
|
||||||
"User-Agent": ua,
|
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
let [, , data] = await httpProxy(url, options);
|
||||||
|
if (Buffer.isBuffer(data)) {
|
||||||
|
try {
|
||||||
|
data = JSON.parse(Buffer.from(data).toString());
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Failed to parse JSON", url, data, Buffer.from(data).toString(), e);
|
||||||
|
data = Buffer.from(data).toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const [, , data] = await httpProxy(url, options);
|
|
||||||
cache.put(url, data, duration * 1000 * 60);
|
cache.put(url, data, duration * 1000 * 60);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user