Skip to content

Commit

Permalink
feat: increase rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 2, 2023
1 parent 1922df2 commit 10dbcc2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
9 changes: 5 additions & 4 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NextResponse } from "next/server";
import type { NextFetchEvent, NextRequest } from "next/server";
import { Redis } from "@upstash/redis";
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
import type { NextFetchEvent, NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { RATE_LIMIT_COUNT } from "./utils/constants";
import { isDev } from "./utils/env";

const redis = Redis.fromEnv();
Expand All @@ -12,7 +13,7 @@ const ratelimit = new Ratelimit({
token: process.env.UPSTASH_RATE_REDIS_REST_TOKEN,
}),
// 速率限制算法 https://github.com/upstash/ratelimit#ratelimiting-algorithms
limiter: Ratelimit.fixedWindow(5, "1 d"),
limiter: Ratelimit.fixedWindow(RATE_LIMIT_COUNT, "1 d"),
analytics: true, // <- Enable analytics
});

Expand Down
4 changes: 2 additions & 2 deletions pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useLocalStorage } from "react-use";
import Sentence from "../components/Sentence";
import SquigglyLines from "../components/SquigglyLines";
import { useSummarize } from "../hooks/useSummarize";
import { checkoutUrl } from "../utils/constants";
import { CHECKOUT_URL } from "../utils/constants";
import { extractTimestamp } from "../utils/extractTimestamp";

let isSecureContext = false;
Expand Down Expand Up @@ -170,7 +170,7 @@ export const Home: NextPage = () => {
(终于,支持
<a
className="text-pink-400 hover:underline"
href={checkoutUrl}
href={CHECKOUT_URL}
target="_blank"
rel="noopener noreferrer"
>
Expand Down
8 changes: 4 additions & 4 deletions pages/shop.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import SquigglyLines from "../components/SquigglyLines";
import { checkoutUrl } from "../utils/constants";
import { CHECKOUT_URL, RATE_LIMIT_COUNT } from "../utils/constants";

export default () => {
return (
<div>
<h2 className="mt-10 max-w-5xl pb-10 text-center text-4xl font-bold sm:text-7xl">
伤不起了啊,每天仅限 5 次,请点击
伤不起了啊,每天仅限 {RATE_LIMIT_COUNT} 次,请点击
<span className="relative whitespace-nowrap text-[#3290EE]">
<SquigglyLines />
<a
className="relative text-pink-400 hover:underline"
href={checkoutUrl}
href={CHECKOUT_URL}
>
点击购买
</a>
Expand All @@ -29,7 +29,7 @@ export default () => {
</div>
</h2>
<div className="min-h-screen min-w-fit border-2 border-purple-700">
<iframe src={checkoutUrl} width="100%" height="1024px"></iframe>
<iframe src={CHECKOUT_URL} width="100%" height="1024px"></iframe>
</div>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const checkoutUrl =
export const CHECKOUT_URL =
"https://jimmylv.lemonsqueezy.com/checkout/buy/1ddaaa34-05eb-4db6-8c48-3ac0faed1b94";
export const RATE_LIMIT_COUNT = 7;

1 comment on commit 10dbcc2

@vercel
Copy link

@vercel vercel bot commented on 10dbcc2 Mar 2, 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.