mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-14 15:05:55 +08:00
Nick: credit usage endpoint
This commit is contained in:
parent
58b8064958
commit
6222152249
45
apps/api/src/controllers/v1/credit-usage.ts
Normal file
45
apps/api/src/controllers/v1/credit-usage.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import { RequestWithAuth } from "./types";
|
||||||
|
import { getACUC } from "../auth";
|
||||||
|
import { logger } from "../../lib/logger";
|
||||||
|
|
||||||
|
export async function creditUsageController(
|
||||||
|
req: RequestWithAuth,
|
||||||
|
res: Response,
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
// If we already have the credit usage info from auth, use it
|
||||||
|
if (req.acuc) {
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
data: {
|
||||||
|
remaining_credits: req.acuc.remaining_credits,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise fetch fresh data
|
||||||
|
const chunk = await getACUC(req.auth.team_id);
|
||||||
|
if (!chunk) {
|
||||||
|
res.status(404).json({
|
||||||
|
success: false,
|
||||||
|
error: "Could not find credit usage information",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
data: {
|
||||||
|
remaining_credits: chunk.remaining_credits,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error in credit usage controller:", error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
error: "Internal server error while fetching credit usage",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,7 @@ import { extractController } from "../controllers/v1/extract";
|
|||||||
// import { keyAuthController } from "../../src/controllers/v1/keyAuth";
|
// import { keyAuthController } from "../../src/controllers/v1/keyAuth";
|
||||||
// import { livenessController } from "../controllers/v1/liveness";
|
// import { livenessController } from "../controllers/v1/liveness";
|
||||||
// import { readinessController } from "../controllers/v1/readiness";
|
// import { readinessController } from "../controllers/v1/readiness";
|
||||||
|
import { creditUsageController } from "../controllers/v1/credit-usage";
|
||||||
|
|
||||||
function checkCreditsMiddleware(
|
function checkCreditsMiddleware(
|
||||||
minimum?: number,
|
minimum?: number,
|
||||||
@ -224,3 +225,10 @@ v1Router.delete(
|
|||||||
// Health/Probe routes
|
// Health/Probe routes
|
||||||
// v1Router.get("/health/liveness", livenessController);
|
// v1Router.get("/health/liveness", livenessController);
|
||||||
// v1Router.get("/health/readiness", readinessController);
|
// v1Router.get("/health/readiness", readinessController);
|
||||||
|
|
||||||
|
v1Router.get(
|
||||||
|
"/team/credit-usage",
|
||||||
|
authMiddleware(RateLimiterMode.CrawlStatus),
|
||||||
|
wrap(creditUsageController),
|
||||||
|
);
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ const RATE_LIMITS = {
|
|||||||
testSuite: {
|
testSuite: {
|
||||||
free: 10000,
|
free: 10000,
|
||||||
default: 10000,
|
default: 10000,
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const redisRateLimitClient = new Redis(
|
export const redisRateLimitClient = new Redis(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user