From a3462e21bc6b36a6e4529c6a84643dc407301be4 Mon Sep 17 00:00:00 2001 From: nai-degen Date: Sun, 19 May 2024 15:17:25 -0500 Subject: [PATCH] adds config setting for PoW verification timeout --- src/config.ts | 10 +++++++ src/info-page.ts | 18 +++++++----- src/shared/views/partials/shared_header.ejs | 3 -- src/user/web/pow-captcha.ts | 6 ++-- .../views/partials/user_challenge_widget.ejs | 29 ++++++++++++------- src/user/web/views/user_request_token.ejs | 9 ++---- 6 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/config.ts b/src/config.ts index ed835b2..7d63094 100644 --- a/src/config.ts +++ b/src/config.ts @@ -127,6 +127,15 @@ type Config = { * details on the available modes. */ powDifficultyLevel: "low" | "medium" | "high" | "extreme"; + /** + * Duration in minutes before a PoW challenge expires. Users' browsers must + * solve the challenge within this time frame or it will be rejected. + * Defaults to 30 minutes. It should be kept somewhat low to prevent abusive + * clients from working on many challenges in parallel, but you may need to + * increase this value for higher difficulty levels or older devices will not + * be able to solve the challenge in time. + */ + powChallengeTimeout: number; /** Per-user limit for requests per minute to text and chat models. */ textModelRateLimit: number; /** Per-user limit for requests per minute to image generation models. */ @@ -322,6 +331,7 @@ export const config: Config = { powTokenHours: getEnvWithDefault("POW_TOKEN_HOURS", 24), powTokenMaxIps: getEnvWithDefault("POW_TOKEN_MAX_IPS", 2), powDifficultyLevel: getEnvWithDefault("POW_DIFFICULTY_LEVEL", "low"), + powChallengeTimeout: getEnvWithDefault("POW_CHALLENGE_TIMEOUT", 30), firebaseRtdbUrl: getEnvWithDefault("FIREBASE_RTDB_URL", undefined), firebaseKey: getEnvWithDefault("FIREBASE_KEY", undefined), textModelRateLimit: getEnvWithDefault("TEXT_MODEL_RATE_LIMIT", 4), diff --git a/src/info-page.ts b/src/info-page.ts index 12c076c..711ccd5 100644 --- a/src/info-page.ts +++ b/src/info-page.ts @@ -16,7 +16,7 @@ const MODEL_FAMILY_FRIENDLY_NAME: { [f in ModelFamily]: string } = { gpt4: "GPT-4", "gpt4-32k": "GPT-4 32k", "gpt4-turbo": "GPT-4 Turbo", - "gpt4o": "GPT-4o", + gpt4o: "GPT-4o", "dall-e": "DALL-E", claude: "Claude (Sonnet)", "claude-opus": "Claude (Opus)", @@ -146,11 +146,15 @@ This proxy keeps full logs of all prompts and AI responses. Prompt logs are anon function getSelfServiceLinks() { if (config.gatekeeper !== "user_token") return ""; - const links = [ - ["Request a user token", "/user/captcha",], - ["Check your user token", "/user/lookup",] - ] - return `
${links.map(([text, link]) => `${text}`).join(" / ")}

`; + + const links = [["Check your user token", "/user/lookup"]]; + if (config.captchaMode !== "none") { + links.unshift(["Request a user token", "/user/captcha"]); + } + + return `
${links + .map(([text, link]) => `${text}`) + .join(" / ")}

`; } function getServerTitle() { @@ -262,7 +266,7 @@ if (config.serviceInfoPassword?.length) { }); infoPageRouter.use(checkIfUnlocked); } -infoPageRouter.get("/", handleInfoPage); +infoPageRouter.get("/", (req, res) => res.sendStatus(204)); infoPageRouter.get("/status", (req, res) => { res.json(buildInfo(req.protocol + "://" + req.get("host"), false)); }); diff --git a/src/shared/views/partials/shared_header.ejs b/src/shared/views/partials/shared_header.ejs index bb0d86a..0726364 100644 --- a/src/shared/views/partials/shared_header.ejs +++ b/src/shared/views/partials/shared_header.ejs @@ -3,7 +3,6 @@ - <%= title %>