config: add comments to all config options

This commit is contained in:
Alex Gleason 2023-08-26 11:55:16 -05:00
parent 4f12e067fc
commit 887c68f052
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { dotenv, nip19, secp } from '@/deps.ts'; import { dotenv, getPublicKey, nip19, secp } from '@/deps.ts';
/** Load environment config from `.env` */ /** Load environment config from `.env` */
await dotenv.load({ await dotenv.load({
@ -9,6 +9,7 @@ await dotenv.load({
/** Application-wide configuration. */ /** Application-wide configuration. */
const Conf = { const Conf = {
/** Ditto admin secret key in nip19 format. This is the way it's configured by an admin. */
get nsec() { get nsec() {
const value = Deno.env.get('DITTO_NSEC'); const value = Deno.env.get('DITTO_NSEC');
if (!value) { if (!value) {
@ -19,13 +20,15 @@ const Conf = {
} }
return value as `nsec1${string}`; return value as `nsec1${string}`;
}, },
/** Ditto admin secret key in hex format. */
get seckey() { get seckey() {
const result = nip19.decode(Conf.nsec); return nip19.decode(Conf.nsec).data;
if (result.type !== 'nsec') {
throw new Error('Invalid DITTO_NSEC');
}
return result.data;
}, },
/** Ditto admin public key in hex format. */
get pubkey() {
return getPublicKey(Conf.seckey);
},
/** Ditto admin secret key as a Web Crypto key. */
get cryptoKey() { get cryptoKey() {
return crypto.subtle.importKey( return crypto.subtle.importKey(
'raw', 'raw',
@ -39,24 +42,31 @@ const Conf = {
const { protocol, host } = Conf.url; const { protocol, host } = Conf.url;
return `${protocol === 'https:' ? 'wss:' : 'ws:'}//${host}/relay`; return `${protocol === 'https:' ? 'wss:' : 'ws:'}//${host}/relay`;
}, },
/** Domain of the Ditto server, including the protocol. */
get localDomain() { get localDomain() {
return Deno.env.get('LOCAL_DOMAIN') || 'http://localhost:8000'; return Deno.env.get('LOCAL_DOMAIN') || 'http://localhost:8000';
}, },
/** Path to the main SQLite database which stores users, events, and more. */
get dbPath() { get dbPath() {
return Deno.env.get('DB_PATH') || 'data/db.sqlite3'; return Deno.env.get('DB_PATH') || 'data/db.sqlite3';
}, },
/** Character limit to enforce for posts made through Mastodon API. */
get postCharLimit() { get postCharLimit() {
return Number(Deno.env.get('POST_CHAR_LIMIT') || 5000); return Number(Deno.env.get('POST_CHAR_LIMIT') || 5000);
}, },
/** Admin contact to expose through various endpoints. This information is public. */
get adminEmail() { get adminEmail() {
return Deno.env.get('ADMIN_EMAIL') || 'webmaster@localhost'; return Deno.env.get('ADMIN_EMAIL') || 'webmaster@localhost';
}, },
/** @deprecated Use relays from the database instead. */
get poolRelays() { get poolRelays() {
return (Deno.env.get('RELAY_POOL') || '').split(',').filter(Boolean); return (Deno.env.get('RELAY_POOL') || '').split(',').filter(Boolean);
}, },
/** @deprecated Publish only to the local relay unless users are mentioned, then try to also send to the relay of those users. Deletions should also be fanned out. */
get publishRelays() { get publishRelays() {
return ['wss://relay.mostr.pub']; return ['wss://relay.mostr.pub'];
}, },
/** Domain of the Ditto server as a `URL` object, for easily grabbing the `hostname`, etc. */
get url() { get url() {
return new URL(Conf.localDomain); return new URL(Conf.localDomain);
}, },