From de5e4050934678b54394fc710ff9aa23c99139ca Mon Sep 17 00:00:00 2001 From: Artyom Ashirov <1323ED5@gmail.com> Date: Fri, 15 Nov 2024 07:07:02 +0300 Subject: [PATCH] import from json --- src/handlers/adminProductHandler.js | 7 +++++-- src/index.js | 4 +--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/handlers/adminProductHandler.js b/src/handlers/adminProductHandler.js index cd8f236..a6860b4 100644 --- a/src/handlers/adminProductHandler.js +++ b/src/handlers/adminProductHandler.js @@ -449,8 +449,11 @@ export default class AdminProductHandler { } const file = await this.bot.getFile(msg.document.file_id); - const fileContent = await this.bot.downloadFile(file.file_id, '/tmp'); + + const fileContent = await this.bot.downloadFile(file.file_id, '.'); jsonContent = await fs.readFile(fileContent, 'utf8'); + await fs.rm(fileContent); + } else if (msg.text) { jsonContent = msg.text; } else { @@ -503,9 +506,9 @@ export default class AdminProductHandler { this.userStates.delete(chatId); } catch (error) { - await db.runAsync('ROLLBACK'); console.error('Error importing products:', error); await this.bot.sendMessage(chatId, 'Error importing products. Please check the data and try again.'); + await db.runAsync('ROLLBACK'); } return true; diff --git a/src/index.js b/src/index.js index 1f832eb..58242f9 100644 --- a/src/index.js +++ b/src/index.js @@ -69,9 +69,7 @@ bot.onText(/\/admin/, async (msg) => { // Handle user menu buttons bot.on('message', async (msg) => { - if (!msg.text) return; - - if (msg.text.toLowerCase() === '/start') { + if (msg.text && msg.text.toLowerCase() === '/start') { return; }