fix(cache): use user-writable ~/.serve.zone/dcrouter for TsmDB and centralize data path logic
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@serve.zone/dcrouter',
|
||||
version: '5.0.3',
|
||||
version: '5.0.4',
|
||||
description: 'A multifaceted routing service handling mail and SMS delivery functions.'
|
||||
}
|
||||
|
||||
5
ts/cache/classes.cachedb.ts
vendored
5
ts/cache/classes.cachedb.ts
vendored
@@ -1,11 +1,12 @@
|
||||
import * as plugins from '../plugins.js';
|
||||
import { logger } from '../logger.js';
|
||||
import { defaultTsmDbPath } from '../paths.js';
|
||||
|
||||
/**
|
||||
* Configuration options for CacheDb
|
||||
*/
|
||||
export interface ICacheDbOptions {
|
||||
/** Base storage path for TsmDB data (default: /etc/dcrouter/tsmdb) */
|
||||
/** Base storage path for TsmDB data (default: ~/.serve.zone/dcrouter/tsmdb) */
|
||||
storagePath?: string;
|
||||
/** Database name (default: dcrouter) */
|
||||
dbName?: string;
|
||||
@@ -29,7 +30,7 @@ export class CacheDb {
|
||||
|
||||
constructor(options: ICacheDbOptions = {}) {
|
||||
this.options = {
|
||||
storagePath: options.storagePath || '/etc/dcrouter/tsmdb',
|
||||
storagePath: options.storagePath || defaultTsmDbPath,
|
||||
dbName: options.dbName || 'dcrouter',
|
||||
debug: options.debug || false,
|
||||
};
|
||||
|
||||
@@ -122,7 +122,7 @@ export interface IDcRouterOptions {
|
||||
cacheConfig?: {
|
||||
/** Enable cache database (default: true) */
|
||||
enabled?: boolean;
|
||||
/** Storage path for TsmDB data (default: /etc/dcrouter/tsmdb) */
|
||||
/** Storage path for TsmDB data (default: ~/.serve.zone/dcrouter/tsmdb) */
|
||||
storagePath?: string;
|
||||
/** Database name (default: dcrouter) */
|
||||
dbName?: string;
|
||||
@@ -349,7 +349,7 @@ export class DcRouter {
|
||||
|
||||
// Initialize CacheDb singleton
|
||||
this.cacheDb = CacheDb.getInstance({
|
||||
storagePath: cacheConfig.storagePath || '/etc/dcrouter/tsmdb',
|
||||
storagePath: cacheConfig.storagePath || paths.defaultTsmDbPath,
|
||||
dbName: cacheConfig.dbName || 'dcrouter',
|
||||
debug: false,
|
||||
});
|
||||
|
||||
16
ts/paths.ts
16
ts/paths.ts
@@ -8,11 +8,17 @@ export const packageDir = plugins.path.join(
|
||||
);
|
||||
export const distServe = plugins.path.join(packageDir, './dist_serve');
|
||||
|
||||
// Configure data directory with environment variable or default to .nogit/data
|
||||
const DEFAULT_DATA_PATH = '.nogit/data';
|
||||
export const dataDir = process.env.DATA_DIR
|
||||
? process.env.DATA_DIR
|
||||
: plugins.path.join(baseDir, DEFAULT_DATA_PATH);
|
||||
// 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');
|
||||
|
||||
// MTA directories
|
||||
export const keysDir = plugins.path.join(dataDir, 'keys');
|
||||
|
||||
Reference in New Issue
Block a user