@alizadefaig/pos-server 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alizadefaig/pos-server",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Server in express js with Proxy to Main server if need and will work with Electron JS",
5
5
  "homepage": "https://gitlab.com/faigalizade/pos-server#readme",
6
6
  "bugs": {
@@ -113,11 +113,18 @@ router.post('/printers.print', (req, res) => {
113
113
  const image = req.body.content;
114
114
  const printer = new escpos.Printer(device, {});
115
115
  const imageBuffer = Buffer.from(image, 'base64');
116
+ const timeOut = req.body.timeout || 5000;
117
+
118
+ let sent = false;
116
119
 
117
120
  device.open((err) => {
118
121
  if (err) {
119
122
  console.error('Ошибка подключения к принтеру:', err);
120
- res.send(err).status(404);
123
+ sent = true;
124
+ res.json({
125
+ success: false,
126
+ error: err
127
+ })
121
128
  return;
122
129
  }
123
130
 
@@ -132,8 +139,19 @@ router.post('/printers.print', (req, res) => {
132
139
  printer.cut()
133
140
  .close();
134
141
 
135
- res.send('ok');
142
+ sent = true;
143
+ res.json({
144
+ success: true
145
+ })
136
146
  });
147
+ setTimeout(() => {
148
+ if (!sent) {
149
+ res.json({
150
+ success: false,
151
+ error: 'timeout'
152
+ })
153
+ }
154
+ }, timeOut);
137
155
  })
138
156
 
139
157
  module.exports = router;