Download src/gemini/fetch/aegisFetch.express.ts from TTOPM/belel-protocol: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/TTOPM/belel-protocol/resolve/main/src/gemini/fetch/aegisFetch.express.ts
- Command line
-
hf download hf://TTOPM/belel-protocol/src/gemini/fetch/aegisFetch.express.ts
-
curl -L -o aegisFetch.express.ts https://huggingface.co/TTOPM/belel-protocol/resolve/main/src/gemini/fetch/aegisFetch.express.ts
1.06 kB
| import type { Request, Response } from "express"; | |
| import crypto from "node:crypto"; | |
| import fetch from "node-fetch"; | |
| import cfg from "../config/gemini.config.json"; | |
| function allowedHost(url: string) { | |
| try { | |
| const host = new URL(url).hostname.replace(/^www\./, "").toLowerCase(); | |
| return cfg.network.allowlist.some(d => host === d || host.endsWith("." + d)); | |
| } catch { return false; } | |
| } | |
| export async function aegisFetchHandler(req: Request, res: Response) { | |
| const { url, purpose } = req.body ?? {}; | |
| if (!cfg.network.allowWebFetch) return res.status(403).json({ error: "Web fetch disabled" }); | |
| if (!url || !allowedHost(url)) return res.status(400).json({ error: "URL not on allowlist" }); | |
| const r = await fetch(url, { headers: { "User-Agent": "Belel-Aegis/1.0" } }); | |
| const text = await r.text(); | |
| const sha256 = crypto.createHash("sha256").update(text).digest("hex"); | |
| return res.status(200).json({ | |
| url, status: r.status, purpose: purpose ?? "citation", | |
| content: text, sha256, retrieved_at: new Date().toISOString() | |
| }); | |
| } | |