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; }