forked from maik/IPFS-portal
99c113b6f5
- swr.ts: remove useBandwidth(), drop bw from useDashboard() - events/route.ts: skip bandwidth SSE (Kubo 0.28.0 unsupported) - usage/page.tsx: remove getBWStats call + bw references - helpers.ts: gatewayLink -> ipfs.maos.dedyn.io (subdomain only) - upload/page.tsx: fix local gatewayLink (subdomain only) - storage.ts: update default gatewayUrl, add defensive getHistory()
20 lines
743 B
TypeScript
20 lines
743 B
TypeScript
/* ── Format bytes to human-readable size ── */
|
|
export function formatBytes(bytes: number): string {
|
|
if (bytes === 0) return '0 B';
|
|
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
|
|
const val = bytes / Math.pow(1024, i);
|
|
return val < 10 ? val.toFixed(1) + ' ' + units[i] : Math.round(val) + ' ' + units[i];
|
|
}
|
|
|
|
/* ── Gateway link for CID ── */
|
|
export function gatewayLink(cid: string): string {
|
|
return `https://ipfs.maos.dedyn.io/${cid}`;
|
|
}
|
|
|
|
/* ── Truncate CID for display ── */
|
|
export function truncateCid(cid: string, chars: number = 12): string {
|
|
if (cid.length <= chars) return cid;
|
|
return `${cid.slice(0, chars)}...`;
|
|
}
|