MCPcopy Create free account
hub / github.com/arctic-cli/interface / GET

Function GET

packages/web/app/api/stats/route.ts:5–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3const redis = Redis.fromEnv()
4
5export async function GET() {
6 try {
7 const [total, linux, darwin, windows, x64, arm64, x86, baseline, musl] = await redis.mget<number[]>(
8 "installs:total",
9 "installs:os:linux",
10 "installs:os:darwin",
11 "installs:os:windows",
12 "installs:arch:x64",
13 "installs:arch:arm64",
14 "installs:arch:x86",
15 "installs:arch:baseline",
16 "installs:arch:musl",
17 )
18
19 const dailyStats: Record<string, Record<string, number>> = {}
20 const keys: string[] = []
21
22 for (let i = 0; i < 30; i++) {
23 const date = new Date()
24 date.setDate(date.getDate() - i)
25 const dateStr = date.toISOString().split("T")[0]
26
27 const oses = ["linux", "darwin", "windows"]
28 const arches = ["x64", "arm64", "x86", "baseline", "musl"]
29
30 for (const os of oses) {
31 for (const arch of arches) {
32 keys.push(`installs:daily:${dateStr}:${os}:${arch}`)
33 }
34 }
35 }
36
37 const dailyValues = await redis.mget<number[]>(...keys)
38
39 let keyIndex = 0
40 for (let i = 0; i < 30; i++) {
41 const date = new Date()
42 date.setDate(date.getDate() - i)
43 const dateStr = date.toISOString().split("T")[0]
44
45 dailyStats[dateStr] = { total: 0 }
46
47 const oses = ["linux", "darwin", "windows"]
48 const arches = ["x64", "arm64", "x86", "baseline", "musl"]
49
50 for (const os of oses) {
51 for (const arch of arches) {
52 const count = dailyValues[keyIndex++] || 0
53 if (count > 0) {
54 dailyStats[dateStr][`${os}:${arch}`] = count
55 dailyStats[dateStr].total += count
56 }
57 }
58 }
59 }
60
61 return Response.json({
62 total: total || 0,

Callers

nothing calls this directly

Calls 2

pushMethod · 0.80
jsonMethod · 0.65

Tested by

no test coverage detected