fix: change onlinefixScraper to fetch

This commit is contained in:
João Martins 2024-05-03 14:33:31 -03:00
parent f6072eeb5c
commit d454d0c00b
No known key found for this signature in database
GPG key ID: 4F4EF2B738A71395
6 changed files with 103 additions and 305 deletions

View file

@ -20,3 +20,19 @@ export const requestWebPage = async (url: string) => {
},
}).then((response) => response.text());
};
export const decodeNonUtf8Response = async (res: Response) => {
const contentType = res.headers.get("content-type");
if (!contentType) return res.text();
const charset = contentType.substring(contentType.indexOf("charset=") + 8);
const text = await res.arrayBuffer().then((ab) => {
const dataView = new DataView(ab);
const decoder = new TextDecoder(charset);
return decoder.decode(dataView);
});
return text;
};