mirror of
https://github.com/mendableai/firecrawl.git
synced 2024-11-16 03:32:22 +08:00
Merge pull request #807 from mendableai/mog/acuc-cache-clear
feat: clear ACUC cache endpoint based on team ID
This commit is contained in:
commit
7432f25523
|
@ -13,7 +13,7 @@ import { setTraceAttributes } from "@hyperdx/node-opentelemetry";
|
||||||
import { sendNotification } from "../services/notification/email_notification";
|
import { sendNotification } from "../services/notification/email_notification";
|
||||||
import { Logger } from "../lib/logger";
|
import { Logger } from "../lib/logger";
|
||||||
import { redlock } from "../services/redlock";
|
import { redlock } from "../services/redlock";
|
||||||
import { getValue } from "../services/redis";
|
import { deleteKey, getValue } from "../services/redis";
|
||||||
import { setValue } from "../services/redis";
|
import { setValue } from "../services/redis";
|
||||||
import { validate } from "uuid";
|
import { validate } from "uuid";
|
||||||
import * as Sentry from "@sentry/node";
|
import * as Sentry from "@sentry/node";
|
||||||
|
@ -128,6 +128,13 @@ export async function getACUC(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function clearACUC(
|
||||||
|
api_key: string,
|
||||||
|
): Promise<void> {
|
||||||
|
const cacheKeyACUC = `acuc_${api_key}`;
|
||||||
|
await deleteKey(cacheKeyACUC);
|
||||||
|
}
|
||||||
|
|
||||||
export async function authenticateUser(
|
export async function authenticateUser(
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
|
|
22
apps/api/src/controllers/v0/admin/acuc-cache-clear.ts
Normal file
22
apps/api/src/controllers/v0/admin/acuc-cache-clear.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import { Request, Response } from "express";
|
||||||
|
import { supabase_service } from "../../../services/supabase";
|
||||||
|
import { clearACUC } from "../../auth";
|
||||||
|
import { Logger } from "../../../lib/logger";
|
||||||
|
|
||||||
|
export async function acucCacheClearController(req: Request, res: Response) {
|
||||||
|
try {
|
||||||
|
const team_id: string = req.body.team_id;
|
||||||
|
|
||||||
|
const keys = await supabase_service
|
||||||
|
.from("api_keys")
|
||||||
|
.select("*")
|
||||||
|
.eq("team_id", team_id);
|
||||||
|
|
||||||
|
await Promise.all(keys.data.map((x) => clearACUC(x.key)));
|
||||||
|
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error(`Error clearing ACUC cache via API route: ${error}`);
|
||||||
|
res.status(500).json({ error: "Internal server error" });
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,8 @@ import {
|
||||||
cleanBefore24hCompleteJobsController,
|
cleanBefore24hCompleteJobsController,
|
||||||
queuesController,
|
queuesController,
|
||||||
} from "../controllers/v0/admin/queue";
|
} from "../controllers/v0/admin/queue";
|
||||||
|
import { acucCacheClearController } from "../controllers/v0/admin/acuc-cache-clear";
|
||||||
|
import { wrap } from "./v1";
|
||||||
|
|
||||||
export const adminRouter = express.Router();
|
export const adminRouter = express.Router();
|
||||||
|
|
||||||
|
@ -33,3 +35,8 @@ adminRouter.get(
|
||||||
`/admin/${process.env.BULL_AUTH_KEY}/autoscaler`,
|
`/admin/${process.env.BULL_AUTH_KEY}/autoscaler`,
|
||||||
autoscalerController
|
autoscalerController
|
||||||
);
|
);
|
||||||
|
|
||||||
|
adminRouter.post(
|
||||||
|
`/admin/${process.env.BULL_AUTH_KEY}/acuc-cache-clear`,
|
||||||
|
wrap(acucCacheClearController),
|
||||||
|
);
|
||||||
|
|
|
@ -94,7 +94,7 @@ function blocklistMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrap(controller: (req: Request, res: Response) => Promise<any>): (req: Request, res: Response, next: NextFunction) => any {
|
export function wrap(controller: (req: Request, res: Response) => Promise<any>): (req: Request, res: Response, next: NextFunction) => any {
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
controller(req, res)
|
controller(req, res)
|
||||||
.catch(err => next(err))
|
.catch(err => next(err))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user