fix(cache): use user-writable ~/.serve.zone/dcrouter for TsmDB and centralize data path logic

This commit is contained in:
2026-02-12 14:20:42 +00:00
parent 5de8d38b78
commit a309145829
8 changed files with 33 additions and 17 deletions

View File

@@ -1,5 +1,14 @@
# Changelog
## 2026-02-12 - 5.0.4 - fix(cache)
use user-writable ~/.serve.zone/dcrouter for TsmDB and centralize data path logic
- Default TsmDB storage changed from /etc/dcrouter/tsmdb to ~/.serve.zone/dcrouter/tsmdb
- Introduced dcrouterHomeDir, dataDir, and defaultTsmDbPath in ts/paths.ts
- CacheDb now defaults to defaultTsmDbPath when no storagePath is provided
- DcRouter initialization updated to use paths.defaultTsmDbPath; README and readme.hints updated to document the new defaults
- Avoids /etc permission issues and prevents starting a real MongoDB process in tests by using a user-writable default path
## 2026-02-12 - 5.0.3 - fix(packaging)
add files whitelist to package.json and remove Playwright-generated screenshots

View File

@@ -46,7 +46,7 @@ Source at `../../push.rocks/smartmta`, release with `gitzone commit -ypbrt`
### SmartProxy v23.1.2 Route Validation
- SmartProxy 23.1.2 enforces stricter route validation
- Forward actions MUST use `targets` (array) instead of `target` (singular)
- Test configurations that call `DcRouter.start()` need `cacheConfig: { enabled: false }` to avoid `/etc/dcrouter` permission errors
- Test configurations that call `DcRouter.start()` need `cacheConfig: { enabled: false }` to avoid starting a real MongoDB process in tests
```typescript
// WRONG - will fail validation
@@ -693,7 +693,7 @@ The configuration UI has been converted from an editable interface to a read-onl
## Smartdata Cache System (2026-02-03)
### Overview
DcRouter now uses smartdata + LocalTsmDb for persistent caching. Data is stored at `/etc/dcrouter/tsmdb`.
DcRouter now uses smartdata + LocalTsmDb for persistent caching. Data is stored at `~/.serve.zone/dcrouter/tsmdb`.
### Technology Stack
| Layer | Package | Purpose |
@@ -747,7 +747,7 @@ await email.delete();
const dcRouter = new DcRouter({
cacheConfig: {
enabled: true,
storagePath: '/etc/dcrouter/tsmdb',
storagePath: '~/.serve.zone/dcrouter/tsmdb',
dbName: 'dcrouter',
cleanupIntervalHours: 1,
ttlConfig: {

View File

@@ -219,7 +219,7 @@ const router = new DcRouter({
storage: { fsPath: '/var/lib/dcrouter/data' },
// Cache database
cacheConfig: { enabled: true, storagePath: '/etc/dcrouter/tsmdb' },
cacheConfig: { enabled: true, storagePath: '~/.serve.zone/dcrouter/tsmdb' },
// TLS & ACME
tls: { contactEmail: 'admin@example.com' },
@@ -388,7 +388,7 @@ interface IDcRouterOptions {
};
cacheConfig?: {
enabled?: boolean; // default: true
storagePath?: string; // default: '/etc/dcrouter/tsmdb'
storagePath?: string; // default: '~/.serve.zone/dcrouter/tsmdb'
dbName?: string; // default: 'dcrouter'
cleanupIntervalHours?: number; // default: 1
ttlConfig?: {
@@ -734,7 +734,7 @@ An embedded MongoDB-compatible database (via smartdata + LocalTsmDb) for persist
```typescript
cacheConfig: {
enabled: true,
storagePath: '/etc/dcrouter/tsmdb',
storagePath: '~/.serve.zone/dcrouter/tsmdb',
dbName: 'dcrouter',
cleanupIntervalHours: 1,
ttlConfig: {

View File

@@ -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.'
}

View File

@@ -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,
};

View File

@@ -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,
});

View File

@@ -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');

View File

@@ -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.'
}