Skip to content

Commit

Permalink
feat: 添加剩余时长显示
Browse files Browse the repository at this point in the history
  • Loading branch information
ChingCdesu committed Feb 4, 2025
1 parent 58622e6 commit 5e91dd3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"yourKey": "Your CDKey",
"invalidOrderId": "Order does not exist",
"orderExpired": "CDKey has expired",
"expireAt": "Valid for {time}",
"expireAt": "Valid until {time}",
"timeLeft": "{relativeTime} remain",
"goBack": "Go Back",
"msg": {
"Order not found": "Order does not exist"
Expand Down
1 change: 1 addition & 0 deletions messages/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"invalidOrderId": "订单不存在哦",
"orderExpired": "CDKey已过期",
"expireAt": "在 {time} 内可用",
"timeLeft": "剩余 {relativeTime}",
"goBack": "返回",
"msg": {
"Order not found": "订单不存在哦"
Expand Down
12 changes: 10 additions & 2 deletions src/app/[locale]/show-key/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BackgroundLines } from "@/components/BackgroundLines"
import { getTranslations, getFormatter } from "next-intl/server"
import { getTranslations, getFormatter, getLocale } from "next-intl/server"
import moment from "moment"

import CopyButton from "@/components/CopyButton"
Expand All @@ -11,6 +11,7 @@ type Props = {

export default async function ShowKey({ searchParams }: Props) {
const t = await getTranslations('ShowKey')
const locale = await getLocale()
const format = await getFormatter()
const { order_id } = await searchParams
const response = await fetch(`https://mirrorc.top/api/billing/order/afdian?order_id=${order_id}`)
Expand All @@ -27,6 +28,10 @@ export default async function ShowKey({ searchParams }: Props) {
minute: 'numeric',
}) : null

moment.locale(locale)

const relativeTime = isSuccessful ? moment.duration(moment(data.expired_at).diff(moment())).humanize() : null

return isSuccessful && !isExpired ? (
<BackgroundLines className="select-none">
<div className="flex min-h-screen flex-1 flex-col justify-center px-6 py-12 lg:px-8">
Expand All @@ -39,7 +44,10 @@ export default async function ShowKey({ searchParams }: Props) {
<p>{t('yourKey')}:&nbsp;
<CopyButton text={data.cdk} />
</p>
<p><span>{t('expireAt', { time })}</span></p>
<p>
<span>{t('expireAt', { time })}</span>
<span>({t('timeLeft', { relativeTime })})</span>
</p>
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/routing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineRouting } from 'next-intl/routing';
import { createNavigation } from 'next-intl/navigation';

import 'moment/locale/zh-cn'

export const routing = defineRouting({
// A list of all locales that are supported
locales: ['en', 'zh'],
Expand Down

0 comments on commit 5e91dd3

Please sign in to comment.