mirror of
https://github.com/placeholder-soft/Babylong.git
synced 2026-01-12 15:14:17 +08:00
feat: add get token list
This commit is contained in:
3
cloudflare.d.ts
vendored
3
cloudflare.d.ts
vendored
@@ -8,5 +8,8 @@ declare module 'vite-plugin-cloudflare-functions/client' {
|
||||
GET: CloudflareResponseBody<typeof import('functions/api/tokens/[tokenId]')['onRequestGet']>;
|
||||
POST: CloudflareResponseBody<typeof import('functions/api/tokens/[tokenId]')['onRequestPost']>;
|
||||
};
|
||||
'/api/tokens/list': {
|
||||
GET: CloudflareResponseBody<typeof import('functions/api/tokens/list')['onRequestGet']>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
20
functions/api/tokens/list.ts
Normal file
20
functions/api/tokens/list.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import {
|
||||
makePagesFunction,
|
||||
makeResponse,
|
||||
} from "vite-plugin-cloudflare-functions/worker"
|
||||
import { PagesFunctionEnv } from "../../types"
|
||||
|
||||
export const onRequestGet = makePagesFunction<unknown, PagesFunctionEnv>(
|
||||
async ({ params, env }) => {
|
||||
const keys = (await env.satlayer_hackathon_tokens.list()).keys.map(key => key.name);
|
||||
|
||||
const tokens = await Promise.all(keys.map(key => env.satlayer_hackathon_tokens.get(key)));
|
||||
|
||||
return makeResponse(tokens, {
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Max-Age": "86400",
|
||||
},
|
||||
})
|
||||
},
|
||||
)
|
||||
@@ -1,5 +1,3 @@
|
||||
import { KVNamespace } from '@cloudflare/workers-types'
|
||||
|
||||
export interface PagesFunctionEnv {
|
||||
satlayer_hackathon_tokens: KVNamespace
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user