flexbiz-server 12.5.9 → 12.5.11

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
@@ -2,7 +2,7 @@
2
2
  "name": "flexbiz-server",
3
3
  "main": "./server/app.js",
4
4
  "description": "Flexible Server",
5
- "version": "12.5.9",
5
+ "version": "12.5.11",
6
6
  "author": {
7
7
  "name": "Van Truong Pham",
8
8
  "email": "invncur@gmail.com"
@@ -195,10 +195,21 @@ class controllerRPT {
195
195
  res.setHeader('Content-Disposition', 'attachment; filename="' + rptId + '".xlsx');
196
196
  //convert sang buffer nếu data là một object có type ==Buffer
197
197
  let data = result;
198
- if(data?.type == "Buffer" && data?.data){
199
- console.log("[controllerRPT] convert data to Buffer...");
198
+ console.log(data);
199
+
200
+ if (Buffer.isBuffer(data)) {
201
+ // OK
202
+ }
203
+ else if (data?.type === 'Buffer' && Array.isArray(data.data)) {
200
204
  data = Buffer.from(data.data);
201
205
  }
206
+ else if (typeof data === 'string') {
207
+ data = Buffer.from(data, 'base64');
208
+ }
209
+ else {
210
+ return res.status(400).send({error:'Dữ liệu không hợp lệ'});
211
+ }
212
+
202
213
  res.setHeader('Content-Length', data.length);
203
214
  res.end(data);
204
215
  break;
@@ -208,9 +219,19 @@ class controllerRPT {
208
219
  res.setHeader('Content-Disposition', 'attachment; filename="' + rptId + '".docx');
209
220
  //convert sang buffer nếu data là một object có type ==Buffer
210
221
  let data = result;
211
- if(data?.type == "Buffer" && data?.data){
222
+
223
+ if (Buffer.isBuffer(data)) {
224
+ // OK
225
+ }
226
+ else if (data?.type === 'Buffer' && Array.isArray(data.data)) {
212
227
  data = Buffer.from(data.data);
213
228
  }
229
+ else if (typeof data === 'string') {
230
+ data = Buffer.from(data, 'base64');
231
+ }
232
+ else {
233
+ return res.status(400).send({error:'Dữ liệu không hợp lệ'});
234
+ }
214
235
 
215
236
  res.setHeader('Content-Length', data.length);
216
237
  res.end(data);
@@ -232,10 +253,20 @@ class controllerRPT {
232
253
  res.setHeader('Content-Disposition', 'attachment; filename="' + rptId + '".xlsx');
233
254
  //convert sang buffer nếu data là một object có type ==Buffer
234
255
  let data = result;
235
- if(data?.type == "Buffer" && data?.data){
236
- console.log("[controllerRPT] convert data to Buffer...");
256
+
257
+ if (Buffer.isBuffer(data)) {
258
+ // OK
259
+ }
260
+ else if (data?.type === 'Buffer' && Array.isArray(data.data)) {
237
261
  data = Buffer.from(data.data);
238
262
  }
263
+ else if (typeof data === 'string') {
264
+ data = Buffer.from(data, 'base64');
265
+ }
266
+ else {
267
+ return res.status(400).send({error:'Dữ liệu không hợp lệ'});
268
+ }
269
+
239
270
  res.setHeader('Content-Length', data.length);
240
271
  res.end(data);
241
272
  break;
@@ -245,9 +276,20 @@ class controllerRPT {
245
276
  res.setHeader('Content-Disposition', 'attachment; filename="' + rptId + '".docx');
246
277
  //convert sang buffer nếu data là một object có type ==Buffer
247
278
  let data = result;
248
- if(data?.type == "Buffer" && data?.data){
279
+
280
+ if (Buffer.isBuffer(data)) {
281
+ // OK
282
+ }
283
+ else if (data?.type === 'Buffer' && Array.isArray(data.data)) {
249
284
  data = Buffer.from(data.data);
250
285
  }
286
+ else if (typeof data === 'string') {
287
+ data = Buffer.from(data, 'base64');
288
+ }
289
+ else {
290
+ return res.status(400).send({error:'Dữ liệu không hợp lệ'});
291
+ }
292
+
251
293
  res.setHeader('Content-Length', data.length);
252
294
  res.end(data);
253
295
  break;