From 82c4f0827ef265006deb8557a2db46e057ccda83 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 10 Sep 2023 23:43:06 -0500 Subject: [PATCH] Make registrations configurable by env --- src/config.ts | 4 ++++ src/controllers/api/accounts.ts | 4 ++++ src/controllers/api/instance.ts | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index 440cd26..ba36898 100644 --- a/src/config.ts +++ b/src/config.ts @@ -126,6 +126,10 @@ const Conf = { 'system', ]; }, + /** Whether registrations are open or closed. */ + get registrations() { + return optionalBooleanSchema.parse(Deno.env.get('DITTO_REGISTRATIONS')) ?? false; + }, /** Proof-of-work configuration. */ pow: { get registrations() { diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 7ac74a0..1d37f70 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -22,6 +22,10 @@ const createAccountSchema = z.object({ }); const createAccountController: AppController = async (c) => { + if (!Conf.registrations) { + return c.json({ error: 'Registrations are disabled.' }, 403); + } + const pubkey = c.get('pubkey')!; const result = createAccountSchema.safeParse(await c.req.json()); diff --git a/src/controllers/api/instance.ts b/src/controllers/api/instance.ts index 8ef38a7..10b359b 100644 --- a/src/controllers/api/instance.ts +++ b/src/controllers/api/instance.ts @@ -12,7 +12,7 @@ const instanceController: AppController = (c) => { title: 'Ditto', description: 'An efficient and flexible social media server.', short_description: 'An efficient and flexible social media server.', - registrations: false, + registrations: Conf.registrations, max_toot_chars: Conf.postCharLimit, configuration: { media_attachments: {