summaryrefslogtreecommitdiff
path: root/src/server/activitypub/user.ts
diff options
context:
space:
mode:
authorAkihiko Odaki <nekomanma@pixiv.co.jp>2018-04-01 15:58:49 +0900
committerAkihiko Odaki <nekomanma@pixiv.co.jp>2018-04-01 15:58:49 +0900
commitfabf233478ad79488cd95b1fcfb511a0c5d348bb (patch)
tree81dc6c331736839875e5cdaccf87fbddf24c24a9 /src/server/activitypub/user.ts
parentImplement WebFinger (diff)
downloadsharkey-fabf233478ad79488cd95b1fcfb511a0c5d348bb.tar.gz
sharkey-fabf233478ad79488cd95b1fcfb511a0c5d348bb.tar.bz2
sharkey-fabf233478ad79488cd95b1fcfb511a0c5d348bb.zip
Implement inbox
Diffstat (limited to 'src/server/activitypub/user.ts')
-rw-r--r--src/server/activitypub/user.ts62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/server/activitypub/user.ts b/src/server/activitypub/user.ts
new file mode 100644
index 0000000000..488de93a92
--- /dev/null
+++ b/src/server/activitypub/user.ts
@@ -0,0 +1,62 @@
+import * as express from 'express';
+import config from '../../conf';
+import { extractPublic } from '../../crypto_key';
+import parseAcct from '../../common/user/parse-acct';
+import User, { ILocalAccount } from '../../models/user';
+
+const app = express();
+app.disable('x-powered-by');
+
+app.get('/@:user', async (req, res, next) => {
+ const accepted = req.accepts(['html', 'application/activity+json', 'application/ld+json']);
+ if (!(['application/activity+json', 'application/ld+json'] as Array<any>).includes(accepted)) {
+ return next();
+ }
+
+ const { username, host } = parseAcct(req.params.user);
+ if (host !== null) {
+ return res.sendStatus(422);
+ }
+
+ const user = await User.findOne({
+ usernameLower: username.toLowerCase(),
+ host: null
+ });
+ if (user === null) {
+ return res.sendStatus(404);
+ }
+
+ const id = `${config.url}/@${user.username}`;
+
+ if (username !== user.username) {
+ return res.redirect(id);
+ }
+
+ res.json({
+ '@context': [
+ 'https://www.w3.org/ns/activitystreams',
+ 'https://w3id.org/security/v1'
+ ],
+ type: 'Person',
+ id,
+ inbox: `${id}/inbox`,
+ preferredUsername: user.username,
+ name: user.name,
+ summary: user.description,
+ icon: user.avatarId && {
+ type: 'Image',
+ url: `${config.drive_url}/${user.avatarId}`
+ },
+ image: user.bannerId && {
+ type: 'Image',
+ url: `${config.drive_url}/${user.bannerId}`
+ },
+ publicKey: {
+ type: 'Key',
+ owner: id,
+ publicKeyPem: extractPublic((user.account as ILocalAccount).keypair)
+ }
+ });
+});
+
+export default app;