Changes to work with Mastodon. Also fixed variable rename issue

This commit is contained in:
Nathan Byrd 2023-01-06 16:09:08 -06:00
parent d278307a81
commit b252f69f05
2 changed files with 10 additions and 5 deletions

View File

@ -45,6 +45,10 @@ function selfUrl(webServer, user) {
} }
function userFromAccount(accountName, cb) { function userFromAccount(accountName, cb) {
if (accountName.startsWith('@')) {
accountName = accountName.slice(1);
}
User.getUserIdAndName(accountName, (err, userId) => { User.getUserIdAndName(accountName, (err, userId) => {
if (err) { if (err) {
return cb(err); return cb(err);

View File

@ -66,7 +66,8 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
} }
const accept = req.headers['accept'] || '*/*'; const accept = req.headers['accept'] || '*/*';
if (accept === 'application/activity+json') { const headerValues = ['application/activity+json', 'application/ld+json', 'application/json'];
if (headerValues.some(mime => accept.includes(mime))) {
sendActor = true; sendActor = true;
} }
@ -81,14 +82,14 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
} }
_selfAsActorHandler(user, req, resp) { _selfAsActorHandler(user, req, resp) {
const selfUrl = selfUrl(this.webServer, user); const sUrl = selfUrl(this.webServer, user);
const bodyJson = { const bodyJson = {
'@context': [ '@context': [
'https://www.w3.org/ns/activitystreams', 'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1', 'https://w3id.org/security/v1',
], ],
id: selfUrl, id: sUrl,
type: 'Person', type: 'Person',
preferredUsername: user.username, preferredUsername: user.username,
name: user.getSanitizedName('real'), name: user.getSanitizedName('real'),
@ -108,7 +109,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
const publicKeyPem = user.getProperty(UserProps.PublicKeyMain); const publicKeyPem = user.getProperty(UserProps.PublicKeyMain);
if (!_.isEmpty(publicKeyPem)) { if (!_.isEmpty(publicKeyPem)) {
bodyJson['publicKey'] = { bodyJson['publicKey'] = {
id: selfUrl + '#main-key', id: sUrl + '#main-key',
owner: sUrl, owner: sUrl,
publicKeyPem: user.getProperty(UserProps.PublicKeyMain), publicKeyPem: user.getProperty(UserProps.PublicKeyMain),
}; };