Webfinger: actually, remove nostr lookup (this is bloat)

This commit is contained in:
Alex Gleason
2023-07-09 18:16:20 -05:00
parent 60cd92384d
commit 5ec40f285d
2 changed files with 9 additions and 41 deletions

View File

@@ -1,7 +1,6 @@
import { Conf } from '@/config.ts';
import { db } from '@/db.ts';
import { nip19, z } from '@/deps.ts';
import { npubSchema } from '@/schema.ts';
import type { AppContext, AppController } from '@/app.ts';
import type { Webfinger } from '@/schemas/webfinger.ts';
@@ -22,9 +21,6 @@ const webfingerController: AppController = (c) => {
case 'acct:': {
return handleAcct(c, resource);
}
case 'nostr:': {
return handleNostr(c, resource);
}
default:
return c.json({ error: 'Unsupported URI scheme' }, 400);
}
@@ -42,10 +38,17 @@ const acctSchema = z.custom<URL>((value) => value instanceof URL)
async function handleAcct(c: AppContext, resource: URL): Promise<Response> {
try {
const [username] = acctSchema.parse(resource);
const [username, host] = acctSchema.parse(resource);
const user = await db.users.findFirst({ where: { username } });
const json = renderWebfinger({
pubkey: user.pubkey,
username: user.username,
subject: `acct:${username}@${host}`,
});
c.header('content-type', 'application/jrd+json');
return c.body(JSON.stringify(renderWebfinger({ ...user, subject: `acct:${resource.pathname}` })));
return c.body(JSON.stringify(json));
} catch (e) {
if (e instanceof z.ZodError) {
return c.json({ error: 'Invalid acct URI', schema: e }, 400);
@@ -55,21 +58,6 @@ async function handleAcct(c: AppContext, resource: URL): Promise<Response> {
}
}
async function handleNostr(c: AppContext, resource: URL): Promise<Response> {
try {
const pubkey = npubSchema.parse(resource.pathname);
const user = await db.users.findFirst({ where: { pubkey } });
c.header('content-type', 'application/jrd+json');
return c.body(JSON.stringify(renderWebfinger({ ...user, subject: `nostr:${resource.pathname}` })));
} catch (e) {
if (e instanceof z.ZodError) {
return c.json({ error: 'Invalid Nostr URI', schema: e }, 400);
} else {
return c.json({ error: 'Not found' }, 404);
}
}
}
interface RenderWebfingerOpts {
pubkey: string;
username: string;