import { Request, Response } from "express"; import showdown from "showdown"; import { keys } from "./keys"; export const handleInfoPage = (req: Request, res: Response) => { // Huggingface puts spaces behind some cloudflare ssl proxy, so `req.protocol` is `http` but the correct URL is actually `https` const host = req.get("host"); const isHuggingface = host?.includes("hf.space"); const protocol = isHuggingface ? "https" : req.protocol; res.send(getInfoPageHtml(protocol + "://" + host)); }; function getInfoPageHtml(host: string) { const keylist = keys.list(); const info = { message: "OpenAI Reverse Proxy", uptime: process.uptime(), timestamp: Date.now(), baseUrl: host, kobold: host + "/proxy/kobold" + " (not yet implemented)", openai: host + "/proxy/openai", keys: { all: keylist.length, active: keylist.filter((k) => !k.isDisabled).length, trial: keylist.filter((k) => k.isTrial).length, gpt4: keylist.filter((k) => k.isGpt4).length, proompts: keylist.reduce((acc, k) => acc + k.promptCount, 0), }, }; const readme = require("fs").readFileSync("README.md", "utf8"); const readmeBody = readme.split("---")[2]; const converter = new showdown.Converter(); const html = converter.makeHtml(readmeBody); const pageBody = ` OpenAI Reverse Proxy

Service Info

${JSON.stringify(info, null, 2)}
`; return pageBody; }