fixed wrong action sequence

This commit is contained in:
leca 2024-11-14 03:41:34 +03:00
parent 9988cedbc4
commit 7d98ba89c5
2 changed files with 9 additions and 4 deletions

View File

@ -45,15 +45,18 @@ class AbstractProductController {
if (req.file) { if (req.file) {
tempPath = req.file.path; 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_buffer = fs.readFileSync(tempPath);
image_filename = createHash('md5').update(image_buffer).digest('hex'); image_filename = createHash('md5').update(image_buffer).digest('hex');
targetPath = path.join(path.resolve(path.dirname('')) + `/uploads/${image_filename}.png`); targetPath = path.join(path.resolve(path.dirname('')) + `/uploads/${image_filename}.png`);
fs.copyFileSync(tempPath, targetPath); fs.copyFileSync(tempPath, targetPath);
fs.rmSync(tempPath); 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); if (barcode) await AbstractProductService.updateBarcode(groupId, localId, barcode);

View File

@ -32,6 +32,8 @@ app.get('/status', (req, res) => {
wss.on('connection', (client) => { wss.on('connection', (client) => {
client.on('message', async (message) => { client.on('message', async (message) => {
if (message == "keepalive") return;
let parsed = JSON.parse(message); let parsed = JSON.parse(message);
let token = parsed.token; let token = parsed.token;
let currentGroup = parsed.currentGroup; let currentGroup = parsed.currentGroup;
@ -51,7 +53,6 @@ wss.on('connection', (client) => {
return; return;
} }
clients.push({ clients.push({
socket: client, socket: client,
token, token,
@ -62,6 +63,7 @@ wss.on('connection', (client) => {
client.on('close', () => { client.on('close', () => {
for (let i = 0; i < clients.length; i++) { for (let i = 0; i < clients.length; i++) {
if (clients[i].socket == client) { if (clients[i].socket == client) {
log.debug(`Client with token ${clients[i].token} has disconnected`)
clients.splice(i, 1); clients.splice(i, 1);
break; break;
} }