diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index 036f7af..d597818 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -2,7 +2,7 @@ ## v0.7.0 -> 2023-06-20 +> 2023-06-21 ### Fixed @@ -17,6 +17,7 @@ - Guidance when there is insufficient Token for adding: Start Free Trial or Recharge Token - Added token allocation details for Free trial and Premium - Added daily scheduled task to calculate token consumption +- Add promotion codes for Product Hunt/Twitter platforms ### Changed diff --git a/CHANGE_LOG.zh_CN.md b/CHANGE_LOG.zh_CN.md index 768d828..2351abb 100644 --- a/CHANGE_LOG.zh_CN.md +++ b/CHANGE_LOG.zh_CN.md @@ -2,7 +2,7 @@ ## v0.7.0 -> 2023-06-20 +> 2023-06-21 ### 修复 @@ -17,6 +17,7 @@ - 新增 Token 不足时的引导:开始免费试用 or 充值 Token - 新增 Free trial 和 Premium 的 token 赠送数额说明 - 新增定时任务每日核算 Token 消耗 +- 新增 Product Hunt/Twitter 平台活动码 ### 调整 diff --git a/prisma/schema.prisma b/prisma/schema.prisma index cc44247..87b7e37 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -47,24 +47,26 @@ model VerificationToken { } model User { - id String @id @default(cuid()) - name String? - email String? @unique - emailVerified DateTime? - image String? - sessions Session[] - accounts Account[] - createdAt DateTime @default(now()) - updatedAt DateTime? @updatedAt - recentlyUse DateTime? - share Share[] - costTokens Int @default(0) - costUSD Float @default(0) - Cost Cost[] - availableTokens Int @default(0) - freeTrialed Int @default(0) - license_type String? - License License[] + id String @id @default(cuid()) + name String? + email String? @unique + emailVerified DateTime? + image String? + sessions Session[] + accounts Account[] + createdAt DateTime @default(now()) + updatedAt DateTime? @updatedAt + recentlyUse DateTime? + share Share[] + costTokens Int @default(0) + costUSD Float @default(0) + Cost Cost[] + availableTokens Int @default(0) + license_type String? + License License[] + freeTrialed Int @default(0) + productHuntTrialed Int @default(0) + twitterTrialed Int @default(0) } model License { diff --git a/src/app/api/licenses/activate/route.ts b/src/app/api/licenses/activate/route.ts index 9f7af15..33bfb26 100644 --- a/src/app/api/licenses/activate/route.ts +++ b/src/app/api/licenses/activate/route.ts @@ -4,6 +4,19 @@ import { authOptions } from "@/app/api/auth/[...nextauth]/route"; import { prisma } from "@/lib/prisma"; import { LResponseError } from "@/lib"; +const activityCode = [ + { + code: "L-GPT-PH-CODE", + label: "productHuntTrialed", + value: 15000, + }, + { + code: "L-GPT-TWITTER-CODE-2306", + label: "twitterTrialed", + value: 15000, + }, +]; + export async function POST(request: Request) { const session = await getServerSession(authOptions); @@ -17,6 +30,29 @@ export async function POST(request: Request) { const { license_key, instance_name } = await request.json(); + const findActivity = activityCode.find((p) => p.code === license_key); + + if (findActivity) { + if ((user as any)[findActivity.label]) { + return LResponseError("You have already used this license key."); + } + + const updateData = { + availableTokens: user.availableTokens + findActivity.value, + [findActivity.label]: 1, + }; + + await prisma.user.update({ + data: updateData, + where: { id: session?.user.id }, + }); + + return NextResponse.json( + { error: 0, data: { type: "activity" } }, + { status: 200 } + ); + } + try { const variants = await fetch("https://api.lemonsqueezy.com/v1/variants", { headers: { @@ -130,9 +166,6 @@ export async function POST(request: Request) { return NextResponse.json({ error: 0, data: { type } }, { status: 200 }); } catch (error) { console.log(error, "validate licenses error"); - return NextResponse.json( - { error: -1, msg: "validate licenses error" }, - { status: 500 } - ); + return LResponseError("validate licenses error"); } } diff --git a/src/components/chatSection/chatFooter/index.tsx b/src/components/chatSection/chatFooter/index.tsx index c200fff..b76f536 100644 --- a/src/components/chatSection/chatFooter/index.tsx +++ b/src/components/chatSection/chatFooter/index.tsx @@ -24,7 +24,7 @@ import { BASE_PROMPT, ChannelListItem, } from "@/hooks"; -import { Button, Confirm } from "@/components/ui"; +import { Button, Confirm, Link } from "@/components/ui"; import { useScrollToBottom } from "@/components/scrollToBottoms"; import { isMobile, cn, calcTokens } from "@/lib"; import type { IShare } from "@/app/api/share/route"; @@ -611,33 +611,42 @@ const ChatFooter: React.FC = () => { "dark:via-neutral-900 dark:to-neutral-900" )} > - {!!findChannel?.chat_list?.length && ( -