[core] Add local store to WAHA Core

fix #741
This commit is contained in:
devlikepro committed 2025-01-19 14:42:58 +07:00
1 parent 72b796019a
commit e146ecde70
2 files changed
+14 -7

No files matched your search

@@ -1,9 +1,19 @@
import { LocalStore } from '@waha/core/storage/LocalStore';
import { DataStore } from '../../../abc/DataStore';
import { INowebStorage } from './INowebStorage';
import { Sqlite3Storage } from './sqlite3/Sqlite3Storage';
export class NowebStorageFactoryCore {
createStorage(store: DataStore, name: string): INowebStorage {
return new Sqlite3Storage(':memory:');
if (store instanceof LocalStore) {
return this.buildStorageSqlite3(store, name);
}
throw new Error(`Unsupported store type '${store.constructor.name}'`);
}
private buildStorageSqlite3(store: LocalStore, name: string) {
const filePath = store.getFilePath(name, 'store.sqlite3');
return new Sqlite3Storage(filePath);
}
}
+3 -6
View File
@@ -9,10 +9,8 @@ import { LocalStore } from './LocalStore';
const Database = require('better-sqlite3');
export class LocalStoreCore extends LocalStore {
protected readonly baseDirectory: string = path.join(
os.tmpdir(),
'waha-sessions',
);
protected readonly baseDirectory: string =
process.env.WAHA_LOCAL_STORE_BASE_DIR || './.sessions';
private readonly engine: string;
private db: any;
@@ -54,8 +52,7 @@ export class LocalStoreCore extends LocalStore {
}
protected getDirectoryPath(name: string): string {
const suffix = crypto.createHash('md5').update(name).digest('hex');
return path.join(this.getEngineDirectory(), `${name}-${suffix}`);
return path.join(this.getEngineDirectory(), name);
}
getWAHADatabase(): any {