mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Added support for GET /inbox/:owner
ref https://linear.app/tryghost/issue/MOM-127 We're gonna want auth & filtering on this long term, but for now whilst in development it's fine as is.
This commit is contained in:
parent
a70afcd117
commit
fd8bbeebcf
4 changed files with 38 additions and 0 deletions
|
@ -68,6 +68,10 @@ export class Actor extends Entity<ActorData> {
|
|||
return this.username;
|
||||
}
|
||||
|
||||
get inbox() {
|
||||
return this.attr.inbox;
|
||||
}
|
||||
|
||||
get outbox() {
|
||||
return this.attr.outbox;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,23 @@ export class JSONLDService {
|
|||
items: actor.followers.map(item => item.id.getValue(this.url))
|
||||
};
|
||||
}
|
||||
|
||||
async getInbox(owner: ObjectID) {
|
||||
const actor = await this.repository.getOne(owner);
|
||||
if (!actor) {
|
||||
return null;
|
||||
}
|
||||
const json = actor.getJSONLD(this.url);
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: json.inbox,
|
||||
summary: `Inbox for ${actor.username}`,
|
||||
type: 'OrderedCollection',
|
||||
totalItems: actor.inbox.length,
|
||||
orderedItems: actor.inbox.map(activity => activity.getJSONLD(this.url))
|
||||
};
|
||||
}
|
||||
|
||||
async getOutbox(owner: ObjectID) {
|
||||
const actor = await this.repository.getOne(owner);
|
||||
if (!actor) {
|
||||
|
|
|
@ -103,6 +103,12 @@ describe('ActivityPubController', function () {
|
|||
.expect(200);
|
||||
});
|
||||
|
||||
it('Can handle requests to get the inbox', async function () {
|
||||
await request(app.getHttpServer())
|
||||
.get('/activitypub/inbox/deadbeefdeadbeefdeadbeef')
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('Can handle requests to get the following', async function () {
|
||||
await request(app.getHttpServer())
|
||||
.get('/activitypub/following/deadbeefdeadbeefdeadbeef')
|
||||
|
|
|
@ -24,6 +24,17 @@ export class ActivityPubController {
|
|||
return this.service.getActor(ObjectID.createFromHexString(id));
|
||||
}
|
||||
|
||||
@Header('Cache-Control', 'no-store')
|
||||
@Header('Content-Type', 'application/activity+json')
|
||||
@Roles(['Anon'])
|
||||
@Get('inbox/:owner')
|
||||
async getInbox(@Param('owner') owner: unknown) {
|
||||
if (typeof owner !== 'string') {
|
||||
throw new Error('Bad Request');
|
||||
}
|
||||
return this.service.getInbox(ObjectID.createFromHexString(owner));
|
||||
}
|
||||
|
||||
@Header('Cache-Control', 'no-store')
|
||||
@Header('Content-Type', 'application/activity+json')
|
||||
@Roles(['Anon'])
|
||||
|
|
Loading…
Reference in a new issue