Skip to content

Commit

Permalink
feat: Refine interaction details
Browse files Browse the repository at this point in the history
  • Loading branch information
Peek-A-Booo committed Jun 21, 2023
1 parent 60c6868 commit c90dbf1
Show file tree
Hide file tree
Showing 18 changed files with 553 additions and 438 deletions.
7 changes: 7 additions & 0 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
- Added support for Token recharge to unlock more session quotas
- Added activation guide
- 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

### Changed

- Move the activation of the license key to the left menu for better visibility
- Optimize clipboard usage

## v0.6.2

Expand Down
7 changes: 7 additions & 0 deletions CHANGE_LOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
- 新增支持 Token 充值,解锁更多会话额度
- 新增激活许可证引导
- 新增 Token 不足时的引导:开始免费试用 or 充值 Token
- 新增 Free trial 和 Premium 的 token 赠送数额说明
- 新增定时任务每日核算 Token 消耗

### 调整

- 调整激活 license key 的位置到左侧菜单,更加醒目
- 优化 clipboard 使用

## v0.6.2

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
"framer-motion": "10.12.16",
"gpt-tokens": "1.0.9",
"js-tiktoken": "1.0.7",
"l-hooks": "0.4.5",
"l-hooks": "0.4.6",
"math-random": "2.0.1",
"next": "13.4.6",
"next-auth": "4.22.1",
"next-intl": "2.14.6",
"next-intl": "2.15.0",
"next-themes": "0.2.1",
"nodemailer": "6.9.3",
"postcss": "8.4.24",
Expand Down
29 changes: 15 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions src/app/api/cron/cost/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { LResponseError } from "@/lib";

export async function GET() {
try {
const costs = await prisma.cost.findMany({
where: {
createdAt: {
gte: new Date(new Date().setHours(0, 0, 0, 0)),
},
},
});

// if costs exist means already run today
if (costs.length) return LResponseError("already run today");

const users = await prisma.user.findMany({
where: {
costTokens: {
gt: 0,
},
},
});

if (!users.length) return LResponseError("no users need to cost");

for (const user of users) {
const { id, availableTokens, costTokens, costUSD } = user;

await prisma.cost.create({
data: {
costTokens,
costUSD,
userId: id,
},
});

await prisma.user.update({
data: {
costTokens: 0,
costUSD: 0,
availableTokens: availableTokens - costTokens,
},
where: { id: user.id },
});
}

return NextResponse.json({ error: 0 }, { status: 200 });
} catch (error) {
console.log("cost error");
return LResponseError("error");
}
}
11 changes: 3 additions & 8 deletions src/components/chatContent/codeblock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ interface Props {

const CodeBlock: React.FC<Props> = React.memo(({ language, value }) => {
const t = useTranslations("chat");
const { copy } = useClipboard();
const [copied, setCopied] = React.useState(false);
const { isCopied, copy } = useClipboard();

const copyToClipboard = () => {
if (copied) return;
if (isCopied) return;
copy(value);
setCopied(true);
setTimeout(() => {
setCopied(false);
}, 1800);
};

return (
Expand All @@ -35,7 +30,7 @@ const CodeBlock: React.FC<Props> = React.memo(({ language, value }) => {
className="flex gap-0.5 items-center rounded bg-none p-1 text-xs text-white"
onClick={copyToClipboard}
>
{copied ? (
{isCopied ? (
<>
<AiOutlineCheck className="text-[#52c41a] mr-1" size={18} />
{t("copied")}!
Expand Down
Loading

1 comment on commit c90dbf1

@vercel
Copy link

@vercel vercel bot commented on c90dbf1 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.