mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	feat: ability to view federated profiles via url manipulation
This commit is contained in:
		
							
								
								
									
										32
									
								
								src/activitypub/helpers.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/activitypub/helpers.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| const request = require('request-promise-native'); | ||||
|  | ||||
| const Helpers = module.exports; | ||||
|  | ||||
| Helpers.query = async (id) => { | ||||
| 	const [username, hostname] = id.split('@'); | ||||
| 	if (!username || !hostname) { | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	// Make a webfinger query to retrieve routing information | ||||
| 	const response = await request(`https://${hostname}/.well-known/webfinger?resource=acct:${id}`, { | ||||
| 		simple: false, | ||||
| 		resolveWithFullResponse: true, | ||||
| 		json: true, | ||||
| 	}); | ||||
|  | ||||
| 	if (response.statusCode !== 200 || !response.body.hasOwnProperty('links')) { | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	// Parse links to find actor endpoint | ||||
| 	let actorUri = response.body.links.filter(link => link.type === 'application/activity+json' && link.rel === 'self'); | ||||
| 	if (actorUri.length) { | ||||
| 		actorUri = actorUri.pop(); | ||||
| 		({ href: actorUri } = actorUri); | ||||
| 	} | ||||
|  | ||||
| 	return { username, hostname, actorUri }; | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user