0
Fork 0
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:
Fabien O'Carroll 2024-05-16 17:12:16 +07:00 committed by Fabien 'egg' O'Carroll
parent a70afcd117
commit fd8bbeebcf
4 changed files with 38 additions and 0 deletions

View file

@ -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;
}

View file

@ -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) {

View file

@ -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')

View file

@ -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'])