From 7e94b5c44fb58b4b074a177b85eca3972549dc24 Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Mon, 9 Jun 2025 11:47:13 +0300 Subject: [PATCH] feat: expiry time --- src/app/actions.ts | 3 ++- src/app/page.tsx | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app/actions.ts b/src/app/actions.ts index dbc5f4a..e4d18f5 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -23,10 +23,11 @@ async function getUrlApi(email: string) { await redis.set("inbound", JSON.stringify(inbound), "EX", 3600); const users: ClientSettings = JSON.parse(inbound.settings); const user = users.clients.find((user) => user.email === email); + console.log(user); if (!user) { throw new Error("User not found"); } - return getValidUrl({ email, id: user.id }); + return { url: getValidUrl({ email, id: user.id }), expiryTime: user.expiryTime }; } export async function getUrl(initData: string = "") { try { diff --git a/src/app/page.tsx b/src/app/page.tsx index 8d96ad4..909cc61 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -10,6 +10,7 @@ import { getUrl } from "./actions"; export default function Home() { const [url, setUrl] = useState(""); + const [expiryTime, setExpiryTime] = useState(0); const initData = useRawInitData(); const onCopyClick = async () => { if (!url.length) return; @@ -24,7 +25,8 @@ export default function Home() { const fetchData = async () => { try { const data = await getUrl(initData); - setUrl(data); + setUrl(data.url); + setExpiryTime(data.expiryTime); } catch (e) { console.error(e); } @@ -55,16 +57,22 @@ export default function Home() { - Нажмите, чтобы скопировать! + Нажмите на QR, чтобы скопировать!
Статус: - Активна + {expiryTime > Date.now() || expiryTime === 0 ? "Активна" : "Не Активна"}
Активна до: - 01.01.2023 + + {expiryTime === 0 + ? "Всегда" + : expiryTime > Date.now() + ? new Date(expiryTime).toLocaleString("ru-RU") + : "Не Активна"} +