0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Used path instead of query params for ActivityPub API

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)
This commit is contained in:
Fabien O'Carroll 2024-04-18 14:45:13 +07:00 committed by Fabien 'egg' O'Carroll
parent d34884fc6d
commit 55d05f0476
2 changed files with 12 additions and 36 deletions

View file

@ -13,16 +13,6 @@ type CreateActorData = ActorData & {
id? : ObjectID 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> { export class Actor extends Entity<ActorData> {
get username() { get username() {
return this.attr.username; return this.attr.username;
@ -32,25 +22,11 @@ export class Actor extends Entity<ActorData> {
if (!url.href.endsWith('/')) { if (!url.href.endsWith('/')) {
url.href += '/'; url.href += '/';
} }
const actor = makeUrl(url, { const id = this.id.toHexString();
type: 'actor', const actor = new URL(`actor/${id}`, url.href);
id: this.id.toHexString() const publicKey = new URL(`key/${id}`, url.href);
}); const inbox = new URL(`inbox/${id}`, url.href);
const outbox = new URL(`outbox/${id}`, url.href);
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()
});
return { return {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',

View file

@ -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 {Roles} from '../../../common/decorators/permissions.decorator';
import ObjectID from 'bson-objectid'; import ObjectID from 'bson-objectid';
import {JSONLDService} from '../../../core/activitypub/jsonld.service'; import {JSONLDService} from '../../../core/activitypub/jsonld.service';
@ -10,8 +10,8 @@ export class ActivityPubController {
) {} ) {}
@Roles(['Anon']) @Roles(['Anon'])
@Get('actor') @Get('actor/:id')
async getActor(@Query('id') id: unknown) { async getActor(@Param('id') id: unknown) {
if (typeof id !== 'string') { if (typeof id !== 'string') {
throw new Error('Bad Request'); throw new Error('Bad Request');
} }
@ -19,8 +19,8 @@ export class ActivityPubController {
} }
@Roles(['Anon']) @Roles(['Anon'])
@Get('key') @Get('key/:owner')
async getKey(@Query('owner') owner: unknown) { async getKey(@Param('owner') owner: unknown) {
if (typeof owner !== 'string') { if (typeof owner !== 'string') {
throw new Error('Bad Request'); throw new Error('Bad Request');
} }
@ -28,8 +28,8 @@ export class ActivityPubController {
} }
@Roles(['Anon']) @Roles(['Anon'])
@Get('outbox') @Get('outbox/:owner')
async getOutbox(@Query('owner') owner: unknown) { async getOutbox(@Param('owner') owner: unknown) {
if (typeof owner !== 'string') { if (typeof owner !== 'string') {
throw new Error('Bad Request'); throw new Error('Bad Request');
} }