Skip to content

Commit

Permalink
Add cooldown time env variable and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsanghaffar committed May 26, 2024
1 parent 5377bb4 commit 6c995c0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ OPENAI_API_KEY=

ENV_VARIABLE=production_server_only_variable
NEXT_PUBLIC_ENV_VARIABLE=production_public_variable

NEXT_PUBLIC_COOLDOWN_TIME=60
6 changes: 4 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { GeneratedBio } from "@/types/types";
export type VibeType = "حرفه‌ای" | "معمولی" | "طنز";
let vibes: VibeType[] = ["حرفه‌ای", "معمولی", "طنز"];

const NEXT_PUBLIC_COOLDOWN_TIME = process.env.NEXT_PUBLIC_COOLDOWN_TIME

const BioGenerator = () => {
const [loading, setLoading] = useState(false);
const [bio, setBio] = useState("");
Expand Down Expand Up @@ -69,7 +71,7 @@ const BioGenerator = () => {
setLoading(true);
setIsCooldown(true);

setCooldownTimer(90);
setCooldownTimer(NEXT_PUBLIC_COOLDOWN_TIME);

try {
const messages = `Generate 2 ${vibe} biographies with no hashtags, in Persian language. ${
Expand Down Expand Up @@ -112,7 +114,7 @@ const BioGenerator = () => {
});
} finally {
setLoading(false);
setCooldownTimer(90);
setCooldownTimer(NEXT_PUBLIC_COOLDOWN_TIME);
}
};

Expand Down
1 change: 1 addition & 0 deletions environment.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare namespace NodeJS {
export interface ProcessEnv {
readonly NEXT_PUBLIC_OPENAI_API_KEY: string
readonly NEXT_PUBLIC_COOLDOWN_TIME: number
}
}

0 comments on commit 6c995c0

Please sign in to comment.