diff --git a/src/ap/blog.ts b/src/ap/blog.ts deleted file mode 100644 index be050c0..0000000 --- a/src/ap/blog.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { BASE_URL } from "~/config.js"; -import { Blog } from "~/db/entities/blog.js"; - -/** Transforms the given Blog into an ActivityPub Person. It is the caller's responsibility to ensure the blog is local. */ -export function blogToActivityPub(blog: Blog) { - return { - "@context": "https://www.w3.org/ns/activitystreams", - type: "Person", - id: `${BASE_URL}/blogs/${blog.username}`, - inbox: `${BASE_URL}/blogs/${blog.username}/inbox`, - outbox: `${BASE_URL}/blogs/${blog.username}/outbox`, - name: blog.username, - preferredUsername: blog.username, - publicKey: { - id: `${BASE_URL}/blogs/${blog.username}#main-key`, - owner: `${BASE_URL}/blogs/${blog.username}`, - publicKeyPem: blog.publicKey, - }, - }; -} diff --git a/src/config.ts b/src/config.ts index 02337b1..eabcbd4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -11,8 +11,8 @@ export const DATABASE_PASS = process.env.DATABASE_PASS || "postgres"; export const DATABASE_NAME = process.env.DATABASE_NAME || "postgres"; export const HTTPS = process.env.HTTPS === "true"; -export const DOMAIN = process.env.DOMAIN; +export const DOMAIN = process.env.DOMAIN || ""; -if (!DOMAIN) throw "$DOMAIN is empty"; +if (DOMAIN === "") throw "$DOMAIN is empty"; export const BASE_URL = `${HTTPS ? "https" : "http"}://${DOMAIN}`; diff --git a/src/routes/well-known/auth-node.ts b/src/routes/well-known/auth-node.ts index 0160359..4b50c93 100644 --- a/src/routes/well-known/auth-node.ts +++ b/src/routes/well-known/auth-node.ts @@ -1,9 +1,45 @@ import { RouteOptions } from "fastify"; +import { BASE_URL, DOMAIN } from "~/config.js"; +import { Account } from "~/db/entities/account.js"; +import LongmontDataSource from "~/db/index.js"; + +interface AuthNode { + api_base: string; + name_suffix: string; + software: { + name: string; + version: string; + source: string; + }; + features: string[]; + registrations: "open" | "approval" | "closed"; + usage: { + users: number | null; + }; +} + const route: RouteOptions = { method: "GET", url: "/.well-known/longmont/auth-node", handler: async (_, res) => { + const userCount = await LongmontDataSource.getRepository(Account).count(); + + res.send({ + api_base: BASE_URL, + name_suffix: DOMAIN, + software: { + name: "authsrv", + version: "0.1.0-dev", + source: "https://github.com/longmont-chat", + }, + features: [], + registrations: "open", + usage: { + users: userCount, + }, + } satisfies AuthNode); + res.status(204); }, };