diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-09-26 13:47:44 +0000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-09-26 13:47:44 +0000 |
commit | 0bc905a222eed993f65e41700ddedeec7f0eda63 (patch) | |
tree | e2e6a811c47d63ba19b0dea1bbb7791b06f87f01 /src/activitypub/routes/channels | |
parent | various things (diff) | |
download | server-0bc905a222eed993f65e41700ddedeec7f0eda63.tar.xz |
switch to own activitypub types library
Diffstat (limited to 'src/activitypub/routes/channels')
-rw-r--r-- | src/activitypub/routes/channels/#channel_id/inbox.ts | 27 | ||||
-rw-r--r-- | src/activitypub/routes/channels/#channel_id/outbox.ts | 6 |
2 files changed, 6 insertions, 27 deletions
diff --git a/src/activitypub/routes/channels/#channel_id/inbox.ts b/src/activitypub/routes/channels/#channel_id/inbox.ts index 5414ab48..896522b7 100644 --- a/src/activitypub/routes/channels/#channel_id/inbox.ts +++ b/src/activitypub/routes/channels/#channel_id/inbox.ts @@ -1,35 +1,14 @@ import { transformNoteToMessage } from "@spacebar/ap"; import { route } from "@spacebar/api"; import { Message, emitEvent } from "@spacebar/util"; -import { AP } from "activitypub-core-types"; +import { APCreate, APNote } from "activitypub-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); + // TODO: check if the activity exists on the remote server + // TODO: refactor }); export default router; diff --git a/src/activitypub/routes/channels/#channel_id/outbox.ts b/src/activitypub/routes/channels/#channel_id/outbox.ts index 4eedb210..c6388fda 100644 --- a/src/activitypub/routes/channels/#channel_id/outbox.ts +++ b/src/activitypub/routes/channels/#channel_id/outbox.ts @@ -4,7 +4,7 @@ import { } from "@spacebar/ap"; import { route } from "@spacebar/api"; import { Config, Message, Snowflake } from "@spacebar/util"; -import { AP } from "activitypub-core-types"; +import { APAnnounce } from "activitypub-types"; import { Request, Response, Router } from "express"; import { FindManyOptions, FindOperator, LessThan, MoreThan } from "typeorm"; const router = Router(); @@ -19,9 +19,9 @@ router.get("/", route({}), async (req: Request, res: Response) => { page: page != undefined, min_id: min_id?.toString(), max_id: max_id?.toString(), - id: new URL(`https://${host}/federation/channels/${channel_id}/outbox`), + id: `https://${host}/federation/channels/${channel_id}/outbox`, getTotalElements: () => Message.count({ where: { channel_id } }), - getElements: async (before, after): Promise<AP.Announce[]> => { + getElements: async (before, after): Promise<APAnnounce[]> => { const query: FindManyOptions<Message> & { where: { id?: FindOperator<string> | FindOperator<string>[] }; } = { |