Re-enable standard Vercel KV usage

This commit is contained in:
Sam Becker 2024-03-20 19:43:44 -05:00
parent bbe2fbca8d
commit 1371a8dcc4
4 changed files with 5 additions and 15 deletions

View File

@ -2,8 +2,9 @@
import OpenAI from 'openai';
import { createStreamableValue, render } from 'ai/rsc';
import { kv } from '@/services/vercel-kv';
import { kv } from '@vercel/kv';
import { Ratelimit } from '@upstash/ratelimit';
import { HAS_VERCEL_KV } from '@/site/config';
const RATE_LIMIT_IDENTIFIER = 'openai-image-query';
const RATE_LIMIT_MAX_QUERIES_PER_HOUR = 100;
@ -11,7 +12,7 @@ const RATE_LIMIT_MAX_QUERIES_PER_HOUR = 100;
const provider = new OpenAI({ apiKey: process.env.OPENAI_SECRET_KEY });
// Allows 100 requests per hour
const ratelimit = kv
const ratelimit = HAS_VERCEL_KV
? new Ratelimit({
redis: kv,
limiter: Ratelimit.slidingWindow(RATE_LIMIT_MAX_QUERIES_PER_HOUR, '1h'),

View File

@ -1,10 +0,0 @@
import { createClient } from '@vercel/kv';
export const kv =
process.env.REDIS_REST_API_URL &&
process.env.REDIS_REST_API_TOKEN
? createClient({
url: process.env.REDIS_REST_API_URL,
token: process.env.REDIS_REST_API_TOKEN,
})
: undefined;

View File

@ -286,7 +286,7 @@ export default function SiteChecklistClient({
{renderEnvVars(['OPENAI_SECRET_KEY'])}
</ChecklistRow>
<ChecklistRow
title="Rate Limiting"
title="Enable Rate Limiting"
status={hasVercelKV}
isPending={isPendingPage}
optional

View File

@ -43,8 +43,7 @@ export const HAS_VERCEL_POSTGRES =
// STORAGE: VERCEL KV
export const HAS_VERCEL_KV =
(process.env.REDIS_REST_API_URL ?? '').length > 0 &&
(process.env.REDIS_REST_API_TOKEN ?? '').length > 0;
(process.env.KV_URL ?? '').length > 0;
// STORAGE: VERCEL BLOB
export const HAS_VERCEL_BLOB_STORAGE =