w-converhp 2.0.1 → 2.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.
@@ -46,8 +46,6 @@
46
46
  <section>
47
47
  <article>
48
48
  <pre class="prettyprint source linenums"><code>import axios from 'axios'
49
- // import * as FormData from 'form-data/lib/form_data.js'
50
- // import FormData from 'form-data'
51
49
  import get from 'lodash-es/get.js'
52
50
  import isWindow from 'wsemi/src/isWindow.mjs'
53
51
  import genPm from 'wsemi/src/genPm.mjs'
@@ -59,6 +57,7 @@ import isp0int from 'wsemi/src/isp0int.mjs'
59
57
  import isestr from 'wsemi/src/isestr.mjs'
60
58
  import isobj from 'wsemi/src/isobj.mjs'
61
59
  import iseobj from 'wsemi/src/iseobj.mjs'
60
+ import ispm from 'wsemi/src/ispm.mjs'
62
61
  import cint from 'wsemi/src/cint.mjs'
63
62
  import strright from 'wsemi/src/strright.mjs'
64
63
  import evem from 'wsemi/src/evem.mjs'
@@ -76,9 +75,10 @@ import now2strp from 'wsemi/src/now2strp.mjs'
76
75
  * @param {Object} opt 輸入設定參數物件
77
76
  * @param {String} [opt.url='http://localhost:8080'] 輸入Hapi伺服器網址,預設為'http://localhost:8080'
78
77
  * @param {String} [opt.apiName='api'] 輸入API名稱字串,預設'api'
78
+ * @param {Function} [opt.getToken=()=>''] 輸入取得使用者token的回調函數,預設()=>''
79
79
  * @param {Integer} [opt.sizeSlice=1024*1024] 輸入切片上傳檔案之切片檔案大小整數,單位為Byte,預設為1024*1024
80
80
  * @param {Integer} [opt.retry=3] 輸入傳輸失敗重試次數整數,預設為3
81
- * @returns {Object} 回傳通訊物件,可使用函數execute、upload
81
+ * @returns {Object} 回傳事件物件,可使用函數execute、upload
82
82
  * @example
83
83
  *
84
84
  * import WConverhpClient from 'w-converhp/dist/w-converhp-client.umd.js'
@@ -200,6 +200,14 @@ function WConverhpClient(opt) {
200
200
  url = _url + '/' + apiName
201
201
  }
202
202
 
203
+ //getToken
204
+ let getToken = get(opt, 'getToken', null)
205
+ if (!isfun(getToken)) {
206
+ getToken = () => {
207
+ return ''
208
+ }
209
+ }
210
+
203
211
  //sizeSlice
204
212
  let sizeSlice = get(opt, 'sizeSlice')
205
213
  if (!ispint(sizeSlice)) {
@@ -220,7 +228,7 @@ function WConverhpClient(opt) {
220
228
  let ee = evem() //new events.EventEmitter()
221
229
 
222
230
  //eeEmit
223
- function eeEmit(name, ...args) {
231
+ let eeEmit = (name, ...args) => {
224
232
  setTimeout(() => {
225
233
  ee.emit(name, ...args)
226
234
  }, 1)
@@ -253,7 +261,7 @@ function WConverhpClient(opt) {
253
261
  }
254
262
 
255
263
  //send
256
- function send(type, pkg, opt = {}) {
264
+ async function send(type, pkg, opt = {}) {
257
265
 
258
266
  //headers
259
267
  let headers = get(opt, 'headers')
@@ -264,13 +272,16 @@ function WConverhpClient(opt) {
264
272
 
265
273
  //dataType
266
274
  let dataType = get(opt, 'dataType', '')
267
- if (dataType !== 'blob' &amp;&amp; dataType !== 'obj' &amp;&amp; dataType !== 'fmd' &amp;&amp; dataType !== 'json') {
275
+ if (dataType !== 'blob' &amp;&amp; dataType !== 'fmd' &amp;&amp; dataType !== 'json') {
268
276
  dataType = 'blob'
269
277
  }
270
278
  // console.log('dataType', dataType)
271
279
 
272
280
  //cbProgress
273
281
  let cbProgress = get(opt, 'cbProgress')
282
+ if (!isfun(cbProgress)) {
283
+ cbProgress = () => {}
284
+ }
274
285
 
275
286
  //urlUse
276
287
  let urlUse = ''
@@ -286,7 +297,6 @@ function WConverhpClient(opt) {
286
297
  else {
287
298
  throw new Error(`invalid type[${type}]`)
288
299
  }
289
- // console.log('urlUse', urlUse)
290
300
 
291
301
  //pm
292
302
  let pm = genPm()
@@ -334,17 +344,24 @@ function WConverhpClient(opt) {
334
344
  }
335
345
  // console.log('ct', ct)
336
346
  }
347
+ else {
348
+ //browser會自動根據fmd的邊界boundary來設定
349
+ }
337
350
 
338
351
  //set dd
339
352
  dd = fmd
340
353
 
341
354
  }
342
355
  else if (dataType === 'json') {
356
+ //axios預設會將物件自動轉換為JSON, 此處指定Content-Type且強制轉, 避免可能問題
357
+
358
+ //set ct
359
+ ct = {
360
+ 'Content-Type': 'application/json',
361
+ }
362
+
343
363
  dd = JSON.stringify(pkg)
344
364
  }
345
- else if (dataType === 'obj') {
346
- dd = pkg
347
- }
348
365
  // console.log('dd', dd)
349
366
 
350
367
  //rt
@@ -354,12 +371,19 @@ function WConverhpClient(opt) {
354
371
  }
355
372
  // console.log('rt', rt)
356
373
 
374
+ //token
375
+ let token = getToken()
376
+ if (ispm(token)) {
377
+ token = await token
378
+ }
379
+
357
380
  //s
358
381
  let s = {
359
382
  method: 'POST',
360
383
  url: urlUse,
361
384
  data: dd,
362
385
  headers: {
386
+ Authorization: `Bearer ${token}`,
363
387
  ...ct,
364
388
  ...headers,
365
389
  },
@@ -379,9 +403,7 @@ function WConverhpClient(opt) {
379
403
  }
380
404
 
381
405
  //cbProgress
382
- if (isfun(cbProgress)) {
383
- cbProgress(Math.floor(r), loaded, 'upload')
384
- }
406
+ cbProgress(Math.floor(r), loaded, 'upload')
385
407
 
386
408
  },
387
409
  onDownloadProgress: function (ev) {
@@ -397,9 +419,7 @@ function WConverhpClient(opt) {
397
419
  }
398
420
 
399
421
  //cbProgress
400
- if (isfun(cbProgress)) {
401
- cbProgress(Math.floor(r), loaded, 'donwload')
402
- }
422
+ cbProgress(Math.floor(r), loaded, 'download')
403
423
 
404
424
  },
405
425
  }
@@ -435,7 +455,8 @@ function WConverhpClient(opt) {
435
455
  pm.resolve(data.success)
436
456
  }
437
457
  else if (haskey(data, 'error')) {
438
- pm.resolve(data.error)
458
+ eeEmit('error', data.error)
459
+ pm.reject(data.error)
439
460
  }
440
461
  else {
441
462
  // console.log('invalid data', data)
@@ -454,6 +475,10 @@ function WConverhpClient(opt) {
454
475
  //statusText, err
455
476
  let statusText = get(res, 'response.statusText') || get(res, 'message')
456
477
  let err = get(res, 'response.data') || get(res, 'stack')
478
+ // console.log(`get(res, 'response.statusText')`, get(res, 'response.statusText'))
479
+ // console.log(`get(res, 'message')`, get(res, 'message'))
480
+ // console.log(`get(res, 'response.data')`, get(res, 'response.data'))
481
+ // console.log(`get(res, 'stack')`, get(res, 'stack'))
457
482
 
458
483
  if (statusText) {
459
484
  // console.log('statusText', statusText)
@@ -526,7 +551,7 @@ function WConverhpClient(opt) {
526
551
  break
527
552
  }
528
553
  console.log(`retry n=${n}`)
529
- r = await fun(data, cbProgress)
554
+ r = await fun(type, data, cbProgress)
530
555
  }
531
556
 
532
557
  if (r.state === 'success') {
@@ -570,6 +595,29 @@ function WConverhpClient(opt) {
570
595
  let packageId = `${now2strp()}-${genID()}`
571
596
  // console.log('packageId', packageId)
572
597
 
598
+ //progCount, progWeightSlice
599
+ let progCount = 0
600
+ let progWeightSlice = 0.99 //上傳階段進度使用99%
601
+ // let progWeightMerge = 0.01 //合併階段進度使用1%
602
+
603
+ //cbProgressSlice
604
+ let cbProgressSlice = (perc, _psiz, dir) => {
605
+ if (dir === 'upload' &amp;&amp; perc === 100) {
606
+ progCount++
607
+ let r = progCount / chunkTotal
608
+ let prog = r * progWeightSlice * 100
609
+ let psiz = r * n
610
+ cbProgress(prog, psiz, 'upload')
611
+ }
612
+ }
613
+
614
+ //cbProgressMerge
615
+ let cbProgressMerge = (perc, _psiz, dir) => {
616
+ if (dir === 'download' &amp;&amp; perc === 100) {
617
+ cbProgress(100, n, 'upload')
618
+ }
619
+ }
620
+
573
621
  //upload slice
574
622
  for (let i = 0; i &lt; chunkTotal; i++) {
575
623
 
@@ -591,19 +639,19 @@ function WConverhpClient(opt) {
591
639
 
592
640
  //send slice
593
641
  // console.log(`uploading chunk[${i + 1}/${chunkTotal}] of packageId[${packageId}]...`)
594
- await send('slice', chunk, { headers: hd, dataType: 'blob', cbProgress })
642
+ await send('slice', chunk, { headers: hd, dataType: 'blob', cbProgress: cbProgressSlice })
595
643
  // console.log(`upload chunk[${i + 1}/${chunkTotal}] of packageId[${packageId}] done`, res)
596
644
 
597
645
  }
598
646
 
599
647
  //send merge
600
- // console.log(`merging tempId[${tempId}]...`)
648
+ console.log(`merging tempId[${tempId}]...`)
601
649
  let msg = {
602
650
  'filename': tempId,
603
651
  'chunk-total': chunkTotal,
604
652
  'package-id': packageId,
605
653
  }
606
- let resMg = await send('slicemerge', msg, { dataType: 'obj', cbProgress })
654
+ let resMg = await send('slicemerge', msg, { dataType: 'json', cbProgress: cbProgressMerge })
607
655
  // console.log(`merge tempId[${tempId}] done`, resMg)
608
656
 
609
657
  return resMg
@@ -627,7 +675,14 @@ function WConverhpClient(opt) {
627
675
  .then((msg) => {
628
676
  // console.log('msg', msg)
629
677
 
630
- //check
678
+ //check, 若為字串為錯誤訊息
679
+ if (isestr(msg)) {
680
+ state = 'error'
681
+ res = msg
682
+ return
683
+ }
684
+
685
+ //check, 若為非物件為非預期錯誤
631
686
  if (!iseobj(msg)) {
632
687
  console.log('msg is not an effective object', msg)
633
688
  state = 'error'
@@ -635,7 +690,7 @@ function WConverhpClient(opt) {
635
690
  return
636
691
  }
637
692
 
638
- //check, 預期msg格式為{func,input,output}, 但input會刪除
693
+ //check, 若不存在output為非預期錯誤, msg格式為{func,input,output}但input會刪除
639
694
  if (!haskey(msg, 'output')) {
640
695
  console.log('invalid msg.output', msg)
641
696
  state = 'error'
@@ -651,13 +706,6 @@ function WConverhpClient(opt) {
651
706
  res = msg
652
707
  })
653
708
 
654
- //r
655
- let r = {
656
- state,
657
- msg: res,
658
- }
659
- // console.log('sendData r', r)
660
-
661
709
  //check
662
710
  if (state === '') {
663
711
  // console.log('invalid state', r)
@@ -668,11 +716,11 @@ function WConverhpClient(opt) {
668
716
  //check
669
717
  if (state === 'error') {
670
718
  // console.log('send data error', r)
671
- eeEmit('error', `send data error`)
672
- return Promise.reject('send data error')
719
+ // eeEmit('error', res) //一般錯誤會嘗試n次, 每次也都會emit, 故此處不再基於已知state='error'時再emit
720
+ return Promise.reject(res)
673
721
  }
674
722
 
675
- return r.msg
723
+ return res
676
724
  }
677
725
 
678
726
  //upload
@@ -707,7 +755,7 @@ export default WConverhpClient
707
755
  <br class="clear">
708
756
 
709
757
  <footer>
710
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Mar 05 2025 11:15:07 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
758
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Mar 30 2025 19:42:30 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
711
759
  </footer>
712
760
 
713
761
  <script>prettyPrint();</script>
@@ -650,7 +650,7 @@
650
650
 
651
651
 
652
652
  <div class="param-desc">
653
- <p>回傳通訊物件,可監聽事件execute、upload、handler</p>
653
+ <p>回傳事件物件,可監聽事件execute、upload、handler</p>
654
654
  </div>
655
655
 
656
656
 
@@ -709,7 +709,7 @@
709
709
  <br class="clear">
710
710
 
711
711
  <footer>
712
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Mar 05 2025 11:15:07 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
712
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Mar 30 2025 19:42:30 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
713
713
  </footer>
714
714
 
715
715
  <script>prettyPrint();</script>
@@ -85,7 +85,7 @@ import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
85
85
  * @param {Integer} [opt.delayForBasic=0] 輸入基本API用延遲響應時間,單位ms,預設0
86
86
  * @param {Integer} [opt.delayForSlice=100] 輸入切片上傳檔案API用延遲響應時間,單位ms,預設100
87
87
  * @param {Boolean} [opt.serverHapi=null] 輸入外部提供Hapi伺服器物件,預設null
88
- * @returns {Object} 回傳通訊物件,可監聽事件execute、upload、handler
88
+ * @returns {Object} 回傳事件物件,可監聽事件execute、upload、handler
89
89
  * @example
90
90
  *
91
91
  * import _ from 'lodash-es'
@@ -241,8 +241,8 @@ function WConverhpServer(opt = {}) {
241
241
 
242
242
  //create server
243
243
  server = Hapi.server({
244
- port,
245
244
  //host: 'localhost',
245
+ port,
246
246
  routes: {
247
247
  cors: {
248
248
  origin: corsOrigins, //Access-Control-Allow-Origin
@@ -257,7 +257,7 @@ function WConverhpServer(opt = {}) {
257
257
  let ee = evem() //new events.EventEmitter()
258
258
 
259
259
  //eeEmit
260
- function eeEmit(name, ...args) {
260
+ let eeEmit = (name, ...args) => {
261
261
  setTimeout(() => {
262
262
  ee.emit(name, ...args)
263
263
  }, 1)
@@ -356,7 +356,7 @@ function WConverhpServer(opt = {}) {
356
356
  maxBytes: 1024 * 1024 * 1024 * 1024, //預設為1mb, 調整至1tb, 也就是給予3次方
357
357
  maxParts: 1000 * 1000 * 1000, //預設為1000, 給予3次方
358
358
  timeout: false, //避免請求未完成時中斷
359
- output: 'stream',
359
+ output: 'stream', //前端用blob與application/octet-stream傳
360
360
  parse: false,
361
361
  },
362
362
  timeout: {
@@ -379,20 +379,31 @@ function WConverhpServer(opt = {}) {
379
379
  // console.log('query', query)
380
380
 
381
381
  //token
382
- let token = get(query, 'token', '')
382
+ // let token = get(query, 'token', '')
383
+ let token = get(headers, 'authorization', '')
384
+ token = isestr(token) ? token : ''
383
385
 
384
386
  //check
385
387
  if (true) {
386
388
 
387
389
  //funCheck
388
- let m = funCheck({ token, headers, query })
390
+ let m = funCheck({ apiType: 'main', token, headers, query })
389
391
  if (ispm(m)) {
390
392
  m = await m
391
393
  }
392
394
 
393
395
  //check
394
396
  if (m !== true) {
395
- return res.response({ error: 'permission denied' }).code(400)
397
+
398
+ //u8aOut
399
+ let out = {
400
+ error: 'permission denied',
401
+ }
402
+ let u8aOut = obj2u8arr(out)
403
+ // console.log('main u8aOut', u8aOut)
404
+
405
+ // console.log('main return permission denied')
406
+ return responseU8aStream(res, u8aOut)
396
407
  }
397
408
 
398
409
  }
@@ -503,7 +514,7 @@ function WConverhpServer(opt = {}) {
503
514
  maxBytes: 1024 * 1024 * 1024 * 1024, //預設為1mb, 調整至1tb, 也就是給予3次方
504
515
  maxParts: 1000 * 1000 * 1000, //預設為1000, 給予3次方
505
516
  timeout: false, //避免請求未完成時中斷
506
- output: 'stream',
517
+ output: 'stream', //前端用blob與application/octet-stream傳
507
518
  parse: false,
508
519
  },
509
520
  timeout: {
@@ -526,20 +537,31 @@ function WConverhpServer(opt = {}) {
526
537
  // console.log('query', query)
527
538
 
528
539
  //token
529
- let token = get(query, 'token', '')
540
+ // let token = get(query, 'token', '')
541
+ let token = get(headers, 'authorization', '')
542
+ token = isestr(token) ? token : ''
530
543
 
531
544
  //check
532
545
  if (true) {
533
546
 
534
547
  //funCheck
535
- let m = funCheck({ token, headers, query })
548
+ let m = funCheck({ apiType: 'slice', token, headers, query })
536
549
  if (ispm(m)) {
537
550
  m = await m
538
551
  }
539
552
 
540
553
  //check
541
554
  if (m !== true) {
542
- return res.response({ error: 'permission denied' }).code(400)
555
+
556
+ //u8aOut
557
+ let out = {
558
+ error: 'permission denied',
559
+ }
560
+ let u8aOut = obj2u8arr(out)
561
+ // console.log('slice u8aOut', u8aOut)
562
+
563
+ // console.log('slice return permission denied')
564
+ return responseU8aStream(res, u8aOut)
543
565
  }
544
566
 
545
567
  }
@@ -638,7 +660,8 @@ function WConverhpServer(opt = {}) {
638
660
  maxBytes: 1024 * 1024 * 1024 * 1024, //預設為1mb, 調整至1tb, 也就是給予3次方
639
661
  maxParts: 1000 * 1000 * 1000, //預設為1000, 給予3次方
640
662
  timeout: false, //避免請求未完成時中斷
641
- parse: true,
663
+ // output: 'stream',
664
+ parse: true, //前端送obj過來
642
665
  },
643
666
  timeout: {
644
667
  socket: false, //避免socket自動關閉
@@ -660,20 +683,31 @@ function WConverhpServer(opt = {}) {
660
683
  // console.log('query', query)
661
684
 
662
685
  //token
663
- let token = get(query, 'token', '')
686
+ // let token = get(query, 'token', '')
687
+ let token = get(headers, 'authorization', '')
688
+ token = isestr(token) ? token : ''
664
689
 
665
690
  //check
666
691
  if (true) {
667
692
 
668
693
  //funCheck
669
- let m = funCheck({ token, headers, query })
694
+ let m = funCheck({ apiType: 'merge', token, headers, query })
670
695
  if (ispm(m)) {
671
696
  m = await m
672
697
  }
673
698
 
674
699
  //check
675
700
  if (m !== true) {
676
- return res.response({ error: 'permission denied' }).code(400)
701
+
702
+ //u8aOut
703
+ let out = {
704
+ error: 'permission denied',
705
+ }
706
+ let u8aOut = obj2u8arr(out)
707
+ // console.log('mergeu8aOut', u8aOut)
708
+
709
+ // console.log('merge return permission denied')
710
+ return responseU8aStream(res, u8aOut)
677
711
  }
678
712
 
679
713
  }
@@ -731,7 +765,6 @@ function WConverhpServer(opt = {}) {
731
765
  //check
732
766
  if (!fsIsFile(pathFileChunk)) {
733
767
  // console.log(`pathFileChunk[${pathFileChunk}] is not a file`)
734
- // return res.response({ error: `Missing chunk ${i} of filename[${filename}]` }).code(400)
735
768
  throw new Error(`Missing chunk ${i} of filename[${filename}]`)
736
769
  }
737
770
 
@@ -878,7 +911,7 @@ export default WConverhpServer
878
911
  <br class="clear">
879
912
 
880
913
  <footer>
881
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Mar 05 2025 11:15:07 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
914
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Mar 30 2025 19:42:30 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
882
915
  </footer>
883
916
 
884
917
  <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 Mar 05 2025 11:15:07 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 Sun Mar 30 2025 19:42:30 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,13 +1,13 @@
1
1
  {
2
2
  "name": "w-converhp",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "main": "dist/w-converhp-server.umd.js",
5
5
  "dependencies": {
6
- "@hapi/hapi": "^21.3.12",
6
+ "@hapi/hapi": "^21.4.0",
7
7
  "@hapi/inert": "^7.1.0",
8
- "axios": "^1.8.1",
8
+ "axios": "^1.8.4",
9
9
  "lodash-es": "^4.17.21",
10
- "wsemi": "^1.7.70"
10
+ "wsemi": "^1.7.74"
11
11
  },
12
12
  "devDependencies": {
13
13
  "form-data": "^4.0.2",
package/scla.mjs CHANGED
@@ -8,11 +8,18 @@ let opt = {
8
8
  FormData,
9
9
  url: 'http://localhost:8080',
10
10
  apiName: 'api',
11
+ getToken: () => {
12
+ return 'token-for-test'
13
+ },
11
14
  }
12
15
 
13
16
  //new
14
17
  let wo = new WConverhpClient(opt)
15
18
 
19
+ wo.on('error', function(err) {
20
+ console.log(`error`, err)
21
+ })
22
+
16
23
  async function execute(name, u8a) {
17
24
 
18
25
  //p
@@ -30,7 +37,12 @@ async function execute(name, u8a) {
30
37
  //execute
31
38
  await wo.execute('add', { p },
32
39
  function (prog, p, m) {
33
- console.log('client web: execute: prog', prog, p, m)
40
+ if (m === 'upload') {
41
+ console.log('client web: execute: prog', prog * 0.5, p, m)
42
+ }
43
+ if (m === 'download') {
44
+ console.log('client web: execute: prog', 50 + prog * 0.5, p, m)
45
+ }
34
46
  })
35
47
  .then(function(r) {
36
48
  console.log('client web: execute: add', r)
package/sclb.mjs CHANGED
@@ -8,11 +8,18 @@ let opt = {
8
8
  FormData,
9
9
  url: 'http://localhost:8080',
10
10
  apiName: 'api',
11
+ getToken: () => {
12
+ return 'token-for-test'
13
+ },
11
14
  }
12
15
 
13
16
  //new
14
17
  let wo = new WConverhpClient(opt)
15
18
 
19
+ wo.on('error', function(err) {
20
+ console.log(`error`, err)
21
+ })
22
+
16
23
  async function execute(name, u8a) {
17
24
 
18
25
  //p
@@ -30,7 +37,12 @@ async function execute(name, u8a) {
30
37
  //execute
31
38
  await wo.execute('add', { p },
32
39
  function (prog, p, m) {
33
- console.log('client web: execute: prog', prog, p, m)
40
+ if (m === 'upload') {
41
+ console.log('client web: execute: prog', prog * 0.5, p, m)
42
+ }
43
+ if (m === 'download') {
44
+ console.log('client web: execute: prog', 50 + prog * 0.5, p, m)
45
+ }
34
46
  })
35
47
  .then(function(r) {
36
48
  console.log('client web: execute: add', r)
package/sclc.mjs CHANGED
@@ -8,11 +8,18 @@ let opt = {
8
8
  FormData,
9
9
  url: 'http://localhost:8080',
10
10
  apiName: 'api',
11
+ getToken: () => {
12
+ return 'token-for-test'
13
+ },
11
14
  }
12
15
 
13
16
  //new
14
17
  let wo = new WConverhpClient(opt)
15
18
 
19
+ wo.on('error', function(err) {
20
+ console.log(`error`, err)
21
+ })
22
+
16
23
  function uploadLargeFile() {
17
24
  let core = async() => {
18
25
 
@@ -23,7 +30,10 @@ function uploadLargeFile() {
23
30
 
24
31
  await wo.upload('1000mb.7z', u8a,
25
32
  function (prog, p, m) {
26
- console.log('client web: upload: prog', prog, p, m)
33
+ // console.log('client web: upload: prog', prog, p, m)
34
+ if (m === 'upload') {
35
+ console.log('client web: upload: prog', prog)
36
+ }
27
37
  })
28
38
  .then(function(res) {
29
39
  console.log('client web: upload: then', res)