2024-02-16 13:28:40 +01:00
|
|
|
import * as plugins from './plugins.js';
|
2024-02-15 20:30:38 +01:00
|
|
|
|
2026-02-16 09:52:38 +00:00
|
|
|
// Code/asset paths (not affected by baseDir)
|
2024-02-15 20:30:38 +01:00
|
|
|
export const packageDir = plugins.path.join(
|
|
|
|
|
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
|
|
|
|
'../'
|
|
|
|
|
);
|
2025-06-01 19:46:10 +00:00
|
|
|
export const distServe = plugins.path.join(packageDir, './dist_serve');
|
2025-05-07 20:20:17 +00:00
|
|
|
|
2026-02-12 14:20:42 +00:00
|
|
|
// Default base for all dcrouter data (always user-writable)
|
|
|
|
|
export const dcrouterHomeDir = plugins.path.join(plugins.os.homedir(), '.serve.zone', 'dcrouter');
|
|
|
|
|
|
|
|
|
|
// Configure data directory with environment variable or default to ~/.serve.zone/dcrouter/data
|
|
|
|
|
const DEFAULT_DATA_PATH = plugins.path.join(dcrouterHomeDir, 'data');
|
|
|
|
|
export const dataDir = process.env.DATA_DIR
|
|
|
|
|
? process.env.DATA_DIR
|
|
|
|
|
: DEFAULT_DATA_PATH;
|
|
|
|
|
|
|
|
|
|
// Default TsmDB path for CacheDb
|
|
|
|
|
export const defaultTsmDbPath = plugins.path.join(dcrouterHomeDir, 'tsmdb');
|
2025-03-15 13:57:21 +00:00
|
|
|
|
2026-02-16 09:52:38 +00:00
|
|
|
// DNS records directory (only surviving MTA directory reference)
|
2025-03-15 13:57:21 +00:00
|
|
|
export const dnsRecordsDir = plugins.path.join(dataDir, 'dns');
|
|
|
|
|
|
2026-02-16 09:52:38 +00:00
|
|
|
/**
|
|
|
|
|
* Resolve all data paths from a given baseDir.
|
|
|
|
|
* When no baseDir is provided, falls back to ~/.serve.zone/dcrouter.
|
|
|
|
|
* Specific overrides (e.g. DATA_DIR env) take precedence.
|
|
|
|
|
*/
|
|
|
|
|
export function resolvePaths(baseDir?: string) {
|
|
|
|
|
const root = baseDir ?? plugins.path.join(plugins.os.homedir(), '.serve.zone', 'dcrouter');
|
|
|
|
|
const resolvedDataDir = process.env.DATA_DIR ?? plugins.path.join(root, 'data');
|
|
|
|
|
return {
|
|
|
|
|
dcrouterHomeDir: root,
|
|
|
|
|
dataDir: resolvedDataDir,
|
|
|
|
|
defaultTsmDbPath: plugins.path.join(root, 'tsmdb'),
|
|
|
|
|
defaultStoragePath: plugins.path.join(root, 'storage'),
|
|
|
|
|
dnsRecordsDir: plugins.path.join(resolvedDataDir, 'dns'),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ensure only the data directories that are actually used exist.
|
|
|
|
|
*/
|
|
|
|
|
export function ensureDataDirectories(resolvedPaths: ReturnType<typeof resolvePaths>) {
|
|
|
|
|
plugins.fsUtils.ensureDirSync(resolvedPaths.dataDir);
|
|
|
|
|
plugins.fsUtils.ensureDirSync(resolvedPaths.dnsRecordsDir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Legacy wrapper — delegates to ensureDataDirectories with module-level defaults.
|
|
|
|
|
*/
|
2025-03-15 13:57:21 +00:00
|
|
|
export function ensureDirectories() {
|
2026-02-16 09:52:38 +00:00
|
|
|
ensureDataDirectories(resolvePaths());
|
|
|
|
|
}
|