@alizadefaig/pos-server 1.1.5 → 1.2.0

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.1.5",
3
+ "version": "1.2.0",
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": {
@@ -11,17 +11,17 @@
11
11
  "url": "git+ssh://git@gitlab.com/faigalizade/pos-server.git"
12
12
  },
13
13
  "dependencies": {
14
+ "@alizadefaig/cafetap-escpos-usb": "^1.0.1",
14
15
  "axios": "^1.8.4",
15
16
  "cors": "^2.8.5",
17
+ "escpos": "^3.0.0-alpha.6",
18
+ "escpos-network": "^3.0.0-alpha.5",
16
19
  "express": "^5.1.0",
17
20
  "form-data": "^4.0.2",
18
21
  "multer": "^1.4.5-lts.2",
19
22
  "sequelize": "^6.37.7",
20
23
  "socket.io": "^4.8.1",
21
- "socket.io-client": "^4.8.1",
22
- "@alizadefaig/cafetap-escpos-usb": "^1.0.1",
23
- "escpos": "^3.0.0-alpha.6",
24
- "escpos-network": "^3.0.0-alpha.5"
24
+ "socket.io-client": "^4.8.1"
25
25
  },
26
26
  "license": "ISC",
27
27
  "author": "faigalizade@newave.az",
@@ -107,14 +107,19 @@ router.get('/printers.get', async (req, res) => {
107
107
  })
108
108
  });
109
109
 
110
- router.post('/printers.print', (req, res) => {
110
+ router.post('/printers.print', async (req, res) => {
111
111
  const device = getPrinterDevice(req.body.printer)
112
112
  if (!device) {
113
113
  res.send('bad').status(404);
114
114
  }
115
- const image = req.body.content;
115
+ const imageContent = req.body.content.replace(/\r?\n|\r/g, '').replace(/^data:image\/\w+;base64,/, '');
116
116
  const printer = new escpos.Printer(device, {});
117
- const imageBuffer = Buffer.from(image, 'base64');
117
+ const imageBuffer = Buffer.from(imageContent, 'base64');
118
+ const image = await new Promise((resolve) => {
119
+ escpos.Image.load(imageBuffer, 'image/png', (i) => {
120
+ resolve(i);
121
+ })
122
+ })
118
123
  const timeOut = req.body.timeout || 5000;
119
124
 
120
125
  let sent = false;
@@ -130,15 +135,18 @@ router.post('/printers.print', (req, res) => {
130
135
  return;
131
136
  }
132
137
 
133
- printer.image(imageBuffer, 's8');
138
+ printer.raster(image);
134
139
  if (req.body.bell) {
135
- printer.beep(2, 3);
140
+ printer.beep(req.body.bell_count || 2, req.body.bell_time || 3);
136
141
  }
137
- if (req.body.bell) {
138
- printer.cashdraw(2);
142
+ if (req.body.cashdraw) {
143
+ printer.cashdraw(req.body.cashdraw_pin || 2);
139
144
  }
140
145
 
141
- printer.cut()
146
+ printer
147
+ .newLine()
148
+ .newLine()
149
+ .cut()
142
150
  .close();
143
151
 
144
152
  sent = true;
@@ -146,6 +154,7 @@ router.post('/printers.print', (req, res) => {
146
154
  success: true
147
155
  })
148
156
  });
157
+
149
158
  setTimeout(() => {
150
159
  if (!sent) {
151
160
  res.json({