This commit is contained in:
Michael Puckett 2023-07-22 11:58:25 -04:00
parent 274ef202b3
commit ee8dee96b7
26 changed files with 119 additions and 158 deletions

View File

@ -1,5 +1,8 @@
import { EntityGetEndpoint } from '.';
export declare function respond(this: EntityGetEndpoint, render: (...args: unknown[]) => Promise<string>): Promise<{
import { AP } from '@activity-kit/types';
export declare function respond(this: EntityGetEndpoint, render: (args: {
entity: AP.Entity;
}) => Promise<string>): Promise<{
statusCode: number;
contentType?: string;
body: string;

View File

@ -17,7 +17,7 @@ async function respond(render) {
}
if (!(0, types_2.isTypeOf)(entity, types_1.AP.CollectionTypes) &&
!(0, types_2.isTypeOf)(entity, types_1.AP.CollectionPageTypes)) {
return this.handleNotFound();
return this.handleFoundEntity(entity, render);
}
(0, types_1.assertIsApCollection)(entity);
const totalItems = Number(entity.totalItems);

View File

@ -1 +1 @@
{"version":3,"file":"respond.js","sourceRoot":"","sources":["../../src/entity/respond.ts"],"names":[],"mappings":";;;AACA,+CAK6B;AAC7B,+CAAuD;AAEvD,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE9B,KAAK,UAAU,OAAO,CAE3B,MAA+C;IAM/C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACjD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;IAC3D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAEvD,IAAI;QACF,IAAA,wBAAgB,EAAC,MAAM,CAAC,CAAC;KAC1B;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,IAAI,CAAC,cAAc,EA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CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAClB;KACF;IAED,MAAM,cAAc,GAAG;QACrB,GAAG,MAAM;QACT,EAAE,EAAE,UAAU,CAAC,WAAW,CAAC;QAC3B,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC;QAC5B,MAAM,EAAE,OAAO;QACf,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;QACpB,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC;QAC/B,GAAG,CAAC,WAAW,GAAG,CAAC;YACjB,CAAC,CAAC;gBACE,IAAI,EAAE,UAAU,CAAC,WAAW,GAAG,CAAC,CAAC;aAClC;YACH,CAAC,CAAC,IAAI,CAAC;QACT,GAAG,CAAC,WAAW,GAAG,aAAa;YAC7B,CAAC,CAAC;gBACE,IAAI,EAAE,UAAU,CAAC,WAAW,GAAG,CAAC,CAAC;aAClC;YACH,CAAC,CAAC,IAAI,CAAC;KACV,CAAC;IAEF,IAAI,mBAAmB,EAAE;QACvB,MAAM,2BAA2B,GAA6B;YAC5D,GAAG,cAAc;YACjB,IAAI,EAAE,UAAE,CAAC,mBAAmB,CAAC,uBAAuB;YACpD,YAAY,EAAE,KAAK;YACnB,UAAU;SACX,CAAC;QAEF,OAAO,IAAI,CAAC,iBAAiB,CAAC,2BAA2B,EAAE,MAAM,CAAC,CAAC;KACpE;IAED,MAAM,oBAAoB,GAAsB;QAC9C,GAAG,cAAc;QACjB,IAAI,EAAE,UAAE,CAAC,mBAAmB,CAAC,eAAe;QAC5C,KAAK,EAAE,KAAK;KACb,CAAC;IAEF,OAAO,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;AAC9D,CAAC;AA5JD,0BA4JC"}

View File

@ -1,2 +0,0 @@
import { OutboxPostEndpoint } from '.';
export declare function authenticateActor(this: OutboxPostEndpoint): Promise<void>;

View File

@ -1,27 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.authenticateActor = void 0;
const types_1 = require("@activity-kit/types");
const utilities_1 = require("@activity-kit/utilities");
const cookie_1 = __importDefault(require("cookie"));
async function authenticateActor() {
const cookies = cookie_1.default.parse(this.req.headers.cookie ?? '');
const userId = await this.core.getUserIdByToken(cookies.__session ?? '');
try {
const authenticatedActor = await this.core.getActorByUserId(userId);
(0, types_1.assertIsApActor)(authenticatedActor);
const authenticatedActorId = (0, utilities_1.getId)(authenticatedActor);
(0, types_1.assertExists)(authenticatedActorId);
if (authenticatedActorId.toString() !== this.actor.id.toString()) {
throw new Error('No match.');
}
}
catch (error) {
throw new Error('Not authorized.');
}
}
exports.authenticateActor = authenticateActor;
//# sourceMappingURL=authenticateActor.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"authenticateActor.js","sourceRoot":"","sources":["../../src/outbox/authenticateActor.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAoE;AACpE,uDAAgD;AAChD,oDAA4B;AAGrB,KAAK,UAAU,iBAAiB;IACrC,MAAM,OAAO,GAAG,gBAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAEzE,IAAI;QACF,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAEpE,IAAA,uBAAe,EAAC,kBAAkB,CAAC,CAAC;QAEpC,MAAM,oBAAoB,GAAG,IAAA,iBAAK,EAAC,kBAAkB,CAAC,CAAC;QAEvD,IAAA,oBAAY,EAAC,oBAAoB,CAAC,CAAC;QAEnC,IAAI,oBAAoB,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE;YAChE,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;SAC9B;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;KACpC;AACH,CAAC;AAnBD,8CAmBC"}

View File

@ -2,11 +2,9 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.getActor = void 0;
const types_1 = require("@activity-kit/types");
const utilities_1 = require("@activity-kit/utilities");
async function getActor() {
const url = new URL(this.req.url, utilities_1.LOCAL_DOMAIN);
const actor = await this.core.findOne('entity', {
outbox: url.toString(),
outbox: this.url.toString(),
});
(0, types_1.assertIsApActor)(actor);
this.actor = actor;

View File

@ -1 +1 @@
{"version":3,"file":"getActor.js","sourceRoot":"","sources":["../../src/outbox/getActor.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,uDAAuD;AAGhD,KAAK,UAAU,QAAQ;IAC5B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,wBAAY,CAAC,CAAC;IAEhD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;QAC9C,MAAM,EAAE,GAAG,CAAC,QAAQ,EAAE;KACvB,CAAC,CAAC;IAEH,IAAA,uBAAe,EAAC,KAAK,CAAC,CAAC;IAEvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AACrB,CAAC;AAVD,4BAUC"}
{"version":3,"file":"getActor.js","sourceRoot":"","sources":["../../src/outbox/getActor.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AAG/C,KAAK,UAAU,QAAQ;IAC5B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;QAC9C,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE;KAC5B,CAAC,CAAC;IAEH,IAAA,uBAAe,EAAC,KAAK,CAAC,CAAC;IAEvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AACrB,CAAC;AARD,4BAQC"}

View File

@ -1,8 +1,6 @@
/// <reference types="node" />
import { AP, Routes, Plugin, CoreLibrary } from '@activity-kit/types';
import type { IncomingMessage, ServerResponse } from 'http';
import { runSideEffects } from './runSideEffects';
import { authenticateActor } from './authenticateActor';
import { wrapInActivity } from './wrapInActivity';
import { combineAddresses } from './combineAddresses';
import { saveActivity } from './saveActivity';
@ -24,15 +22,20 @@ import { handleUndoAccept } from './sideEffects/undo/undoAccept';
import { handleUndoLike } from './sideEffects/undo/undoLike';
import { handleUndoAnnounce } from './sideEffects/undo/undoAnnounce';
export declare class OutboxPostEndpoint {
readonly core: CoreLibrary;
body: Record<string, unknown>;
url: URL;
routes: Routes;
req: IncomingMessage;
res: ServerResponse;
core: CoreLibrary;
plugins?: Plugin[];
actor: AP.Actor | null;
actor: AP.Actor;
activity: AP.Entity | null;
constructor(routes: Routes, req: IncomingMessage, res: ServerResponse, core: CoreLibrary, plugins?: Plugin[]);
protected authenticateActor: typeof authenticateActor;
constructor(core: CoreLibrary, options: {
body: Record<string, unknown>;
url: URL;
actor: AP.Actor;
routes: Routes;
plugins?: Plugin[];
});
protected getActor: typeof getActor;
protected runSideEffects: typeof runSideEffects;
protected saveActivity: typeof saveActivity;

View File

@ -2,7 +2,6 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutboxPostEndpoint = void 0;
const runSideEffects_1 = require("./runSideEffects");
const authenticateActor_1 = require("./authenticateActor");
const wrapInActivity_1 = require("./wrapInActivity");
const combineAddresses_1 = require("./combineAddresses");
const saveActivity_1 = require("./saveActivity");
@ -24,21 +23,22 @@ const undoAccept_1 = require("./sideEffects/undo/undoAccept");
const undoLike_1 = require("./sideEffects/undo/undoLike");
const undoAnnounce_1 = require("./sideEffects/undo/undoAnnounce");
class OutboxPostEndpoint {
routes;
req;
res;
core;
body;
url;
routes;
plugins;
actor = null;
actor;
activity = null;
constructor(routes, req, res, core, plugins) {
this.routes = routes;
this.req = req;
this.res = res;
constructor(core, options) {
this.core = core;
this.plugins = plugins;
this.core = core;
this.actor = options.actor;
this.body = options.body;
this.url = options.url;
this.routes = options.routes;
this.plugins = options.plugins;
}
authenticateActor = authenticateActor_1.authenticateActor;
getActor = getActor_1.getActor;
runSideEffects = runSideEffects_1.runSideEffects;
saveActivity = saveActivity_1.saveActivity;

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/outbox/index.ts"],"names":[],"mappings":";;;AAEA,qDAAkD;AAClD,2DAAwD;AACxD,qDAAkD;AAClD,yDAAsD;AACtD,iDAA8C;AAC9C,yCAAsC;AACtC,uCAAoC;AACpC,iDAAoD;AACpD,iDAAoD;AACpD,iDAAoD;AACpD,6CAAgD;AAChD,qDAAwD;AACxD,iDAAoD;AACpD,+CAAkD;AAClD,2CAA8C;AAC9C,6CAAgD;AAChD,iDAAoD;AACpD,4DAA+D;AAC/D,8DAAiE;AACjE,8DAAiE;AACjE,0DAA6D;AAC7D,kEAAqE;AAErE,MAAa,kBAAkB;IAC7B,MAAM,CAAS;IACf,GAAG,CAAkB;IACrB,GAAG,CAAiB;IACpB,IAAI,CAAc;IAClB,OAAO,CAAY;IAEnB,KAAK,GAAoB,IAAI,CAAC;IAC9B,QAAQ,GAAqB,IAAI,CAAC;IAElC,YACE,MAAc,EACd,GAAoB,EACpB,GAAmB,EACnB,IAAiB,EACjB,OAAkB;QAElB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAES,iBAAiB,GAAG,qCAAiB,CAAC;IACtC,QAAQ,GAAG,mBAAQ,CAAC;IACpB,cAAc,GAAG,+BAAc,CAAC;IAChC,YA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CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAES,QAAQ,GAAG,mBAAQ,CAAC;IACpB,cAAc,GAAG,+BAAc,CAAC;IAChC,YAAY,GAAG,2BAAY,CAAC;IAC5B,cAAc,GAAG,+BAAc,CAAC;IAChC,gBAAgB,GAAG,mCAAgB,CAAC;IACvC,OAAO,GAAG,iBAAO,CAAC;IAEf,SAAS,GAAG,eAAS,CAAC;IACtB,cAAc,GAAG,yBAAc,CAAC;IAChC,YAAY,GAAG,qBAAY,CAAC;IAC5B,WAAW,GAAG,mBAAW,CAAC;IAC1B,YAAY,GAAG,qBAAY,CAAC;IAC5B,YAAY,GAAG,qBAAY,CAAC;IAC5B,UAAU,GAAG,iBAAU,CAAC;IACxB,YAAY,GAAG,qBAAY,CAAC;IAC5B,YAAY,GAAG,qBAAY,CAAC;IAE5B,UAAU,GAAG,iBAAU,CAAC;IACxB,cAAc,GAAG,yBAAc,CAAC;IAChC,gBAAgB,GAAG,6BAAgB,CAAC;IACpC,gBAAgB,GAAG,6BAAgB,CAAC;IACpC,kBAAkB,GAAG,iCAAkB,CAAC;IACxC,eAAe,GAAG,2BAAe,CAAC;CAC7C;AAlDD,gDAkDC"}

View File

@ -1,2 +1,6 @@
import { OutboxPostEndpoint } from '.';
export declare function respond(this: OutboxPostEndpoint): Promise<void>;
export declare function respond(this: OutboxPostEndpoint): Promise<{
statusCode: number;
contentType: string;
location: string;
}>;

View File

@ -5,14 +5,13 @@ const types_1 = require("@activity-kit/types");
const utilities_1 = require("@activity-kit/utilities");
const path_to_regexp_1 = require("path-to-regexp");
async function respond() {
const body = await (0, utilities_1.parseStream)(this.req);
(0, types_1.assertIsApEntity)(body);
console.log(this.body);
(0, types_1.assertIsApEntity)(this.body);
await this.getActor();
await this.authenticateActor();
(0, types_1.assertIsApActor)(this.actor);
if ((0, types_1.isTypeOf)(body, types_1.AP.ActivityTypes)) {
(0, types_1.assertIsApActivity)(body);
this.activity = body;
if ((0, types_1.isTypeOf)(this.body, types_1.AP.ActivityTypes)) {
(0, types_1.assertIsApActivity)(this.body);
this.activity = this.body;
const [type] = (0, utilities_1.getArray)(this.activity.type);
const activityId = new URL(`${utilities_1.LOCAL_DOMAIN}${(0, path_to_regexp_1.compile)(this.routes[type.toLowerCase()], {
encode: encodeURIComponent,
@ -25,7 +24,7 @@ async function respond() {
await this.runSideEffects();
}
else {
this.activity = await this.wrapInActivity(body);
this.activity = await this.wrapInActivity(this.body);
await this.handleCreate(this.activity);
}
(0, types_1.assertIsApActivity)(this.activity);
@ -33,9 +32,11 @@ async function respond() {
await this.saveActivity();
(0, types_1.assertIsApActor)(this.actor);
this.core.broadcast(this.activity, this.actor);
this.res.statusCode = 201;
this.res.setHeader('Location', this.activity.id.toString());
this.res.end();
return {
statusCode: 201,
contentType: 'application/activity+json',
location: this.activity.id.toString(),
};
}
exports.respond = respond;
//# sourceMappingURL=respond.js.map

View File

@ -1 +1 @@
{"version":3,"file":"respond.js","sourceRoot":"","sources":["../../src/outbox/respond.ts"],"names":[],"mappings":";;;AACA,+CAO6B;AAC7B,uDAA8E;AAC9E,mDAAyC;AAIlC,KAAK,UAAU,OAAO;IAC3B,MAAM,IAAI,GAAG,MAAM,IAAA,uBAAW,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEzC,IAAA,wBAAgB,EAAC,IAAI,CAAC,CAAC;IAEvB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;IACtB,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAE/B,IAAA,uBAAe,EAAC,IA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CAAC,EAAE,CACL,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,UAAU,CAAC;QAG/B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAErD,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;KAC7B;SAAM;QAEL,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAErD,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACxC;IAED,IAAA,0BAAkB,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAElC,IAAA,oBAAY,EAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAE/B,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;IAE1B,IAAA,uBAAe,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAG5B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAE/C,OAAO;QACL,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,2BAA2B;QACxC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE;KACtC,CAAC;AACJ,CAAC;AAtDD,0BAsDC"}

View File

@ -10,12 +10,15 @@ export declare class User {
constructor(rawBody: Record<string, unknown>);
}
export declare class UserPostEndpoint {
routes: Routes;
headers: JSON;
readonly core: CoreLibrary;
body: Record<string, unknown>;
core: CoreLibrary;
routes: Routes;
plugins?: Plugin[];
constructor(routes: Routes, headers: JSON, body: Record<string, unknown>, core: CoreLibrary, plugins?: Plugin[]);
constructor(core: CoreLibrary, options: {
body: Record<string, unknown>;
routes: Routes;
plugins?: Plugin[];
});
protected createServerActor: typeof createServerActor;
protected createUserActor: typeof createUserActor;
respond(): Promise<{

View File

@ -50,17 +50,15 @@ class User {
}
exports.User = User;
class UserPostEndpoint {
routes;
headers;
body;
core;
body;
routes;
plugins;
constructor(routes, headers, body, core, plugins) {
this.routes = routes;
this.headers = headers;
this.body = body;
constructor(core, options) {
this.core = core;
this.plugins = plugins;
this.body = options.body;
this.routes = options.routes;
this.plugins = options.plugins;
}
createServerActor = createServerActor_1.createServerActor;
createUserActor = createUserActor_1.createUserActor;

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/user/index.ts"],"names":[],"mappings":";;;AAAA,uDAGiC;AACjC,2DAAwD;AACxD,uDAAoD;AAGpD,MAAa,IAAI;IACN,IAAI,CAAS;IACb,KAAK,CAAS;IACd,IAAI,CAAS;IACb,iBAAiB,CAAS;IAC1B,QAAQ,CAAS;IAE1B,YAAY,OAAgC;QAC1C,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;YACpC,MAAM;gBACJ,KAAK,EAAE,kBAAkB;gBACzB,KAAK,EAAE,MAAM;aACd,CAAC;SACH;QAED,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;YACrC,MAAM;gBACJ,KAAK,EAAE,oBAAoB;gBAC3B,KAAK,EAAE,OAAO;aACf,CAAC;SACH;QAED,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;YACpC,MAAM;gBACJ,KAAK,EAAE,mBAAmB;gBAC1B,KAAK,EAAE,MAAM;aACd,CAAC;SACH;QAED,IAAI,OAAO,OAAO,CAAC,iBAAiB,KAAK,QAAQ,EAAE;YACjD,MAAM;gBACJ,KAAK,EAAE,iCAAiC;gBACxC,KAAK,EAAE,mBAAmB;aAC3B,CAAC;SACH;QAED,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE;YACxC,MAAM;gBACJ,KAAK,EAAE,uBAAuB;gBAC9B,KAA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@activity-kit/types';
import { isType, isTypeOf } from '@activity-kit/types';
import { getId } from '@activity-kit/utilities';
const ITEMS_PER_COLLECTION_PAGE = 50;
export async function respond(
this: EntityGetEndpoint,
render: (...args: unknown[]) => Promise<string>,
render: (args: { entity: AP.Entity }) => Promise<string>,
): Promise<{
statusCode: number;
contentType?: string;
@ -32,7 +33,7 @@ export async function respond(
!isTypeOf<AP.EitherCollection>(entity, AP.CollectionTypes) &&
!isTypeOf<AP.EitherCollectionPage>(entity, AP.CollectionPageTypes)
) {
return this.handleNotFound();
return this.handleFoundEntity(entity, render);
}
assertIsApCollection(entity);

View File

@ -1,25 +0,0 @@
import { assertExists, assertIsApActor } from '@activity-kit/types';
import { getId } from '@activity-kit/utilities';
import cookie from 'cookie';
import { OutboxPostEndpoint } from '.';
export async function authenticateActor(this: OutboxPostEndpoint) {
const cookies = cookie.parse(this.req.headers.cookie ?? '');
const userId = await this.core.getUserIdByToken(cookies.__session ?? '');
try {
const authenticatedActor = await this.core.getActorByUserId(userId);
assertIsApActor(authenticatedActor);
const authenticatedActorId = getId(authenticatedActor);
assertExists(authenticatedActorId);
if (authenticatedActorId.toString() !== this.actor.id.toString()) {
throw new Error('No match.');
}
} catch (error) {
throw new Error('Not authorized.');
}
}

View File

@ -1,12 +1,9 @@
import { assertIsApActor } from '@activity-kit/types';
import { LOCAL_DOMAIN } from '@activity-kit/utilities';
import { OutboxPostEndpoint } from '.';
export async function getActor(this: OutboxPostEndpoint) {
const url = new URL(this.req.url, LOCAL_DOMAIN);
const actor = await this.core.findOne('entity', {
outbox: url.toString(),
outbox: this.url.toString(),
});
assertIsApActor(actor);

View File

@ -1,7 +1,5 @@
import { AP, Routes, Plugin, CoreLibrary } from '@activity-kit/types';
import type { IncomingMessage, ServerResponse } from 'http';
import { runSideEffects } from './runSideEffects';
import { authenticateActor } from './authenticateActor';
import { wrapInActivity } from './wrapInActivity';
import { combineAddresses } from './combineAddresses';
import { saveActivity } from './saveActivity';
@ -24,30 +22,32 @@ import { handleUndoLike } from './sideEffects/undo/undoLike';
import { handleUndoAnnounce } from './sideEffects/undo/undoAnnounce';
export class OutboxPostEndpoint {
body: Record<string, unknown>;
url: URL;
routes: Routes;
req: IncomingMessage;
res: ServerResponse;
core: CoreLibrary;
plugins?: Plugin[];
actor: AP.Actor;
actor: AP.Actor | null = null;
activity: AP.Entity | null = null;
constructor(
routes: Routes,
req: IncomingMessage,
res: ServerResponse,
core: CoreLibrary,
plugins?: Plugin[],
readonly core: CoreLibrary,
options: {
body: Record<string, unknown>;
url: URL;
actor: AP.Actor;
routes: Routes;
plugins?: Plugin[];
},
) {
this.routes = routes;
this.req = req;
this.res = res;
this.core = core;
this.plugins = plugins;
this.actor = options.actor;
this.body = options.body;
this.url = options.url;
this.routes = options.routes;
this.plugins = options.plugins;
}
protected authenticateActor = authenticateActor;
protected getActor = getActor;
protected runSideEffects = runSideEffects;
protected saveActivity = saveActivity;

View File

@ -7,25 +7,22 @@ import {
assertIsApActor,
assertIsApEntity,
} from '@activity-kit/types';
import { parseStream, getArray, LOCAL_DOMAIN } from '@activity-kit/utilities';
import { getArray, LOCAL_DOMAIN } from '@activity-kit/utilities';
import { compile } from 'path-to-regexp';
// TODO: Accept Object instead of Activity...
export async function respond(this: OutboxPostEndpoint) {
const body = await parseStream(this.req);
console.log(this.body);
assertIsApEntity(body);
assertIsApEntity(this.body);
await this.getActor();
await this.authenticateActor();
assertIsApActor(this.actor);
if (isTypeOf<AP.Activity>(body, AP.ActivityTypes)) {
assertIsApActivity(body);
if (isTypeOf<AP.Activity>(this.body, AP.ActivityTypes)) {
assertIsApActivity(this.body);
this.activity = body;
this.activity = this.body;
const [type] = getArray(this.activity.type);
@ -46,7 +43,7 @@ export async function respond(this: OutboxPostEndpoint) {
await this.runSideEffects();
} else {
// If not activity type, wrap object in a Create activity.
this.activity = await this.wrapInActivity(body);
this.activity = await this.wrapInActivity(this.body);
await this.handleCreate(this.activity);
}
@ -62,7 +59,9 @@ export async function respond(this: OutboxPostEndpoint) {
// Broadcast to Fediverse.
this.core.broadcast(this.activity, this.actor);
this.res.statusCode = 201;
this.res.setHeader('Location', this.activity.id.toString());
this.res.end();
return {
statusCode: 201,
contentType: 'application/activity+json',
location: this.activity.id.toString(),
};
}

View File

@ -58,24 +58,21 @@ export class User {
}
export class UserPostEndpoint {
routes: Routes;
headers: JSON;
body: Record<string, unknown>;
core: CoreLibrary;
routes: Routes;
plugins?: Plugin[];
constructor(
routes: Routes,
headers: JSON,
body: Record<string, unknown>,
core: CoreLibrary,
plugins?: Plugin[],
readonly core: CoreLibrary,
options: {
body: Record<string, unknown>;
routes: Routes;
plugins?: Plugin[];
},
) {
this.routes = routes;
this.headers = headers;
this.body = body;
this.core = core;
this.plugins = plugins;
this.body = options.body;
this.routes = options.routes;
this.plugins = options.plugins;
}
protected createServerActor = createServerActor;

View File

@ -2,7 +2,13 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.getArray = void 0;
const getArray = (items) => {
return items ? (Array.isArray(items) ? items : [items]) : [];
return items
? Array.isArray(items)
? items
: items instanceof URL
? []
: [items]
: [];
};
exports.getArray = getArray;
//# sourceMappingURL=getArray.js.map

View File

@ -1 +1 @@
{"version":3,"file":"getArray.js","sourceRoot":"","sources":["../src/getArray.ts"],"names":[],"mappings":";;;AAAO,MAAM,QAAQ,GAAG,CAAI,KAAiC,EAAO,EAAE;IACpE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/D,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB"}
{"version":3,"file":"getArray.js","sourceRoot":"","sources":["../src/getArray.ts"],"names":[],"mappings":";;;AAAO,MAAM,QAAQ,GAAG,CAAI,KAAiC,EAAO,EAAE;IACpE,OAAO,KAAK;QACV,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YACpB,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,KAAK,YAAY,GAAG;gBACtB,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,CAAC,KAAK,CAAC;QACX,CAAC,CAAC,EAAE,CAAC;AACT,CAAC,CAAC;AARW,QAAA,QAAQ,YAQnB"}

View File

@ -1,3 +1,9 @@
export const getArray = <T>(items: null | undefined | T | T[]): T[] => {
return items ? (Array.isArray(items) ? items : [items]) : [];
return items
? Array.isArray(items)
? items
: items instanceof URL
? []
: [items]
: [];
};