2024-12-30 20:18:48 +01:00
|
|
|
import { apiRoute } from "@/api";
|
2024-05-29 02:59:49 +02:00
|
|
|
import { urlToContentFormat } from "@/content_types";
|
2024-09-16 15:29:09 +02:00
|
|
|
import { createRoute } from "@hono/zod-openapi";
|
|
|
|
|
import { InstanceMetadata as InstanceMetadataSchema } from "@versia/federation/schemas";
|
2024-11-01 20:57:16 +01:00
|
|
|
import { User } from "@versia/kit/db";
|
2024-11-01 21:05:54 +01:00
|
|
|
import { Users } from "@versia/kit/tables";
|
2024-09-16 15:29:09 +02:00
|
|
|
import { asc } from "drizzle-orm";
|
2025-02-15 02:47:29 +01:00
|
|
|
import { config } from "~/config.ts";
|
2024-05-29 02:59:49 +02:00
|
|
|
import pkg from "~/package.json";
|
2023-11-04 04:34:31 +01:00
|
|
|
|
2024-09-16 15:29:09 +02:00
|
|
|
const route = createRoute({
|
|
|
|
|
method: "get",
|
|
|
|
|
path: "/.well-known/versia",
|
|
|
|
|
summary: "Get instance metadata",
|
|
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "Instance metadata",
|
|
|
|
|
content: {
|
|
|
|
|
"application/json": {
|
|
|
|
|
schema: InstanceMetadataSchema,
|
|
|
|
|
},
|
2024-08-26 19:06:49 +02:00
|
|
|
},
|
2024-09-16 15:29:09 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default apiRoute((app) =>
|
|
|
|
|
app.openapi(route, async (context) => {
|
|
|
|
|
// Get date of first user creation
|
|
|
|
|
const firstUser = await User.fromSql(undefined, asc(Users.createdAt));
|
|
|
|
|
|
2025-02-15 02:47:29 +01:00
|
|
|
const publicKey = Buffer.from(
|
|
|
|
|
await crypto.subtle.exportKey("spki", config.instance.keys.public),
|
|
|
|
|
).toString("base64");
|
|
|
|
|
|
2024-09-16 15:29:09 +02:00
|
|
|
return context.json(
|
|
|
|
|
{
|
|
|
|
|
type: "InstanceMetadata" as const,
|
|
|
|
|
compatibility: {
|
2024-11-25 16:54:46 +01:00
|
|
|
extensions: [
|
|
|
|
|
"pub.versia:custom_emojis",
|
|
|
|
|
"pub.versia:instance_messaging",
|
|
|
|
|
],
|
2025-02-17 13:07:43 +01:00
|
|
|
versions: ["0.5.0"],
|
2024-09-16 15:29:09 +02:00
|
|
|
},
|
2025-02-13 01:31:15 +01:00
|
|
|
host: config.http.base_url.host,
|
2024-09-16 15:29:09 +02:00
|
|
|
name: config.instance.name,
|
|
|
|
|
description: config.instance.description,
|
|
|
|
|
public_key: {
|
2025-02-15 02:47:29 +01:00
|
|
|
key: publicKey,
|
2024-09-16 15:29:09 +02:00
|
|
|
algorithm: "ed25519" as const,
|
|
|
|
|
},
|
|
|
|
|
software: {
|
|
|
|
|
name: "Versia Server",
|
|
|
|
|
version: pkg.version,
|
|
|
|
|
},
|
2025-02-15 02:47:29 +01:00
|
|
|
banner: config.instance.branding.banner
|
|
|
|
|
? urlToContentFormat(config.instance.branding.banner)
|
2024-12-16 23:57:21 +01:00
|
|
|
: undefined,
|
2025-02-15 02:47:29 +01:00
|
|
|
logo: config.instance.branding.logo
|
|
|
|
|
? urlToContentFormat(config.instance.branding.logo)
|
2024-12-16 23:57:21 +01:00
|
|
|
: undefined,
|
2024-11-25 17:05:53 +01:00
|
|
|
shared_inbox: new URL(
|
|
|
|
|
"/inbox",
|
|
|
|
|
config.http.base_url,
|
|
|
|
|
).toString(),
|
2024-09-16 15:29:09 +02:00
|
|
|
created_at: new Date(
|
|
|
|
|
firstUser?.data.createdAt ?? 0,
|
|
|
|
|
).toISOString(),
|
2024-11-25 16:54:46 +01:00
|
|
|
extensions: {
|
|
|
|
|
"pub.versia:instance_messaging": {
|
|
|
|
|
endpoint: new URL(
|
|
|
|
|
"/messaging",
|
|
|
|
|
config.http.base_url,
|
|
|
|
|
).toString(),
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-08-26 19:06:49 +02:00
|
|
|
},
|
2024-09-16 15:29:09 +02:00
|
|
|
200,
|
|
|
|
|
);
|
2024-08-19 20:06:38 +02:00
|
|
|
}),
|
|
|
|
|
);
|