Skip to content

Commit f77e279

Browse files
committed
Fix ajax error response, fix paths
1 parent b7dd9f3 commit f77e279

File tree

9 files changed

+15
-179
lines changed

9 files changed

+15
-179
lines changed

ZplEscPrinter/css/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ input[type=checkbox]._big, input[type=radio]._big, ._big>input[type=checkbox], .
3838

3939
.escpos-col > div > div > span {
4040
width: 100%;
41+
padding: 0.1rem 0.5rem;
4142
}
File renamed without changes.

ZplEscPrinter/js/escpos_commands.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

ZplEscPrinter/js/main.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ const { ipcRenderer } = require('electron');
55
const fs = require('fs');;
66
const net = require('net');
77

8-
const EscposCommands = require('./commands');
9-
10-
118
let clientSocketInfo;
129
let server;
1310
let configs = {};
@@ -168,7 +165,7 @@ async function zpl(data){
168165
}
169166

170167
/**
171-
*
168+
*
172169
* @param {string} data - The incoming socket data from the client
173170
* @param {boolean} b64 - If true, data is base64 encoded
174171
* @returns {Promise<Buffer<ArrayBufferLike> | null>} - The response to send back to the client
@@ -187,7 +184,7 @@ async function escpos(data,b64){
187184
return Buffer.from(escposCommands.getRollPaperStatus())
188185
}
189186

190-
187+
191188
if (!dataAux || !dataAux.trim().length) {
192189
console.warn(`esc/pos = '${data}', seems invalid`);
193190
return;
@@ -294,13 +291,19 @@ function startTcpServer() {
294291
if (regex.test(data)) {
295292
const response = JSON.stringify({success: true});
296293
sock.write('HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: ' + Buffer.byteLength(response) + '\r\n\r\n' + response);
294+
sock.end();
297295
data = data.replace(regex,'');
298296
}
299297

300298
const code = data + '';
301299
if (code.includes('Host:') && code.includes('Connection: keep-alive') && code.includes('HTTP')) {
302-
console.log('It\'s an ajax call');
303-
sock.end();
300+
const responseErrorMsg = 'Ajax call could not be handled!',
301+
responseError = JSON.stringify({success: false, message: responseErrorMsg});
302+
notify(responseErrorMsg, 'remove', 'danger', 0);
303+
try {
304+
sock.write('HTTP/1.1 500 Internal Server Error\r\nContent-Type: application/json\r\nContent-Length: ' + Buffer.byteLength(responseError) + '\r\n\r\n' + responseError);
305+
sock.end();
306+
} catch (error) {}
304307
return;
305308
}
306309

ZplEscPrinter/main.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<title>Printer Emulator</title>
55
<link href="css/style.css" type="text/css" rel="stylesheet"/>
6+
<script src="js/commands.js" type="text/javascript"></script>
67
<script src="js/main.js" type="module"></script>
78
</head>
89

@@ -92,7 +93,7 @@ <h5 id="mdlPrinterTest" class="modal-title modal-title">
9293
<button type="button" class="btn-close btn-close-save-settings" data-bs-dismiss="modal" aria-label="Close"></button>
9394
</div>
9495
<form id="configsForm" class="mb-0">
95-
<div class="modal-body ps-2 pe-2">
96+
<div class="modal-body ps-2 pe-2 pt-1">
9697
<fieldset class="border rounded p-2 mb-1">
9798
<legend class="float-none w-auto px-2 mb-0 fs-6 fw-semibold">Printer Properties</legend>
9899
<div class="row mb-2 is-zpl">
@@ -198,7 +199,7 @@ <h5 id="mdlPrinterTest" class="modal-title modal-title">
198199
<fieldset class="border rounded p-2 mb-1 is-esc">
199200
<legend class="float-none w-auto px-2 mb-0 fs-6 fw-semibold">ESC/POS Status</legend>
200201
<div class="container">
201-
<div class="row row-cols-2 escpos-col row-gap-2">
202+
<div class="row row-cols-2 escpos-col row-gap-1">
202203
<div class="col">
203204
<div class="input-group">
204205
<span class="input-group-text">

ZplEscPrinter/manifest.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

new 2.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

new1.txt

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zpl-escpos-printer",
33
"productName": "Zpl/EscPos Printer",
4-
"version": "3.0.6",
4+
"version": "3.0.7",
55
"description": "Printer emulator for Zpl/EscPos rendering engine.",
66
"main": "main.js",
77
"scripts": {

0 commit comments

Comments
 (0)