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-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-03-29 03:30:06 +01:00
|
|
|
import { describeRoute } from "hono-openapi";
|
|
|
|
|
import { resolver } from "hono-openapi/zod";
|
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";
|
2025-04-08 21:54:55 +02:00
|
|
|
import { InstanceMetadataSchema } from "~/packages/sdk/schemas";
|
2023-11-04 04:34:31 +01:00
|
|
|
|
2025-03-29 03:30:06 +01:00
|
|
|
export default apiRoute((app) =>
|
|
|
|
|
app.get(
|
|
|
|
|
"/.well-known/versia",
|
|
|
|
|
describeRoute({
|
|
|
|
|
summary: "Get instance metadata",
|
|
|
|
|
tags: ["Federation"],
|
|
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "Instance metadata",
|
|
|
|
|
content: {
|
|
|
|
|
"application/json": {
|
|
|
|
|
schema: resolver(InstanceMetadataSchema),
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-09-16 15:29:09 +02:00
|
|
|
},
|
2024-08-26 19:06:49 +02:00
|
|
|
},
|
2025-03-29 03:30:06 +01:00
|
|
|
}),
|
|
|
|
|
async (context) => {
|
|
|
|
|
// Get date of first user creation
|
|
|
|
|
const firstUser = await User.fromSql(
|
|
|
|
|
undefined,
|
|
|
|
|
asc(Users.createdAt),
|
|
|
|
|
);
|
2024-09-16 15:29:09 +02:00
|
|
|
|
2025-03-29 03:30:06 +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
|
|
|
|
2025-03-29 03:30:06 +01:00
|
|
|
return context.json(
|
|
|
|
|
{
|
|
|
|
|
type: "InstanceMetadata" as const,
|
|
|
|
|
compatibility: {
|
|
|
|
|
extensions: [
|
|
|
|
|
"pub.versia:custom_emojis",
|
|
|
|
|
"pub.versia:instance_messaging",
|
|
|
|
|
],
|
|
|
|
|
versions: ["0.5.0"],
|
|
|
|
|
},
|
|
|
|
|
host: config.http.base_url.host,
|
|
|
|
|
name: config.instance.name,
|
|
|
|
|
description: config.instance.description,
|
|
|
|
|
public_key: {
|
|
|
|
|
key: publicKey,
|
|
|
|
|
algorithm: "ed25519" as const,
|
|
|
|
|
},
|
|
|
|
|
software: {
|
|
|
|
|
name: "Versia Server",
|
|
|
|
|
version: pkg.version,
|
|
|
|
|
},
|
|
|
|
|
banner: config.instance.branding.banner
|
|
|
|
|
? urlToContentFormat(config.instance.branding.banner)
|
|
|
|
|
: undefined,
|
|
|
|
|
logo: config.instance.branding.logo
|
|
|
|
|
? urlToContentFormat(config.instance.branding.logo)
|
|
|
|
|
: undefined,
|
|
|
|
|
shared_inbox: new URL(
|
|
|
|
|
"/inbox",
|
|
|
|
|
config.http.base_url,
|
|
|
|
|
).toString(),
|
|
|
|
|
created_at: new Date(
|
|
|
|
|
firstUser?.data.createdAt ?? 0,
|
|
|
|
|
).toISOString(),
|
|
|
|
|
extensions: {
|
|
|
|
|
"pub.versia:instance_messaging": {
|
|
|
|
|
endpoint: new URL(
|
|
|
|
|
"/messaging",
|
|
|
|
|
config.http.base_url,
|
|
|
|
|
).toString(),
|
|
|
|
|
},
|
2024-11-25 16:54:46 +01:00
|
|
|
},
|
|
|
|
|
},
|
2025-03-29 03:30:06 +01:00
|
|
|
200,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2024-08-19 20:06:38 +02:00
|
|
|
);
|