* Update activitypub.ts * Update activitypub.ts * Update activitypub.ts * Update activitypub.ts * fix type error * trust the module * remove space * accept charset
This commit is contained in:
parent
533884dcaa
commit
75e2b075e1
1 changed files with 9 additions and 6 deletions
|
@ -40,18 +40,21 @@ function inbox(ctx: Router.RouterContext) {
|
||||||
ctx.status = 202;
|
ctx.status = 202;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ACTIVITY_JSON = 'application/activity+json; charset=utf-8';
|
||||||
|
const LD_JSON = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"; charset=utf-8';
|
||||||
|
|
||||||
function isActivityPubReq(ctx: Router.RouterContext) {
|
function isActivityPubReq(ctx: Router.RouterContext) {
|
||||||
ctx.response.vary('Accept');
|
ctx.response.vary('Accept');
|
||||||
const accepted = ctx.accepts('html', 'application/activity+json', 'application/ld+json');
|
const accepted = ctx.accepts('html', ACTIVITY_JSON, LD_JSON);
|
||||||
return ['application/activity+json', 'application/ld+json'].includes(accepted as string);
|
return typeof accepted === 'string' && !accepted.match(/html/);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setResponseType(ctx: Router.RouterContext) {
|
export function setResponseType(ctx: Router.RouterContext) {
|
||||||
const accept = ctx.accepts('application/activity+json', 'application/ld+json');
|
const accept = ctx.accepts(ACTIVITY_JSON, LD_JSON);
|
||||||
if (accept === 'application/ld+json') {
|
if (accept === LD_JSON) {
|
||||||
ctx.response.type = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"; charset=utf-8';
|
ctx.response.type = LD_JSON;
|
||||||
} else {
|
} else {
|
||||||
ctx.response.type = 'application/activity+json; charset=utf-8';
|
ctx.response.type = ACTIVITY_JSON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue