Updated backend to cache headers for embeded chat link
This commit is contained in:
parent
97717b525c
commit
163cecf9f0
|
|
@ -17,7 +17,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
//NPM Imports
|
//NPM Imports
|
||||||
const validator = require('validator');//No express here, so regular validator it is!
|
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){
|
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
|
//Set max file size to 4MB
|
||||||
const maxSize = 4000000;
|
const maxSize = 4000000;
|
||||||
//Assume links are guilty until proven innocent
|
//Assume links are guilty until proven innocent
|
||||||
|
|
@ -66,8 +78,20 @@ module.exports.markLink = async function(link){
|
||||||
}catch{};
|
}catch{};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
//Create the link object from processed information
|
||||||
|
const linkObj = {
|
||||||
link,
|
link,
|
||||||
type
|
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;
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue