mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { apiRoute, handleZodError } from "@/api";
|
|
import type { Entity } from "@versia/federation/types";
|
|
import { describeRoute } from "hono-openapi";
|
|
import { validator } from "hono-openapi/zod";
|
|
import { z } from "zod";
|
|
import { InboxJobType, inboxQueue } from "~/classes/queues/inbox";
|
|
|
|
export default apiRoute((app) =>
|
|
app.post(
|
|
"/inbox",
|
|
describeRoute({
|
|
summary: "Instance federation inbox",
|
|
tags: ["Federation"],
|
|
responses: {
|
|
200: {
|
|
description: "Request processing initiated",
|
|
},
|
|
},
|
|
}),
|
|
validator("json", z.any(), handleZodError),
|
|
validator(
|
|
"header",
|
|
z.object({
|
|
"versia-signature": z.string().optional(),
|
|
"versia-signed-at": z.coerce.number().optional(),
|
|
"versia-signed-by": z
|
|
.string()
|
|
.url()
|
|
.or(z.string().startsWith("instance "))
|
|
.optional(),
|
|
authorization: z.string().optional(),
|
|
}),
|
|
handleZodError,
|
|
),
|
|
async (context) => {
|
|
const body: Entity = await context.req.valid("json");
|
|
|
|
await inboxQueue.add(InboxJobType.ProcessEntity, {
|
|
data: body,
|
|
headers: context.req.valid("header"),
|
|
request: {
|
|
body: await context.req.text(),
|
|
method: context.req.method,
|
|
url: context.req.url,
|
|
},
|
|
ip: context.env.ip ?? null,
|
|
});
|
|
|
|
return context.body(
|
|
"Request processing initiated.\nImplement the Instance Messaging Extension to receive any eventual feedback (errors, etc.)",
|
|
200,
|
|
);
|
|
},
|
|
),
|
|
);
|