2025-06-15 23:50:34 +02:00
|
|
|
import { apiRoute, handleZodError } from "@versia-server/kit/api";
|
2025-06-29 22:56:52 +02:00
|
|
|
import { InboxJobType, inboxQueue } from "@versia-server/kit/queues/inbox";
|
2025-07-07 03:42:35 +02:00
|
|
|
import { describeRoute, validator } from "hono-openapi";
|
|
|
|
|
import { z } from "zod/v4";
|
2024-11-25 17:05:53 +01:00
|
|
|
|
2025-03-29 03:30:06 +01:00
|
|
|
export default apiRoute((app) =>
|
|
|
|
|
app.post(
|
|
|
|
|
"/inbox",
|
|
|
|
|
describeRoute({
|
|
|
|
|
summary: "Instance federation inbox",
|
|
|
|
|
tags: ["Federation"],
|
|
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "Request processing initiated",
|
2024-11-25 17:05:53 +01:00
|
|
|
},
|
|
|
|
|
},
|
2025-03-29 03:30:06 +01:00
|
|
|
}),
|
|
|
|
|
validator(
|
|
|
|
|
"header",
|
|
|
|
|
z.object({
|
|
|
|
|
"versia-signature": z.string().optional(),
|
|
|
|
|
"versia-signed-at": z.coerce.number().optional(),
|
|
|
|
|
"versia-signed-by": z
|
|
|
|
|
.url()
|
|
|
|
|
.or(z.string().startsWith("instance "))
|
|
|
|
|
.optional(),
|
|
|
|
|
authorization: z.string().optional(),
|
|
|
|
|
}),
|
|
|
|
|
handleZodError,
|
|
|
|
|
),
|
|
|
|
|
async (context) => {
|
2025-04-19 13:16:53 +02:00
|
|
|
const body = await context.req.json();
|
2025-04-18 14:58:04 +02:00
|
|
|
const {
|
|
|
|
|
"versia-signature": signature,
|
|
|
|
|
"versia-signed-at": signedAt,
|
|
|
|
|
"versia-signed-by": signedBy,
|
|
|
|
|
authorization,
|
|
|
|
|
} = context.req.valid("header");
|
2024-11-25 17:05:53 +01:00
|
|
|
|
2025-03-29 03:30:06 +01:00
|
|
|
await inboxQueue.add(InboxJobType.ProcessEntity, {
|
|
|
|
|
data: body,
|
2025-04-18 14:58:04 +02:00
|
|
|
headers: {
|
|
|
|
|
"versia-signature": signature,
|
|
|
|
|
"versia-signed-at": signedAt,
|
|
|
|
|
"versia-signed-by": signedBy,
|
|
|
|
|
authorization,
|
|
|
|
|
},
|
2025-03-29 03:30:06 +01:00
|
|
|
request: {
|
|
|
|
|
body: await context.req.text(),
|
|
|
|
|
method: context.req.method,
|
|
|
|
|
url: context.req.url,
|
|
|
|
|
},
|
2025-04-19 13:16:53 +02:00
|
|
|
ip: context.env?.ip ?? null,
|
2025-03-29 03:30:06 +01:00
|
|
|
});
|
2024-11-25 17:05:53 +01:00
|
|
|
|
2025-03-29 03:30:06 +01:00
|
|
|
return context.body(
|
|
|
|
|
"Request processing initiated.\nImplement the Instance Messaging Extension to receive any eventual feedback (errors, etc.)",
|
|
|
|
|
200,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2024-11-25 17:05:53 +01:00
|
|
|
);
|