mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
feat(federation): ✨ Implement Instance Messaging Extension
This commit is contained in:
parent
4594c69808
commit
756f67c0f3
5 changed files with 67 additions and 1 deletions
48
api/messaging/index.ts
Normal file
48
api/messaging/index.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { apiRoute, applyConfig } from "@/api";
|
||||
import { createRoute } from "@hono/zod-openapi";
|
||||
import { getLogger } from "@logtape/logtape";
|
||||
import chalk from "chalk";
|
||||
import { z } from "zod";
|
||||
|
||||
export const meta = applyConfig({
|
||||
auth: {
|
||||
required: false,
|
||||
},
|
||||
ratelimits: {
|
||||
duration: 60,
|
||||
max: 500,
|
||||
},
|
||||
route: "/messaging",
|
||||
});
|
||||
|
||||
const route = createRoute({
|
||||
method: "post",
|
||||
path: "/messaging",
|
||||
summary: "Endpoint for the Instance Messaging Versia Extension.",
|
||||
description: "https://versia.pub/extensions/instance-messaging.",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"text/plain": {
|
||||
schema: z.string(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
description: "Message saved",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default apiRoute((app) =>
|
||||
app.openapi(route, async (context) => {
|
||||
const content = await context.req.text();
|
||||
|
||||
getLogger(["federation", "messaging"])
|
||||
.info`Received message via ${chalk.bold("Instance Messaging")}:\n${content}`;
|
||||
|
||||
return context.newResponse(null, 200);
|
||||
}),
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue