import { Redis } from "@upstash/redis";
const redis = Redis.fromEnv();
export const revalidate = 60;
export const Stats = asyncComponent(async () => {
const [reads, writes] = await redis
.pipeline()
.get("envshare:metrics:reads")
.get("envshare:metrics:writes")
.exec<[number, number]>();
const stars = await fetch("https://api.github.com/repos/retrofor/ChienDice")
.then((res) => res.json())
.then((json) => json.stargazers_count as number);
const stats = [
{
label: "Documents Encrypted",
value: writes,
},
{
label: "Documents Decrypted",
value: reads,
},
] satisfies { label: string; value: number }[];
if (stars) {
stats.push({
label: "GitHub Stars",
value: stars,
});
}
return (
{stats.map(({ label, value }) => (
-
-
{Intl.NumberFormat("en-US", { notation: "compact" }).format(value)}
- {label}
))}
);
});
// stupid hack to make "server components" actually work with components
// https://www.youtube.com/watch?v=h_9Vx6kio2s
function asyncComponent(fn: (arg: T) => Promise): (arg: T) => R {
return fn as (arg: T) => R;
}