w-converhp 2.0.47 → 2.0.48
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/README.md +1 -1
- package/dist/w-converhp-client.umd.js +2 -2
- package/dist/w-converhp-client.umd.js.map +1 -1
- package/dist/w-converhp-server.umd.js +1 -1
- package/docs/WConverhpClient.html +2 -2
- package/docs/WConverhpClient.mjs.html +177 -196
- package/docs/WConverhpServer.html +1 -1
- package/docs/WConverhpServer.mjs.html +8 -8
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/WConverhpClient.mjs +176 -195
- package/src/WConverhpServer.mjs +7 -7
- package/srv.mjs +1 -1
package/src/WConverhpClient.mjs
CHANGED
|
@@ -12,12 +12,14 @@ import isobj from 'wsemi/src/isobj.mjs'
|
|
|
12
12
|
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
13
13
|
import ispm from 'wsemi/src/ispm.mjs'
|
|
14
14
|
import cint from 'wsemi/src/cint.mjs'
|
|
15
|
+
import dig from 'wsemi/src/dig.mjs'
|
|
15
16
|
import strright from 'wsemi/src/strright.mjs'
|
|
16
17
|
import b642str from 'wsemi/src/b642str.mjs'
|
|
17
18
|
import blob2u8arr from 'wsemi/src/blob2u8arr.mjs'
|
|
18
19
|
import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
|
|
19
20
|
import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
|
|
20
21
|
import pmConvertResolve from 'wsemi/src/pmConvertResolve.mjs'
|
|
22
|
+
import delay from 'wsemi/src/delay.mjs'
|
|
21
23
|
import getFileXxHash from 'wsemi/src/getFileXxHash.mjs'
|
|
22
24
|
|
|
23
25
|
|
|
@@ -136,7 +138,7 @@ function WConverhpClient(opt) {
|
|
|
136
138
|
//retry
|
|
137
139
|
let retry = get(opt, 'retry')
|
|
138
140
|
if (!isp0int(retry)) {
|
|
139
|
-
retry =
|
|
141
|
+
retry = 10
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
//env
|
|
@@ -159,22 +161,22 @@ function WConverhpClient(opt) {
|
|
|
159
161
|
//urlUse
|
|
160
162
|
let urlUse = ''
|
|
161
163
|
if (type === 'basic') {
|
|
162
|
-
urlUse = `${url}/main`
|
|
164
|
+
urlUse = `${url}/main`
|
|
163
165
|
}
|
|
164
166
|
else if (type === 'upload-controller') {
|
|
165
|
-
urlUse = `${url}/ulctr`
|
|
167
|
+
urlUse = `${url}/ulctr`
|
|
166
168
|
}
|
|
167
169
|
else if (type === 'slice') {
|
|
168
|
-
urlUse = `${url}/slc`
|
|
170
|
+
urlUse = `${url}/slc`
|
|
169
171
|
}
|
|
170
172
|
else if (type === 'download-get-filename') {
|
|
171
|
-
urlUse = `${url}/dwgfn`
|
|
173
|
+
urlUse = `${url}/dwgfn`
|
|
172
174
|
}
|
|
173
175
|
else if (type === 'download-get') {
|
|
174
|
-
urlUse = `${url}/dwgf`
|
|
176
|
+
urlUse = `${url}/dwgf`
|
|
175
177
|
}
|
|
176
178
|
else if (type === 'download') {
|
|
177
|
-
urlUse = `${url}/dw`
|
|
179
|
+
urlUse = `${url}/dw`
|
|
178
180
|
}
|
|
179
181
|
else {
|
|
180
182
|
throw new Error(`invalid type[${type}]`)
|
|
@@ -184,7 +186,7 @@ function WConverhpClient(opt) {
|
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
//res2u8arr
|
|
187
|
-
|
|
189
|
+
let res2u8arr = async(bb) => {
|
|
188
190
|
//blob(in browser) or buffer(in nodejs) to u8a
|
|
189
191
|
let u8a
|
|
190
192
|
if (env === 'browser') {
|
|
@@ -197,7 +199,7 @@ function WConverhpClient(opt) {
|
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
//u8arr2bb
|
|
200
|
-
|
|
202
|
+
let u8arr2bb = (u8a) => {
|
|
201
203
|
//u8a to blob(in browser) or buffer(in nodejs)
|
|
202
204
|
let bb
|
|
203
205
|
if (env === 'browser') {
|
|
@@ -210,7 +212,7 @@ function WConverhpClient(opt) {
|
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
//send
|
|
213
|
-
|
|
215
|
+
let send = async(type, pkg, opt = {}) => {
|
|
214
216
|
|
|
215
217
|
//headers
|
|
216
218
|
let headers = get(opt, 'headers')
|
|
@@ -317,54 +319,6 @@ function WConverhpClient(opt) {
|
|
|
317
319
|
token = await token
|
|
318
320
|
}
|
|
319
321
|
|
|
320
|
-
//s
|
|
321
|
-
let s = {
|
|
322
|
-
method: 'POST',
|
|
323
|
-
url: urlUse,
|
|
324
|
-
data: dd,
|
|
325
|
-
headers: {
|
|
326
|
-
Authorization: `${tokenType} ${token}`,
|
|
327
|
-
...ct,
|
|
328
|
-
...headers,
|
|
329
|
-
},
|
|
330
|
-
timeout: 60 * 60 * 1000, //1hr
|
|
331
|
-
maxContentLength: Infinity, //1024 * 1024 * 1024, Infinity //axios於nodejs中會限制內容大小故需改為無限
|
|
332
|
-
maxBodyLength: Infinity, //1024 * 1024 * 1024, Infinity //axios於nodejs中會限制內容大小故需改為無限
|
|
333
|
-
responseType: rt,
|
|
334
|
-
onUploadProgress: function(ev) {
|
|
335
|
-
//console.log('onUploadProgress', ev)
|
|
336
|
-
|
|
337
|
-
//r
|
|
338
|
-
let r = 0
|
|
339
|
-
let loaded = ev.loaded
|
|
340
|
-
let total = ev.total
|
|
341
|
-
if (ispint(total)) {
|
|
342
|
-
r = (loaded * 100) / total
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
//cbProgress
|
|
346
|
-
cbProgress({ prog: Math.floor(r), p: loaded, m: 'upload' })
|
|
347
|
-
|
|
348
|
-
},
|
|
349
|
-
onDownloadProgress: function (ev) {
|
|
350
|
-
// console.log('onDownloadProgress', ev)
|
|
351
|
-
|
|
352
|
-
//r
|
|
353
|
-
let r = 0
|
|
354
|
-
let loaded = ev.loaded
|
|
355
|
-
// let total = ev.srcElement.getResponseHeader('Content-length') //若需要得知下載進度, 需於伺服器回傳時提供Content-length
|
|
356
|
-
let total = ev.total
|
|
357
|
-
if (ispint(total)) {
|
|
358
|
-
r = (loaded * 100) / total
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
//cbProgress
|
|
362
|
-
cbProgress({ prog: Math.floor(r), p: loaded, m: 'download' })
|
|
363
|
-
|
|
364
|
-
},
|
|
365
|
-
}
|
|
366
|
-
// console.log('s', s)
|
|
367
|
-
|
|
368
322
|
//getFilenameByHeader
|
|
369
323
|
let getFilenameByHeader = (contentDisposition) => {
|
|
370
324
|
let fn = 'unknow'
|
|
@@ -378,7 +332,7 @@ function WConverhpClient(opt) {
|
|
|
378
332
|
}
|
|
379
333
|
|
|
380
334
|
//downloadStream
|
|
381
|
-
let downloadStream = async
|
|
335
|
+
let downloadStream = async(res) => {
|
|
382
336
|
// console.log('res.headers', res.headers)
|
|
383
337
|
|
|
384
338
|
//pm
|
|
@@ -476,61 +430,151 @@ function WConverhpClient(opt) {
|
|
|
476
430
|
return pm
|
|
477
431
|
}
|
|
478
432
|
|
|
479
|
-
//
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
433
|
+
//s
|
|
434
|
+
let s = {
|
|
435
|
+
method: 'POST',
|
|
436
|
+
url: urlUse,
|
|
437
|
+
data: dd,
|
|
438
|
+
headers: {
|
|
439
|
+
Authorization: `${tokenType} ${token}`,
|
|
440
|
+
...ct,
|
|
441
|
+
...headers,
|
|
442
|
+
},
|
|
443
|
+
timeout: 60 * 60 * 1000, //1hr
|
|
444
|
+
maxContentLength: Infinity, //1024 * 1024 * 1024, Infinity //axios於nodejs中會限制內容大小故需改為無限
|
|
445
|
+
maxBodyLength: Infinity, //1024 * 1024 * 1024, Infinity //axios於nodejs中會限制內容大小故需改為無限
|
|
446
|
+
responseType: rt,
|
|
447
|
+
onUploadProgress: function(ev) {
|
|
448
|
+
//console.log('onUploadProgress', ev)
|
|
449
|
+
|
|
450
|
+
//r
|
|
451
|
+
let r = 0
|
|
452
|
+
let loaded = ev.loaded
|
|
453
|
+
let total = ev.total
|
|
454
|
+
if (ispint(total)) {
|
|
455
|
+
r = (loaded * 100) / total
|
|
494
456
|
}
|
|
495
457
|
|
|
496
|
-
//
|
|
497
|
-
|
|
498
|
-
// console.log('bb', bb)
|
|
458
|
+
//cbProgress
|
|
459
|
+
cbProgress({ prog: Math.floor(r), p: loaded, m: 'upload' })
|
|
499
460
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
// console.log('
|
|
461
|
+
},
|
|
462
|
+
onDownloadProgress: function (ev) {
|
|
463
|
+
// console.log('onDownloadProgress', ev)
|
|
503
464
|
|
|
504
|
-
//
|
|
505
|
-
let
|
|
506
|
-
|
|
465
|
+
//r
|
|
466
|
+
let r = 0
|
|
467
|
+
let loaded = ev.loaded
|
|
468
|
+
// let total = ev.srcElement.getResponseHeader('Content-length') //若需要得知下載進度, 需於伺服器回傳時提供Content-length
|
|
469
|
+
let total = ev.total
|
|
470
|
+
if (ispint(total)) {
|
|
471
|
+
r = (loaded * 100) / total
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
//cbProgress
|
|
475
|
+
cbProgress({ prog: Math.floor(r), p: loaded, m: 'download' })
|
|
476
|
+
|
|
477
|
+
},
|
|
478
|
+
}
|
|
479
|
+
// console.log('s', s)
|
|
480
|
+
|
|
481
|
+
//callApiCore, 處理axios成功then時訊息, catch時直接向外傳遞
|
|
482
|
+
let callApiCore = async() => {
|
|
483
|
+
|
|
484
|
+
//axios, catch時直接向外傳遞
|
|
485
|
+
let res = await axios(s)
|
|
486
|
+
|
|
487
|
+
//check, download時直接轉由downloadStream處理res, catch時直接向外傳遞
|
|
488
|
+
if (type === 'download') {
|
|
489
|
+
return await downloadStream(res)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
//bb
|
|
493
|
+
let bb = get(res, 'data')
|
|
494
|
+
// console.log('bb', bb)
|
|
495
|
+
|
|
496
|
+
//res2u8arr, catch時直接向外傳遞
|
|
497
|
+
let u8a = await res2u8arr(bb)
|
|
498
|
+
// console.log('u8a', u8a)
|
|
499
|
+
|
|
500
|
+
//u8arr2obj
|
|
501
|
+
let data = u8arr2obj(u8a)
|
|
502
|
+
// console.log('data', data)
|
|
503
|
+
|
|
504
|
+
//check
|
|
505
|
+
if (!iseobj(data)) {
|
|
506
|
+
eeEmit('error', `data is not an effective object`)
|
|
507
|
+
return Promise.reject(`data is not an effective object`)
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
//分離伺服器資料的success或error
|
|
511
|
+
if (haskey(data, 'success')) {
|
|
512
|
+
return Promise.resolve(data.success)
|
|
513
|
+
}
|
|
514
|
+
else if (haskey(data, 'error')) {
|
|
515
|
+
eeEmit('error', data.error)
|
|
516
|
+
return Promise.reject(data.error)
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
eeEmit('error', `data does not contain success or error`)
|
|
520
|
+
return Promise.reject(`data does not contain success or error`)
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
//callApi, 處理callApiCore失敗catch時retry
|
|
526
|
+
let callApi = async() => {
|
|
527
|
+
|
|
528
|
+
//pmConvertResolve
|
|
529
|
+
let fun = pmConvertResolve(callApiCore)
|
|
530
|
+
|
|
531
|
+
//fun
|
|
532
|
+
let r = await fun(s)
|
|
533
|
+
// console.log('r', r)
|
|
534
|
+
|
|
535
|
+
//while
|
|
536
|
+
let maxRetry = 10
|
|
537
|
+
let baseDelay = 1000 //初始延遲為1秒
|
|
538
|
+
let ratio = Math.pow(180000 / baseDelay, 1 / (maxRetry - 1)) //1.888
|
|
539
|
+
let n = 0
|
|
540
|
+
while (r.state === 'error') {
|
|
541
|
+
|
|
542
|
+
//add
|
|
543
|
+
n += 1
|
|
507
544
|
|
|
508
545
|
//check
|
|
509
|
-
if (
|
|
510
|
-
|
|
511
|
-
eeEmit('error', `data is not an effective object`)
|
|
512
|
-
pm.reject(`data is not an effective object`)
|
|
513
|
-
return
|
|
546
|
+
if (n > retry) {
|
|
547
|
+
break
|
|
514
548
|
}
|
|
515
549
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
else if (haskey(data, 'error')) {
|
|
521
|
-
eeEmit('error', data.error)
|
|
522
|
-
pm.reject(data.error)
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
// console.log('invalid data', data)
|
|
526
|
-
eeEmit('error', `invalid data`)
|
|
527
|
-
pm.reject(`invalid data`)
|
|
528
|
-
}
|
|
550
|
+
//delay
|
|
551
|
+
let t = Math.round(baseDelay * Math.pow(ratio, n - 1))
|
|
552
|
+
console.log(`wait ${dig(t / 1000, 1)}(second) to retry...`)
|
|
553
|
+
await delay(t)
|
|
529
554
|
|
|
555
|
+
//retry
|
|
556
|
+
console.log(`retry n=${n}...`)
|
|
557
|
+
r = await fun(s)
|
|
558
|
+
// console.log(`retry n=${n} done`)
|
|
559
|
+
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (r.state === 'success') {
|
|
563
|
+
return r.msg
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
return Promise.reject(r.msg)
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
//callApi
|
|
571
|
+
await callApi()
|
|
572
|
+
.then((res) => {
|
|
573
|
+
pm.resolve(res)
|
|
530
574
|
})
|
|
531
|
-
.catch(async
|
|
575
|
+
.catch(async(res) => {
|
|
532
576
|
// console.log('axios catch', res.toJSON())
|
|
533
|
-
//Network Error除可能是網路斷線之外, 可能被瀏覽器外掛封鎖阻擋,
|
|
577
|
+
//Network Error除可能是網路斷線之外, 可能被瀏覽器外掛封鎖阻擋, 亦可能因硬碟空間不足無法下載被瀏覽器拒絕
|
|
534
578
|
|
|
535
579
|
//data
|
|
536
580
|
let data = null
|
|
@@ -572,7 +616,7 @@ function WConverhpClient(opt) {
|
|
|
572
616
|
}
|
|
573
617
|
|
|
574
618
|
//sendPkg
|
|
575
|
-
|
|
619
|
+
let sendPkg = async(type, data, cbProgress) => {
|
|
576
620
|
|
|
577
621
|
//bb
|
|
578
622
|
let bb = null
|
|
@@ -597,35 +641,8 @@ function WConverhpClient(opt) {
|
|
|
597
641
|
return res
|
|
598
642
|
}
|
|
599
643
|
|
|
600
|
-
//sendData
|
|
601
|
-
async function sendData(type, data, cbProgress) {
|
|
602
|
-
|
|
603
|
-
//fun
|
|
604
|
-
let fun = pmConvertResolve(sendPkg)
|
|
605
|
-
|
|
606
|
-
//sendPkg
|
|
607
|
-
let r = await fun(type, data, cbProgress)
|
|
608
|
-
|
|
609
|
-
let n = 0
|
|
610
|
-
while (r.state === 'error') {
|
|
611
|
-
n += 1
|
|
612
|
-
if (n > retry) {
|
|
613
|
-
break
|
|
614
|
-
}
|
|
615
|
-
console.log(`retry n=${n}`)
|
|
616
|
-
r = await fun(type, data, cbProgress)
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
if (r.state === 'success') {
|
|
620
|
-
return r.msg
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
return Promise.reject(r.msg)
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
644
|
//calcHash
|
|
628
|
-
|
|
645
|
+
let calcHash = async(inp) => {
|
|
629
646
|
|
|
630
647
|
//bb
|
|
631
648
|
let bb = null
|
|
@@ -644,7 +661,7 @@ function WConverhpClient(opt) {
|
|
|
644
661
|
}
|
|
645
662
|
|
|
646
663
|
//sendDataSlice
|
|
647
|
-
|
|
664
|
+
let sendDataSlice = async(fileTotalName, bb, cbProgress) => {
|
|
648
665
|
|
|
649
666
|
//n
|
|
650
667
|
let n = 0
|
|
@@ -816,65 +833,29 @@ function WConverhpClient(opt) {
|
|
|
816
833
|
//chunk
|
|
817
834
|
let chunk = bb.slice(start, end)
|
|
818
835
|
|
|
819
|
-
//
|
|
820
|
-
let
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
'chunk-index': i,
|
|
825
|
-
'chunk-total': chunkTotal,
|
|
826
|
-
'package-id': packageId,
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
//send slice
|
|
830
|
-
let resSl = await send('slice', chunk, {
|
|
831
|
-
headers: hd,
|
|
832
|
-
dataType: 'blob',
|
|
833
|
-
cbProgress: (msg) => {
|
|
834
|
-
// console.log('cbProgress', msg)
|
|
835
|
-
// let perc = msg.prog
|
|
836
|
-
// let dir = msg.m
|
|
837
|
-
// if (dir === 'upload' && perc === 100) {
|
|
838
|
-
// }
|
|
839
|
-
}
|
|
840
|
-
})
|
|
841
|
-
// console.log('resSl', resSl)
|
|
842
|
-
|
|
843
|
-
//cbProgressSlice, 因其內有累加progCount, 實際代表是須成功傳輸後才能計算與回應外部進度, 故不能直接用於send的opt.cbProgress
|
|
844
|
-
cbProgressSlice()
|
|
845
|
-
|
|
846
|
-
return resSl
|
|
836
|
+
//hd
|
|
837
|
+
let hd = { //用header傳key與value時, key不分大小寫, 故使用kebabCase
|
|
838
|
+
'chunk-index': i,
|
|
839
|
+
'chunk-total': chunkTotal,
|
|
840
|
+
'package-id': packageId,
|
|
847
841
|
}
|
|
848
842
|
|
|
849
|
-
//
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
while (r.state === 'error') {
|
|
860
|
-
n += 1
|
|
861
|
-
if (n > retry) {
|
|
862
|
-
break
|
|
863
|
-
}
|
|
864
|
-
console.log(`retry n=${n}`)
|
|
865
|
-
r = await fun()
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
if (r.state === 'success') {
|
|
869
|
-
return r.msg
|
|
843
|
+
//send slice
|
|
844
|
+
await send('slice', chunk, {
|
|
845
|
+
headers: hd,
|
|
846
|
+
dataType: 'blob',
|
|
847
|
+
cbProgress: (msg) => {
|
|
848
|
+
// console.log('cbProgress', msg)
|
|
849
|
+
// let perc = msg.prog
|
|
850
|
+
// let dir = msg.m
|
|
851
|
+
// if (dir === 'upload' && perc === 100) {
|
|
852
|
+
// }
|
|
870
853
|
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
}
|
|
874
|
-
}
|
|
854
|
+
})
|
|
855
|
+
// console.log('resSl', resSl)
|
|
875
856
|
|
|
876
|
-
//
|
|
877
|
-
|
|
857
|
+
//cbProgressSlice, 因其內有累加progCount, 實際代表是須成功傳輸後才能計算與回應外部進度, 故不能直接用於send的opt.cbProgress
|
|
858
|
+
cbProgressSlice()
|
|
878
859
|
|
|
879
860
|
}
|
|
880
861
|
|
|
@@ -950,7 +931,7 @@ function WConverhpClient(opt) {
|
|
|
950
931
|
}
|
|
951
932
|
|
|
952
933
|
//execute
|
|
953
|
-
|
|
934
|
+
let execute = async(func, input, cbProgress) => {
|
|
954
935
|
|
|
955
936
|
//msg
|
|
956
937
|
let msg = {
|
|
@@ -960,10 +941,10 @@ function WConverhpClient(opt) {
|
|
|
960
941
|
input,
|
|
961
942
|
}
|
|
962
943
|
|
|
963
|
-
//
|
|
944
|
+
//sendPkg
|
|
964
945
|
let state = ''
|
|
965
946
|
let res = null
|
|
966
|
-
await
|
|
947
|
+
await sendPkg('basic', msg, cbProgress)
|
|
967
948
|
.then((msg) => {
|
|
968
949
|
// console.log('msg', msg)
|
|
969
950
|
|
|
@@ -1016,7 +997,7 @@ function WConverhpClient(opt) {
|
|
|
1016
997
|
}
|
|
1017
998
|
|
|
1018
999
|
//upload
|
|
1019
|
-
|
|
1000
|
+
let upload = (filename, input, cbProgress) => {
|
|
1020
1001
|
|
|
1021
1002
|
//bb
|
|
1022
1003
|
let bb = input
|
|
@@ -1025,7 +1006,7 @@ function WConverhpClient(opt) {
|
|
|
1025
1006
|
}
|
|
1026
1007
|
|
|
1027
1008
|
//downloadNodejs
|
|
1028
|
-
|
|
1009
|
+
let downloadNodejs = async(fileId, cbProgress, opt = {}) => {
|
|
1029
1010
|
|
|
1030
1011
|
//send download
|
|
1031
1012
|
let msg = { fileId }
|
|
@@ -1036,7 +1017,7 @@ function WConverhpClient(opt) {
|
|
|
1036
1017
|
}
|
|
1037
1018
|
|
|
1038
1019
|
//downloadBrowser
|
|
1039
|
-
|
|
1020
|
+
let downloadBrowser = async(fileId, cbProgress, opt = {}) => {
|
|
1040
1021
|
//交由瀏覽器下載與管理故無法監聽進度, 不使用cbProgress
|
|
1041
1022
|
|
|
1042
1023
|
//token
|
|
@@ -1073,7 +1054,7 @@ function WConverhpClient(opt) {
|
|
|
1073
1054
|
}
|
|
1074
1055
|
|
|
1075
1056
|
//download
|
|
1076
|
-
|
|
1057
|
+
let download = async(fileId, cbProgress, opt = {}) => {
|
|
1077
1058
|
if (env === 'browser') {
|
|
1078
1059
|
return downloadBrowser(fileId, cbProgress, opt)
|
|
1079
1060
|
}
|
package/src/WConverhpServer.mjs
CHANGED
|
@@ -448,7 +448,7 @@ function WConverhpServer(opt = {}) {
|
|
|
448
448
|
|
|
449
449
|
//apiMain
|
|
450
450
|
let apiMain = {
|
|
451
|
-
path: `/${apiName}/main`,
|
|
451
|
+
path: `/${apiName}/main`,
|
|
452
452
|
method: 'POST',
|
|
453
453
|
options: {
|
|
454
454
|
payload: {
|
|
@@ -604,7 +604,7 @@ function WConverhpServer(opt = {}) {
|
|
|
604
604
|
|
|
605
605
|
//apiUploadCheck
|
|
606
606
|
let apiUploadCheck = {
|
|
607
|
-
path: `/${apiName}/ulctr`,
|
|
607
|
+
path: `/${apiName}/ulctr`,
|
|
608
608
|
method: 'POST',
|
|
609
609
|
options: {
|
|
610
610
|
payload: {
|
|
@@ -822,7 +822,7 @@ function WConverhpServer(opt = {}) {
|
|
|
822
822
|
|
|
823
823
|
//apiUploadSlice
|
|
824
824
|
let apiUploadSlice = {
|
|
825
|
-
path: `/${apiName}/slc`,
|
|
825
|
+
path: `/${apiName}/slc`,
|
|
826
826
|
method: 'POST',
|
|
827
827
|
options: {
|
|
828
828
|
payload: {
|
|
@@ -960,7 +960,7 @@ function WConverhpServer(opt = {}) {
|
|
|
960
960
|
// console.log('u8aOut', u8aOut)
|
|
961
961
|
|
|
962
962
|
// //測試失敗重傳
|
|
963
|
-
// if (Math.random() < 0.
|
|
963
|
+
// if (Math.random() < 0.6) {
|
|
964
964
|
// out = {
|
|
965
965
|
// error: 'force error'
|
|
966
966
|
// }
|
|
@@ -976,7 +976,7 @@ function WConverhpServer(opt = {}) {
|
|
|
976
976
|
|
|
977
977
|
//apiDownloadGetFilename
|
|
978
978
|
let apiDownloadGetFilename = {
|
|
979
|
-
path: `/${apiName}/dwgfn`,
|
|
979
|
+
path: `/${apiName}/dwgfn`,
|
|
980
980
|
method: 'POST',
|
|
981
981
|
options: {
|
|
982
982
|
payload: {
|
|
@@ -1098,7 +1098,7 @@ function WConverhpServer(opt = {}) {
|
|
|
1098
1098
|
|
|
1099
1099
|
//apiDownloadGetFile
|
|
1100
1100
|
let apiDownloadGetFile = {
|
|
1101
|
-
path: `/${apiName}/dwgf`,
|
|
1101
|
+
path: `/${apiName}/dwgf`,
|
|
1102
1102
|
method: 'GET',
|
|
1103
1103
|
options: {
|
|
1104
1104
|
timeout: {
|
|
@@ -1222,7 +1222,7 @@ function WConverhpServer(opt = {}) {
|
|
|
1222
1222
|
|
|
1223
1223
|
//apiDownload
|
|
1224
1224
|
let apiDownload = {
|
|
1225
|
-
path: `/${apiName}/dw`,
|
|
1225
|
+
path: `/${apiName}/dw`,
|
|
1226
1226
|
method: 'POST',
|
|
1227
1227
|
options: {
|
|
1228
1228
|
payload: {
|