Updated backend to cache headers for embeded chat link

This commit is contained in:
rainbow napkin 2024-12-20 02:31:37 -05:00
parent 97717b525c
commit 163cecf9f0

View file

@ -17,7 +17,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
//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;
}