mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-10 17:14:20 +01:00
Add nostr.json (NIP-05)
This commit is contained in:
34
src/controllers/well-known/nostr.ts
Normal file
34
src/controllers/well-known/nostr.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { db } from '@/db.ts';
|
||||
import { z } from '@/deps.ts';
|
||||
|
||||
import type { AppController } from '@/app.ts';
|
||||
import { Conf } from '../../config.ts';
|
||||
|
||||
const nameSchema = z.string().min(1).regex(/^[\w_]+$/);
|
||||
|
||||
/**
|
||||
* Serves NIP-05's nostr.json.
|
||||
* https://github.com/nostr-protocol/nips/blob/master/05.md
|
||||
*/
|
||||
const nostrController: AppController = async (c) => {
|
||||
try {
|
||||
const name = nameSchema.parse(c.req.query('name'));
|
||||
const user = await db.users.findFirst({ where: { username: name } });
|
||||
const relay = Conf.relay;
|
||||
|
||||
return c.json({
|
||||
names: {
|
||||
[user.username]: user.pubkey,
|
||||
},
|
||||
relays: relay
|
||||
? {
|
||||
[user.pubkey]: [relay],
|
||||
}
|
||||
: {},
|
||||
});
|
||||
} catch (_e) {
|
||||
return c.json({ names: {}, relays: {} });
|
||||
}
|
||||
};
|
||||
|
||||
export { nostrController };
|
||||
Reference in New Issue
Block a user