w-converhp 2.0.10 → 2.0.12

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.
@@ -51,6 +51,7 @@ import Hapi from '@hapi/hapi'
51
51
  import Inert from '@hapi/inert' //提供靜態檔案
52
52
  import get from 'lodash-es/get.js'
53
53
  import genPm from 'wsemi/src/genPm.mjs'
54
+ import evem from 'wsemi/src/evem.mjs'
54
55
  import iseobj from 'wsemi/src/iseobj.mjs'
55
56
  import isestr from 'wsemi/src/isestr.mjs'
56
57
  import isp0int from 'wsemi/src/isp0int.mjs'
@@ -58,9 +59,10 @@ import ispint from 'wsemi/src/ispint.mjs'
58
59
  import isearr from 'wsemi/src/isearr.mjs'
59
60
  import isbol from 'wsemi/src/isbol.mjs'
60
61
  import isfun from 'wsemi/src/isfun.mjs'
62
+ import isnum from 'wsemi/src/isnum.mjs'
61
63
  import ispm from 'wsemi/src/ispm.mjs'
62
64
  import cint from 'wsemi/src/cint.mjs'
63
- import evem from 'wsemi/src/evem.mjs'
65
+ import haskey from 'wsemi/src/haskey.mjs'
64
66
  import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
65
67
  import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
66
68
  import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
@@ -157,6 +159,44 @@ import mergeFiles from './mergeFiles.wk.umd.js'
157
159
  * }
158
160
  *
159
161
  * })
162
+ * wo.on('download', (input, pm) => {
163
+ * console.log(`Server[port:${opt.port}]: download`, input)
164
+ *
165
+ * try {
166
+ * ms.push({ 'download': input })
167
+ *
168
+ * //fp
169
+ * let fp = `./test/1mb.7z`
170
+ *
171
+ * //streamRead
172
+ * let streamRead = fs.createReadStream(fp)
173
+ *
174
+ * //fileName
175
+ * let fileName = `1mb.7z`
176
+ *
177
+ * //fileSize
178
+ * let stats = fs.statSync(fp)
179
+ * let fileSize = stats.size
180
+ *
181
+ * //fileType
182
+ * let fileType = 'application/x-7z-compressed'
183
+ *
184
+ * //output
185
+ * let output = {
186
+ * streamRead,
187
+ * fileName,
188
+ * fileSize,
189
+ * fileType,
190
+ * }
191
+ *
192
+ * pm.resolve(output)
193
+ * }
194
+ * catch (err) {
195
+ * console.log('download error', err)
196
+ * pm.reject('download error')
197
+ * }
198
+ *
199
+ * })
160
200
  * wo.on('handler', (data) => {
161
201
  * // console.log(`Server[port:${opt.port}]: handler`, data)
162
202
  * })
@@ -188,8 +228,11 @@ function WConverhpServer(opt = {}) {
188
228
  apiName = 'api'
189
229
  }
190
230
 
191
- //apiSliceName
192
- let apiSliceName = `${apiName}slc`
231
+ //apiUploadSliceName
232
+ let apiUploadSliceName = `${apiName}slc`
233
+
234
+ //apiDownloadName
235
+ let apiDownloadName = `${apiName}dw`
193
236
 
194
237
  //pathUploadTemp
195
238
  let pathUploadTemp = get(opt, 'pathUploadTemp')
@@ -307,7 +350,7 @@ function WConverhpServer(opt = {}) {
307
350
 
308
351
  //procUpload
309
352
  async function procUpload(input) {
310
- //console.log('procUpload', data)
353
+ //console.log('procUpload', input)
311
354
 
312
355
  //pm, pmm
313
356
  let pm = genPm()
@@ -327,7 +370,7 @@ function WConverhpServer(opt = {}) {
327
370
 
328
371
  if (true) {
329
372
 
330
- //upload 上傳檔案
373
+ //upload, 上傳檔案
331
374
  eeEmit('upload', input, pmm)
332
375
 
333
376
  }
@@ -335,8 +378,38 @@ function WConverhpServer(opt = {}) {
335
378
  return pm
336
379
  }
337
380
 
381
+ //procDownload
382
+ async function procDownload(input) {
383
+ // console.log('procDownload', input)
384
+
385
+ //pm, pmm
386
+ let pm = genPm()
387
+ let pmm = genPm()
388
+
389
+ //重新處理回傳結果
390
+ pmm
391
+ .then((output) => {
392
+
393
+ //resolve
394
+ pm.resolve(output)
395
+
396
+ })
397
+ .catch((err) => {
398
+ pm.reject(err)
399
+ })
400
+
401
+ if (true) {
402
+
403
+ //download, 下載檔案
404
+ eeEmit('download', input, pmm)
405
+
406
+ }
407
+
408
+ return pm
409
+ }
410
+
338
411
  //responseU8aStream
339
- function responseU8aStream(res, u8a) {
412
+ function responseU8aStream(res, u8a, opt = {}) {
340
413
 
341
414
  //stream
342
415
  let smr = new stream.Readable()
@@ -344,12 +417,32 @@ function WConverhpServer(opt = {}) {
344
417
  smr.push(u8a)
345
418
  smr.push(null)
346
419
 
420
+ //returnType
421
+ let returnType = get(opt, 'returnType', '')
422
+
423
+ //returnMsg
424
+ let returnMsg = get(opt, 'returnMsg', '')
425
+
347
426
  return res.response(smr)
427
+ .header('Return-Type', returnType)
428
+ .header('Return-Msg', returnMsg)
348
429
  .header('Cache-Control', 'no-cache, no-store, must-revalidate')
349
430
  .header('Content-Type', 'application/octet-stream')
350
431
  .header('Content-Length', smr.readableLength)
351
432
  }
352
433
 
434
+ //responseU8aStreamWithError
435
+ function responseU8aStreamWithError(res, msg) {
436
+
437
+ //u8aOut
438
+ let u8aOut = obj2u8arr({
439
+ error: msg,
440
+ })
441
+ // console.log('download u8aOut', u8aOut)
442
+
443
+ return responseU8aStream(res, u8aOut, { returnType: 'error', returnMsg: msg })
444
+ }
445
+
353
446
  //apiMain
354
447
  let apiMain = {
355
448
  path: `/${apiName}`,
@@ -359,7 +452,7 @@ function WConverhpServer(opt = {}) {
359
452
  maxBytes: 1024 * 1024 * 1024 * 1024, //預設為1mb, 調整至1tb, 也就是給予3次方
360
453
  maxParts: 1000 * 1000 * 1000, //預設為1000, 給予3次方
361
454
  timeout: false, //避免請求未完成時中斷
362
- output: 'stream', //前端用blob與application/octet-stream
455
+ output: 'stream', //代表前端用stream傳至伺服器(Content-Type為application/octet-stream)
363
456
  parse: false,
364
457
  },
365
458
  timeout: {
@@ -381,8 +474,7 @@ function WConverhpServer(opt = {}) {
381
474
  query = iseobj(query) ? query : ''
382
475
  // console.log('query', query)
383
476
 
384
- //token
385
- // let token = get(query, 'token', '')
477
+ //authorization
386
478
  let authorization = get(headers, 'authorization', '')
387
479
  authorization = isestr(authorization) ? authorization : ''
388
480
 
@@ -397,16 +489,7 @@ function WConverhpServer(opt = {}) {
397
489
 
398
490
  //check
399
491
  if (m !== true) {
400
-
401
- //u8aOut
402
- let out = {
403
- error: 'permission denied',
404
- }
405
- let u8aOut = obj2u8arr(out)
406
- // console.log('main u8aOut', u8aOut)
407
-
408
- // console.log('main return permission denied')
409
- return responseU8aStream(res, u8aOut)
492
+ return responseU8aStreamWithError(res, 'permission denied')
410
493
  }
411
494
 
412
495
  }
@@ -424,21 +507,15 @@ function WConverhpServer(opt = {}) {
424
507
  //pm
425
508
  let pm = genPm()
426
509
 
427
- //totalSize, chunks
428
- // let totalSize = 0
510
+ //chunks
429
511
  let chunks = []
430
-
431
- //smw
432
512
  let smw = new stream.Writable({
433
513
  write(chunk, encoding, cb) {
434
514
  // console.log('receive payload', chunk)
435
515
 
436
- // //totalSize
437
- // totalSize += chunk.length
438
-
439
516
  //push
440
517
  chunks.push(chunk)
441
- // console.log('chunk.length', chunk.length, 'totalSize', totalSize)
518
+ // console.log('chunk.length', chunk.length)
442
519
 
443
520
  //setTimeout, 延遲觸發cb
444
521
  setTimeout(() => {
@@ -455,7 +532,7 @@ function WConverhpServer(opt = {}) {
455
532
  req.payload.on('end', () => {
456
533
  // console.log(`receive payload done`)
457
534
 
458
- //concat
535
+ //fileBuffer
459
536
  let fileBuffer = Buffer.concat(chunks)
460
537
  // console.log('fileBuffer', fileBuffer, fileBuffer.length)
461
538
 
@@ -491,12 +568,18 @@ function WConverhpServer(opt = {}) {
491
568
 
492
569
  //procDeal
493
570
  let out = {}
571
+ let returnType = ''
572
+ let returnMsg = ''
494
573
  await procDeal(inp)
495
574
  .then(function(msg) {
496
575
  out.success = msg
576
+ returnType = 'success'
577
+ returnMsg = 'need to parse'
497
578
  })
498
579
  .catch(function(msg) {
499
580
  out.error = msg
581
+ returnType = 'error'
582
+ returnMsg = 'need to parse'
500
583
  })
501
584
  // console.log('out', out)
502
585
 
@@ -504,20 +587,20 @@ function WConverhpServer(opt = {}) {
504
587
  let u8aOut = obj2u8arr(out)
505
588
  // console.log('u8aOut', u8aOut)
506
589
 
507
- return responseU8aStream(res, u8aOut)
590
+ return responseU8aStream(res, u8aOut, { returnType, returnMsg })
508
591
  },
509
592
  }
510
593
 
511
- //apiSlice
512
- let apiSlice = {
513
- path: `/${apiSliceName}`,
594
+ //apiUploadSlice
595
+ let apiUploadSlice = {
596
+ path: `/${apiUploadSliceName}`,
514
597
  method: 'POST',
515
598
  options: {
516
599
  payload: {
517
600
  maxBytes: 1024 * 1024 * 1024 * 1024, //預設為1mb, 調整至1tb, 也就是給予3次方
518
601
  maxParts: 1000 * 1000 * 1000, //預設為1000, 給予3次方
519
602
  timeout: false, //避免請求未完成時中斷
520
- output: 'stream', //前端用blob與application/octet-stream
603
+ output: 'stream', //代表前端用stream傳至伺服器(Content-Type為application/octet-stream)
521
604
  parse: false,
522
605
  },
523
606
  timeout: {
@@ -539,8 +622,7 @@ function WConverhpServer(opt = {}) {
539
622
  query = iseobj(query) ? query : ''
540
623
  // console.log('query', query)
541
624
 
542
- //token
543
- // let token = get(query, 'token', '')
625
+ //authorization
544
626
  let authorization = get(headers, 'authorization', '')
545
627
  authorization = isestr(authorization) ? authorization : ''
546
628
 
@@ -548,30 +630,21 @@ function WConverhpServer(opt = {}) {
548
630
  if (true) {
549
631
 
550
632
  //verifyConn
551
- let m = verifyConn({ apiType: 'slice', authorization, headers, query })
633
+ let m = verifyConn({ apiType: 'upload-slice', authorization, headers, query })
552
634
  if (ispm(m)) {
553
635
  m = await m
554
636
  }
555
637
 
556
638
  //check
557
639
  if (m !== true) {
558
-
559
- //u8aOut
560
- let out = {
561
- error: 'permission denied',
562
- }
563
- let u8aOut = obj2u8arr(out)
564
- // console.log('slice u8aOut', u8aOut)
565
-
566
- // console.log('slice return permission denied')
567
- return responseU8aStream(res, u8aOut)
640
+ return responseU8aStreamWithError(res, 'permission denied')
568
641
  }
569
642
 
570
643
  }
571
644
 
572
645
  //eeEmit
573
646
  eeEmit('handler', {
574
- api: 'apiSlice',
647
+ api: 'apiUploadSlice',
575
648
  headers,
576
649
  query,
577
650
  })
@@ -637,12 +710,18 @@ function WConverhpServer(opt = {}) {
637
710
 
638
711
  //receive
639
712
  let out = {}
713
+ let returnType = ''
714
+ let returnMsg = ''
640
715
  await receive()
641
716
  .then(function(msg) {
642
717
  out.success = msg
718
+ returnType = 'success'
719
+ returnMsg = 'need to parse'
643
720
  })
644
721
  .catch(function(msg) {
645
722
  out.error = msg
723
+ returnType = 'error'
724
+ returnMsg = 'need to parse'
646
725
  })
647
726
  // console.log('out', out)
648
727
 
@@ -650,13 +729,13 @@ function WConverhpServer(opt = {}) {
650
729
  let u8aOut = obj2u8arr(out)
651
730
  // console.log('u8aOut', u8aOut)
652
731
 
653
- return responseU8aStream(res, u8aOut)
732
+ return responseU8aStream(res, u8aOut, { returnType, returnMsg })
654
733
  },
655
734
  }
656
735
 
657
- //apiSliceMerge
658
- let apiSliceMerge = {
659
- path: `/${apiSliceName}m`,
736
+ //apiUploadSliceMerge
737
+ let apiUploadSliceMerge = {
738
+ path: `/${apiUploadSliceName}m`,
660
739
  method: 'POST',
661
740
  options: {
662
741
  payload: {
@@ -685,8 +764,7 @@ function WConverhpServer(opt = {}) {
685
764
  query = iseobj(query) ? query : ''
686
765
  // console.log('query', query)
687
766
 
688
- //token
689
- // let token = get(query, 'token', '')
767
+ //authorization
690
768
  let authorization = get(headers, 'authorization', '')
691
769
  authorization = isestr(authorization) ? authorization : ''
692
770
 
@@ -694,30 +772,21 @@ function WConverhpServer(opt = {}) {
694
772
  if (true) {
695
773
 
696
774
  //verifyConn
697
- let m = verifyConn({ apiType: 'merge', authorization, headers, query })
775
+ let m = verifyConn({ apiType: 'upload-slice-merge', authorization, headers, query })
698
776
  if (ispm(m)) {
699
777
  m = await m
700
778
  }
701
779
 
702
780
  //check
703
781
  if (m !== true) {
704
-
705
- //u8aOut
706
- let out = {
707
- error: 'permission denied',
708
- }
709
- let u8aOut = obj2u8arr(out)
710
- // console.log('mergeu8aOut', u8aOut)
711
-
712
- // console.log('merge return permission denied')
713
- return responseU8aStream(res, u8aOut)
782
+ return responseU8aStreamWithError(res, 'permission denied')
714
783
  }
715
784
 
716
785
  }
717
786
 
718
787
  //eeEmit
719
788
  eeEmit('handler', {
720
- api: 'apiSliceMerge',
789
+ api: 'apiUploadSliceMerge',
721
790
  headers,
722
791
  query,
723
792
  })
@@ -761,12 +830,18 @@ function WConverhpServer(opt = {}) {
761
830
 
762
831
  //core
763
832
  let out = {}
833
+ let returnType = ''
834
+ let returnMsg = ''
764
835
  await core()
765
836
  .then(function(msg) {
766
837
  out.success = msg
838
+ returnType = 'success'
839
+ returnMsg = 'need to parse'
767
840
  })
768
841
  .catch(function(msg) {
769
842
  out.error = msg
843
+ returnType = 'error'
844
+ returnMsg = 'need to parse'
770
845
  })
771
846
  // console.log('out', out)
772
847
 
@@ -774,7 +849,118 @@ function WConverhpServer(opt = {}) {
774
849
  let u8aOut = obj2u8arr(out)
775
850
  // console.log('u8aOut', u8aOut)
776
851
 
777
- return responseU8aStream(res, u8aOut)
852
+ return responseU8aStream(res, u8aOut, { returnType, returnMsg })
853
+ },
854
+ }
855
+
856
+ //apiDownload
857
+ let apiDownload = {
858
+ path: `/${apiDownloadName}`,
859
+ method: 'POST',
860
+ options: {
861
+ payload: {
862
+ maxBytes: 1024 * 1024 * 1024 * 1024, //預設為1mb, 調整至1tb, 也就是給予3次方
863
+ maxParts: 1000 * 1000 * 1000, //預設為1000, 給予3次方
864
+ timeout: false, //避免請求未完成時中斷
865
+ // output: 'stream',
866
+ parse: true, //前端送obj過來
867
+ },
868
+ timeout: {
869
+ server: false, //關閉伺服器超時
870
+ socket: false, //關閉socket超時
871
+ },
872
+ },
873
+ handler: async function (req, res) {
874
+ // console.log(req, res)
875
+ // console.log('payload', req.payload)
876
+
877
+ //headers
878
+ let headers = get(req, 'headers')
879
+ headers = iseobj(headers) ? headers : ''
880
+ // console.log('headers', headers)
881
+
882
+ //query
883
+ let query = get(req, 'query')
884
+ query = iseobj(query) ? query : ''
885
+ // console.log('query', query)
886
+
887
+ //authorization
888
+ let authorization = get(headers, 'authorization', '')
889
+ authorization = isestr(authorization) ? authorization : ''
890
+
891
+ //check
892
+ if (true) {
893
+
894
+ //verifyConn
895
+ let m = verifyConn({ apiType: 'download', authorization, headers, query })
896
+ if (ispm(m)) {
897
+ m = await m
898
+ }
899
+
900
+ //check
901
+ if (m !== true) {
902
+ return responseU8aStreamWithError(res, 'permission denied')
903
+ }
904
+
905
+ }
906
+
907
+ //eeEmit
908
+ eeEmit('handler', {
909
+ api: 'apiDownload',
910
+ headers,
911
+ query,
912
+ })
913
+
914
+ //fileId, 從payload接收
915
+ let fileId = get(req, 'payload.fileId', '')
916
+ // console.log('fileId', fileId)
917
+
918
+ //check
919
+ if (!isestr(fileId)) {
920
+ // console.log('invalid fileId in payload')
921
+ return responseU8aStreamWithError(res, 'invalid fileId in payload')
922
+ }
923
+
924
+ //inp
925
+ let inp = { fileId }
926
+
927
+ //procDownload
928
+ let out = {}
929
+ await procDownload(inp)
930
+ .then(function(msg) {
931
+ out.success = msg
932
+ })
933
+ .catch(function(msg) {
934
+ out.error = msg
935
+ })
936
+ // console.log('out', out)
937
+
938
+ //return
939
+ if (haskey(out, 'error')) {
940
+ // console.log('out.error', out.error)
941
+ return responseU8aStreamWithError(res, `can not get file from fileId[${fileId}]`)
942
+ }
943
+
944
+ //streamRead, fileName, fileSize, fileType
945
+ let r = get(out, 'success')
946
+ let streamRead = get(r, 'streamRead')
947
+ let fileName = get(r, 'fileName')
948
+ if (!isestr(fileName)) {
949
+ return res.response({ error: `invalid fileName` }).code(400)
950
+ }
951
+ let fileSize = get(r, 'fileSize')
952
+ if (!isnum(fileSize)) {
953
+ return res.response({ error: `invalid fileSize` }).code(400)
954
+ }
955
+ let fileType = get(r, 'fileType')
956
+ if (!isestr(fileType)) {
957
+ return res.response({ error: `invalid fileType` }).code(400)
958
+ }
959
+
960
+ return res.response(streamRead)
961
+ .type(fileType)
962
+ .header('Content-Disposition', `attachment; filename="${fileName}"`)
963
+ .header('Content-Length', fileSize)
778
964
  },
779
965
  }
780
966
 
@@ -807,8 +993,9 @@ function WConverhpServer(opt = {}) {
807
993
  apiRoutes = [
808
994
  ...apiRoutes,
809
995
  apiMain,
810
- apiSlice,
811
- apiSliceMerge,
996
+ apiUploadSlice,
997
+ apiUploadSliceMerge,
998
+ apiDownload,
812
999
  ]
813
1000
  }
814
1001
 
@@ -824,8 +1011,8 @@ function WConverhpServer(opt = {}) {
824
1011
 
825
1012
  //start
826
1013
  if (get(opt, 'serverHapi')) {
827
- // opt.serverHapi.route([apiMain, apiSlice, apiSliceMerge])
828
- server.route([apiMain, apiSlice, apiSliceMerge])
1014
+ // opt.serverHapi.route([apiMain, apiUploadSlice, apiUploadSliceMerge, apiDownload])
1015
+ server.route([apiMain, apiUploadSlice, apiUploadSliceMerge, apiDownload])
829
1016
  }
830
1017
  else {
831
1018
  startServer()
@@ -858,7 +1045,7 @@ export default WConverhpServer
858
1045
  <br class="clear">
859
1046
 
860
1047
  <footer>
861
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Apr 02 2025 12:17:28 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1048
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Tue Apr 08 2025 12:28:45 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
862
1049
  </footer>
863
1050
 
864
1051
  <script>prettyPrint();</script>
package/docs/index.html CHANGED
@@ -71,7 +71,7 @@
71
71
  <br class="clear">
72
72
 
73
73
  <footer>
74
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Apr 02 2025 12:17:28 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
74
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Tue Apr 08 2025 12:28:45 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
75
75
  </footer>
76
76
 
77
77
  <script>prettyPrint();</script>
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "w-converhp",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "main": "dist/w-converhp-server.umd.js",
5
5
  "dependencies": {
6
6
  "@hapi/hapi": "^21.4.0",
7
7
  "@hapi/inert": "^7.1.0",
8
8
  "axios": "^1.8.4",
9
9
  "lodash-es": "^4.17.21",
10
- "wsemi": "^1.7.74"
10
+ "wsemi": "^1.7.75"
11
11
  },
12
12
  "devDependencies": {
13
13
  "form-data": "^4.0.2",
14
- "w-package-tools": "^1.0.85"
14
+ "w-package-tools": "^1.0.87"
15
15
  },
16
16
  "scripts": {
17
17
  "@hapi/hapi": "^20.2.1",
package/sclc.mjs CHANGED
@@ -25,13 +25,15 @@ wo.on('error', (err) => {
25
25
  function uploadLargeFile() {
26
26
  let core = async() => {
27
27
 
28
+ let fsz = '1000mb' //0mb 10mb 100mb 1000mb
29
+
28
30
  //u8a
29
- let u8a = new Uint8Array(fs.readFileSync('../_data/0mb.7z')) //1000mb
31
+ let u8a = new Uint8Array(fs.readFileSync(`../_data/${fsz}.7z`)) //後端並無blob格式, 用fs讀有檔案大小上限
30
32
  console.log('u8a.length', u8a.length)
31
33
  // console.log('uploadLargeFile u8a', u8a)
32
34
  ms.push({ 'upload u8a.length': u8a.length })
33
35
 
34
- await wo.upload('0mb.7z', u8a,
36
+ await wo.upload(`${fsz}.7z`, u8a,
35
37
  function ({ prog, p, m }) {
36
38
  // console.log('client web: upload: prog', prog, p, m)
37
39
  if (m === 'upload') {
package/scld.mjs ADDED
@@ -0,0 +1,54 @@
1
+ import w from 'wsemi'
2
+ import FormData from 'form-data'
3
+ import WConverhpClient from './src/WConverhpClient.mjs'
4
+
5
+
6
+ let ms = []
7
+
8
+ let opt = {
9
+ FormData,
10
+ url: 'http://localhost:8080',
11
+ apiName: 'api',
12
+ getToken: () => {
13
+ return 'token-for-test'
14
+ },
15
+ }
16
+
17
+ //new
18
+ let wo = new WConverhpClient(opt)
19
+
20
+ wo.on('error', (err) => {
21
+ console.log(`error`, err)
22
+ })
23
+
24
+ function downloadLargeFile() {
25
+ let core = async() => {
26
+
27
+ await wo.download('id-for-file',
28
+ function ({ prog, p, m }) {
29
+ // console.log('client web: download: prog', prog, p, m)
30
+ if (m === 'download') {
31
+ console.log('client web: download: prog', prog)
32
+ }
33
+ },
34
+ {
35
+ fdDownload: './',
36
+ })
37
+ .then(function(res) {
38
+ console.log('client web: download: then', res)
39
+ ms.push({ 'download output': res })
40
+ })
41
+ .catch(function (err) {
42
+ console.log('client web: download: catch', err)
43
+ })
44
+
45
+ console.log('ms', ms)
46
+
47
+ }
48
+ core()
49
+ }
50
+
51
+ downloadLargeFile()
52
+
53
+
54
+ //node --experimental-modules scld.mjs