From 163cecf9f097c507f99b818bad4e09461ffe423e Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Fri, 20 Dec 2024 02:31:37 -0500 Subject: [PATCH] Updated backend to cache headers for embeded chat link --- src/utils/linkUtils.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/utils/linkUtils.js b/src/utils/linkUtils.js index 29e25e2..6123ab9 100644 --- a/src/utils/linkUtils.js +++ b/src/utils/linkUtils.js @@ -17,7 +17,19 @@ along with this program. If not, see .*/ //NPM Imports const validator = require('validator');//No express here, so regular validator it is! +//Create link cache +module.exports.cache = new Map(); + module.exports.markLink = async function(link){ + //Check link cache for the requested link + const cachedLink = module.exports.cache.get(link); + + //If we have a cached result + if(cachedLink){ + //return the cached link + return cachedLink; + } + //Set max file size to 4MB const maxSize = 4000000; //Assume links are guilty until proven innocent @@ -66,8 +78,20 @@ module.exports.markLink = async function(link){ }catch{}; } - return { + //Create the link object from processed information + const linkObj = { link, type } + + //Cache the result + module.exports.cache.set(link, linkObj); + + //Set timer to remove cache entry in five minutes + setTimeout(()=>{ + module.exports.cache.delete(link); + }, 300000) + + //return the link + return linkObj; } \ No newline at end of file