Add an endpoint to request a NIP-05 name

This commit is contained in:
Alex Gleason 2024-06-06 14:14:59 -05:00
parent 4361c340b0
commit 616c405f0f
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 25 additions and 1 deletions

View File

@ -30,7 +30,7 @@ import { adminAccountAction, adminAccountsController } from '@/controllers/api/a
import { appCredentialsController, createAppController } from '@/controllers/api/apps.ts'; import { appCredentialsController, createAppController } from '@/controllers/api/apps.ts';
import { blocksController } from '@/controllers/api/blocks.ts'; import { blocksController } from '@/controllers/api/blocks.ts';
import { bookmarksController } from '@/controllers/api/bookmarks.ts'; import { bookmarksController } from '@/controllers/api/bookmarks.ts';
import { adminRelaysController, adminSetRelaysController } from '@/controllers/api/ditto.ts'; import { adminRelaysController, adminSetRelaysController, inviteRequestController } from '@/controllers/api/ditto.ts';
import { emptyArrayController, emptyObjectController, notImplementedController } from '@/controllers/api/fallback.ts'; import { emptyArrayController, emptyObjectController, notImplementedController } from '@/controllers/api/fallback.ts';
import { instanceController } from '@/controllers/api/instance.ts'; import { instanceController } from '@/controllers/api/instance.ts';
import { markersController, updateMarkersController } from '@/controllers/api/markers.ts'; import { markersController, updateMarkersController } from '@/controllers/api/markers.ts';
@ -239,6 +239,7 @@ app.delete('/api/v1/pleroma/admin/statuses/:id', requireRole('admin'), pleromaAd
app.get('/api/v1/admin/ditto/relays', requireRole('admin'), adminRelaysController); app.get('/api/v1/admin/ditto/relays', requireRole('admin'), adminRelaysController);
app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysController); app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysController);
app.post('/api/v1/ditto/nip05', requireSigner, inviteRequestController);
app.post('/api/v1/ditto/zap', requireSigner, zapController); app.post('/api/v1/ditto/zap', requireSigner, zapController);
app.post('/api/v1/reports', requireSigner, reportController); app.post('/api/v1/reports', requireSigner, reportController);

View File

@ -5,6 +5,7 @@ import { AppController } from '@/app.ts';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { Storages } from '@/storages.ts'; import { Storages } from '@/storages.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts'; import { AdminSigner } from '@/signers/AdminSigner.ts';
import { createEvent } from '@/utils/api.ts';
const markerSchema = z.enum(['read', 'write']); const markerSchema = z.enum(['read', 'write']);
@ -58,3 +59,25 @@ function renderRelays(event: NostrEvent): RelayEntity[] {
return acc; return acc;
}, [] as RelayEntity[]); }, [] as RelayEntity[]);
} }
const inviteRequestSchema = z.object({
nip05: z.string().email(),
reason: z.string().max(500).optional(),
});
export const inviteRequestController: AppController = async (c) => {
const { nip05, reason } = inviteRequestSchema.parse(await c.req.json());
await createEvent({
kind: 3036,
content: reason,
tags: [
['r', nip05],
['L', 'nip05.domain'],
['l', nip05.split('@')[1], 'nip05.domain'],
['p', Conf.pubkey],
],
}, c);
return new Response('', { status: 204 });
};