Skip to content

Commit

Permalink
feat: Add promotion codes for Product Hunt/Twitter platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Peek-A-Booo committed Jun 21, 2023
1 parent c90dbf1 commit 6067426
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 52 deletions.
3 changes: 2 additions & 1 deletion CHANGE_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## v0.7.0

> 2023-06-20
> 2023-06-21
### Fixed

Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion CHANGE_LOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## v0.7.0

> 2023-06-20
> 2023-06-21
### 修复

Expand All @@ -17,6 +17,7 @@
- 新增 Token 不足时的引导:开始免费试用 or 充值 Token
- 新增 Free trial 和 Premium 的 token 赠送数额说明
- 新增定时任务每日核算 Token 消耗
- 新增 Product Hunt/Twitter 平台活动码

### 调整

Expand Down
38 changes: 20 additions & 18 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
41 changes: 37 additions & 4 deletions src/app/api/licenses/activate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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: {
Expand Down Expand Up @@ -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");
}
}
65 changes: 37 additions & 28 deletions src/components/chatSection/chatFooter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -611,33 +611,42 @@ const ChatFooter: React.FC = () => {
"dark:via-neutral-900 dark:to-neutral-900"
)}
>
{!!findChannel?.chat_list?.length && (
<div className="flex py-2 gap-2 justify-center items-center">
<Button
className="group"
size="sm"
type="outline"
onClick={generate}
leftIcon={
loadingChannel ? (
<BsStop size={20} />
) : (
<AiOutlineRedo size={20} className="group:hover:bg-[red]" />
)
}
>
{loadingChannel ? t("stop-generate") : t("re-generate")}
</Button>
<Button
type="outline"
leftIcon={<AiOutlineShareAlt size={18} />}
loading={loadingShare}
onClick={handleShare}
>
{tShare("share")}
</Button>
</div>
)}
<div className="flex py-2 gap-3 justify-center items-center">
{!!findChannel?.chat_list?.length && (
<>
<Button
className="group"
size="sm"
type="outline"
onClick={generate}
leftIcon={
loadingChannel ? (
<BsStop size={20} />
) : (
<AiOutlineRedo size={20} className="group:hover:bg-[red]" />
)
}
>
{loadingChannel ? t("stop-generate") : t("re-generate")}
</Button>
<Button
type="outline"
leftIcon={<AiOutlineShareAlt size={18} />}
loading={loadingShare}
onClick={handleShare}
>
{tShare("share")}
</Button>
</>
)}
<Link
className="underline text-sm hidden md:block"
target="_blank"
href="https://docs.ltopx.com"
>
{tCommon("docs")}
</Link>
</div>

<div className="flex">
<div className="flex items-end">
Expand Down
2 changes: 2 additions & 0 deletions src/components/premium/activate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const Activate = React.forwardRef((_, forwardedRef) => {
toastInfo = t("tokens-recharged");
} else if (res.data.type === "license") {
toastInfo = t("license-key-activated");
} else if (res.data.type === "activity") {
toastInfo = t("gift-code-used-success");
}

toast.success(toastInfo, { id: "activated", duration: 5000 });
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"add": "Add",
"cancel": "Cancel",
"create": "Create",
"docs": "Docs",
"ok": "OK",
"please-enter": "Please enter",
"premium": "L-GPT Premium",
Expand Down Expand Up @@ -105,6 +106,7 @@
"free-trial-already": "Free Trial already used",
"get-free-trial": "Get L-GPT Free Trial",
"get-more-token": "Get more tokens?",
"gift-code-used-success": "Gift code used successfully",
"learn-more-license": "Learn more about L-GPT License...",
"license": "L-GPT License",
"license-activate": "L-GPT License Activate",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"add": "新 增",
"cancel": "取 消",
"create": "新 增",
"docs": "文档",
"ok": "确 定",
"please-enter": "请输入",
"premium": "L-GPT 高级版",
Expand Down Expand Up @@ -105,6 +106,7 @@
"free-trial-already": "已免费试用",
"get-free-trial": "获取免费试用",
"get-more-token": "获取更多Token?",
"gift-code-used-success": "礼品码使用成功",
"learn-more-license": "了解更多关于L-GPT License的信息...",
"license": "L-GPT 许可证",
"license-activate": "L-GPT 许可证激活",
Expand Down

1 comment on commit 6067426

@vercel
Copy link

@vercel vercel bot commented on 6067426 Jun 21, 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.