Fix path to datadir and custom policies

This commit is contained in:
Alex Gleason 2025-02-16 12:52:27 -06:00
parent 561efeffde
commit af0e688ca3
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -1,4 +1,7 @@
import Module from 'node:module';
import os from 'node:os';
import path from 'node:path';
import ISO6391, { type LanguageCode } from 'iso-639-1';
import { getPublicKey, nip19 } from 'nostr-tools';
import { decodeBase64 } from '@std/encoding/base64';
@ -346,12 +349,12 @@ export class DittoConf {
/** Path to the custom policy module. Must be an absolute path, https:, npm:, or jsr: URI. */
get policy(): string {
return this.env.get('DITTO_POLICY') || new URL('../data/policy.ts', import.meta.url).pathname;
return this.env.get('DITTO_POLICY') || path.join(this.dataDir, 'policy.ts');
}
/** Absolute path to the data directory used by Ditto. */
get dataDir(): string {
return this.env.get('DITTO_DATA_DIR') || new URL('../data', import.meta.url).pathname;
return this.env.get('DITTO_DATA_DIR') || path.join(cwd(), 'data');
}
/** Absolute path of the Deno directory. */
@ -462,3 +465,12 @@ export class DittoConf {
return Number(this.env.get('STREAK_WINDOW') || 129600);
}
}
/**
* HACK: get cwd without read permissions.
* https://github.com/denoland/deno/issues/27080#issuecomment-2504150155
*/
function cwd() {
// @ts-ignore Internal method, but it does exist.
return Module._nodeModulePaths('a')[0].slice(0, -15);
}