summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/activitypub.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/server/activitypub.ts')
-rw-r--r--packages/backend/src/server/activitypub.ts31
1 files changed, 29 insertions, 2 deletions
diff --git a/packages/backend/src/server/activitypub.ts b/packages/backend/src/server/activitypub.ts
index 133dd36066..cd5f917c40 100644
--- a/packages/backend/src/server/activitypub.ts
+++ b/packages/backend/src/server/activitypub.ts
@@ -1,6 +1,6 @@
import Router from '@koa/router';
import json from 'koa-json-body';
-import httpSignature from 'http-signature';
+import httpSignature from '@peertube/http-signature';
import { renderActivity } from '@/remote/activitypub/renderer/index.js';
import renderNote from '@/remote/activitypub/renderer/note.js';
@@ -15,9 +15,10 @@ import { inbox as processInbox } from '@/queue/index.js';
import { isSelfHost } from '@/misc/convert-host.js';
import { Notes, Users, Emojis, NoteReactions } from '@/models/index.js';
import { ILocalUser, User } from '@/models/entities/user.js';
-import { In, IsNull } from 'typeorm';
+import { In, IsNull, Not } from 'typeorm';
import { renderLike } from '@/remote/activitypub/renderer/like.js';
import { getUserKeypair } from '@/misc/keypair-store.js';
+import renderFollow from '@/remote/activitypub/renderer/follow.js';
// Init router
const router = new Router();
@@ -224,4 +225,30 @@ router.get('/likes/:like', async ctx => {
setResponseType(ctx);
});
+// follow
+router.get('/follows/:follower/:followee', async ctx => {
+ // This may be used before the follow is completed, so we do not
+ // check if the following exists.
+
+ const [follower, followee] = await Promise.all([
+ Users.findOneBy({
+ id: ctx.params.follower,
+ host: IsNull(),
+ }),
+ Users.findOneBy({
+ id: ctx.params.followee,
+ host: Not(IsNull()),
+ }),
+ ]);
+
+ if (follower == null || followee == null) {
+ ctx.status = 404;
+ return;
+ }
+
+ ctx.body = renderActivity(renderFollow(follower, followee));
+ ctx.set('Cache-Control', 'public, max-age=180');
+ setResponseType(ctx);
+});
+
export default router;