From a2ae855c10197db330dde6f0520c22d97872540c Mon Sep 17 00:00:00 2001 From: Sosthene Date: Wed, 3 Sep 2025 15:08:54 +0200 Subject: [PATCH] Fix broken db operation for raw bytes --- src/database.service.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/database.service.ts b/src/database.service.ts index 172a8a1..b9ec5ea 100644 --- a/src/database.service.ts +++ b/src/database.service.ts @@ -73,10 +73,14 @@ export default class Database { * Get a single object from a store * O(log n) operation - only reads specific key */ - public async getObject(storeName: string, key: string): Promise { + public async getObject(storeName: string, key: string, isBuffer: boolean = false): Promise { try { const fullKey = this.getKey(storeName, key); - return await this.db.get(fullKey); + if (isBuffer) { + return await this.db.get(fullKey, { valueEncoding: 'buffer' }); + } else { + return await this.db.get(fullKey); + } } catch (error) { if ((error as any).code === 'LEVEL_NOT_FOUND') { return null; @@ -89,12 +93,16 @@ export default class Database { * Add or update an object in a store * O(log n) operation - only writes specific key-value pair */ - public async addObject(operation: DatabaseObject): Promise { + public async addObject(operation: DatabaseObject, isBuffer: boolean = false): Promise { const { storeName, object, key } = operation; if (key) { const fullKey = this.getKey(storeName, key); - await this.db.put(fullKey, object); + if (isBuffer) { + await this.db.put(fullKey, object, { valueEncoding: 'buffer' }); + } else { + await this.db.put(fullKey, object); + } } else { // Auto-generate key if none provided const autoKey = Date.now().toString() + Math.random().toString(36).substr(2, 9);