1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-25 11:43:07 +01:00

fix body parser config

add user inbox for dm channels
fix missing prop in federated keys generation
This commit is contained in:
Madeline 2023-09-25 16:13:51 +00:00
parent c237247f89
commit a209a3dc29
4 changed files with 51 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import {
registerRoutes,
setupMorganLogging,
} from "@spacebar/util";
import bodyParser from "body-parser";
import { Request, Response, Router } from "express";
import { Server, ServerOptions } from "lambert-server";
import path from "path";
@ -32,7 +33,14 @@ export class FederationServer extends Server {
this.app.set("json replacer", JSONReplacer);
this.app.use(CORS);
this.app.use(BodyParser({ inflate: true, limit: "10mb" }));
this.app.use(
BodyParser({
inflate: true,
limit: "10mb",
type: "application/activity+json",
}),
);
this.app.use(bodyParser.urlencoded({ extended: true }));
const app = this.app;
const api = Router();

View File

@ -235,7 +235,7 @@ export const transformPersonToUser = async (person: AP.Person) => {
return await User.findOneOrFail({ where: { id: cachedKeys.actorId } });
}
await FederationKey.create({
const keys = await FederationKey.create({
actorId: Snowflake.generate(),
federatedId: url.toString(),
domain: url.hostname,
@ -243,7 +243,8 @@ export const transformPersonToUser = async (person: AP.Person) => {
type: ActorType.USER,
}).save();
return User.create({
return await User.create({
id: keys.actorId,
username: person.preferredUsername,
discriminator: url.hostname,
bio: new TurndownService().turndown(person.summary),

View File

@ -0,0 +1,35 @@
import { transformNoteToMessage } from "@spacebar/ap";
import { route } from "@spacebar/api";
import { Message, emitEvent } from "@spacebar/util";
import { AP } from "activitypub-core-types";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
const router = Router();
// TODO: check if the activity exists on the remote server
router.post("/", route({}), async (req: Request, res: Response) => {
const body = req.body as AP.Create;
if (body.type != "Create") throw new HTTPError("not implemented");
const object = Array.isArray(body.object) ? body.object[0] : body.object;
if (!object) return res.status(400);
if (!("type" in object) || object.type != "Note")
throw new HTTPError("must be Note");
const message = await transformNoteToMessage(object as AP.Note);
if ((await Message.count({ where: { nonce: object.id!.toString() } })) != 0)
return res.status(200);
await message.save();
await emitEvent({
event: "MESSAGE_CREATE",
channel_id: message.channel_id,
data: message.toJSON(),
});
return res.status(200);
});
export default router;

View File

@ -45,10 +45,13 @@ export class FederationKey extends BaseClassWithoutId {
// Lazy loading config to prevent circular dep
const { Config } = await import("../util/Config");
const { accountDomain, host } = Config.get().federation;
const keys = FederationKey.create({
actorId,
type,
domain: Config.get().federation.accountDomain,
federatedId: `https://${host}/federation/${type}/${actorId}`,
domain: accountDomain,
...(await generateKeyPair("rsa", {
modulusLength: 4096,
publicKeyEncoding: {