MCPcopy
hub / github.com/anomalyco/opencode / fetch

Function fetch

packages/console/function/src/stat.ts:7–42  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

5
6export default {
7 async fetch(request: Request) {
8 if (request.method !== "POST") return new Response("Method Not Allowed", { status: 405 })
9
10 const body = (await request.json()) as { ids: string[] }
11 const ids = body.ids
12 if (ids.length === 0) return Response.json({} satisfies Result)
13
14 const toInterval = (date: Date) =>
15 parseInt(
16 date
17 .toISOString()
18 .replace(/[^0-9]/g, "")
19 .substring(0, 12),
20 )
21 const now = Date.now()
22 const intervals = Array.from({ length: 30 }, (_, i) => toInterval(new Date(now - i * 60 * 1000)))
23
24 const rows = await Database.use((tx) =>
25 tx
26 .select()
27 .from(ModelTpsRateLimitTable)
28 .where(and(inArray(ModelTpsRateLimitTable.id, ids), inArray(ModelTpsRateLimitTable.interval, intervals))),
29 )
30
31 const rowsByKey = new Map(rows.map((row) => [`${row.id}:${row.interval}`, row]))
32 const result: Result = Object.fromEntries(
33 ids.map((id) => [
34 id,
35 intervals.map((interval) => {
36 const row = rowsByKey.get(`${id}:${interval}`)
37 return { interval, qualify: row?.qualify ?? 0, unqualify: row?.unqualify ?? 0 }
38 }),
39 ]),
40 )
41 return Response.json(result)
42 },
43}

Callers 15

tailFunction · 0.70
executeFunction · 0.50
fetchSvgContentFunction · 0.50
email-signup.tsxFile · 0.50
GETFunction · 0.50
downloadFileFunction · 0.50
fetchWith429RetryFunction · 0.50
handlerFunction · 0.50
handlerFunction · 0.50
subscribeFunction · 0.50
handleSubmitFunction · 0.50
handlerFunction · 0.50

Calls 7

toIntervalFunction · 0.70
jsonMethod · 0.65
getMethod · 0.65
fromMethod · 0.45
useMethod · 0.45
whereMethod · 0.45
selectMethod · 0.45

Tested by

no test coverage detected