add index route info, make it fetch per hour instead of every user, add health route, update to latest biome config aswell as logger
All checks were successful
Code quality checks / biome (push) Successful in 15s
All checks were successful
Code quality checks / biome (push) Successful in 15s
This commit is contained in:
parent
8cfa75ec57
commit
75d3dab85e
21 changed files with 943 additions and 364 deletions
|
@ -1,3 +1,5 @@
|
|||
import { badgeServices, getServiceDescription, gitUrl } from "@config";
|
||||
|
||||
const routeDef: RouteDef = {
|
||||
method: "GET",
|
||||
accepts: "*/*",
|
||||
|
@ -8,15 +10,56 @@ async function handler(request: ExtendedRequest): Promise<Response> {
|
|||
const endPerf: number = Date.now();
|
||||
const perf: number = endPerf - request.startPerf;
|
||||
|
||||
const { query, params } = request;
|
||||
|
||||
const response: Record<string, unknown> = {
|
||||
perf,
|
||||
query,
|
||||
params,
|
||||
const response = {
|
||||
name: "Badge Aggregator API",
|
||||
description:
|
||||
"A fast Discord badge aggregation API built with Bun and Redis caching",
|
||||
version: "1.0.0",
|
||||
author: "creations.works",
|
||||
repository: gitUrl,
|
||||
performance: {
|
||||
responseTime: `${perf}ms`,
|
||||
uptime: `${process.uptime()}s`,
|
||||
},
|
||||
routes: {
|
||||
"GET /": "API information and available routes",
|
||||
"GET /:userId": "Get badges for a Discord user",
|
||||
"GET /health": "Health check endpoint",
|
||||
},
|
||||
endpoints: {
|
||||
badges: {
|
||||
path: "/:userId",
|
||||
method: "GET",
|
||||
description: "Fetch badges for a Discord user",
|
||||
parameters: {
|
||||
path: {
|
||||
userId: "Discord User ID (17-20 digits)",
|
||||
},
|
||||
query: {
|
||||
services: "Comma/space separated list of services (optional)",
|
||||
cache: "Enable/disable caching (true/false, default: true)",
|
||||
seperated:
|
||||
"Return results grouped by service (true/false, default: false)",
|
||||
},
|
||||
},
|
||||
example: "/:userId?services=discord,vencord&seperated=true&cache=true",
|
||||
},
|
||||
},
|
||||
supportedServices: badgeServices.map((service) => ({
|
||||
name: service.service,
|
||||
description: getServiceDescription(service.service),
|
||||
})),
|
||||
ratelimit: {
|
||||
window: "60 seconds",
|
||||
requests: 60,
|
||||
},
|
||||
};
|
||||
|
||||
return Response.json(response);
|
||||
return Response.json(response, {
|
||||
headers: {
|
||||
"Cache-Control": "public, max-age=300",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export { handler, routeDef };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue