mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
refactor(api): ♻️ Move from @hono/zod-openapi to hono-openapi
hono-openapi is easier to work with and generates better OpenAPI definitions
This commit is contained in:
parent
0576aff972
commit
58342e86e1
240 changed files with 9494 additions and 9575 deletions
|
|
@ -1,76 +1,80 @@
|
|||
import { apiRoute } from "@/api";
|
||||
import { createRoute, z } from "@hono/zod-openapi";
|
||||
import { Note, User } from "@versia/kit/db";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
import { config } from "~/config.ts";
|
||||
import manifest from "~/package.json";
|
||||
|
||||
const route = createRoute({
|
||||
method: "get",
|
||||
path: "/.well-known/nodeinfo/2.0",
|
||||
summary: "Well-known nodeinfo 2.0",
|
||||
tags: ["Federation"],
|
||||
responses: {
|
||||
200: {
|
||||
description: "Nodeinfo 2.0",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
version: z.string(),
|
||||
software: z.object({
|
||||
name: z.string(),
|
||||
version: z.string(),
|
||||
}),
|
||||
protocols: z.array(z.string()),
|
||||
services: z.object({
|
||||
outbound: z.array(z.string()),
|
||||
inbound: z.array(z.string()),
|
||||
}),
|
||||
usage: z.object({
|
||||
users: z.object({
|
||||
total: z.number(),
|
||||
activeMonth: z.number(),
|
||||
activeHalfyear: z.number(),
|
||||
}),
|
||||
localPosts: z.number(),
|
||||
}),
|
||||
openRegistrations: z.boolean(),
|
||||
metadata: z.object({}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default apiRoute((app) =>
|
||||
app.openapi(route, async (context) => {
|
||||
const userCount = await User.getCount();
|
||||
const userActiveMonth = await User.getActiveInPeriod(
|
||||
1000 * 60 * 60 * 24 * 30,
|
||||
);
|
||||
const userActiveHalfyear = await User.getActiveInPeriod(
|
||||
1000 * 60 * 60 * 24 * 30 * 6,
|
||||
);
|
||||
const noteCount = await Note.getCount();
|
||||
|
||||
return context.json({
|
||||
version: "2.0",
|
||||
software: { name: "versia-server", version: manifest.version },
|
||||
protocols: ["versia"],
|
||||
services: { outbound: [], inbound: [] },
|
||||
usage: {
|
||||
users: {
|
||||
total: userCount,
|
||||
activeMonth: userActiveMonth,
|
||||
activeHalfyear: userActiveHalfyear,
|
||||
app.get(
|
||||
"/.well-known/nodeinfo/2.0",
|
||||
describeRoute({
|
||||
summary: "Well-known nodeinfo 2.0",
|
||||
tags: ["Federation"],
|
||||
responses: {
|
||||
200: {
|
||||
description: "Nodeinfo 2.0",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: resolver(
|
||||
z.object({
|
||||
version: z.string(),
|
||||
software: z.object({
|
||||
name: z.string(),
|
||||
version: z.string(),
|
||||
}),
|
||||
protocols: z.array(z.string()),
|
||||
services: z.object({
|
||||
outbound: z.array(z.string()),
|
||||
inbound: z.array(z.string()),
|
||||
}),
|
||||
usage: z.object({
|
||||
users: z.object({
|
||||
total: z.number(),
|
||||
activeMonth: z.number(),
|
||||
activeHalfyear: z.number(),
|
||||
}),
|
||||
localPosts: z.number(),
|
||||
}),
|
||||
openRegistrations: z.boolean(),
|
||||
metadata: z.object({}),
|
||||
}),
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
localPosts: noteCount,
|
||||
},
|
||||
openRegistrations: config.registration.allow,
|
||||
metadata: {
|
||||
nodeName: config.instance.name,
|
||||
nodeDescription: config.instance.description,
|
||||
},
|
||||
});
|
||||
}),
|
||||
}),
|
||||
async (context) => {
|
||||
const userCount = await User.getCount();
|
||||
const userActiveMonth = await User.getActiveInPeriod(
|
||||
1000 * 60 * 60 * 24 * 30,
|
||||
);
|
||||
const userActiveHalfyear = await User.getActiveInPeriod(
|
||||
1000 * 60 * 60 * 24 * 30 * 6,
|
||||
);
|
||||
const noteCount = await Note.getCount();
|
||||
|
||||
return context.json({
|
||||
version: "2.0",
|
||||
software: { name: "versia-server", version: manifest.version },
|
||||
protocols: ["versia"],
|
||||
services: { outbound: [], inbound: [] },
|
||||
usage: {
|
||||
users: {
|
||||
total: userCount,
|
||||
activeMonth: userActiveMonth,
|
||||
activeHalfyear: userActiveHalfyear,
|
||||
},
|
||||
localPosts: noteCount,
|
||||
},
|
||||
openRegistrations: config.registration.allow,
|
||||
metadata: {
|
||||
nodeName: config.instance.name,
|
||||
nodeDescription: config.instance.description,
|
||||
},
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,43 +1,47 @@
|
|||
import { apiRoute } from "@/api";
|
||||
import { createRoute, z } from "@hono/zod-openapi";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
import { config } from "~/config.ts";
|
||||
|
||||
const route = createRoute({
|
||||
method: "get",
|
||||
path: "/.well-known/nodeinfo",
|
||||
summary: "Well-known nodeinfo",
|
||||
tags: ["Federation"],
|
||||
responses: {
|
||||
200: {
|
||||
description: "Nodeinfo links",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
rel: z.string(),
|
||||
href: z.string(),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
export default apiRoute((app) =>
|
||||
app.get(
|
||||
"/.well-known/nodeinfo",
|
||||
describeRoute({
|
||||
summary: "Well-known nodeinfo",
|
||||
tags: ["Federation"],
|
||||
responses: {
|
||||
200: {
|
||||
description: "Nodeinfo links",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: resolver(
|
||||
z.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
rel: z.string(),
|
||||
href: z.string(),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
(context) => {
|
||||
return context.json({
|
||||
links: [
|
||||
{
|
||||
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
href: new URL(
|
||||
"/.well-known/nodeinfo/2.0",
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default apiRoute((app) =>
|
||||
app.openapi(route, (context) => {
|
||||
return context.json({
|
||||
links: [
|
||||
{
|
||||
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
href: new URL(
|
||||
"/.well-known/nodeinfo/2.0",
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
},
|
||||
],
|
||||
});
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue