Files
lnreader-plugins/libs/fetch.ts
T
nyagami 20efcf404c refactor: Classes for Plugins (#631)
* set target to ES5

* refactor types

* use .gitkeep

* use dot to make dist/js dirs on top

* add hako

* add Hako

* add madara

* fix: url path js -> .js

* fix: branch

* freestyle for using UA, cookie

* add parseNovels for Hako

* update readme

* fix: conflict types

* add Kolnovel, remove node-fetch

* add bestlightnovel

* add plugins

* WQMangaStreamScraper
* PandaMTL
* NobleMTL
* LightNovelBrasil
* WPMangaStream

* add filters for popularNovels

* fix undefined json

* Linovelib (#26)

* linovelib CN

* icon for linovelib

* fix undefined chapter

* add check

* fix: add artist

* TuNovelaLigera ES + Madara Fix (#28)

* app repo test

* POST is now working

* update madara template + run generator

* template fix didnt get pushed commited idk why

* template update POST

* generated

* fix: useNewChapterEndpoint update (#29)

* useNewChapterEndpoint update

* Update Selectors

---------

Co-authored-by: K1ngfish3r <trulyihu@gmail.com>
2023-11-04 15:45:49 +05:30

26 lines
744 B
TypeScript

const defaultUserAgentString =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36";
export async function fetchApi(
url: string,
init?: RequestInit,
) {
const headers = {
"User-Agent": defaultUserAgentString,
...init?.headers,
};
return await fetch(url, { ...init, headers });
}
export const fetchFile = async function (url: string, init?: RequestInit) {
if (!init) init = {};
try {
const res = await fetch(url, init);
if (!res.ok) return undefined;
const arrayBuffer = await res.arrayBuffer();
return Buffer.from(arrayBuffer).toString("base64");
} catch (e) {
return undefined;
}
};