feat: expiry time

This commit is contained in:
2025-06-09 11:47:13 +03:00
parent 2bbc34f1cb
commit 7e94b5c44f
2 changed files with 14 additions and 5 deletions

View File

@@ -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 {

View File

@@ -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() {
</div>
<QRCodeSVG value={url} className="size-48" />
</div>
<span className="text-center text-sm font-semibold">Нажмите, чтобы скопировать!</span>
<span className="text-center text-sm font-semibold">Нажмите на QR, чтобы скопировать!</span>
</Block>
<Block name="Подписка">
<div className="flex flex-col items-center gap-0.5">
<span>Статус:</span>
<span>Активна</span>
<span>{expiryTime > Date.now() || expiryTime === 0 ? "Активна" : "Не Активна"}</span>
</div>
<div className="flex flex-col items-center gap-0.5">
<span>Активна до:</span>
<span>01.01.2023</span>
<span>
{expiryTime === 0
? "Всегда"
: expiryTime > Date.now()
? new Date(expiryTime).toLocaleString("ru-RU")
: "Не Активна"}
</span>
</div>
</Block>
</main>