Fix POST to Accept Follow Request
This commit is contained in:
parent
51308a5ad3
commit
930308e07f
|
@ -1,9 +1,6 @@
|
|||
const {
|
||||
ActivityStreamsContext,
|
||||
messageBodyToHtml,
|
||||
selfUrl,
|
||||
makeUserUrl,
|
||||
} = require('./util');
|
||||
const { messageBodyToHtml, selfUrl, makeUserUrl } = require('./util');
|
||||
const { ActivityStreamsContext, WellKnownActivityTypes } = require('./const');
|
||||
const ActivityPubObject = require('./object');
|
||||
const User = require('../user');
|
||||
const Actor = require('./actor');
|
||||
const { Errors } = require('../enig_error');
|
||||
|
@ -14,31 +11,18 @@ const { getOutboxEntries } = require('./db');
|
|||
const { WellKnownLocations } = require('../servers/content/web');
|
||||
|
||||
// deps
|
||||
const { isString, isObject } = require('lodash');
|
||||
//const { isString, isObject } = require('lodash');
|
||||
const { v4: UUIDv4 } = require('uuid');
|
||||
const async = require('async');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = class Activity {
|
||||
module.exports = class Activity extends ActivityPubObject {
|
||||
constructor(obj) {
|
||||
this['@context'] = ActivityStreamsContext;
|
||||
Object.assign(this, obj);
|
||||
super(obj);
|
||||
}
|
||||
|
||||
static get ActivityTypes() {
|
||||
return [
|
||||
'Create',
|
||||
'Update',
|
||||
'Delete',
|
||||
'Follow',
|
||||
'Accept',
|
||||
'Reject',
|
||||
'Add',
|
||||
'Remove',
|
||||
'Like',
|
||||
'Announce',
|
||||
'Undo',
|
||||
];
|
||||
return WellKnownActivityTypes;
|
||||
}
|
||||
|
||||
static fromJsonString(json) {
|
||||
|
@ -46,21 +30,21 @@ module.exports = class Activity {
|
|||
return new Activity(parsed);
|
||||
}
|
||||
|
||||
isValid() {
|
||||
if (
|
||||
this['@context'] !== ActivityStreamsContext ||
|
||||
!isString(this.id) ||
|
||||
!isString(this.actor) ||
|
||||
(!isString(this.object) && !isObject(this.object)) ||
|
||||
!Activity.ActivityTypes.includes(this.type)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
// isValid() {
|
||||
// if (
|
||||
// this['@context'] !== ActivityStreamsContext ||
|
||||
// !isString(this.id) ||
|
||||
// !isString(this.actor) ||
|
||||
// (!isString(this.object) && !isObject(this.object)) ||
|
||||
// !Activity.ActivityTypes.includes(this.type)
|
||||
// ) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// :TODO: Additional validation
|
||||
// // :TODO: Additional validation
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// https://www.w3.org/TR/activitypub/#accept-activity-inbox
|
||||
static makeAccept(webServer, localActor, followRequest, id = null) {
|
||||
|
|
|
@ -9,8 +9,8 @@ const {
|
|||
makeUserUrl,
|
||||
selfUrl,
|
||||
isValidLink,
|
||||
ActivityStreamsContext,
|
||||
} = require('../activitypub/util');
|
||||
const { ActivityStreamsContext } = require('./const');
|
||||
const Log = require('../logger').log;
|
||||
const { queryWebFinger } = require('../webfinger');
|
||||
const EnigAssert = require('../enigma_assert');
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const { ActivityStreamsContext, makeUserUrl } = require('./util');
|
||||
const { makeUserUrl } = require('./util');
|
||||
const { ActivityStreamsContext } = require('./const');
|
||||
const { FollowerEntryStatus, getFollowerEntries } = require('./db');
|
||||
|
||||
module.exports = class Collection {
|
||||
|
|
|
@ -49,10 +49,9 @@ function _makeRequest(url, options, cb) {
|
|||
options.headers['Content-Length'] = options.body.length;
|
||||
|
||||
if (options?.sign?.headers?.includes('digest')) {
|
||||
options.headers['Digest'] = `SHA-256=${crypto
|
||||
.createHash('sha256')
|
||||
.update(options.body)
|
||||
.digest('base64')}`;
|
||||
options.headers['Digest'] =
|
||||
'SHA-256=' +
|
||||
crypto.createHash('sha256').update(options.body).digest('base64');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,5 +94,8 @@ function _makeRequest(url, options, cb) {
|
|||
return cb(Errors.Timeout('Timeout making HTTP request'));
|
||||
});
|
||||
|
||||
if (options.body) {
|
||||
req.write(options.body);
|
||||
}
|
||||
req.end();
|
||||
}
|
||||
|
|
|
@ -53,10 +53,13 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
|||
this.webServer.addRoute({
|
||||
method: 'GET',
|
||||
path: /^\/_enig\/ap\/users\/.+\/outbox$/,
|
||||
handler: this._enforceSigningPolicy.bind(
|
||||
this,
|
||||
handler: (req, resp) => {
|
||||
return this._enforceSigningPolicy(
|
||||
req,
|
||||
resp,
|
||||
this._outboxGetHandler.bind(this)
|
||||
),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
this.webServer.addRoute({
|
||||
|
@ -259,7 +262,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
|||
}
|
||||
|
||||
const page = url.searchParams.get('page');
|
||||
Collection.followers(user, page, this.webServe, (err, collection) => {
|
||||
Collection.followers(user, page, this.webServer, (err, collection) => {
|
||||
if (err) {
|
||||
// :TODO: LOG ME
|
||||
return this.webServer.internalServerError(resp);
|
||||
|
|
Loading…
Reference in New Issue