Skip to content

Commit

Permalink
fix: support user to enter multiple keys
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 5, 2023
1 parent 73e1796 commit e43c0ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Redis } from "@upstash/redis";
import type { NextFetchEvent, NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { validateLicenseKey } from "./utils/3rd/lemon";
import { checkOpenaiApiKey } from "./utils/3rd/openai";
import { checkOpenaiApiKeys } from "./utils/3rd/openai";
import { ratelimit } from "./utils/3rd/upstash";
import { isDev } from "./utils/env";

Expand All @@ -18,7 +18,7 @@ export async function middleware(req: NextRequest, context: NextFetchEvent) {

// licenseKeys
if (apiKey) {
if (checkOpenaiApiKey(apiKey)) {
if (checkOpenaiApiKeys(apiKey)) {
return NextResponse.next();
}

Expand Down
26 changes: 26 additions & 0 deletions pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default () => {
return (
<section className="bg-white dark:bg-gray-900">
<div className="mx-auto max-w-screen-xl py-8 px-4 lg:py-16 lg:px-6">
<div className="mx-auto max-w-screen-sm text-center">
<h1 className="text-primary-600 dark:text-primary-500 mb-4 text-7xl font-extrabold tracking-tight lg:text-9xl">
404
</h1>
<p className="mb-4 text-3xl font-bold tracking-tight text-gray-900 dark:text-white md:text-4xl">
Something's missing.
</p>
<p className="mb-4 text-lg font-light text-gray-500 dark:text-gray-400">
Sorry, we can't find that page. You'll find lots to explore on the
home page.{" "}
</p>
<a
href="#"
className="bg-primary-600 hover:bg-primary-800 focus:ring-primary-300 dark:focus:ring-primary-900 my-4 inline-flex rounded-lg px-5 py-2.5 text-center text-sm font-medium focus:outline-none focus:ring-4"
>
Back to Homepage
</a>
</div>
</div>
</section>
);
};
9 changes: 9 additions & 0 deletions utils/3rd/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@ export function checkOpenaiApiKey(str: string) {
var pattern = /^sk-[A-Za-z0-9]{48}$/;
return pattern.test(str);
}

export function checkOpenaiApiKeys(str: string) {
if (str.includes(",")) {
const userApiKeys = str.split(",");
return userApiKeys.every(checkOpenaiApiKey);
}

return checkOpenaiApiKey(str);
}

1 comment on commit e43c0ec

@vercel
Copy link

@vercel vercel bot commented on e43c0ec Mar 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.