bitrix24guru/testtest
0
1import { Request, Response } from "express";2import showdown from "showdown";3import { keys } from "./keys";4 5export const handleInfoPage = (req: Request, res: Response) => {6 // Huggingface puts spaces behind some cloudflare ssl proxy, so `req.protocol` is `http` but the correct URL is actually `https`7 const host = req.get("host");8 const isHuggingface = host?.includes("hf.space");9 const protocol = isHuggingface ? "https" : req.protocol;10 res.send(getInfoPageHtml(protocol + "://" + host));11};12 13function getInfoPageHtml(host: string) {14 const keylist = keys.list();15 const info = {16 message: "OpenAI Reverse Proxy",17 uptime: process.uptime(),18 timestamp: Date.now(),19 baseUrl: host,20 kobold: host + "/proxy/kobold" + " (not yet implemented)",21 openai: host + "/proxy/openai",22 keys: {23 all: keylist.length,24 active: keylist.filter((k) => !k.isDisabled).length,25 trial: keylist.filter((k) => k.isTrial).length,26 gpt4: keylist.filter((k) => k.isGpt4).length,27 proompts: keylist.reduce((acc, k) => acc + k.promptCount, 0),28 },29 };30 31 const readme = require("fs").readFileSync("README.md", "utf8");32 const readmeBody = readme.split("---")[2];33 const converter = new showdown.Converter();34 const html = converter.makeHtml(readmeBody);35 36 const pageBody = `<!DOCTYPE html>37<html lang="en">38 <head>39 <meta charset="utf-8" />40 <title>OpenAI Reverse Proxy</title>41 </head>42 <body style="font-family: sans-serif; background-color: #f0f0f0; padding: 1em;"43 ${html}44 <hr />45 <h2>Service Info</h2>46 <pre>${JSON.stringify(info, null, 2)}</pre>47 </body>48</html>`;49 50 return pageBody;51}52 