From 7d98ba89c544f9dcacb6654f7d85e9e7e47515cc Mon Sep 17 00:00:00 2001 From: leca Date: Thu, 14 Nov 2024 03:41:34 +0300 Subject: [PATCH] fixed wrong action sequence --- src/controllers/abstractproduct.js | 9 ++++++--- src/index.js | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/controllers/abstractproduct.js b/src/controllers/abstractproduct.js index 015d6fb..a72f5ab 100644 --- a/src/controllers/abstractproduct.js +++ b/src/controllers/abstractproduct.js @@ -45,15 +45,18 @@ class AbstractProductController { if (req.file) { tempPath = req.file.path; + + let previousImageHash = (await AbstractProductService.getByLocalId(groupId, localId)).image_filename + let previousImagePath = path.join(path.resolve(path.dirname('')), `/uploads/${previousImageHash}.png`); + fs.unlinkSync(previousImagePath) + image_buffer = fs.readFileSync(tempPath); image_filename = createHash('md5').update(image_buffer).digest('hex'); targetPath = path.join(path.resolve(path.dirname('')) + `/uploads/${image_filename}.png`); fs.copyFileSync(tempPath, targetPath); fs.rmSync(tempPath); - let previousImageHash = (await AbstractProductService.getByLocalId(groupId, localId)).image_filename - let previousImagePath = path.join(path.resolve(path.dirname('')), `/uploads/${previousImageHash}.png`); - fs.unlinkSync(previousImagePath) + } if (barcode) await AbstractProductService.updateBarcode(groupId, localId, barcode); diff --git a/src/index.js b/src/index.js index 78410cb..34d5619 100644 --- a/src/index.js +++ b/src/index.js @@ -32,6 +32,8 @@ app.get('/status', (req, res) => { wss.on('connection', (client) => { client.on('message', async (message) => { + if (message == "keepalive") return; + let parsed = JSON.parse(message); let token = parsed.token; let currentGroup = parsed.currentGroup; @@ -51,7 +53,6 @@ wss.on('connection', (client) => { return; } - clients.push({ socket: client, token, @@ -62,6 +63,7 @@ wss.on('connection', (client) => { client.on('close', () => { for (let i = 0; i < clients.length; i++) { if (clients[i].socket == client) { + log.debug(`Client with token ${clients[i].token} has disconnected`) clients.splice(i, 1); break; }