feat: ability to query remote users by webfinger handle

This commit is contained in:
Julian Lam
2024-05-07 10:11:36 -04:00
parent a7aeabc80d
commit 9761526710
3 changed files with 27 additions and 10 deletions

View File

@@ -15,6 +15,7 @@ const ttl = require('../cache/ttl');
const user = require('../user');
const activitypub = require('.');
const webfingerRegex = /^(@|acct:)?\w+@.+$/;
const webfingerCache = ttl({ ttl: 1000 * 60 * 60 * 24 }); // 24 hours
const Helpers = module.exports;
@@ -33,6 +34,21 @@ Helpers.isUri = (value) => {
});
};
Helpers.isWebfinger = (value) => {
// N.B. returns normalized handle, so truthy check!
if (webfingerRegex.test(value) && !Helpers.isUri(value)) {
if (value.startsWith('@')) {
return value.slice(1);
} else if (value.startsWith('acct:')) {
return value.slice(5);
}
return value;
}
return false;
};
Helpers.query = async (id) => {
const isUri = Helpers.isUri(id);
// username@host ids use acct: URI schema