Skip to content

Commit

Permalink
Used path instead of query params for ActivityPub API
Browse files Browse the repository at this point in the history
ref https://linear.app/tryghost/issue/MOM-25

This makes it easier to work with on the frontend, as we don't need to
whitelist query params for Ghost(Pro)
  • Loading branch information
allouis committed Apr 18, 2024
1 parent d34884f commit 55d05f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
34 changes: 5 additions & 29 deletions ghost/ghost/src/core/activitypub/actor.entity.ts
Expand Up @@ -13,16 +13,6 @@ type CreateActorData = ActorData & {
id? : ObjectID
};

function makeUrl(base: URL, props: Record<string, string>): URL {
const url = new URL(`${props.type}`, base.href);
for (const [key, value] of Object.entries(props)) {
if (key !== 'type') {
url.searchParams.set(key, value);
}
}
return url;
}

export class Actor extends Entity<ActorData> {
get username() {
return this.attr.username;
Expand All @@ -32,25 +22,11 @@ export class Actor extends Entity<ActorData> {
if (!url.href.endsWith('/')) {
url.href += '/';
}
const actor = makeUrl(url, {
type: 'actor',
id: this.id.toHexString()
});

const publicKey = makeUrl(url, {
type: 'key',
owner: this.id.toHexString()
});

const inbox = makeUrl(url, {
type: 'inbox',
owner: this.id.toHexString()
});

const outbox = makeUrl(url, {
type: 'outbox',
owner: this.id.toHexString()
});
const id = this.id.toHexString();
const actor = new URL(`actor/${id}`, url.href);
const publicKey = new URL(`key/${id}`, url.href);
const inbox = new URL(`inbox/${id}`, url.href);
const outbox = new URL(`outbox/${id}`, url.href);

return {
'@context': 'https://www.w3.org/ns/activitystreams',
Expand Down
14 changes: 7 additions & 7 deletions ghost/ghost/src/http/admin/controllers/activitypub.controller.ts
@@ -1,4 +1,4 @@
import {Controller, Get, Query} from '@nestjs/common';
import {Controller, Get, Param} from '@nestjs/common';
import {Roles} from '../../../common/decorators/permissions.decorator';
import ObjectID from 'bson-objectid';
import {JSONLDService} from '../../../core/activitypub/jsonld.service';
Expand All @@ -10,26 +10,26 @@ export class ActivityPubController {
) {}

@Roles(['Anon'])
@Get('actor')
async getActor(@Query('id') id: unknown) {
@Get('actor/:id')
async getActor(@Param('id') id: unknown) {
if (typeof id !== 'string') {
throw new Error('Bad Request');
}
return this.service.getActor(ObjectID.createFromHexString(id));
}

@Roles(['Anon'])
@Get('key')
async getKey(@Query('owner') owner: unknown) {
@Get('key/:owner')
async getKey(@Param('owner') owner: unknown) {
if (typeof owner !== 'string') {
throw new Error('Bad Request');
}
return this.service.getPublicKey(ObjectID.createFromHexString(owner));
}

@Roles(['Anon'])
@Get('outbox')
async getOutbox(@Query('owner') owner: unknown) {
@Get('outbox/:owner')
async getOutbox(@Param('owner') owner: unknown) {
if (typeof owner !== 'string') {
throw new Error('Bad Request');
}
Expand Down

0 comments on commit 55d05f0

Please sign in to comment.