mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
feat(federation): ✨ Implement Shared Inboxes
This commit is contained in:
parent
756f67c0f3
commit
eb466a0cc7
|
|
@ -10,6 +10,7 @@ Versia Server `0.8.0` is fully backwards compatible with `0.7.0`.
|
|||
- Added an administration UI for managing the queue.
|
||||
- Upgraded Bun to `1.1.36`.
|
||||
- Implemented support for the [Instance Messaging Extension](https://versia.pub/extensions/instance-messaging)
|
||||
- Implement [Shared Inboxes](https://versia.pub/federation#inboxes)
|
||||
- Allowed `<div>` and `<span>` tags in Markdown.
|
||||
- Added `--password` flag to the user creation CLI.
|
||||
|
||||
|
|
|
|||
73
api/inbox/index.ts
Normal file
73
api/inbox/index.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import { apiRoute, applyConfig } from "@/api";
|
||||
import { createRoute } from "@hono/zod-openapi";
|
||||
import type { Entity } from "@versia/federation/types";
|
||||
import { z } from "zod";
|
||||
import { InboxJobType, inboxQueue } from "~/worker";
|
||||
|
||||
export const meta = applyConfig({
|
||||
auth: {
|
||||
required: false,
|
||||
},
|
||||
ratelimits: {
|
||||
duration: 60,
|
||||
max: 500,
|
||||
},
|
||||
route: "/inbox",
|
||||
});
|
||||
|
||||
export const schemas = {
|
||||
header: z.object({
|
||||
"x-signature": z.string().optional(),
|
||||
"x-nonce": z.string().optional(),
|
||||
"x-signed-by": z
|
||||
.string()
|
||||
.url()
|
||||
.or(z.string().startsWith("instance "))
|
||||
.optional(),
|
||||
authorization: z.string().optional(),
|
||||
}),
|
||||
body: z.any(),
|
||||
};
|
||||
|
||||
const route = createRoute({
|
||||
method: "post",
|
||||
path: "/inbox",
|
||||
summary: "Instance federation inbox",
|
||||
request: {
|
||||
headers: schemas.header,
|
||||
body: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: schemas.body,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
description: "Request processing initiated",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default apiRoute((app) =>
|
||||
app.openapi(route, 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.newResponse(
|
||||
"Request processing initiated.\nImplement the Instance Messaging Extension to receive any eventual errors",
|
||||
200,
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
|
@ -63,6 +63,10 @@ export default apiRoute((app) =>
|
|||
},
|
||||
banner: urlToContentFormat(config.instance.banner),
|
||||
logo: urlToContentFormat(config.instance.logo),
|
||||
shared_inbox: new URL(
|
||||
"/inbox",
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
created_at: new Date(
|
||||
firstUser?.data.createdAt ?? 0,
|
||||
).toISOString(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue