diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2018-04-01 12:27:16 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-01 12:27:16 +0900 |
| commit | 55f716fc629e603547eeaa912f0eb94014bb12ec (patch) | |
| tree | 69ad12db603363747dcfb48d9d6911542e8fae44 /src/server/activitypub.ts | |
| parent | Fix (diff) | |
| parent | Implement Activity Streams representation of user (diff) | |
| download | sharkey-55f716fc629e603547eeaa912f0eb94014bb12ec.tar.gz sharkey-55f716fc629e603547eeaa912f0eb94014bb12ec.tar.bz2 sharkey-55f716fc629e603547eeaa912f0eb94014bb12ec.zip | |
Merge pull request #1346 from akihikodaki/user
Implement Activity Streams representation of user
Diffstat (limited to 'src/server/activitypub.ts')
| -rw-r--r-- | src/server/activitypub.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts new file mode 100644 index 0000000000..6cc31de7b5 --- /dev/null +++ b/src/server/activitypub.ts @@ -0,0 +1,60 @@ +import config from '../conf'; +import { extractPublic } from '../crypto_key'; +import parseAcct from '../common/user/parse-acct'; +import User, { ILocalAccount } from '../models/user'; +const express = require('express'); + +const app = express(); + +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'].includes(accepted)) { + return next(); + } + + const { username, host } = parseAcct(req.params.user); + if (host !== null) { + return res.send(422); + } + + const user = await User.findOne({ + usernameLower: username.toLowerCase(), + host: null + }); + if (user === null) { + return res.send(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, + 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; |