mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	feat: add webfinger ttl cache
This commit is contained in:
		| @@ -2,6 +2,10 @@ | |||||||
|  |  | ||||||
| const request = require('request-promise-native'); | const request = require('request-promise-native'); | ||||||
|  |  | ||||||
|  | const ttl = require('../cache/ttl'); | ||||||
|  |  | ||||||
|  | const webfingerCache = ttl({ ttl: 1000 * 60 * 60 * 24 }); // 24 hours | ||||||
|  |  | ||||||
| const Helpers = module.exports; | const Helpers = module.exports; | ||||||
|  |  | ||||||
| Helpers.query = async (id) => { | Helpers.query = async (id) => { | ||||||
| @@ -10,6 +14,10 @@ Helpers.query = async (id) => { | |||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	if (webfingerCache.has(id)) { | ||||||
|  | 		return webfingerCache.get(id); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	// Make a webfinger query to retrieve routing information | 	// Make a webfinger query to retrieve routing information | ||||||
| 	const response = await request(`https://${hostname}/.well-known/webfinger?resource=acct:${id}`, { | 	const response = await request(`https://${hostname}/.well-known/webfinger?resource=acct:${id}`, { | ||||||
| 		simple: false, | 		simple: false, | ||||||
| @@ -28,5 +36,6 @@ Helpers.query = async (id) => { | |||||||
| 		({ href: actorUri } = actorUri); | 		({ href: actorUri } = actorUri); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	webfingerCache.set(id, { username, hostname, actorUri }); | ||||||
| 	return { username, hostname, actorUri }; | 	return { username, hostname, actorUri }; | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user