Bug squashing and refactored inbox
This commit is contained in:
parent
84dde6c5c5
commit
c796a856b1
|
@ -183,11 +183,11 @@ module.exports = class Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendTo(actorUrl, fromUser, webServer, cb) {
|
sendTo(actorUrl, fromUser, webServer, cb) {
|
||||||
const privateKey = fromUser.getProperty(UserProps.PrivateKeyMain);
|
const privateKey = fromUser.getProperty(UserProps.PrivateActivityPubSigningKey);
|
||||||
if (_.isEmpty(privateKey)) {
|
if (_.isEmpty(privateKey)) {
|
||||||
return cb(
|
return cb(
|
||||||
Errors.MissingProperty(
|
Errors.MissingProperty(
|
||||||
`User "${fromUser.username}" is missing the '${UserProps.PrivateKeyMain}' property`
|
`User "${fromUser.username}" is missing the '${UserProps.PrivateActivityPubSigningKey}' property`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,24 +130,28 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
||||||
|
|
||||||
if (!activity.isValid()) {
|
if (!activity.isValid()) {
|
||||||
this.log.warn({ activity }, 'Invalid or unsupported Activity');
|
this.log.warn({ activity }, 'Invalid or unsupported Activity');
|
||||||
return this.webServer.webServer.badRequest(resp);
|
return this.webServer.badRequest(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (activity.type) {
|
const activityFunctions = {
|
||||||
case 'Follow':
|
Follow: this._inboxFollowRequestHandler.bind(this),
|
||||||
return this._inboxFollowRequestHandler(
|
// TODO: 'Create', 'Update', etc.
|
||||||
signature,
|
};
|
||||||
activity,
|
|
||||||
req,
|
|
||||||
resp
|
|
||||||
);
|
|
||||||
|
|
||||||
default:
|
if (_.has(activityFunctions, activity.type)) {
|
||||||
this.log.debug(
|
return this._withUserRequestHandler(
|
||||||
{ type: activity.type },
|
signature,
|
||||||
`Unsupported Activity type "${activity.type}"`
|
activity,
|
||||||
);
|
activityFunctions[activity.type],
|
||||||
return this.webServer.resourceNotFound(resp);
|
req,
|
||||||
|
resp
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.log.debug(
|
||||||
|
{ type: activity.type },
|
||||||
|
`Unsupported Activity type "${activity.type}"`
|
||||||
|
);
|
||||||
|
return this.webServer.resourceNotFound(resp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -228,11 +232,70 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
||||||
return keyId.endsWith('#main-key');
|
return keyId.endsWith('#main-key');
|
||||||
}
|
}
|
||||||
|
|
||||||
_inboxFollowRequestHandler(signature, activity, req, resp) {
|
_inboxFollowRequestHandler(activity, user, resp) {
|
||||||
this.log.trace(
|
this.log.debug({ user: user, type: activity.type }, 'Got a follow request!');
|
||||||
{ actor: activity.actor },
|
// :TODO: return OK and kick off a async job of persisting and sending and 'Accepted'
|
||||||
`Follow request from ${activity.actor}`
|
|
||||||
);
|
//
|
||||||
|
// If the user blindly accepts Followers, we can persist
|
||||||
|
// and send an 'Accept' now. Otherwise, we need to queue this
|
||||||
|
// request for the user to review and decide what to do with
|
||||||
|
// at a later time.
|
||||||
|
//
|
||||||
|
// :TODO: Implement the queue
|
||||||
|
const activityPubSettings = ActivityPubSettings.fromUser(user);
|
||||||
|
if (!activityPubSettings.manuallyApproveFollowers) {
|
||||||
|
Actor.fromLocalUser(user, this.webServer, (err, localActor) => {
|
||||||
|
if (err) {
|
||||||
|
return this.log.warn(
|
||||||
|
{ user: user, error: err.message },
|
||||||
|
'Failed to load local Actor for "Accept"'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const accept = Activity.makeAccept(this.webServer, localActor, activity);
|
||||||
|
|
||||||
|
accept.sendTo(
|
||||||
|
localActor.inbox,
|
||||||
|
user,
|
||||||
|
this.webServer,
|
||||||
|
(err, respBody, res) => {
|
||||||
|
if (err) {
|
||||||
|
return this.log.warn(
|
||||||
|
{
|
||||||
|
inbox: localActor.inbox,
|
||||||
|
statusCode: res.statusCode,
|
||||||
|
error: err.message,
|
||||||
|
},
|
||||||
|
'Failed POSTing "Accept" to inbox'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res.statusCode !== 202 && res.statusCode !== 200) {
|
||||||
|
return this.log.warn(
|
||||||
|
{
|
||||||
|
inbox: localActor.inbox,
|
||||||
|
statusCode: res.statusCode,
|
||||||
|
},
|
||||||
|
'Unexpected status code'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.log.trace(
|
||||||
|
{ inbox: localActor.inbox },
|
||||||
|
'Remote server received our "Accept" successfully'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.writeHead(200, { 'Content-Type': 'text/html' });
|
||||||
|
return resp.end('');
|
||||||
|
}
|
||||||
|
|
||||||
|
_withUserRequestHandler(signature, activity, activityHandler, req, resp) {
|
||||||
|
this.log.trace({ actor: activity.actor }, `Inbox request from ${activity.actor}`);
|
||||||
|
|
||||||
// :TODO: trace
|
// :TODO: trace
|
||||||
const accountName = accountFromSelfUrl(activity.object);
|
const accountName = accountFromSelfUrl(activity.object);
|
||||||
|
@ -274,68 +337,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
||||||
return this.webServer.accessDenied(resp);
|
return this.webServer.accessDenied(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// :TODO: return OK and kick off a async job of persisting and sending and 'Accepted'
|
return activityHandler(activity, user, resp);
|
||||||
|
|
||||||
//
|
|
||||||
// If the user blindly accepts Followers, we can persist
|
|
||||||
// and send an 'Accept' now. Otherwise, we need to queue this
|
|
||||||
// request for the user to review and decide what to do with
|
|
||||||
// at a later time.
|
|
||||||
//
|
|
||||||
// :TODO: Implement the queue
|
|
||||||
const activityPubSettings = ActivityPubSettings.fromUser(user);
|
|
||||||
if (!activityPubSettings.manuallyApproveFollowers) {
|
|
||||||
Actor.fromLocalUser(user, this.webServer, (err, localActor) => {
|
|
||||||
if (err) {
|
|
||||||
return this.log.warn(
|
|
||||||
{ inbox: actor.inbox, error: err.message },
|
|
||||||
'Failed to load local Actor for "Accept"'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const accept = Activity.makeAccept(
|
|
||||||
this.webServer,
|
|
||||||
localActor,
|
|
||||||
activity
|
|
||||||
);
|
|
||||||
|
|
||||||
accept.sendTo(
|
|
||||||
actor.inbox,
|
|
||||||
user,
|
|
||||||
this.webServer,
|
|
||||||
(err, respBody, res) => {
|
|
||||||
if (err) {
|
|
||||||
return this.log.warn(
|
|
||||||
{
|
|
||||||
inbox: actor.inbox,
|
|
||||||
statusCode: res.statusCode,
|
|
||||||
error: err.message,
|
|
||||||
},
|
|
||||||
'Failed POSTing "Accept" to inbox'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res.statusCode !== 202 && res.statusCode !== 200) {
|
|
||||||
return this.log.warn(
|
|
||||||
{
|
|
||||||
inbox: actor.inbox,
|
|
||||||
statusCode: res.statusCode,
|
|
||||||
},
|
|
||||||
'Unexpected status code'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.log.trace(
|
|
||||||
{ inbox: actor.inbox },
|
|
||||||
'Remote server received our "Accept" successfully'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.writeHead(200, { 'Content-Type': 'text/html' });
|
|
||||||
return resp.end('');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue