[core] WAHA_NAMESPACE and WAHA_SESSION_NAMESPACE

This commit is contained in:
devlikepro committed 2026-03-05 12:41:22 +07:00
1 parent 441ebbd525
commit 3ba92dec04
3 files changed
+30 -7

No files matched your search

+12
View File
@@ -5,3 +5,15 @@ export function getEngineName(): string {
// If not set - use WEBJS
return process.env.WHATSAPP_DEFAULT_ENGINE || WAHAEngine.WEBJS;
}
export function getNamespace(): string {
// Controls the prefix used for the main database and folder (non-session data)
// If not set - falls back to engine name for backward compatibility
return (process.env.WAHA_NAMESPACE || getEngineName()).toLowerCase();
}
export function getSessionNamespace(): string {
// Controls the prefix used for session databases and folders
// If not set - falls back to engine name for backward compatibility
return (process.env.WAHA_SESSION_NAMESPACE || getEngineName()).toLowerCase();
}
+2 -1
View File
@@ -25,6 +25,7 @@ import { PinoLogger } from 'nestjs-pino';
import { Observable, retry, share } from 'rxjs';
import { map } from 'rxjs/operators';
import { getNamespace, getSessionNamespace } from '../config';
import { WhatsappConfigService } from '../config.service';
import {
WAHAEngine,
@@ -107,7 +108,7 @@ export class SessionManagerCore extends SessionManager implements OnModuleInit {
}),
);
this.store = new LocalStoreCore(engineName.toLowerCase());
this.store = new LocalStoreCore(getNamespace(), getSessionNamespace());
this.sessionAuthRepository = new LocalSessionAuthRepository(this.store);
this.clearStorage().catch((error) => {
this.log.error({ error }, 'Error while clearing storage');
+16 -6
View File
@@ -10,15 +10,18 @@ export class LocalStoreCore extends LocalStore {
protected readonly baseDirectory: string =
process.env.WAHA_LOCAL_STORE_BASE_DIR || './.sessions';
private readonly engine: string;
private readonly namespace: string;
private readonly sessionNamespace: string;
private knex: Knex.Knex;
constructor(engine: string) {
constructor(namespace: string, sessionNamespace: string) {
super();
this.engine = engine;
this.namespace = namespace;
this.sessionNamespace = sessionNamespace;
}
async init(sessionName?: string) {
await fs.mkdir(this.getMainDirectory(), { recursive: true });
await fs.mkdir(this.getEngineDirectory(), { recursive: true });
if (!this.knex) {
this.knex = this.buildKnex();
@@ -40,11 +43,18 @@ export class LocalStoreCore extends LocalStore {
return path.resolve(this.baseDirectory);
}
/**
* Get the directory where the main WAHA database (SQLite) is stored
*/
getMainDirectory() {
return safeJoin(this.baseDirectory, this.namespace);
}
/**
* Get the directory where the engine sessions are stored
*/
getEngineDirectory() {
return safeJoin(this.baseDirectory, this.engine);
return safeJoin(this.baseDirectory, this.sessionNamespace);
}
getSessionDirectory(name: string): string {
@@ -67,8 +77,8 @@ export class LocalStoreCore extends LocalStore {
}
buildKnex(): Knex.Knex {
const engineDir = this.getEngineDirectory();
const database = path.join(engineDir, 'waha.sqlite3');
const mainDir = this.getMainDirectory();
const database = path.join(mainDir, 'waha.sqlite3');
return Knex({
client: KNEX_SQLITE_CLIENT,
connection: { filename: database },