broken commit

This commit is contained in:
Michael Puckett 2023-07-22 09:45:01 -04:00
parent d02b0fc0fe
commit 81b26ecfb3
30 changed files with 262 additions and 330 deletions

View File

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

View File

@ -3,41 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.handleFoundEntity = void 0;
const utilities_1 = require("@activity-kit/utilities");
const utilities_2 = require("@activity-kit/utilities");
async function handleFoundEntity(render, entity, authorizedActor) {
this.res.statusCode = 200;
if (this.req.headers.accept?.includes(utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE) ||
this.req.headers.accept?.includes(utilities_1.LINKED_DATA_CONTENT_TYPE) ||
this.req.headers.accept?.includes(utilities_1.JSON_CONTENT_TYPE)) {
this.res.setHeader(utilities_1.CONTENT_TYPE_HEADER, utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE);
this.res.write(JSON.stringify((0, utilities_2.convertEntityToJson)((0, utilities_1.cleanProps)((0, utilities_1.applyContext)(entity)))));
async function handleFoundEntity(entity, render) {
if (this.returnHtml) {
return {
statusCode: 200,
body: await render({
entity,
}),
};
}
else {
this.res.setHeader(utilities_1.CONTENT_TYPE_HEADER, utilities_1.HTML_CONTENT_TYPE);
let props = {
entity,
actor: authorizedActor,
const json = (0, utilities_2.convertEntityToJson)((0, utilities_1.cleanProps)((0, utilities_1.applyContext)(entity)));
return {
statusCode: 200,
body: JSON.stringify(json),
};
if (this.plugins) {
for (const plugin of this.plugins) {
if ('getEntityPageProps' in plugin && plugin.getEntityPageProps) {
props = {
...props,
...(await plugin.getEntityPageProps.call(this, entity)),
};
}
}
}
const formattedProps = Object.fromEntries(Object.entries(props).map(([key, value]) => {
if (typeof value === 'object') {
return [key, (0, utilities_2.convertEntityToJson)(value)];
}
else {
return [key, value];
}
}));
this.res.write(await render(formattedProps));
}
this.res.end();
}
exports.handleFoundEntity = handleFoundEntity;
//# sourceMappingURL=handleFoundEntity.js.map

View File

@ -1 +1 @@
{"version":3,"file":"handleFoundEntity.js","sourceRoot":"","sources":["../../src/entity/handleFoundEntity.ts"],"names":[],"mappings":";;;AAEA,uDAQiC;AACjC,uDAA8D;AAEvD,KAAK,UAAU,iBAAiB,CAErC,MAA+C,EAC/C,MAAiB,EACjB,eAA0B;IAE1B,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;IAE1B,IACE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,wCAA4B,CAAC;QAC/D,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,oCAAwB,CAAC;QAC3D,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,6BAAiB,CAAC,EACpD;QACA,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,+BAAmB,EAAE,wCAA4B,CAAC,CAAC;QACtE,IAAI,CAAC,GAAG,CAAC,KAAK,CACZ,IAAI,CAAC,SAAS,CACZ,IAAA,+BAAmB,EAAC,IAAA,sBAAU,EAAC,IAAA,wBAAY,EAAY,MAAM,CAAC,CAAC,CAAC,CACjE,CACF,CAAC;KACH;SAAM;QACL,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,+BAAmB,EAAE,6BAAiB,CAAC,CAAC;QAE3D,IAAI,KAAK,GAAG;YACV,MAAM;YACN,KAAK,EAAE,eAAe;SACvB,CAAC;QAEF,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE;gBACjC,IAAI,oBAAoB,IAAI,MAAM,IAAI,MAAM,CA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C3B,CAAC;KACH;AACH,CAAC;AAtBD,8CAsBC"}

View File

@ -1,27 +1,23 @@
/// <reference types="node" />
/// <reference types="node" />
import { Plugin, Routes, CoreLibrary } from '@activity-kit/types';
import { CoreLibrary } from '@activity-kit/types';
import { handleFoundEntity } from './handleFoundEntity';
import { respond } from './respond';
import type { IncomingMessage, ServerResponse } from 'http';
export declare class EntityGetEndpoint {
req: IncomingMessage & {
params: Record<string, string>;
};
res: ServerResponse;
core: CoreLibrary;
plugins?: Plugin[];
routes?: Routes;
url: URL;
constructor(req: IncomingMessage & {
params: Record<string, string>;
}, res: ServerResponse, core: CoreLibrary, plugins?: Plugin[], url?: URL);
protected readonly core: CoreLibrary;
protected url: URL;
protected returnHtml: boolean;
constructor(core: CoreLibrary, options: {
url: URL;
returnHtml?: boolean;
});
protected handleFoundEntity: typeof handleFoundEntity;
protected handleBadRequest(): {
props: {};
statusCode: number;
body: string;
};
protected handleNotFound(): {
props: {};
statusCode: number;
body: string;
};
respond: typeof respond;
}

View File

@ -1,38 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityGetEndpoint = void 0;
const utilities_1 = require("@activity-kit/utilities");
const handleFoundEntity_1 = require("./handleFoundEntity");
const respond_1 = require("./respond");
class EntityGetEndpoint {
req;
res;
core;
plugins;
routes;
url;
constructor(req, res, core, plugins, url) {
this.req = req;
this.res = res;
returnHtml;
constructor(core, options) {
this.core = core;
this.plugins = plugins;
this.url = url ?? new URL(req.url, utilities_1.LOCAL_DOMAIN);
this.url = options.url;
this.returnHtml = options.returnHtml;
}
handleFoundEntity = handleFoundEntity_1.handleFoundEntity;
handleBadRequest() {
this.res.statusCode = 500;
this.res.write('Bad request');
this.res.end();
return {
props: {},
statusCode: 500,
body: JSON.stringify({
error: 'Bad request',
}),
};
}
handleNotFound() {
this.res.statusCode = 404;
this.res.write('Not found');
this.res.end();
return {
props: {},
statusCode: 404,
body: JSON.stringify({
error: 'Not found',
}),
};
}
respond = respond_1.respond;

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":";;;AACA,uDAAuD;AACvD,2DAAwD;AACxD,uCAAoC;AAGpC,MAAa,iBAAiB;IAC5B,GAAG,CAED;IACF,GAAG,CAAiB;IACpB,IAAI,CAAc;IAClB,OAAO,CAAY;IACnB,MAAM,CAAU;IAChB,GAAG,CAAM;IAET,YACE,GAEC,EACD,GAAmB,EACnB,IAAiB,EACjB,OAAkB,EAClB,GAAS;QAET,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;QACvB,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,wBAAY,CAAC,CAAC;IACnD,CAAC;IAES,iBAAiB,GAAG,qCAAiB,CAAC;IAEtC,gBAAgB;QACxB,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;QAC1B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QAEf,OAAO;YACL,KAAK,EAAE,EAAE;SACV,CAAC;IACJ,CAAC;IAES,cAAc;QACtB,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;QAC1B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QAEf,OAAO;YACL,KAAK,EAAE,EAAE;SACV,CAAC;IACJ,CAAC;IAEM,OAAO,GAAG,iBAAO,CAAC;CAC1B;AAjDD,8CAiDC"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":";;;AACA,2DAAwD;AACxD,uCAAoC;AAEpC,MAAa,iBAAiB;IAKP;IAJX,GAAG,CAAM;IACT,UAAU,CAAU;IAE9B,YACqB,IAAiB,EACpC,OAGC;QAJkB,SAAI,GAAJ,IAAI,CAAa;QAMpC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACvC,CAAC;IAES,iBAAiB,GAAG,qCAAiB,CAAC;IAEtC,gBAAgB;QACxB,OAAO;YACL,UAAU,EAAE,GAAG;YACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,KAAK,EAAE,aAAa;aACrB,CAAC;SACH,CAAC;IACJ,CAAC;IAES,cAAc;QACtB,OAAO;YACL,UAAU,EAAE,GAAG;YACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,KAAK,EAAE,WAAW;aACnB,CAAC;SACH,CAAC;IACJ,CAAC;IAEM,OAAO,GAAG,iBAAO,CAAC;CAC1B;AApCD,8CAoCC"}

View File

@ -1,4 +1,6 @@
import { EntityGetEndpoint } from '.';
export declare function respond(this: EntityGetEndpoint, render: (...args: unknown[]) => Promise<string>): Promise<void | {
props: {};
export declare function respond(this: EntityGetEndpoint, render: (...args: unknown[]) => Promise<string>): Promise<{
statusCode: number;
contentType?: string;
body: string;
}>;

View File

@ -1,45 +1,33 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.respond = void 0;
const types_1 = require("@activity-kit/types");
const types_2 = require("@activity-kit/types");
const utilities_1 = require("@activity-kit/utilities");
const cookie_1 = __importDefault(require("cookie"));
const ITEMS_PER_COLLECTION_PAGE = 50;
async function respond(render) {
const cookies = cookie_1.default.parse(this.req.headers.cookie ?? '');
const authorizedActor = await this.core.getActorByUserId(await this.core.getUserIdByToken(cookies.__session ?? ''));
const urlParts = this.url.pathname.split('/');
const pageParam = urlParts.pop();
const hasPage = this.req.params['page'] === pageParam;
if (hasPage) {
urlParts.pop();
}
const pathname = hasPage ? urlParts.join('/') : this.url.pathname;
const entity = await this.core.findEntityById(new URL(`${utilities_1.LOCAL_DOMAIN}${pathname}`));
const hasPage = this.url.href.includes('/page/');
const pageParts = this.url.href.split('/page/');
const baseUrl = hasPage ? new URL(pageParts[0]) : this.url;
const entity = await this.core.findEntityById(baseUrl);
try {
(0, types_1.assertIsApEntity)(entity);
}
catch (error) {
return this.handleNotFound();
}
this.res.setHeader('Vary', 'Accept');
if (!(0, types_2.isTypeOf)(entity, types_1.AP.CollectionTypes) &&
!(0, types_2.isTypeOf)(entity, types_1.AP.CollectionPageTypes)) {
return await this.handleFoundEntity(render, entity, authorizedActor);
return this.handleNotFound();
}
(0, types_1.assertIsApCollection)(entity);
const isOrderedCollection = (0, types_2.isType)(entity, types_1.AP.CollectionTypes.ORDERED_COLLECTION);
const totalItems = Number(entity.totalItems);
const lastPageIndex = Math.max(1, Math.ceil(totalItems / ITEMS_PER_COLLECTION_PAGE));
const currentPage = Number(pageParam) || 1;
const isOrderedCollection = (0, types_2.isType)(entity, types_1.AP.CollectionTypes.ORDERED_COLLECTION);
const getPageUrl = (page) => new URL(`${this.url.pathname === '/' ? '' : this.url.pathname}/page/${page}`, this.url.origin);
const page = pageParts[1];
const currentPage = page ? Number(page) : 1;
const firstItemIndex = (currentPage - 1) * ITEMS_PER_COLLECTION_PAGE;
const startIndex = firstItemIndex + 1;
const baseUrl = new URL(pathname, new URL(utilities_1.LOCAL_DOMAIN));
const getPageUrl = (page) => new URL(`${pathname === '/' ? '' : pathname}/page/${page}`, new URL(utilities_1.LOCAL_DOMAIN));
if (!hasPage) {
(0, types_1.assertIsApCollection)(entity);
delete entity.orderedItems;
@ -49,7 +37,7 @@ async function respond(render) {
first: getPageUrl(1),
last: getPageUrl(lastPageIndex),
};
return await this.handleFoundEntity(render, collectionEntity, authorizedActor);
return this.handleFoundEntity(collectionEntity, render);
}
const expandedCollection = await this.core.expandCollection(entity);
const expandedItems = (() => {
@ -105,14 +93,14 @@ async function respond(render) {
orderedItems: items,
startIndex,
};
return await this.handleFoundEntity(render, orderedCollectionPageEntity, authorizedActor);
return this.handleFoundEntity(orderedCollectionPageEntity, render);
}
const collectionPageEntity = {
...collectionPage,
type: types_1.AP.CollectionPageTypes.COLLECTION_PAGE,
items: items,
};
return await this.handleFoundEntity(render, collectionPageEntity, authorizedActor);
return this.handleFoundEntity(collectionPageEntity, render);
}
exports.respond = respond;
//# sourceMappingURL=respond.js.map

View File

@ -1 +1 @@
{"version":3,"file":"respond.js","sourceRoot":"","sources":["../../src/entity/respond.ts"],"names":[],"mappings":";;;;;;AACA,+CAK6B;AAC7B,+CAAuD;AACvD,uDAAuD;AACvD,oDAA4B;AAE5B,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE9B,KAAK,UAAU,OAAO,CAE3B,MAA+C;IAE/C,MAAM,OAAO,GAAG,gBAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAE5D,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,gBAAgB,CACtD,MAAM,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAC1D,CAAC;IAKF,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC;IACtD,IAAI,OAAO,EAAE;QACX,QAAQ,CAAC,GAAG,EAAE,CAAC;KAChB;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CA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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

@ -7,6 +7,7 @@ import { authenticateActor } from './authenticateActor';
import { parseBody } from './parseBody';
import { cleanup } from './cleanup';
import { saveActivity } from './saveActivity';
import { AnyTransitiveActivityType } from '@activity-kit/types/lib/activitypub';
export declare class UploadMediaPostEndpoint {
routes: Routes;
req: IncomingMessage;
@ -14,7 +15,7 @@ export declare class UploadMediaPostEndpoint {
core: CoreLibrary;
plugins?: Plugin[];
actor: AP.Actor | null;
activity: AP.TransitiveActivity | null;
activity: AP.TransitiveActivity<AnyTransitiveActivityType> | null;
file: File | null;
protected getActor: typeof getActor;
protected authenticateActor: typeof authenticateActor;

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/uploadMedia/index.ts"],"names":[],"mappings":";;;AAAA,+CAM6B;AAG7B,yCAAsC;AACtC,2DAAwD;AACxD,2CAAwC;AACxC,uCAAoC;AACpC,iDAA8C;AAE9C,MAAa,uBAAuB;IAClC,MAAM,CAAS;IACf,GAAG,CAAkB;IACrB,GAAG,CAAiB;IACpB,IAAI,CAAc;IAClB,OAAO,CAAY;IAEnB,KAAK,GAAoB,IAAI,CAAC;IAC9B,QAAQ,GAAiC,IAAI,CAAC;IAC9C,IAAI,GAAgB,IAAI,CAAC;IAEf,QAAQ,GAAG,mBAAQ,CAAC;IACpB,iBAAiB,GAAG,qCAAiB,CAAC;IACtC,SAAS,GAAG,qBAAS,CAAC;IACtB,OAAO,GAAG,iBAAO,CAAC;IAClB,YAAY,GAAG,2BAAY,CAAC;IAEtC,YACE,MAAc,EACd,GAAoB,EACpB,G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,GAAG,GAAG,CAAC;YAC/B,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;YACrB,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;YAE1B,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC5D,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;SAChB;QAAC,OAAO,KAAc,EAAE;YACvB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACnB,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;SAChB;IACH,CAAC;CACF;AApDD,0DAoDC"}

View File

@ -5,6 +5,7 @@ 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 saveActivity() {
(0, types_1.assertIsApEntity)(this.activity);
(0, types_1.assertIsApTransitiveActivity)(this.activity);
(0, types_1.assertIsApExtendedObject)(this.activity.object);
const publishedDate = new Date();

View File

@ -1 +1 @@
{"version":3,"file":"saveActivity.js","sourceRoot":"","sources":["../../src/uploadMedia/saveActivity.ts"],"names":[],"mappings":";;;AAAA,+CAI6B;AAC7B,uDAA4E;AAE5E,mDAAyC;AAElC,KAAK,UAAU,YAAY;IAChC,IAAA,oCAA4B,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAA,gCAAwB,EAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE/C,MAAM,aAAa,GAAG,IAAI,IAAI,EAAE,CAAC;IAEjC,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,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IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAA,iBAAK,EAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;KACzE,CAAC,CAAC;AACL,CAAC;AAnFD,oCAmFC"}

View File

@ -1,10 +1,7 @@
/// <reference types="node" />
import { createServerActor } from './createServerActor';
import { createUserActor } from './createUserActor';
import type { IncomingMessage, ServerResponse } from 'http';
import { CoreLibrary, Plugin, Routes } from '@activity-kit/types';
export declare class User {
readonly uid: string;
readonly type: string;
readonly email: string;
readonly name: string;
@ -14,12 +11,15 @@ export declare class User {
}
export declare class UserPostEndpoint {
routes: Routes;
req: IncomingMessage;
res: ServerResponse;
headers: JSON;
body: Record<string, unknown>;
core: CoreLibrary;
plugins?: Plugin[];
constructor(routes: Routes, req: IncomingMessage, res: ServerResponse, core: CoreLibrary, plugins?: Plugin[]);
constructor(routes: Routes, headers: JSON, body: Record<string, unknown>, core: CoreLibrary, plugins?: Plugin[]);
protected createServerActor: typeof createServerActor;
protected createUserActor: typeof createUserActor;
respond(): Promise<void>;
respond(): Promise<{
statusCode: number;
body: string;
}>;
}

View File

@ -5,19 +5,12 @@ const utilities_1 = require("@activity-kit/utilities");
const createServerActor_1 = require("./createServerActor");
const createUserActor_1 = require("./createUserActor");
class User {
uid;
type;
email;
name;
preferredUsername;
password;
constructor(rawBody) {
if (typeof rawBody.uid !== 'string') {
throw {
error: 'No uid provided',
field: 'uid',
};
}
if (typeof rawBody.type !== 'string') {
throw {
error: 'No type provided',
@ -48,7 +41,6 @@ class User {
field: 'password',
};
}
this.uid = rawBody.uid;
this.type = rawBody.type;
this.email = rawBody.email;
this.name = rawBody.name;
@ -59,43 +51,47 @@ class User {
exports.User = User;
class UserPostEndpoint {
routes;
req;
res;
headers;
body;
core;
plugins;
constructor(routes, req, res, core, plugins) {
constructor(routes, headers, body, core, plugins) {
this.routes = routes;
this.req = req;
this.res = res;
this.headers = headers;
this.body = body;
this.core = core;
this.plugins = plugins;
}
createServerActor = createServerActor_1.createServerActor;
createUserActor = createUserActor_1.createUserActor;
async respond() {
const body = JSON.parse(await (0, utilities_1.streamToString)(this.req));
const user = await new Promise((resolve) => {
resolve(new User(body));
const result = await new Promise((resolve) => {
resolve(new User(this.body));
}).catch((error) => {
this.res.statusCode = 300;
this.res.write(JSON.stringify(error));
this.res.end();
console.log(error);
return new Error(`${error}`);
});
if (!user) {
return;
if (result instanceof Error) {
return {
statusCode: 500,
body: JSON.stringify({
message: 'Internal server error.',
}),
};
}
const user = result;
const isUsernameTaken = !!(await this.core.findOne('entity', {
preferredUsername: user.preferredUsername,
}));
if (isUsernameTaken ||
utilities_1.RESERVED_USERNAMES.includes(user.preferredUsername)) {
this.res.statusCode = 409;
this.res.write(JSON.stringify({
error: 'Username taken.',
field: 'username',
}));
this.res.end();
return;
return {
statusCode: 409,
body: JSON.stringify({
error: 'Username taken.',
field: 'username',
}),
};
}
try {
const { uid, token } = await this.core.createUser({
@ -110,18 +106,20 @@ class UserPostEndpoint {
await this.createServerActor();
}
await this.createUserActor(user, uid);
this.res.statusCode = 200;
this.res.write(JSON.stringify({
token,
}));
this.res.end();
return {
statusCode: 201,
body: JSON.stringify({
token,
}),
};
}
catch (error) {
this.res.statusCode = 300;
this.res.write(JSON.stringify({
error: error.toString(),
}));
this.res.end();
return {
statusCode: 300,
body: JSON.stringify({
error: error.toString(),
}),
};
}
}
}

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/user/index.ts"],"names":[],"mappings":";;;AAAA,uDAIiC;AACjC,2DAAwD;AACxD,uDAAoD;AAIpD,MAAa,IAAI;IACN,GAAG,CAAS;IACZ,IAAI,CAAS;IACb,KAAK,CAAS;IACd,IAAI,CAAS;IACb,iBAAiB,CAAS;IAC1B,QAAQ,CAAS;IAE1B,YAAY,OAAgC;QAC1C,IAAI,O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it/types';
import {
ACTIVITYSTREAMS_CONTENT_TYPE,
CONTENT_TYPE_HEADER,
HTML_CONTENT_TYPE,
JSON_CONTENT_TYPE,
LINKED_DATA_CONTENT_TYPE,
applyContext,
cleanProps,
} from '@activity-kit/utilities';
import { applyContext, cleanProps } from '@activity-kit/utilities';
import { convertEntityToJson } from '@activity-kit/utilities';
export async function handleFoundEntity(
this: EntityGetEndpoint,
render: (...args: unknown[]) => Promise<string>,
entity: AP.Entity,
authorizedActor?: AP.Actor,
render: (...args: unknown[]) => Promise<string>,
) {
this.res.statusCode = 200;
if (
this.req.headers.accept?.includes(ACTIVITYSTREAMS_CONTENT_TYPE) ||
this.req.headers.accept?.includes(LINKED_DATA_CONTENT_TYPE) ||
this.req.headers.accept?.includes(JSON_CONTENT_TYPE)
) {
this.res.setHeader(CONTENT_TYPE_HEADER, ACTIVITYSTREAMS_CONTENT_TYPE);
this.res.write(
JSON.stringify(
convertEntityToJson(cleanProps(applyContext<AP.Entity>(entity))),
),
);
} else {
this.res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE);
let props = {
entity,
actor: authorizedActor,
};
if (this.plugins) {
for (const plugin of this.plugins) {
if ('getEntityPageProps' in plugin && plugin.getEntityPageProps) {
props = {
...props,
...(await plugin.getEntityPageProps.call(this, entity)),
};
}
}
}
const formattedProps = Object.fromEntries(
Object.entries(props).map(([key, value]) => {
if (typeof value === 'object') {
return [key, convertEntityToJson(value)];
} else {
return [key, value];
}
if (this.returnHtml) {
return {
statusCode: 200,
body: await render({
entity,
}),
};
} else {
const json = convertEntityToJson(
cleanProps(applyContext<AP.Entity>(entity)),
);
this.res.write(await render(formattedProps));
return {
statusCode: 200,
body: JSON.stringify(json),
};
}
this.res.end();
}

View File

@ -1,54 +1,39 @@
import { Plugin, Routes, CoreLibrary } from '@activity-kit/types';
import { LOCAL_DOMAIN } from '@activity-kit/utilities';
import { CoreLibrary } from '@activity-kit/types';
import { handleFoundEntity } from './handleFoundEntity';
import { respond } from './respond';
import type { IncomingMessage, ServerResponse } from 'http';
export class EntityGetEndpoint {
req: IncomingMessage & {
params: Record<string, string>;
};
res: ServerResponse;
core: CoreLibrary;
plugins?: Plugin[];
routes?: Routes;
url: URL;
protected url: URL;
protected returnHtml: boolean;
constructor(
req: IncomingMessage & {
params: Record<string, string>;
protected readonly core: CoreLibrary,
options: {
url: URL;
returnHtml?: boolean;
},
res: ServerResponse,
core: CoreLibrary,
plugins?: Plugin[],
url?: URL,
) {
this.req = req;
this.res = res;
this.core = core;
this.plugins = plugins;
this.url = url ?? new URL(req.url, LOCAL_DOMAIN);
this.url = options.url;
this.returnHtml = options.returnHtml;
}
protected handleFoundEntity = handleFoundEntity;
protected handleBadRequest() {
this.res.statusCode = 500;
this.res.write('Bad request');
this.res.end();
return {
props: {},
statusCode: 500,
body: JSON.stringify({
error: 'Bad request',
}),
};
}
protected handleNotFound() {
this.res.statusCode = 404;
this.res.write('Not found');
this.res.end();
return {
props: {},
statusCode: 404,
body: JSON.stringify({
error: 'Not found',
}),
};
}

View File

@ -6,35 +6,21 @@ import {
assertIsArray,
} from '@activity-kit/types';
import { isType, isTypeOf } from '@activity-kit/types';
import { LOCAL_DOMAIN } from '@activity-kit/utilities';
import cookie from 'cookie';
const ITEMS_PER_COLLECTION_PAGE = 50;
export async function respond(
this: EntityGetEndpoint,
render: (...args: unknown[]) => Promise<string>,
) {
const cookies = cookie.parse(this.req.headers.cookie ?? '');
const authorizedActor = await this.core.getActorByUserId(
await this.core.getUserIdByToken(cookies.__session ?? ''),
);
// TODO authorize entity posts by actor.
// Remove CollectionPage URL /page/:page param
const urlParts = this.url.pathname.split('/');
const pageParam = urlParts.pop();
const hasPage = this.req.params['page'] === pageParam;
if (hasPage) {
urlParts.pop();
}
const pathname = hasPage ? urlParts.join('/') : this.url.pathname;
const entity = await this.core.findEntityById(
new URL(`${LOCAL_DOMAIN}${pathname}`),
);
): Promise<{
statusCode: number;
contentType?: string;
body: string;
}> {
const hasPage = this.url.href.includes('/page/');
const pageParts = this.url.href.split('/page/');
const baseUrl = hasPage ? new URL(pageParts[0]) : this.url;
const entity = await this.core.findEntityById(baseUrl);
try {
assertIsApEntity(entity);
@ -42,40 +28,40 @@ export async function respond(
return this.handleNotFound();
}
this.res.setHeader('Vary', 'Accept');
if (
!isTypeOf<AP.EitherCollection>(entity, AP.CollectionTypes) &&
!isTypeOf<AP.EitherCollectionPage>(entity, AP.CollectionPageTypes)
) {
return await this.handleFoundEntity(render, entity, authorizedActor);
return this.handleNotFound();
}
assertIsApCollection(entity);
const totalItems = Number(entity.totalItems);
const lastPageIndex = Math.max(
1,
Math.ceil(totalItems / ITEMS_PER_COLLECTION_PAGE),
);
const isOrderedCollection = isType<AP.OrderedCollection>(
entity,
AP.CollectionTypes.ORDERED_COLLECTION,
);
const totalItems = Number(entity.totalItems);
const lastPageIndex = Math.max(
1,
Math.ceil(totalItems / ITEMS_PER_COLLECTION_PAGE),
);
const currentPage = Number(pageParam) || 1;
const firstItemIndex = (currentPage - 1) * ITEMS_PER_COLLECTION_PAGE;
const startIndex = firstItemIndex + 1;
const baseUrl = new URL(pathname, new URL(LOCAL_DOMAIN));
const getPageUrl = (page: number) =>
new URL(
`${pathname === '/' ? '' : pathname}/page/${page}`,
new URL(LOCAL_DOMAIN),
`${this.url.pathname === '/' ? '' : this.url.pathname}/page/${page}`,
this.url.origin,
);
// Treat as a Collection.
const page = pageParts[1];
const currentPage = page ? Number(page) : 1;
const firstItemIndex = (currentPage - 1) * ITEMS_PER_COLLECTION_PAGE;
const startIndex = firstItemIndex + 1;
if (!hasPage) {
assertIsApCollection(entity);
@ -88,11 +74,7 @@ export async function respond(
last: getPageUrl(lastPageIndex),
};
return await this.handleFoundEntity(
render,
collectionEntity,
authorizedActor,
);
return this.handleFoundEntity(collectionEntity, render);
}
// Treat as CollectionPage.
@ -173,11 +155,7 @@ export async function respond(
startIndex,
};
return await this.handleFoundEntity(
render,
orderedCollectionPageEntity,
authorizedActor,
);
return this.handleFoundEntity(orderedCollectionPageEntity, render);
}
const collectionPageEntity: AP.CollectionPage = {
@ -186,9 +164,5 @@ export async function respond(
items: items,
};
return await this.handleFoundEntity(
render,
collectionPageEntity,
authorizedActor,
);
return this.handleFoundEntity(collectionPageEntity, render);
}

View File

@ -12,6 +12,7 @@ import { authenticateActor } from './authenticateActor';
import { parseBody } from './parseBody';
import { cleanup } from './cleanup';
import { saveActivity } from './saveActivity';
import { AnyTransitiveActivityType } from '@activity-kit/types/lib/activitypub';
export class UploadMediaPostEndpoint {
routes: Routes;
@ -21,7 +22,7 @@ export class UploadMediaPostEndpoint {
plugins?: Plugin[];
actor: AP.Actor | null = null;
activity: AP.TransitiveActivity | null = null;
activity: AP.TransitiveActivity<AnyTransitiveActivityType> | null = null;
file: File | null = null;
protected getActor = getActor;

View File

@ -1,5 +1,6 @@
import {
AP,
assertIsApEntity,
assertIsApExtendedObject,
assertIsApTransitiveActivity,
} from '@activity-kit/types';
@ -8,6 +9,7 @@ import { UploadMediaPostEndpoint } from '.';
import { compile } from 'path-to-regexp';
export async function saveActivity(this: UploadMediaPostEndpoint) {
assertIsApEntity(this.activity);
assertIsApTransitiveActivity(this.activity);
assertIsApExtendedObject(this.activity.object);

View File

@ -1,15 +1,12 @@
import {
RESERVED_USERNAMES,
SERVER_ACTOR_USERNAME,
streamToString,
} from '@activity-kit/utilities';
import { createServerActor } from './createServerActor';
import { createUserActor } from './createUserActor';
import type { IncomingMessage, ServerResponse } from 'http';
import { CoreLibrary, Plugin, Routes } from '@activity-kit/types';
export class User {
readonly uid: string;
readonly type: string;
readonly email: string;
readonly name: string;
@ -17,13 +14,6 @@ export class User {
readonly password: string;
constructor(rawBody: Record<string, unknown>) {
if (typeof rawBody.uid !== 'string') {
throw {
error: 'No uid provided',
field: 'uid',
};
}
if (typeof rawBody.type !== 'string') {
throw {
error: 'No type provided',
@ -59,7 +49,6 @@ export class User {
};
}
this.uid = rawBody.uid;
this.type = rawBody.type;
this.email = rawBody.email;
this.name = rawBody.name;
@ -70,21 +59,21 @@ export class User {
export class UserPostEndpoint {
routes: Routes;
req: IncomingMessage;
res: ServerResponse;
headers: JSON;
body: Record<string, unknown>;
core: CoreLibrary;
plugins?: Plugin[];
constructor(
routes: Routes,
req: IncomingMessage,
res: ServerResponse,
headers: JSON,
body: Record<string, unknown>,
core: CoreLibrary,
plugins?: Plugin[],
) {
this.routes = routes;
this.req = req;
this.res = res;
this.headers = headers;
this.body = body;
this.core = core;
this.plugins = plugins;
}
@ -93,22 +82,24 @@ export class UserPostEndpoint {
protected createUserActor = createUserActor;
public async respond() {
const body: Record<string, unknown> = JSON.parse(
await streamToString(this.req),
);
const user = await new Promise<User>((resolve) => {
resolve(new User(body));
}).catch((error: Record<string, string>) => {
this.res.statusCode = 300;
this.res.write(JSON.stringify(error));
this.res.end();
const result = await new Promise<User>((resolve) => {
resolve(new User(this.body));
}).catch((error: unknown) => {
console.log(error);
return new Error(`${error}`);
});
if (!user) {
return;
if (result instanceof Error) {
return {
statusCode: 500,
body: JSON.stringify({
message: 'Internal server error.',
}),
};
}
const user = result;
const isUsernameTaken = !!(await this.core.findOne('entity', {
preferredUsername: user.preferredUsername,
}));
@ -117,15 +108,13 @@ export class UserPostEndpoint {
isUsernameTaken ||
RESERVED_USERNAMES.includes(user.preferredUsername)
) {
this.res.statusCode = 409;
this.res.write(
JSON.stringify({
return {
statusCode: 409,
body: JSON.stringify({
error: 'Username taken.',
field: 'username',
}),
);
this.res.end();
return;
};
}
try {
@ -145,21 +134,19 @@ export class UserPostEndpoint {
await this.createUserActor(user, uid);
this.res.statusCode = 200;
this.res.write(
JSON.stringify({
return {
statusCode: 201,
body: JSON.stringify({
token,
}),
);
this.res.end();
};
} catch (error) {
this.res.statusCode = 300;
this.res.write(
JSON.stringify({
return {
statusCode: 300,
body: JSON.stringify({
error: error.toString(),
}),
);
this.res.end();
};
}
}
}

2
packages/utilities/lib/getEntity.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
import { AP } from '@activity-kit/types';
export declare const getEntity: (entity: undefined | null | AP.EntityReference | AP.EntityReference[]) => AP.Entity | null;

View File

@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEntity = void 0;
const getEntity = (entity) => {
if (!entity) {
return null;
}
if (entity instanceof URL) {
return null;
}
if (Array.isArray(entity)) {
if (entity.length === 1) {
if (entity[0] instanceof URL) {
return null;
}
return entity[0];
}
return null;
}
return entity;
};
exports.getEntity = getEntity;
//# sourceMappingURL=getEntity.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"getEntity.js","sourceRoot":"","sources":["../src/getEntity.ts"],"names":[],"mappings":";;;AAEO,MAAM,SAAS,GAAG,CACvB,MAAoE,EAClD,EAAE;IACpB,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,IAAI,CAAC;KACb;IAED,IAAI,MAAM,YAAY,GAAG,EAAE;QACzB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YACvB,IAAI,MAAM,CAAC,CAAC,CAAC,YAAY,GAAG,EAAE;gBAC5B,OAAO,IAAI,CAAC;aACb;YAED,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;SAClB;QAED,OAAO,IAAI,CAAC;KACb;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAxBW,QAAA,SAAS,aAwBpB"}

View File

@ -7,6 +7,7 @@ export { convertJsonToEntity } from './convertJsonToEntity';
export { convertEntityToJson } from './convertEntityToJson';
export { getCollectionNameByUrl } from './getCollectionNameByUrl';
export { getId } from './getId';
export { getEntity } from './getEntity';
export { parseStream } from './parseStream';
export { streamToString } from './streamToString';
export { deduplicateUrls } from './deduplicateUrls';

View File

@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getArray = exports.isLocal = exports.deduplicateUrls = exports.streamToString = exports.parseStream = exports.getId = exports.getCollectionNameByUrl = exports.convertEntityToJson = exports.convertJsonToEntity = exports.convertJsonLdToEntity = exports.compressEntity = exports.cleanProps = exports.applyContext = void 0;
exports.getArray = exports.isLocal = exports.deduplicateUrls = exports.streamToString = exports.parseStream = exports.getEntity = exports.getId = exports.getCollectionNameByUrl = exports.convertEntityToJson = exports.convertJsonToEntity = exports.convertJsonLdToEntity = exports.compressEntity = exports.cleanProps = exports.applyContext = void 0;
__exportStar(require("./globals"), exports);
var applyContext_1 = require("./applyContext");
Object.defineProperty(exports, "applyContext", { enumerable: true, get: function () { return applyContext_1.applyContext; } });
@ -32,6 +32,8 @@ var getCollectionNameByUrl_1 = require("./getCollectionNameByUrl");
Object.defineProperty(exports, "getCollectionNameByUrl", { enumerable: true, get: function () { return getCollectionNameByUrl_1.getCollectionNameByUrl; } });
var getId_1 = require("./getId");
Object.defineProperty(exports, "getId", { enumerable: true, get: function () { return getId_1.getId; } });
var getEntity_1 = require("./getEntity");
Object.defineProperty(exports, "getEntity", { enumerable: true, get: function () { return getEntity_1.getEntity; } });
var parseStream_1 = require("./parseStream");
Object.defineProperty(exports, "parseStream", { enumerable: true, get: function () { return parseStream_1.parseStream; } });
var streamToString_1 = require("./streamToString");

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,iEAAgE;AAAvD,8HAAA,qBAAqB,OAAA;AAC9B,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAC5B,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAC5B,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,iEAAgE;AAAvD,8HAAA,qBAAqB,OAAA;AAC9B,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAC5B,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAC5B,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA"}

View File

@ -0,0 +1,27 @@
import { AP } from '@activity-kit/types';
export const getEntity = (
entity: undefined | null | AP.EntityReference | AP.EntityReference[],
): AP.Entity | null => {
if (!entity) {
return null;
}
if (entity instanceof URL) {
return null;
}
if (Array.isArray(entity)) {
if (entity.length === 1) {
if (entity[0] instanceof URL) {
return null;
}
return entity[0];
}
return null;
}
return entity;
};

View File

@ -7,6 +7,7 @@ export { convertJsonToEntity } from './convertJsonToEntity';
export { convertEntityToJson } from './convertEntityToJson';
export { getCollectionNameByUrl } from './getCollectionNameByUrl';
export { getId } from './getId';
export { getEntity } from './getEntity';
export { parseStream } from './parseStream';
export { streamToString } from './streamToString';
export { deduplicateUrls } from './deduplicateUrls';