Compare commits

...

1 commit

Author SHA1 Message Date
555699635f chore: fix backend activitypub.ts lints and logic
lints: mostly function signatures
logic: remote user logic is incorrect and overly lengthy,
       public key checks are leaky
TODO:  default export lint
2022-08-17 19:47:09 -04:00

View file

@ -25,7 +25,7 @@ const router = new Router();
//#region Routing
function inbox(ctx: Router.RouterContext) {
function inbox(ctx: Router.RouterContext): void {
let signature;
try {
@ -43,13 +43,13 @@ function inbox(ctx: Router.RouterContext) {
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): boolean {
ctx.response.vary('Accept');
const accepted = ctx.accepts('html', ACTIVITY_JSON, LD_JSON);
return typeof accepted === 'string' && !accepted.match(/html/);
}
export function setResponseType(ctx: Router.RouterContext) {
export function setResponseType(ctx: Router.RouterContext): void {
const accept = ctx.accepts(ACTIVITY_JSON, LD_JSON);
if (accept === LD_JSON) {
ctx.response.type = LD_JSON;
@ -77,13 +77,9 @@ router.get('/notes/:note', async (ctx, next) => {
return;
}
// リモートだったらリダイレクト
if (note.userHost != null) {
if (note.uri == null || isSelfHost(note.userHost)) {
ctx.status = 500;
return;
}
ctx.redirect(note.uri);
if (!isSelfHost(note.userHost)) {
if (note.uri != null) ctx.redirect(note.uri);
else ctx.status = 500;
return;
}
@ -132,24 +128,19 @@ router.get('/users/:user/publickey', async ctx => {
host: IsNull(),
});
if (user == null) {
if (user == null || !Users.isLocalUser(user)) {
ctx.status = 404;
return;
}
const keypair = await getUserKeypair(user.id);
if (Users.isLocalUser(user)) {
ctx.body = renderActivity(renderKey(user, keypair));
ctx.set('Cache-Control', 'public, max-age=180');
setResponseType(ctx);
} else {
ctx.status = 400;
}
ctx.body = renderActivity(renderKey(user, keypair));
ctx.set('Cache-Control', 'public, max-age=180');
setResponseType(ctx);
});
// user
async function userInfo(ctx: Router.RouterContext, user: User | null) {
async function userInfo(ctx: Router.RouterContext, user: User | null): void {
if (user == null) {
ctx.status = 404;
return;