diff --git a/README.md b/README.md index 08e2eee..c4496c2 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,6 @@ Balances are net amounts in the supplied history, without any inferred opening b ## Live social previews -`/api/share-image` generates a 1600×1200 PNG server-side from D1 and the baseline using the bundled `next/og` renderer. It shows balance, deposits/withdrawals, low-balance count, top eight members, eight members needing a refill and their required top-ups, the four most recent transactions, and the latest game timestamp. Both the image and ledger API bypass application caching. Root metadata reads the same data and adds a content-derived revision to the image URL. The revision changes for backdated imports too; duplicates leave it unchanged. The footer's copy button fetches a fresh versioned page URL immediately before copying, allowing a new Discord unfurl after updates. Discord controls its own cache: embeds already posted are not guaranteed to refresh automatically. The image endpoint always reads current data, including when requested using an older revision query. +`/api/share-image` generates a 1600×1200 PNG server-side from D1 and the baseline using the bundled `next/og` renderer. It shows balance, deposits/withdrawals, low-balance count, top eight members, eight members needing a refill and their required top-ups, the four most recent transactions, and the latest game timestamp. Both the image and ledger API bypass application caching. Root metadata reads the same data and adds a content-derived revision to the image URL. The revision changes for backdated imports too; duplicates leave it unchanged. The header's sharing button adds the current Unix time in seconds as `t` to the versioned page URL, then opens native sharing when available or copies the URL. Root metadata propagates the same timestamp to the image URL, allowing a fresh Discord unfurl even if ledger data has not changed. Native share cancellation does not copy a link; failed native sharing falls back to clipboard or a selectable URL. Discord controls its own cache: embeds already posted are not guaranteed to refresh automatically. The image endpoint always reads current data, including when requested using an older revision query. The live card uses bundled OFL-licensed Vazirmatn regular/bold fonts. Persian labels are shaped into presentation forms for Satori, with explicit column ordering so player names and numbers retain their correct order. Persian numbers and dates use Persian digits; game timestamps are not converted to another timezone. The card edition is included in revisioned share links to invalidate earlier English previews. diff --git a/app/dashboard.tsx b/app/dashboard.tsx index e2a979f..0682b60 100644 --- a/app/dashboard.tsx +++ b/app/dashboard.tsx @@ -1,6 +1,7 @@ 'use client'; import {useEffect,useState,useMemo} from 'react'; -import {Shield,ArrowUpRight,ArrowDownLeft,Search,ChevronLeft,Trophy,Flame,Coins,History,Lock,Upload,CheckCircle2,AlertTriangle,X,RefreshCw,Copy} from 'lucide-react'; +import {Shield,ArrowUpRight,ArrowDownLeft,Search,ChevronLeft,Trophy,Flame,Coins,History,Lock,Upload,CheckCircle2,AlertTriangle,X,RefreshCw,Copy,Share2} from 'lucide-react'; +import {withShareTimestamp} from '../lib/share-link.mjs'; import {seed,summarize,parseLog,identity,minimum} from '../lib/ledger.mjs'; type Row={id:string;date:string;player:string;reason:string;amount:number}; const num=(n:number)=>n.toLocaleString('fa-IR'); @@ -15,16 +16,29 @@ export default function Dashboard({adminMode=false}:{adminMode?:boolean}){ useEffect(()=>{if(!selected)return;const onKey=(e:KeyboardEvent)=>{if(e.key==='Escape')setSelected(null);};document.addEventListener('keydown',onKey);return()=>document.removeEventListener('keydown',onKey);},[selected]); const profile=players.find(p=>p.name.toLowerCase()===selected?.toLowerCase()); const preview=useMemo(()=>{if(!log.trim())return null;try{const parsed=parseLog(log);const ids=new Set(rows.map(identity));let fresh=0;for(const r of parsed){const id=identity(r);if(!ids.has(id)){fresh++;ids.add(id);}}return {total:parsed.length,fresh,duplicates:parsed.length-fresh,error:''};}catch(e){return {error:(e as Error).message,total:0,fresh:0,duplicates:0};}},[log,rows]); - async function copyShareLink(){setSharing(true);setShareNotice('');try{const response=await fetch('/api/ledger',{cache:'no-store'});const data=await response.json() as {shareUrl:string;error?:string};if(!response.ok)throw Error(data.error||'دریافت آخرین وضعیت ممکن نشد.');setShareUrl(data.shareUrl);try{await navigator.clipboard.writeText(data.shareUrl);setShareNotice('لینک آخرین وضعیت کپی شد؛ در دیسکورد پیست کن.');}catch{setShareNotice(data.shareUrl);}}catch(e){setShareNotice((e as Error).message);}finally{setSharing(false);}} + async function shareLatest(){ + setSharing(true);setShareNotice(''); + const url=withShareTimestamp(shareUrl,Math.floor(Date.now()/1000)); + try { + if(navigator.share){ + try{await navigator.share({title:'آخرین وضعیت خزانه سایفوند',url});setShareNotice('لینک آخرین وضعیت به اشتراک گذاشته شد.');return;} + catch(e){if((e as Error).name==='AbortError')return;} + } + try{if(!navigator.clipboard)throw Error('Clipboard unavailable');await navigator.clipboard.writeText(url);setShareNotice('لینک آخرین وضعیت کپی شد؛ در دیسکورد پیست کن.');} + catch{setShareNotice(url);} + }finally{setSharing(false);} + } + async function importLog(){setSaving(true);setMessage('');try{const r=await fetch('/api/import',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({log})});const d=await r.json() as {error?:string;added:number;duplicates:number};if(!r.ok)throw Error(d.error);setMessage(`${num(d.added)} تراکنش جدید ثبت شد؛ ${num(d.duplicates)} رکورد تکراری کنار گذاشته شد.`);setLog('');await refresh();}catch(e){setMessage((e as Error).message);}finally{setSaving(false);}} return
-
گیلد خزانهٔ سایفوند
نمای عمومی
قدرت گیلد، از خزانه شروع می‌شود

خزانه پُر. گیلد قدرتمند.

سهمت را ببین، جایگاهت را بشناس و برای نبرد بعدی آماده باش.

شفاف برای همهٔ اعضا به‌روزرسانی با لاگ بازی
+
گیلد خزانهٔ سایفوند
نمای عمومی
قدرت گیلد، از خزانه شروع می‌شود

خزانه پُر. گیلد قدرتمند.

سهمت را ببین، جایگاهت را بشناس و برای نبرد بعدی آماده باش.

شفاف برای همهٔ اعضا به‌روزرسانی با لاگ بازی
{error&&
{error} داده‌های اولیه نمایش داده می‌شوند.
}
بالانس خزانه
{num(total)}سایفوندخالص واریز و برداشت اعضا
کل واریزها
{num(deposits)}واریزسهم اعضا در قدرت گیلد
کل برداشت‌ها
{num(withdrawals)}برداشت{num(rows.length)} تراکنش ثبت‌شده
اعضای نیازمند اقدام
{num(low.length)}از {num(players.length)} عضوبالانس کمتر از {num(minimum)} سایفوند
{adminMode&&
خزانه را به‌روز نگه دار

ورود لاگ خزانه

خروجی بازی را همراه عنوان ستون‌ها اینجا پیست کن. پیش‌نمایش را بررسی و سپس ثبت کن.