Download src/lib/http.js from bilaku/komik: direct link, hf CLI and curl.
- Browser
- Download file 929 Bytes
-
https://huggingface.co/spaces/bilaku/komik/resolve/main/src/lib/http.js
- Command line
-
hf download hf://spaces/bilaku/komik/src/lib/http.js
-
curl -L -o http.js https://huggingface.co/spaces/bilaku/komik/resolve/main/src/lib/http.js
929 Bytes
| import axios from "axios"; | |
| import { USER_AGENT, BASE_URL } from "../config.js"; | |
| import { getCache, setCache } from "./cache.js"; | |
| const client = axios.create({ | |
| timeout: 20000, | |
| headers: { | |
| "User-Agent": USER_AGENT, | |
| "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | |
| "Accept-Language": "id-ID,id;q=0.9,en;q=0.8", | |
| "Referer": BASE_URL + "/", | |
| }, | |
| }); | |
| export async function fetchHtml(url, { useCache = true, retries = 2 } = {}) { | |
| if (useCache) { | |
| const cached = getCache(url); | |
| if (cached) return cached; | |
| } | |
| let lastErr; | |
| for (let attempt = 0; attempt <= retries; attempt++) { | |
| try { | |
| const res = await client.get(url); | |
| if (useCache) setCache(url, res.data); | |
| return res.data; | |
| } catch (err) { | |
| lastErr = err; | |
| if (attempt < retries) { | |
| await new Promise((r) => setTimeout(r, 600 * (attempt + 1))); | |
| } | |
| } | |
| } | |
| throw lastErr; | |
| } | |