@alizadefaig/pos-server 1.0.0 → 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.0",
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": {
@@ -10,6 +10,16 @@
10
10
  "type": "git",
11
11
  "url": "git+ssh://git@gitlab.com/faigalizade/pos-server.git"
12
12
  },
13
+ "dependencies": {
14
+ "axios": "^1.8.4",
15
+ "cors": "^2.8.5",
16
+ "express": "^5.1.0",
17
+ "form-data": "^4.0.2",
18
+ "multer": "^1.4.5-lts.2",
19
+ "sequelize": "^6.37.7",
20
+ "socket.io": "^4.8.1",
21
+ "socket.io-client": "^4.8.1"
22
+ },
13
23
  "license": "ISC",
14
24
  "author": "faigalizade@newave.az",
15
25
  "type": "commonjs",
@@ -20,18 +30,5 @@
20
30
  "scripts": {
21
31
  "test": "echo \"Error: no test specified\" && exit 1",
22
32
  "start": "node server.js"
23
- },
24
- "dependencies": {
25
- "axios": "^1.8.4",
26
- "cors": "^2.8.5",
27
- "express": "^5.1.0",
28
- "form-data": "^4.0.2",
29
- "multer": "^1.4.5-lts.2",
30
- "sequelize": "^6.37.7",
31
- "socket.io": "^4.8.1",
32
- "socket.io-client": "^4.8.1",
33
- "cafetap-escpos-usb": "gitlab:faigalizade/escpos-usb",
34
- "escpos": "^3.0.0-alpha.6",
35
- "escpos-network": "^3.0.0-alpha.5"
36
33
  }
37
34
  }
@@ -24,12 +24,6 @@ const getUsbPrinters = async () => {
24
24
  });
25
25
  usbDevice.close();
26
26
  }
27
- result.push({
28
- type: 'USB',
29
- name: 'Text',
30
- vendor_id: 123,
31
- product_id: 345
32
- });
33
27
 
34
28
  return result;
35
29
  }
@@ -99,14 +93,16 @@ const getNetworkDevices = async () => {
99
93
  router.get('/printers.get', async (req, res) => {
100
94
  let usbPrinters = await getUsbPrinters();
101
95
  let networkPrinters = await getNetworkDevices();
102
- axios.get(PROXY_TARGET + '/api/printers.get', {
96
+ const printers = [...usbPrinters, ...networkPrinters]
97
+ axios.post(PROXY_TARGET + '/api/printers.get', {
98
+ printers
99
+ },{
103
100
  headers: {...req.headers, host: new URL(PROXY_TARGET).host},
104
- }).then(data => {
105
- console.log(data.data);
101
+ }).then(({data}) => {
102
+ res.json(data);
103
+ }).catch(e => {
104
+ res.json([...usbPrinters, ...networkPrinters])
106
105
  })
107
-
108
-
109
- res.json([...usbPrinters, ...networkPrinters]);
110
106
  });
111
107
 
112
108
  router.post('/printers.print', (req, res) => {
@@ -117,11 +113,18 @@ router.post('/printers.print', (req, res) => {
117
113
  const image = req.body.content;
118
114
  const printer = new escpos.Printer(device, {});
119
115
  const imageBuffer = Buffer.from(image, 'base64');
116
+ const timeOut = req.body.timeout || 5000;
117
+
118
+ let sent = false;
120
119
 
121
120
  device.open((err) => {
122
121
  if (err) {
123
122
  console.error('Ошибка подключения к принтеру:', err);
124
- res.send(err).status(404);
123
+ sent = true;
124
+ res.json({
125
+ success: false,
126
+ error: err
127
+ })
125
128
  return;
126
129
  }
127
130
 
@@ -136,8 +139,19 @@ router.post('/printers.print', (req, res) => {
136
139
  printer.cut()
137
140
  .close();
138
141
 
139
- res.send('ok');
142
+ sent = true;
143
+ res.json({
144
+ success: true
145
+ })
140
146
  });
147
+ setTimeout(() => {
148
+ if (!sent) {
149
+ res.json({
150
+ success: false,
151
+ error: 'timeout'
152
+ })
153
+ }
154
+ }, timeOut);
141
155
  })
142
156
 
143
157
  module.exports = router;