Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ type Summary = {
}>;
totals: { last_week: number; last_month: number };
};
marketplace?: {
extensions: Array<{
extension: string;
installs: number;
downloads: number;
rating: number;
rating_count: number;
}>;
totals: { installs: number; downloads: number };
};
generated_at: string;
};

Expand All @@ -71,7 +81,12 @@ export default function AdminPage() {
const [loading, setLoading] = useState(false);

useEffect(() => {
// Read the saved admin token AFTER mount (not via a lazy useState
// initializer) so the server and initial client render match — reading
// localStorage during render would cause a hydration mismatch on the
// controlled password input below.
const saved = window.localStorage.getItem(TOKEN_KEY);
// eslint-disable-next-line react-hooks/set-state-in-effect
if (saved) setToken(saved);
}, []);

Expand Down Expand Up @@ -166,6 +181,45 @@ export default function AdminPage() {
</table>
</section>
)}
{data.marketplace && data.marketplace.extensions.length > 0 && (
<section>
<h2 className="text-lg font-semibold">VS Code Marketplace</h2>
<div className="mt-3 grid grid-cols-2 gap-3 sm:grid-cols-2">
<Stat
label="Total installs"
value={fmt(data.marketplace.totals.installs)}
/>
<Stat
label="Total downloads"
value={fmt(data.marketplace.totals.downloads)}
/>
</div>
<table className="mt-4 w-full text-sm">
<thead className="text-left text-xs uppercase text-slate-500">
<tr>
<th className="py-2">Extension</th>
<th className="text-right">Installs</th>
<th className="text-right">Downloads</th>
<th className="text-right">Rating</th>
</tr>
</thead>
<tbody>
{data.marketplace.extensions.map((e) => (
<tr key={e.extension} className="border-t border-slate-100">
<td className="py-2 font-mono text-xs">{e.extension}</td>
<td className="text-right">{fmt(e.installs)}</td>
<td className="text-right">{fmt(e.downloads)}</td>
<td className="text-right">
{e.rating_count > 0
? `${e.rating.toFixed(1)}★ (${e.rating_count})`
: "—"}
</td>
</tr>
))}
</tbody>
</table>
</section>
)}
<section>
<h2 className="text-lg font-semibold">Revenue (Polar)</h2>
{polarError && (
Expand Down
58 changes: 58 additions & 0 deletions app/api/admin/summary/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,68 @@ export async function GET(req: Request) {
{ last_week: 0, last_month: 0 }
);

// VS Code Marketplace — the one distribution channel npm can't see. Public
// gallery API; resilient (any failure yields zeros, never breaks the page).
const VSCODE_EXTENSIONS = ["asafamos.axle-a11y"];
const marketplaceData = await Promise.all(
VSCODE_EXTENSIONS.map(async (ext) => {
try {
const res = await fetch(
"https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery",
{
method: "POST",
cache: "no-store",
headers: {
"Content-Type": "application/json",
Accept: "application/json;api-version=3.0-preview.1",
},
body: JSON.stringify({
filters: [{ criteria: [{ filterType: 7, value: ext }] }],
flags: 914,
}),
}
);
const json = (await res.json()) as {
results?: Array<{
extensions?: Array<{
statistics?: Array<{ statisticName: string; value: number }>;
}>;
}>;
};
const stats = json?.results?.[0]?.extensions?.[0]?.statistics ?? [];
const stat = (name: string) =>
Number(stats.find((s) => s.statisticName === name)?.value ?? 0);
return {
extension: ext,
installs: stat("install"),
downloads: stat("downloadCount"),
rating: stat("averagerating"),
rating_count: stat("ratingcount"),
};
} catch {
return {
extension: ext,
installs: 0,
downloads: 0,
rating: 0,
rating_count: 0,
};
}
})
);
const marketplaceTotals = marketplaceData.reduce(
(acc, row) => ({
installs: acc.installs + row.installs,
downloads: acc.downloads + row.downloads,
}),
{ installs: 0, downloads: 0 }
);

return NextResponse.json({
stats: kvData,
polar: polarData,
npm: { packages: npmData, totals: npmTotals },
marketplace: { extensions: marketplaceData, totals: marketplaceTotals },
generated_at: new Date().toISOString(),
});
}
Loading