w-converhp 2.0.1 → 2.0.3

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,11 @@ 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
+ * @param {String} [opt.tokenType='Bearer'] 輸入token類型字串,預設'Bearer'
79
80
  * @param {Integer} [opt.sizeSlice=1024*1024] 輸入切片上傳檔案之切片檔案大小整數,單位為Byte,預設為1024*1024
80
81
  * @param {Integer} [opt.retry=3] 輸入傳輸失敗重試次數整數,預設為3
81
- * @returns {Object} 回傳通訊物件,可使用函數execute、upload
82
+ * @returns {Object} 回傳事件物件,可使用函數execute、upload
82
83
  * @example
83
84
  *
84
85
  * import WConverhpClient from 'w-converhp/dist/w-converhp-client.umd.js'
@@ -200,6 +201,20 @@ function WConverhpClient(opt) {
200
201
  url = _url + '/' + apiName
201
202
  }
202
203
 
204
+ //getToken
205
+ let getToken = get(opt, 'getToken', null)
206
+ if (!isfun(getToken)) {
207
+ getToken = () => {
208
+ return ''
209
+ }
210
+ }
211
+
212
+ //tokenType
213
+ let tokenType = get(opt, 'tokenType')
214
+ if (!isestr(tokenType)) {
215
+ tokenType = 'Bearer'
216
+ }
217
+
203
218
  //sizeSlice
204
219
  let sizeSlice = get(opt, 'sizeSlice')
205
220
  if (!ispint(sizeSlice)) {
@@ -220,7 +235,7 @@ function WConverhpClient(opt) {
220
235
  let ee = evem() //new events.EventEmitter()
221
236
 
222
237
  //eeEmit
223
- function eeEmit(name, ...args) {
238
+ let eeEmit = (name, ...args) => {
224
239
  setTimeout(() => {
225
240
  ee.emit(name, ...args)
226
241
  }, 1)
@@ -253,7 +268,7 @@ function WConverhpClient(opt) {
253
268
  }
254
269
 
255
270
  //send
256
- function send(type, pkg, opt = {}) {
271
+ async function send(type, pkg, opt = {}) {
257
272
 
258
273
  //headers
259
274
  let headers = get(opt, 'headers')
@@ -264,13 +279,16 @@ function WConverhpClient(opt) {
264
279
 
265
280
  //dataType
266
281
  let dataType = get(opt, 'dataType', '')
267
- if (dataType !== 'blob' &amp;&amp; dataType !== 'obj' &amp;&amp; dataType !== 'fmd' &amp;&amp; dataType !== 'json') {
282
+ if (dataType !== 'blob' &amp;&amp; dataType !== 'fmd' &amp;&amp; dataType !== 'json') {
268
283
  dataType = 'blob'
269
284
  }
270
285
  // console.log('dataType', dataType)
271
286
 
272
287
  //cbProgress
273
288
  let cbProgress = get(opt, 'cbProgress')
289
+ if (!isfun(cbProgress)) {
290
+ cbProgress = () => {}
291
+ }
274
292
 
275
293
  //urlUse
276
294
  let urlUse = ''
@@ -286,7 +304,6 @@ function WConverhpClient(opt) {
286
304
  else {
287
305
  throw new Error(`invalid type[${type}]`)
288
306
  }
289
- // console.log('urlUse', urlUse)
290
307
 
291
308
  //pm
292
309
  let pm = genPm()
@@ -334,17 +351,24 @@ function WConverhpClient(opt) {
334
351
  }
335
352
  // console.log('ct', ct)
336
353
  }
354
+ else {
355
+ //browser會自動根據fmd的邊界boundary來設定
356
+ }
337
357
 
338
358
  //set dd
339
359
  dd = fmd
340
360
 
341
361
  }
342
362
  else if (dataType === 'json') {
363
+ //axios預設會將物件自動轉換為JSON, 此處指定Content-Type且強制轉, 避免可能問題
364
+
365
+ //set ct
366
+ ct = {
367
+ 'Content-Type': 'application/json',
368
+ }
369
+
343
370
  dd = JSON.stringify(pkg)
344
371
  }
345
- else if (dataType === 'obj') {
346
- dd = pkg
347
- }
348
372
  // console.log('dd', dd)
349
373
 
350
374
  //rt
@@ -354,12 +378,19 @@ function WConverhpClient(opt) {
354
378
  }
355
379
  // console.log('rt', rt)
356
380
 
381
+ //token
382
+ let token = getToken()
383
+ if (ispm(token)) {
384
+ token = await token
385
+ }
386
+
357
387
  //s
358
388
  let s = {
359
389
  method: 'POST',
360
390
  url: urlUse,
361
391
  data: dd,
362
392
  headers: {
393
+ Authorization: `${tokenType} ${token}`,
363
394
  ...ct,
364
395
  ...headers,
365
396
  },
@@ -379,9 +410,7 @@ function WConverhpClient(opt) {
379
410
  }
380
411
 
381
412
  //cbProgress
382
- if (isfun(cbProgress)) {
383
- cbProgress(Math.floor(r), loaded, 'upload')
384
- }
413
+ cbProgress(Math.floor(r), loaded, 'upload')
385
414
 
386
415
  },
387
416
  onDownloadProgress: function (ev) {
@@ -397,9 +426,7 @@ function WConverhpClient(opt) {
397
426
  }
398
427
 
399
428
  //cbProgress
400
- if (isfun(cbProgress)) {
401
- cbProgress(Math.floor(r), loaded, 'donwload')
402
- }
429
+ cbProgress(Math.floor(r), loaded, 'download')
403
430
 
404
431
  },
405
432
  }
@@ -435,7 +462,8 @@ function WConverhpClient(opt) {
435
462
  pm.resolve(data.success)
436
463
  }
437
464
  else if (haskey(data, 'error')) {
438
- pm.resolve(data.error)
465
+ eeEmit('error', data.error)
466
+ pm.reject(data.error)
439
467
  }
440
468
  else {
441
469
  // console.log('invalid data', data)
@@ -454,6 +482,10 @@ function WConverhpClient(opt) {
454
482
  //statusText, err
455
483
  let statusText = get(res, 'response.statusText') || get(res, 'message')
456
484
  let err = get(res, 'response.data') || get(res, 'stack')
485
+ // console.log(`get(res, 'response.statusText')`, get(res, 'response.statusText'))
486
+ // console.log(`get(res, 'message')`, get(res, 'message'))
487
+ // console.log(`get(res, 'response.data')`, get(res, 'response.data'))
488
+ // console.log(`get(res, 'stack')`, get(res, 'stack'))
457
489
 
458
490
  if (statusText) {
459
491
  // console.log('statusText', statusText)
@@ -526,7 +558,7 @@ function WConverhpClient(opt) {
526
558
  break
527
559
  }
528
560
  console.log(`retry n=${n}`)
529
- r = await fun(data, cbProgress)
561
+ r = await fun(type, data, cbProgress)
530
562
  }
531
563
 
532
564
  if (r.state === 'success') {
@@ -570,6 +602,29 @@ function WConverhpClient(opt) {
570
602
  let packageId = `${now2strp()}-${genID()}`
571
603
  // console.log('packageId', packageId)
572
604
 
605
+ //progCount, progWeightSlice
606
+ let progCount = 0
607
+ let progWeightSlice = 0.99 //上傳階段進度使用99%
608
+ // let progWeightMerge = 0.01 //合併階段進度使用1%
609
+
610
+ //cbProgressSlice
611
+ let cbProgressSlice = (perc, _psiz, dir) => {
612
+ if (dir === 'upload' &amp;&amp; perc === 100) {
613
+ progCount++
614
+ let r = progCount / chunkTotal
615
+ let prog = r * progWeightSlice * 100
616
+ let psiz = r * n
617
+ cbProgress(prog, psiz, 'upload')
618
+ }
619
+ }
620
+
621
+ //cbProgressMerge
622
+ let cbProgressMerge = (perc, _psiz, dir) => {
623
+ if (dir === 'download' &amp;&amp; perc === 100) {
624
+ cbProgress(100, n, 'upload')
625
+ }
626
+ }
627
+
573
628
  //upload slice
574
629
  for (let i = 0; i &lt; chunkTotal; i++) {
575
630
 
@@ -591,19 +646,19 @@ function WConverhpClient(opt) {
591
646
 
592
647
  //send slice
593
648
  // console.log(`uploading chunk[${i + 1}/${chunkTotal}] of packageId[${packageId}]...`)
594
- await send('slice', chunk, { headers: hd, dataType: 'blob', cbProgress })
649
+ await send('slice', chunk, { headers: hd, dataType: 'blob', cbProgress: cbProgressSlice })
595
650
  // console.log(`upload chunk[${i + 1}/${chunkTotal}] of packageId[${packageId}] done`, res)
596
651
 
597
652
  }
598
653
 
599
654
  //send merge
600
- // console.log(`merging tempId[${tempId}]...`)
655
+ console.log(`merging tempId[${tempId}]...`)
601
656
  let msg = {
602
657
  'filename': tempId,
603
658
  'chunk-total': chunkTotal,
604
659
  'package-id': packageId,
605
660
  }
606
- let resMg = await send('slicemerge', msg, { dataType: 'obj', cbProgress })
661
+ let resMg = await send('slicemerge', msg, { dataType: 'json', cbProgress: cbProgressMerge })
607
662
  // console.log(`merge tempId[${tempId}] done`, resMg)
608
663
 
609
664
  return resMg
@@ -627,7 +682,14 @@ function WConverhpClient(opt) {
627
682
  .then((msg) => {
628
683
  // console.log('msg', msg)
629
684
 
630
- //check
685
+ //check, 若為字串為錯誤訊息
686
+ if (isestr(msg)) {
687
+ state = 'error'
688
+ res = msg
689
+ return
690
+ }
691
+
692
+ //check, 若為非物件為非預期錯誤
631
693
  if (!iseobj(msg)) {
632
694
  console.log('msg is not an effective object', msg)
633
695
  state = 'error'
@@ -635,7 +697,7 @@ function WConverhpClient(opt) {
635
697
  return
636
698
  }
637
699
 
638
- //check, 預期msg格式為{func,input,output}, 但input會刪除
700
+ //check, 若不存在output為非預期錯誤, msg格式為{func,input,output}但input會刪除
639
701
  if (!haskey(msg, 'output')) {
640
702
  console.log('invalid msg.output', msg)
641
703
  state = 'error'
@@ -651,13 +713,6 @@ function WConverhpClient(opt) {
651
713
  res = msg
652
714
  })
653
715
 
654
- //r
655
- let r = {
656
- state,
657
- msg: res,
658
- }
659
- // console.log('sendData r', r)
660
-
661
716
  //check
662
717
  if (state === '') {
663
718
  // console.log('invalid state', r)
@@ -668,11 +723,11 @@ function WConverhpClient(opt) {
668
723
  //check
669
724
  if (state === 'error') {
670
725
  // console.log('send data error', r)
671
- eeEmit('error', `send data error`)
672
- return Promise.reject('send data error')
726
+ // eeEmit('error', res) //一般錯誤會嘗試n次, 每次也都會emit, 故此處不再基於已知state='error'時再emit
727
+ return Promise.reject(res)
673
728
  }
674
729
 
675
- return r.msg
730
+ return res
676
731
  }
677
732
 
678
733
  //upload
@@ -707,7 +762,7 @@ export default WConverhpClient
707
762
  <br class="clear">
708
763
 
709
764
  <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.
765
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Mar 30 2025 20:22:48 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
711
766
  </footer>
712
767
 
713
768
  <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 20:22:48 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 authorization = get(headers, 'authorization', '')
384
+ authorization = isestr(authorization) ? authorization : ''
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', authorization, 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 authorization = get(headers, 'authorization', '')
542
+ authorization = isestr(authorization) ? authorization : ''
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', authorization, 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 authorization = get(headers, 'authorization', '')
688
+ authorization = isestr(authorization) ? authorization : ''
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', authorization, 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 20:22:48 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 20:22:48 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.3",
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)