2024-12-30 20:18:48 +01:00
|
|
|
import { apiRoute, auth } from "@/api";
|
2025-02-14 16:44:32 +01:00
|
|
|
import { renderMarkdownInPath } from "@/markdown";
|
2024-08-19 21:03:59 +02:00
|
|
|
import { proxyUrl } from "@/response";
|
2025-02-14 16:44:32 +01:00
|
|
|
import { createRoute, type z } from "@hono/zod-openapi";
|
2024-11-01 20:57:16 +01:00
|
|
|
import { Instance, Note, User } from "@versia/kit/db";
|
2024-11-01 21:05:54 +01:00
|
|
|
import { Users } from "@versia/kit/tables";
|
2024-06-30 09:08:03 +02:00
|
|
|
import { and, eq, isNull } from "drizzle-orm";
|
2025-02-14 16:44:32 +01:00
|
|
|
import { InstanceV1 as InstanceV1Schema } from "~/classes/schemas/instance-v1";
|
2024-05-29 02:59:49 +02:00
|
|
|
import manifest from "~/package.json";
|
|
|
|
|
import { config } from "~/packages/config-manager";
|
2023-10-01 05:24:58 +02:00
|
|
|
|
2024-09-15 14:28:47 +02:00
|
|
|
const route = createRoute({
|
|
|
|
|
method: "get",
|
|
|
|
|
path: "/api/v1/instance",
|
2025-02-14 16:44:32 +01:00
|
|
|
summary: "View server information (v1)",
|
|
|
|
|
description:
|
|
|
|
|
"Obtain general information about the server. See api/v2/instance instead.",
|
|
|
|
|
deprecated: true,
|
|
|
|
|
externalDocs: {
|
|
|
|
|
url: "https://docs.joinmastodon.org/methods/instance/#v1",
|
|
|
|
|
},
|
|
|
|
|
tags: ["Instance"],
|
2024-12-30 19:18:31 +01:00
|
|
|
middleware: [
|
|
|
|
|
auth({
|
|
|
|
|
auth: false,
|
|
|
|
|
}),
|
|
|
|
|
],
|
2024-09-15 14:28:47 +02:00
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "Instance information",
|
|
|
|
|
content: {
|
|
|
|
|
"application/json": {
|
2025-02-14 16:44:32 +01:00
|
|
|
schema: InstanceV1Schema,
|
2024-09-15 14:28:47 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-19 20:06:38 +02:00
|
|
|
export default apiRoute((app) =>
|
2024-09-15 14:28:47 +02:00
|
|
|
app.openapi(route, async (context) => {
|
|
|
|
|
// Get software version from package.json
|
|
|
|
|
const version = manifest.version;
|
2023-10-01 05:24:58 +02:00
|
|
|
|
2024-09-15 14:28:47 +02:00
|
|
|
const statusCount = await Note.getCount();
|
2023-11-29 04:57:35 +01:00
|
|
|
|
2024-09-15 14:28:47 +02:00
|
|
|
const userCount = await User.getCount();
|
2024-04-11 13:39:07 +02:00
|
|
|
|
2025-02-14 17:49:34 +01:00
|
|
|
// Get first admin, or first user if no admin exists
|
2025-02-14 16:44:32 +01:00
|
|
|
const contactAccount =
|
|
|
|
|
(await User.fromSql(
|
|
|
|
|
and(isNull(Users.instanceId), eq(Users.isAdmin, true)),
|
|
|
|
|
)) ?? (await User.fromSql(isNull(Users.instanceId)));
|
2023-10-01 05:24:58 +02:00
|
|
|
|
2024-09-15 14:28:47 +02:00
|
|
|
const knownDomainsCount = await Instance.getCount();
|
2023-11-29 04:57:35 +01:00
|
|
|
|
2024-10-11 17:03:33 +02:00
|
|
|
const oidcConfig = config.plugins?.config?.["@versia/openid"] as
|
|
|
|
|
| {
|
2024-10-11 17:07:17 +02:00
|
|
|
forced?: boolean;
|
|
|
|
|
providers?: {
|
2024-10-11 17:03:33 +02:00
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
icon: string;
|
|
|
|
|
}[];
|
|
|
|
|
}
|
|
|
|
|
| undefined;
|
|
|
|
|
|
2025-02-14 16:44:32 +01:00
|
|
|
const { content } = await renderMarkdownInPath(
|
|
|
|
|
config.instance.extended_description_path ?? "",
|
|
|
|
|
"This is a [Versia](https://versia.pub) server with the default extended description.",
|
|
|
|
|
);
|
|
|
|
|
|
2024-09-15 14:28:47 +02:00
|
|
|
// TODO: fill in more values
|
|
|
|
|
return context.json({
|
|
|
|
|
approval_required: false,
|
|
|
|
|
configuration: {
|
|
|
|
|
polls: {
|
|
|
|
|
max_characters_per_option:
|
|
|
|
|
config.validation.max_poll_option_size,
|
|
|
|
|
max_expiration: config.validation.max_poll_duration,
|
|
|
|
|
max_options: config.validation.max_poll_options,
|
|
|
|
|
min_expiration: config.validation.min_poll_duration,
|
2024-05-06 09:16:33 +02:00
|
|
|
},
|
2024-09-15 14:28:47 +02:00
|
|
|
statuses: {
|
|
|
|
|
characters_reserved_per_url: 0,
|
|
|
|
|
max_characters: config.validation.max_note_size,
|
|
|
|
|
max_media_attachments:
|
|
|
|
|
config.validation.max_media_attachments,
|
2024-06-08 06:57:29 +02:00
|
|
|
},
|
2025-01-29 16:05:04 +01:00
|
|
|
media_attachments: {
|
|
|
|
|
supported_mime_types: config.validation.allowed_mime_types,
|
|
|
|
|
image_size_limit: config.validation.max_media_size,
|
|
|
|
|
image_matrix_limit: config.validation.max_media_size,
|
|
|
|
|
video_size_limit: config.validation.max_media_size,
|
|
|
|
|
video_frame_rate_limit: config.validation.max_media_size,
|
|
|
|
|
video_matrix_limit: config.validation.max_media_size,
|
|
|
|
|
},
|
|
|
|
|
accounts: {
|
|
|
|
|
max_featured_tags: 100,
|
|
|
|
|
},
|
2024-09-15 14:28:47 +02:00
|
|
|
},
|
2025-02-14 16:44:32 +01:00
|
|
|
short_description: config.instance.description,
|
|
|
|
|
description: content,
|
|
|
|
|
// TODO: Add contact email
|
2024-09-15 14:28:47 +02:00
|
|
|
email: "",
|
|
|
|
|
invites_enabled: false,
|
|
|
|
|
registrations: config.signups.registration,
|
2025-02-14 16:44:32 +01:00
|
|
|
// TODO: Implement
|
2024-09-15 14:28:47 +02:00
|
|
|
languages: ["en"],
|
|
|
|
|
rules: config.signups.rules.map((r, index) => ({
|
|
|
|
|
id: String(index),
|
|
|
|
|
text: r,
|
|
|
|
|
})),
|
|
|
|
|
stats: {
|
|
|
|
|
domain_count: knownDomainsCount,
|
|
|
|
|
status_count: statusCount,
|
|
|
|
|
user_count: userCount,
|
|
|
|
|
},
|
2025-02-01 16:32:18 +01:00
|
|
|
thumbnail: config.instance.logo
|
|
|
|
|
? proxyUrl(config.instance.logo).toString()
|
|
|
|
|
: null,
|
2024-09-15 14:28:47 +02:00
|
|
|
title: config.instance.name,
|
2025-02-14 16:44:32 +01:00
|
|
|
uri: config.http.base_url.host,
|
2024-09-15 14:28:47 +02:00
|
|
|
urls: {
|
2025-02-14 16:44:32 +01:00
|
|
|
// TODO: Implement Streaming API
|
2024-09-15 14:28:47 +02:00
|
|
|
streaming_api: "",
|
|
|
|
|
},
|
|
|
|
|
version: "4.3.0-alpha.3+glitch",
|
|
|
|
|
versia_version: version,
|
2024-10-11 17:03:33 +02:00
|
|
|
// TODO: Put into plugin directly
|
2024-09-15 14:28:47 +02:00
|
|
|
sso: {
|
2024-10-11 17:03:33 +02:00
|
|
|
forced: oidcConfig?.forced ?? false,
|
|
|
|
|
providers:
|
2024-10-11 17:07:17 +02:00
|
|
|
oidcConfig?.providers?.map((p) => ({
|
2024-10-11 17:03:33 +02:00
|
|
|
name: p.name,
|
2025-02-01 16:32:18 +01:00
|
|
|
icon: p.icon
|
|
|
|
|
? proxyUrl(new URL(p.icon)).toString()
|
|
|
|
|
: undefined,
|
2024-10-11 17:03:33 +02:00
|
|
|
id: p.id,
|
|
|
|
|
})) ?? [],
|
2024-09-15 14:28:47 +02:00
|
|
|
},
|
2025-02-14 17:49:34 +01:00
|
|
|
contact_account: (contactAccount as User)?.toApi(),
|
2025-02-14 16:44:32 +01:00
|
|
|
} satisfies z.infer<typeof InstanceV1Schema>);
|
2024-09-15 14:28:47 +02:00
|
|
|
}),
|
2024-08-19 20:06:38 +02:00
|
|
|
);
|