From 013d45162dd1401d86641d2b8f67532788c8133f Mon Sep 17 00:00:00 2001 From: Rafael Solorzano <61289255+rafasdc@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:08:12 -0700 Subject: [PATCH] chore: revert --- app/backend/lib/s3download.ts | 81 +++++++++++++++-------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/app/backend/lib/s3download.ts b/app/backend/lib/s3download.ts index e15fb2c4f..8c4bfd0c6 100644 --- a/app/backend/lib/s3download.ts +++ b/app/backend/lib/s3download.ts @@ -1,16 +1,10 @@ import { Router } from 'express'; -import RateLimit from 'express-rate-limit'; import config from '../../config'; import getAuthRole from '../../utils/getAuthRole'; import { getFileTagging, getFileFromS3 } from './s3client'; const AWS_S3_BUCKET = config.get('AWS_S3_BUCKET'); -const limiter = RateLimit({ - windowMs: 1 * 60 * 1000, - max: 2000, -}); - const s3download = Router(); const detectInfected = async (uuid: string) => { const params = { @@ -22,47 +16,42 @@ const detectInfected = async (uuid: string) => { }; // eslint-disable-next-line consistent-return -s3download.get( - '/api/s3/download/:uuid/:fileName', - limiter, - // eslint-disable-next-line consistent-return - async (req, res) => { - const { uuid, fileName } = req.params; - - const authRole = getAuthRole(req); - const isRoleAuthorized = - authRole?.pgRole === 'ccbc_admin' || - authRole?.pgRole === 'ccbc_analyst' || - authRole?.pgRole === 'ccbc_auth_user' || - authRole?.pgRole === 'cbc_admin' || - authRole?.pgRole === 'super_admin'; - - if (!isRoleAuthorized || !uuid || !fileName) { - return res.status(404).end(); - } - if ( - authRole?.pgRole === 'ccbc_admin' || - authRole?.pgRole === 'ccbc_analyst' || - authRole?.pgRole === 'cbc_admin' || - authRole?.pgRole === 'super_admin' - ) { - // first check AV tag - // only for admin and analyst - const healthCheck = await detectInfected(uuid); - const suspect = healthCheck.TagSet.find((x) => x.Key === 'av-status'); - if (suspect?.Value === 'dirty') { - return res.json({ avstatus: 'dirty' }); - } +s3download.get('/api/s3/download/:uuid/:fileName', async (req, res) => { + const { uuid, fileName } = req.params; + + const authRole = getAuthRole(req); + const isRoleAuthorized = + authRole?.pgRole === 'ccbc_admin' || + authRole?.pgRole === 'ccbc_analyst' || + authRole?.pgRole === 'ccbc_auth_user' || + authRole?.pgRole === 'cbc_admin' || + authRole?.pgRole === 'super_admin'; + + if (!isRoleAuthorized || !uuid || !fileName) { + return res.status(404).end(); + } + if ( + authRole?.pgRole === 'ccbc_admin' || + authRole?.pgRole === 'ccbc_analyst' || + authRole?.pgRole === 'cbc_admin' || + authRole?.pgRole === 'super_admin' + ) { + // first check AV tag + // only for admin and analyst + const healthCheck = await detectInfected(uuid); + const suspect = healthCheck.TagSet.find((x) => x.Key === 'av-status'); + if (suspect?.Value === 'dirty') { + return res.json({ avstatus: 'dirty' }); } - - getFileFromS3(uuid, fileName, res) - .then(() => { - res.end(); - }) - .catch(() => { - res.status(500).end(); - }); } -); + + getFileFromS3(uuid, fileName, res) + .then(() => { + res.end(); + }) + .catch(() => { + res.status(500).end(); + }); +}); export default s3download;