Node.js based forum software built for the modern web
fix: move all actor object urls to immutable variants
Julian Lam86a607ce8c32
diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.jsindex be430eb2f5..4de3147adf 100644--- a/src/activitypub/helpers.js+++ b/src/activitypub/helpers.js@@ -94,9 +94,15 @@ Helpers.resolveLocalUid = async (input) => {const { host, pathname } = new URL(input);if (host === nconf.get('url_parsed').host) {- return pathname.replace(nconf.get('relative_path'), '').split('/').filter(Boolean)[1];+ const [type, value] = pathname.replace(nconf.get('relative_path'), '').split('/').filter(Boolean)[1];+ if (type === 'uid') {+ return value;+ }++ slug = value;+ } else {+ throw new Error('[[error:activitypub.invalid-id]]');}- throw new Error('[[error:activitypub.invalid-id]]');} else if (input.indexOf('@') !== -1) { // Webfinger([slug] = input.replace(/^acct:/, '').split('@'));} else {diff --git a/src/activitypub/index.js b/src/activitypub/index.jsindex d783f12e9a..4957217f72 100644--- a/src/activitypub/index.js+++ b/src/activitypub/index.js@@ -87,8 +87,7 @@ ActivityPub.sign = async (uid, url, payload) => {const { host, pathname } = new URL(url);const date = new Date().toUTCString();const key = await ActivityPub.getPrivateKey(uid);- const userslug = await user.getUserField(uid, 'userslug');- const keyId = `${nconf.get('url')}${uid > 0 ? `/user/${userslug}` : '/actor'}#key`;+ const keyId = `${nconf.get('url')}${uid > 0 ? `/uid/${uid}` : '/actor'}#key`;let digest = null;let headers = '(request-target) host date';diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.jsindex a19a59cdff..7211568e4c 100644--- a/src/activitypub/mocks.js+++ b/src/activitypub/mocks.js@@ -137,10 +137,10 @@ Mocks.actor = async (uid) => {'@context': 'https://www.w3.org/ns/activitystreams',id: `${nconf.get('url')}/uid/${uid}`,url: `${nconf.get('url')}/user/${userslug}`,- followers: `${nconf.get('url')}/user/${userslug}/followers`,- following: `${nconf.get('url')}/user/${userslug}/following`,- inbox: `${nconf.get('url')}/user/${userslug}/inbox`,- outbox: `${nconf.get('url')}/user/${userslug}/outbox`,+ followers: `${nconf.get('url')}/uid/${uid}/followers`,+ following: `${nconf.get('url')}/uid/${uid}/following`,+ inbox: `${nconf.get('url')}/uid/${uid}/inbox`,+ outbox: `${nconf.get('url')}/uid/${uid}/outbox`,type: 'Person',name,@@ -150,8 +150,8 @@ Mocks.actor = async (uid) => {image: cover,publicKey: {- id: `${nconf.get('url')}/user/${userslug}#key`,- owner: `${nconf.get('url')}/user/${userslug}`,+ id: `${nconf.get('url')}/uid/${uid}#key`,+ owner: `${nconf.get('url')}/uid/${uid}`,publicKeyPem: publicKey,},};@@ -161,14 +161,11 @@ Mocks.note = async (post) => {const id = `${nconf.get('url')}/post/${post.pid}`;const published = new Date(parseInt(post.timestamp, 10)).toISOString();- const [raw, userslug] = await Promise.all([- posts.getPostField(post.pid, 'content'),- user.getUserField(post.user.uid, 'userslug'),- ]);+ const raw = await posts.getPostField(post.pid, 'content');// todo: post visibility, category privileges integrationconst to = [activitypub._constants.publicAddress];- const cc = [`${nconf.get('url')}/user/${userslug}/followers`];+ const cc = [`${nconf.get('url')}/uid/${post.user.uid}/followers`];let inReplyTo = null;let name = null;diff --git a/src/controllers/activitypub/index.js b/src/controllers/activitypub/index.jsindex 9f1c4f32a1..2aae681b93 100644--- a/src/controllers/activitypub/index.js+++ b/src/controllers/activitypub/index.js@@ -11,14 +11,14 @@ Controller.actors = require('./actors');Controller.topics = require('./topics');Controller.getFollowing = async (req, res) => {- const { followingCount: totalItems } = await user.getUserFields(res.locals.uid, ['followingCount']);+ const { followingCount: totalItems } = await user.getUserFields(req.params.uid, ['followingCount']);const page = parseInt(req.query.page, 10) || 1;const resultsPerPage = 50;const start = Math.max(0, page - 1) * resultsPerPage;const stop = start + resultsPerPage - 1;- let orderedItems = await user.getFollowing(res.locals.uid, start, stop);+ let orderedItems = await user.getFollowing(req.params.uid, start, stop);orderedItems = orderedItems.map(({ userslug }) => `${nconf.get('url')}/user/${userslug}`);res.status(200).json({'@context': 'https://www.w3.org/ns/activitystreams',@@ -29,14 +29,14 @@ Controller.getFollowing = async (req, res) => {};Controller.getFollowers = async (req, res) => {- const { followerCount: totalItems } = await user.getUserFields(res.locals.uid, ['followerCount']);+ const { followerCount: totalItems } = await user.getUserFields(req.params.uid, ['followerCount']);const page = parseInt(req.query.page, 10) || 1;const resultsPerPage = 50;const start = Math.max(0, page - 1) * resultsPerPage;const stop = start + resultsPerPage - 1;- let orderedItems = await user.getFollowers(res.locals.uid, start, stop);+ let orderedItems = await user.getFollowers(req.params.uid, start, stop);orderedItems = orderedItems.map(({ userslug }) => `${nconf.get('url')}/user/${userslug}`);res.status(200).json({'@context': 'https://www.w3.org/ns/activitystreams',diff --git a/src/routes/activitypub.js b/src/routes/activitypub.jsindex 48d29304f0..ffc3a52bcd 100644--- a/src/routes/activitypub.js+++ b/src/routes/activitypub.js@@ -18,14 +18,14 @@ module.exports = function (app, middleware, controllers) {app.get('/uid/:uid', middlewares, controllers.activitypub.actors.user);app.get('/user/:userslug', [...middlewares, middleware.exposeUid], controllers.activitypub.actors.userBySlug);- app.get('/user/:userslug/inbox', [...middlewares, middleware.exposeUid], controllers.activitypub.getInbox);- app.post('/user/:userslug/inbox', [...middlewares, middleware.activitypub.validate, middleware.exposeUid], controllers.activitypub.postInbox);+ app.get('/uid/:uid/inbox', middlewares, controllers.activitypub.getInbox);+ app.post('/uid/:uid/inbox', [...middlewares, middleware.activitypub.validate], controllers.activitypub.postInbox);- app.get('/user/:userslug/outbox', [...middlewares, middleware.exposeUid], controllers.activitypub.getOutbox);- app.post('/user/:userslug/outbox', [...middlewares, middleware.exposeUid], controllers.activitypub.postOutbox);+ app.get('/uid/:uid/outbox', middlewares, controllers.activitypub.getOutbox);+ app.post('/uid/:uid/outbox', middlewares, controllers.activitypub.postOutbox);- app.get('/user/:userslug/following', [...middlewares, middleware.exposeUid], controllers.activitypub.getFollowing);- app.get('/user/:userslug/followers', [...middlewares, middleware.exposeUid], controllers.activitypub.getFollowers);+ app.get('/uid/:uid/following', middlewares, controllers.activitypub.getFollowing);+ app.get('/uid/:uid/followers', middlewares, controllers.activitypub.getFollowers);app.get('/post/:pid', middlewares, controllers.activitypub.actors.note);};