2023-08-04 19:17:50 +00:00
|
|
|
import { dotenv, nip19, secp } from '@/deps.ts';
|
|
|
|
|
|
|
|
/** Load environment config from `.env` */
|
|
|
|
await dotenv.load({
|
|
|
|
export: true,
|
|
|
|
defaultsPath: null,
|
|
|
|
examplePath: null,
|
|
|
|
});
|
2023-07-14 03:00:27 +00:00
|
|
|
|
2023-06-10 22:15:08 +00:00
|
|
|
/** Application-wide configuration. */
|
|
|
|
const Conf = {
|
|
|
|
get nsec() {
|
2023-07-14 03:00:27 +00:00
|
|
|
const value = Deno.env.get('DITTO_NSEC');
|
|
|
|
if (!value) {
|
|
|
|
throw new Error('Missing DITTO_NSEC');
|
|
|
|
}
|
|
|
|
if (!value.startsWith('nsec1')) {
|
|
|
|
throw new Error('Invalid DITTO_NSEC');
|
|
|
|
}
|
|
|
|
return value as `nsec1${string}`;
|
|
|
|
},
|
|
|
|
get seckey() {
|
|
|
|
const result = nip19.decode(Conf.nsec);
|
|
|
|
if (result.type !== 'nsec') {
|
|
|
|
throw new Error('Invalid DITTO_NSEC');
|
|
|
|
}
|
|
|
|
return result.data;
|
|
|
|
},
|
|
|
|
get cryptoKey() {
|
|
|
|
return crypto.subtle.importKey(
|
|
|
|
'raw',
|
|
|
|
secp.utils.hexToBytes(Conf.seckey),
|
|
|
|
{ name: 'HMAC', hash: 'SHA-256' },
|
|
|
|
false,
|
|
|
|
['sign', 'verify'],
|
|
|
|
);
|
2023-06-10 22:15:08 +00:00
|
|
|
},
|
2023-07-09 17:55:37 +00:00
|
|
|
get relay() {
|
2023-07-25 20:30:58 +00:00
|
|
|
const value = Deno.env.get('DITTO_RELAY');
|
|
|
|
if (!value) {
|
|
|
|
throw new Error('Missing DITTO_RELAY');
|
|
|
|
}
|
|
|
|
return value;
|
2023-07-09 17:55:37 +00:00
|
|
|
},
|
2023-06-10 22:15:08 +00:00
|
|
|
get localDomain() {
|
|
|
|
return Deno.env.get('LOCAL_DOMAIN') || 'http://localhost:8000';
|
|
|
|
},
|
|
|
|
get postCharLimit() {
|
|
|
|
return Number(Deno.env.get('POST_CHAR_LIMIT') || 5000);
|
|
|
|
},
|
|
|
|
get adminEmail() {
|
|
|
|
return Deno.env.get('ADMIN_EMAIL') || 'webmaster@localhost';
|
|
|
|
},
|
|
|
|
get poolRelays() {
|
|
|
|
return (Deno.env.get('RELAY_POOL') || '').split(',').filter(Boolean);
|
|
|
|
},
|
|
|
|
get publishRelays() {
|
|
|
|
return ['wss://relay.mostr.pub'];
|
|
|
|
},
|
2023-07-09 23:26:33 +00:00
|
|
|
get url() {
|
|
|
|
return new URL(Conf.localDomain);
|
|
|
|
},
|
2023-07-09 19:23:02 +00:00
|
|
|
/** Merges the path with the localDomain. */
|
2023-07-09 23:26:33 +00:00
|
|
|
local(path: string): string {
|
2023-07-09 19:23:02 +00:00
|
|
|
if (path.startsWith('/')) {
|
|
|
|
// Path is a path.
|
|
|
|
return new URL(path, Conf.localDomain).toString();
|
|
|
|
} else {
|
|
|
|
// Path is possibly a full URL. Replace the domain.
|
|
|
|
const { pathname } = new URL(path);
|
|
|
|
return new URL(pathname, Conf.localDomain).toString();
|
|
|
|
}
|
|
|
|
},
|
2023-06-10 22:15:08 +00:00
|
|
|
};
|
2023-03-05 04:10:56 +00:00
|
|
|
|
2023-06-10 22:15:08 +00:00
|
|
|
export { Conf };
|