From f2f4716ea88f088b5afb25ef3505aebb3a4213a1 Mon Sep 17 00:00:00 2001 From: Phillip Ho Date: Tue, 10 Dec 2024 11:42:33 +0800 Subject: [PATCH] lint --- src/server/middleware/adminRoutes.ts | 110 +++++++++++++-------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/src/server/middleware/adminRoutes.ts b/src/server/middleware/adminRoutes.ts index 789b471d..13b01630 100644 --- a/src/server/middleware/adminRoutes.ts +++ b/src/server/middleware/adminRoutes.ts @@ -22,71 +22,71 @@ const ADMIN_ROUTES_PASSWORD = env.THIRDWEB_API_SECRET_KEY; // Add queues to monitor here. const QUEUES: Queue[] = [ - SendWebhookQueue.q, - ProcessEventsLogQueue.q, - ProcessTransactionReceiptsQueue.q, - SendTransactionQueue.q, - MineTransactionQueue.q, - CancelRecycledNoncesQueue.q, - PruneTransactionsQueue.q, - NonceResyncQueue.q, - NonceHealthCheckQueue.q, + SendWebhookQueue.q, + ProcessEventsLogQueue.q, + ProcessTransactionReceiptsQueue.q, + SendTransactionQueue.q, + MineTransactionQueue.q, + CancelRecycledNoncesQueue.q, + PruneTransactionsQueue.q, + NonceResyncQueue.q, + NonceHealthCheckQueue.q, ]; export const withAdminRoutes = async (fastify: FastifyInstance) => { - fastify.after(async () => { - // Create a new route for Bullboard routes. - const serverAdapter = new FastifyAdapter(); - serverAdapter.setBasePath(ADMIN_QUEUES_BASEPATH); + fastify.after(async () => { + // Create a new route for Bullboard routes. + const serverAdapter = new FastifyAdapter(); + serverAdapter.setBasePath(ADMIN_QUEUES_BASEPATH); - createBullBoard({ - queues: QUEUES.map((q) => new BullMQAdapter(q)), - serverAdapter, - }); + createBullBoard({ + queues: QUEUES.map((q) => new BullMQAdapter(q)), + serverAdapter, + }); - await fastify.register(serverAdapter.registerPlugin(), { - basePath: ADMIN_QUEUES_BASEPATH, - prefix: ADMIN_QUEUES_BASEPATH, - }); + await fastify.register(serverAdapter.registerPlugin(), { + basePath: ADMIN_QUEUES_BASEPATH, + prefix: ADMIN_QUEUES_BASEPATH, + }); - fastify.addHook("onRequest", async (req, reply) => { - if (req.url.startsWith(ADMIN_QUEUES_BASEPATH)) { - const authHeader = req.headers.authorization; + fastify.addHook("onRequest", async (req, reply) => { + if (req.url.startsWith(ADMIN_QUEUES_BASEPATH)) { + const authHeader = req.headers.authorization; - if (!authHeader || !authHeader.startsWith("Basic ")) { - reply - .status(StatusCodes.UNAUTHORIZED) - .header("WWW-Authenticate", 'Basic realm="Admin Routes"') - .send({ error: "Unauthorized" }); - return; - } + if (!authHeader || !authHeader.startsWith("Basic ")) { + reply + .status(StatusCodes.UNAUTHORIZED) + .header("WWW-Authenticate", 'Basic realm="Admin Routes"') + .send({ error: "Unauthorized" }); + return; + } - // Parse the basic auth credentials (`Basic `). - const base64Credentials = authHeader.split(" ")[1]; - const credentials = Buffer.from(base64Credentials, "base64").toString( - "utf8", - ); - const [username, password] = credentials.split(":"); + // Parse the basic auth credentials (`Basic `). + const base64Credentials = authHeader.split(" ")[1]; + const credentials = Buffer.from(base64Credentials, "base64").toString( + "utf8", + ); + const [username, password] = credentials.split(":"); - if (!assertAdminBasicAuth(username, password)) { - reply - .status(StatusCodes.UNAUTHORIZED) - .header("WWW-Authenticate", 'Basic realm="Admin Routes"') - .send({ error: "Unauthorized" }); - return; - } - } - }); - }); + if (!assertAdminBasicAuth(username, password)) { + reply + .status(StatusCodes.UNAUTHORIZED) + .header("WWW-Authenticate", 'Basic realm="Admin Routes"') + .send({ error: "Unauthorized" }); + return; + } + } + }); + }); }; const assertAdminBasicAuth = (username: string, password: string) => { - if (username === ADMIN_ROUTES_USERNAME) { - try { - const buf1 = Buffer.from(password.padEnd(100)); - const buf2 = Buffer.from(ADMIN_ROUTES_PASSWORD.padEnd(100)); - return timingSafeEqual(buf1, buf2); - } catch {} - } - return false; + if (username === ADMIN_ROUTES_USERNAME) { + try { + const buf1 = Buffer.from(password.padEnd(100)); + const buf2 = Buffer.from(ADMIN_ROUTES_PASSWORD.padEnd(100)); + return timingSafeEqual(buf1, buf2); + } catch {} + } + return false; };