mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 01:13:08 +02:00
commit
8d81bd0dc0
1 changed files with 27 additions and 11 deletions
|
@ -7,7 +7,7 @@ const httpSignature = require('http-signature');
|
||||||
import { createHttp } from '../queue';
|
import { createHttp } from '../queue';
|
||||||
import pack from '../remote/activitypub/renderer';
|
import pack from '../remote/activitypub/renderer';
|
||||||
import Note from '../models/note';
|
import Note from '../models/note';
|
||||||
import User, { isLocalUser, ILocalUser } from '../models/user';
|
import User, { isLocalUser, ILocalUser, IUser } from '../models/user';
|
||||||
import renderNote from '../remote/activitypub/renderer/note';
|
import renderNote from '../remote/activitypub/renderer/note';
|
||||||
import renderKey from '../remote/activitypub/renderer/key';
|
import renderKey from '../remote/activitypub/renderer/key';
|
||||||
import renderPerson from '../remote/activitypub/renderer/person';
|
import renderPerson from '../remote/activitypub/renderer/person';
|
||||||
|
@ -41,17 +41,18 @@ function inbox(ctx: Koa.Context) {
|
||||||
ctx.status = 202;
|
ctx.status = 202;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isActivityPubReq(ctx: Router.IRouterContext) {
|
||||||
|
const accepted = ctx.accepts('html', 'application/activity+json', 'application/ld+json');
|
||||||
|
return ['application/activity+json', 'application/ld+json'].includes(accepted as string);
|
||||||
|
}
|
||||||
|
|
||||||
// inbox
|
// inbox
|
||||||
router.post('/inbox', json(), inbox);
|
router.post('/inbox', json(), inbox);
|
||||||
router.post('/users/:user/inbox', json(), inbox);
|
router.post('/users/:user/inbox', json(), inbox);
|
||||||
|
|
||||||
// note
|
// note
|
||||||
router.get('/notes/:note', async (ctx, next) => {
|
router.get('/notes/:note', async (ctx, next) => {
|
||||||
const accepted = ctx.accepts('html', 'application/activity+json', 'application/ld+json');
|
if (!isActivityPubReq(ctx)) return await next();
|
||||||
if (!['application/activity+json', 'application/ld+json'].includes(accepted as string)) {
|
|
||||||
await next();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const note = await Note.findOne({
|
const note = await Note.findOne({
|
||||||
_id: new mongo.ObjectID(ctx.params.note)
|
_id: new mongo.ObjectID(ctx.params.note)
|
||||||
|
@ -112,6 +113,15 @@ router.get('/users/:user/publickey', async ctx => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// user
|
// user
|
||||||
|
function userInfo(ctx: Router.IRouterContext, user: IUser) {
|
||||||
|
if (user === null) {
|
||||||
|
ctx.status = 404;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.body = pack(renderPerson(user as ILocalUser));
|
||||||
|
}
|
||||||
|
|
||||||
router.get('/users/:user', async ctx => {
|
router.get('/users/:user', async ctx => {
|
||||||
const userId = new mongo.ObjectID(ctx.params.user);
|
const userId = new mongo.ObjectID(ctx.params.user);
|
||||||
|
|
||||||
|
@ -120,12 +130,18 @@ router.get('/users/:user', async ctx => {
|
||||||
host: null
|
host: null
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user === null) {
|
userInfo(ctx, user);
|
||||||
ctx.status = 404;
|
});
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.body = pack(renderPerson(user as ILocalUser));
|
router.get('/@:user', async (ctx, next) => {
|
||||||
|
if (!isActivityPubReq(ctx)) return await next();
|
||||||
|
|
||||||
|
const user = await User.findOne({
|
||||||
|
usernameLower: ctx.params.user.toLowerCase(),
|
||||||
|
host: null
|
||||||
|
});
|
||||||
|
|
||||||
|
userInfo(ctx, user);
|
||||||
});
|
});
|
||||||
|
|
||||||
// follow form
|
// follow form
|
||||||
|
|
Loading…
Reference in a new issue