mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-01 21:13:39 +01:00
Fix: Google search suggestions with accented characters (#2993)
This commit is contained in:
parent
67d99a5512
commit
1893c9b8da
@ -19,5 +19,5 @@ export default async function handler(req, res) {
|
|||||||
return res.json([query, []]); // Responde with the same array format but with no suggestions.
|
return res.json([query, []]); // Responde with the same array format but with no suggestions.
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.send(await cachedFetch(`${provider.suggestionUrl}${encodeURIComponent(query)}`, 5));
|
return res.send(await cachedFetch(`${provider.suggestionUrl}${encodeURIComponent(query)}`, 5, "Mozilla/5.0"));
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import cache from "memory-cache";
|
|||||||
|
|
||||||
const defaultDuration = 5;
|
const defaultDuration = 5;
|
||||||
|
|
||||||
export default async function cachedFetch(url, duration) {
|
export default async function cachedFetch(url, duration, ua) {
|
||||||
const cached = cache.get(url);
|
const cached = cache.get(url);
|
||||||
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
@ -13,7 +13,13 @@ export default async function cachedFetch(url, duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wrapping text in JSON.parse to handle utf-8 issues
|
// wrapping text in JSON.parse to handle utf-8 issues
|
||||||
const data = JSON.parse(await fetch(url).then((res) => res.text()));
|
const options = {};
|
||||||
|
if (ua) {
|
||||||
|
options.headers = {
|
||||||
|
"User-Agent": ua,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const data = await fetch(url, options).then((res) => res.json());
|
||||||
cache.put(url, data, duration * 1000 * 60);
|
cache.put(url, data, duration * 1000 * 60);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user