mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Fix path to datadir and custom policies
This commit is contained in:
parent
561efeffde
commit
af0e688ca3
1 changed files with 14 additions and 2 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
|
import Module from 'node:module';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
import ISO6391, { type LanguageCode } from 'iso-639-1';
|
import ISO6391, { type LanguageCode } from 'iso-639-1';
|
||||||
import { getPublicKey, nip19 } from 'nostr-tools';
|
import { getPublicKey, nip19 } from 'nostr-tools';
|
||||||
import { decodeBase64 } from '@std/encoding/base64';
|
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. */
|
/** Path to the custom policy module. Must be an absolute path, https:, npm:, or jsr: URI. */
|
||||||
get policy(): string {
|
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. */
|
/** Absolute path to the data directory used by Ditto. */
|
||||||
get dataDir(): string {
|
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. */
|
/** Absolute path of the Deno directory. */
|
||||||
|
|
@ -462,3 +465,12 @@ export class DittoConf {
|
||||||
return Number(this.env.get('STREAK_WINDOW') || 129600);
|
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);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue