w-converhp 2.0.46 → 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 +2 -2
- package/dist/w-converhp-server.umd.js.map +1 -1
- package/docs/WConverhpClient.html +2 -2
- package/docs/WConverhpClient.mjs.html +179 -201
- 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 +178 -200
- package/src/WConverhpServer.mjs +7 -7
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,25 +161,22 @@ function WConverhpClient(opt) {
|
|
|
159
161
|
//urlUse
|
|
160
162
|
let urlUse = ''
|
|
161
163
|
if (type === 'basic') {
|
|
162
|
-
urlUse = url
|
|
163
|
-
}
|
|
164
|
-
else if (type === 'slice') {
|
|
165
|
-
urlUse = `${url}slc`
|
|
164
|
+
urlUse = `${url}/main`
|
|
166
165
|
}
|
|
167
166
|
else if (type === 'upload-controller') {
|
|
168
|
-
urlUse = `${url}ulctr`
|
|
167
|
+
urlUse = `${url}/ulctr`
|
|
168
|
+
}
|
|
169
|
+
else if (type === 'slice') {
|
|
170
|
+
urlUse = `${url}/slc`
|
|
169
171
|
}
|
|
170
|
-
// else if (type === 'slice-merge') {
|
|
171
|
-
// urlUse = `${url}slcm`
|
|
172
|
-
// }
|
|
173
172
|
else if (type === 'download-get-filename') {
|
|
174
|
-
urlUse = `${url}dwgfn`
|
|
173
|
+
urlUse = `${url}/dwgfn`
|
|
175
174
|
}
|
|
176
175
|
else if (type === 'download-get') {
|
|
177
|
-
urlUse = `${url}dwgf`
|
|
176
|
+
urlUse = `${url}/dwgf`
|
|
178
177
|
}
|
|
179
178
|
else if (type === 'download') {
|
|
180
|
-
urlUse = `${url}dw`
|
|
179
|
+
urlUse = `${url}/dw`
|
|
181
180
|
}
|
|
182
181
|
else {
|
|
183
182
|
throw new Error(`invalid type[${type}]`)
|
|
@@ -187,7 +186,7 @@ function WConverhpClient(opt) {
|
|
|
187
186
|
}
|
|
188
187
|
|
|
189
188
|
//res2u8arr
|
|
190
|
-
|
|
189
|
+
let res2u8arr = async(bb) => {
|
|
191
190
|
//blob(in browser) or buffer(in nodejs) to u8a
|
|
192
191
|
let u8a
|
|
193
192
|
if (env === 'browser') {
|
|
@@ -200,7 +199,7 @@ function WConverhpClient(opt) {
|
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
//u8arr2bb
|
|
203
|
-
|
|
202
|
+
let u8arr2bb = (u8a) => {
|
|
204
203
|
//u8a to blob(in browser) or buffer(in nodejs)
|
|
205
204
|
let bb
|
|
206
205
|
if (env === 'browser') {
|
|
@@ -213,7 +212,7 @@ function WConverhpClient(opt) {
|
|
|
213
212
|
}
|
|
214
213
|
|
|
215
214
|
//send
|
|
216
|
-
|
|
215
|
+
let send = async(type, pkg, opt = {}) => {
|
|
217
216
|
|
|
218
217
|
//headers
|
|
219
218
|
let headers = get(opt, 'headers')
|
|
@@ -320,54 +319,6 @@ function WConverhpClient(opt) {
|
|
|
320
319
|
token = await token
|
|
321
320
|
}
|
|
322
321
|
|
|
323
|
-
//s
|
|
324
|
-
let s = {
|
|
325
|
-
method: 'POST',
|
|
326
|
-
url: urlUse,
|
|
327
|
-
data: dd,
|
|
328
|
-
headers: {
|
|
329
|
-
Authorization: `${tokenType} ${token}`,
|
|
330
|
-
...ct,
|
|
331
|
-
...headers,
|
|
332
|
-
},
|
|
333
|
-
timeout: 60 * 60 * 1000, //1hr
|
|
334
|
-
maxContentLength: Infinity, //1024 * 1024 * 1024, Infinity //axios於nodejs中會限制內容大小故需改為無限
|
|
335
|
-
maxBodyLength: Infinity, //1024 * 1024 * 1024, Infinity //axios於nodejs中會限制內容大小故需改為無限
|
|
336
|
-
responseType: rt,
|
|
337
|
-
onUploadProgress: function(ev) {
|
|
338
|
-
//console.log('onUploadProgress', ev)
|
|
339
|
-
|
|
340
|
-
//r
|
|
341
|
-
let r = 0
|
|
342
|
-
let loaded = ev.loaded
|
|
343
|
-
let total = ev.total
|
|
344
|
-
if (ispint(total)) {
|
|
345
|
-
r = (loaded * 100) / total
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
//cbProgress
|
|
349
|
-
cbProgress({ prog: Math.floor(r), p: loaded, m: 'upload' })
|
|
350
|
-
|
|
351
|
-
},
|
|
352
|
-
onDownloadProgress: function (ev) {
|
|
353
|
-
// console.log('onDownloadProgress', ev)
|
|
354
|
-
|
|
355
|
-
//r
|
|
356
|
-
let r = 0
|
|
357
|
-
let loaded = ev.loaded
|
|
358
|
-
// let total = ev.srcElement.getResponseHeader('Content-length') //若需要得知下載進度, 需於伺服器回傳時提供Content-length
|
|
359
|
-
let total = ev.total
|
|
360
|
-
if (ispint(total)) {
|
|
361
|
-
r = (loaded * 100) / total
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
//cbProgress
|
|
365
|
-
cbProgress({ prog: Math.floor(r), p: loaded, m: 'download' })
|
|
366
|
-
|
|
367
|
-
},
|
|
368
|
-
}
|
|
369
|
-
// console.log('s', s)
|
|
370
|
-
|
|
371
322
|
//getFilenameByHeader
|
|
372
323
|
let getFilenameByHeader = (contentDisposition) => {
|
|
373
324
|
let fn = 'unknow'
|
|
@@ -381,7 +332,7 @@ function WConverhpClient(opt) {
|
|
|
381
332
|
}
|
|
382
333
|
|
|
383
334
|
//downloadStream
|
|
384
|
-
let downloadStream = async
|
|
335
|
+
let downloadStream = async(res) => {
|
|
385
336
|
// console.log('res.headers', res.headers)
|
|
386
337
|
|
|
387
338
|
//pm
|
|
@@ -479,61 +430,151 @@ function WConverhpClient(opt) {
|
|
|
479
430
|
return pm
|
|
480
431
|
}
|
|
481
432
|
|
|
482
|
-
//
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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
|
|
497
456
|
}
|
|
498
457
|
|
|
499
|
-
//
|
|
500
|
-
|
|
501
|
-
// console.log('bb', bb)
|
|
458
|
+
//cbProgress
|
|
459
|
+
cbProgress({ prog: Math.floor(r), p: loaded, m: 'upload' })
|
|
502
460
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
// console.log('
|
|
461
|
+
},
|
|
462
|
+
onDownloadProgress: function (ev) {
|
|
463
|
+
// console.log('onDownloadProgress', ev)
|
|
506
464
|
|
|
507
|
-
//
|
|
508
|
-
let
|
|
509
|
-
|
|
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
|
|
510
544
|
|
|
511
545
|
//check
|
|
512
|
-
if (
|
|
513
|
-
|
|
514
|
-
eeEmit('error', `data is not an effective object`)
|
|
515
|
-
pm.reject(`data is not an effective object`)
|
|
516
|
-
return
|
|
546
|
+
if (n > retry) {
|
|
547
|
+
break
|
|
517
548
|
}
|
|
518
549
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
// console.log('invalid data', data)
|
|
529
|
-
eeEmit('error', `invalid data`)
|
|
530
|
-
pm.reject(`invalid data`)
|
|
531
|
-
}
|
|
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)
|
|
554
|
+
|
|
555
|
+
//retry
|
|
556
|
+
console.log(`retry n=${n}...`)
|
|
557
|
+
r = await fun(s)
|
|
558
|
+
// console.log(`retry n=${n} done`)
|
|
532
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)
|
|
533
574
|
})
|
|
534
|
-
.catch(async
|
|
575
|
+
.catch(async(res) => {
|
|
535
576
|
// console.log('axios catch', res.toJSON())
|
|
536
|
-
//Network Error除可能是網路斷線之外, 可能被瀏覽器外掛封鎖阻擋,
|
|
577
|
+
//Network Error除可能是網路斷線之外, 可能被瀏覽器外掛封鎖阻擋, 亦可能因硬碟空間不足無法下載被瀏覽器拒絕
|
|
537
578
|
|
|
538
579
|
//data
|
|
539
580
|
let data = null
|
|
@@ -575,7 +616,7 @@ function WConverhpClient(opt) {
|
|
|
575
616
|
}
|
|
576
617
|
|
|
577
618
|
//sendPkg
|
|
578
|
-
|
|
619
|
+
let sendPkg = async(type, data, cbProgress) => {
|
|
579
620
|
|
|
580
621
|
//bb
|
|
581
622
|
let bb = null
|
|
@@ -600,35 +641,8 @@ function WConverhpClient(opt) {
|
|
|
600
641
|
return res
|
|
601
642
|
}
|
|
602
643
|
|
|
603
|
-
//sendData
|
|
604
|
-
async function sendData(type, data, cbProgress) {
|
|
605
|
-
|
|
606
|
-
//fun
|
|
607
|
-
let fun = pmConvertResolve(sendPkg)
|
|
608
|
-
|
|
609
|
-
//sendPkg
|
|
610
|
-
let r = await fun(type, data, cbProgress)
|
|
611
|
-
|
|
612
|
-
let n = 0
|
|
613
|
-
while (r.state === 'error') {
|
|
614
|
-
n += 1
|
|
615
|
-
if (n > retry) {
|
|
616
|
-
break
|
|
617
|
-
}
|
|
618
|
-
console.log(`retry n=${n}`)
|
|
619
|
-
r = await fun(type, data, cbProgress)
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (r.state === 'success') {
|
|
623
|
-
return r.msg
|
|
624
|
-
}
|
|
625
|
-
else {
|
|
626
|
-
return Promise.reject(r.msg)
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
|
|
630
644
|
//calcHash
|
|
631
|
-
|
|
645
|
+
let calcHash = async(inp) => {
|
|
632
646
|
|
|
633
647
|
//bb
|
|
634
648
|
let bb = null
|
|
@@ -647,7 +661,7 @@ function WConverhpClient(opt) {
|
|
|
647
661
|
}
|
|
648
662
|
|
|
649
663
|
//sendDataSlice
|
|
650
|
-
|
|
664
|
+
let sendDataSlice = async(fileTotalName, bb, cbProgress) => {
|
|
651
665
|
|
|
652
666
|
//n
|
|
653
667
|
let n = 0
|
|
@@ -819,65 +833,29 @@ function WConverhpClient(opt) {
|
|
|
819
833
|
//chunk
|
|
820
834
|
let chunk = bb.slice(start, end)
|
|
821
835
|
|
|
822
|
-
//
|
|
823
|
-
let
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
'chunk-index': i,
|
|
828
|
-
'chunk-total': chunkTotal,
|
|
829
|
-
'package-id': packageId,
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
//send slice
|
|
833
|
-
let resSl = await send('slice', chunk, {
|
|
834
|
-
headers: hd,
|
|
835
|
-
dataType: 'blob',
|
|
836
|
-
cbProgress: (msg) => {
|
|
837
|
-
// console.log('cbProgress', msg)
|
|
838
|
-
// let perc = msg.prog
|
|
839
|
-
// let dir = msg.m
|
|
840
|
-
// if (dir === 'upload' && perc === 100) {
|
|
841
|
-
// }
|
|
842
|
-
}
|
|
843
|
-
})
|
|
844
|
-
// console.log('resSl', resSl)
|
|
845
|
-
|
|
846
|
-
//cbProgressSlice, 因其內有累加progCount, 實際代表是須成功傳輸後才能計算與回應外部進度, 故不能直接用於send的opt.cbProgress
|
|
847
|
-
cbProgressSlice()
|
|
848
|
-
|
|
849
|
-
return resSl
|
|
836
|
+
//hd
|
|
837
|
+
let hd = { //用header傳key與value時, key不分大小寫, 故使用kebabCase
|
|
838
|
+
'chunk-index': i,
|
|
839
|
+
'chunk-total': chunkTotal,
|
|
840
|
+
'package-id': packageId,
|
|
850
841
|
}
|
|
851
842
|
|
|
852
|
-
//
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
while (r.state === 'error') {
|
|
863
|
-
n += 1
|
|
864
|
-
if (n > retry) {
|
|
865
|
-
break
|
|
866
|
-
}
|
|
867
|
-
console.log(`retry n=${n}`)
|
|
868
|
-
r = await fun()
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
if (r.state === 'success') {
|
|
872
|
-
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
|
+
// }
|
|
873
853
|
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
}
|
|
877
|
-
}
|
|
854
|
+
})
|
|
855
|
+
// console.log('resSl', resSl)
|
|
878
856
|
|
|
879
|
-
//
|
|
880
|
-
|
|
857
|
+
//cbProgressSlice, 因其內有累加progCount, 實際代表是須成功傳輸後才能計算與回應外部進度, 故不能直接用於send的opt.cbProgress
|
|
858
|
+
cbProgressSlice()
|
|
881
859
|
|
|
882
860
|
}
|
|
883
861
|
|
|
@@ -953,7 +931,7 @@ function WConverhpClient(opt) {
|
|
|
953
931
|
}
|
|
954
932
|
|
|
955
933
|
//execute
|
|
956
|
-
|
|
934
|
+
let execute = async(func, input, cbProgress) => {
|
|
957
935
|
|
|
958
936
|
//msg
|
|
959
937
|
let msg = {
|
|
@@ -963,10 +941,10 @@ function WConverhpClient(opt) {
|
|
|
963
941
|
input,
|
|
964
942
|
}
|
|
965
943
|
|
|
966
|
-
//
|
|
944
|
+
//sendPkg
|
|
967
945
|
let state = ''
|
|
968
946
|
let res = null
|
|
969
|
-
await
|
|
947
|
+
await sendPkg('basic', msg, cbProgress)
|
|
970
948
|
.then((msg) => {
|
|
971
949
|
// console.log('msg', msg)
|
|
972
950
|
|
|
@@ -1019,7 +997,7 @@ function WConverhpClient(opt) {
|
|
|
1019
997
|
}
|
|
1020
998
|
|
|
1021
999
|
//upload
|
|
1022
|
-
|
|
1000
|
+
let upload = (filename, input, cbProgress) => {
|
|
1023
1001
|
|
|
1024
1002
|
//bb
|
|
1025
1003
|
let bb = input
|
|
@@ -1028,7 +1006,7 @@ function WConverhpClient(opt) {
|
|
|
1028
1006
|
}
|
|
1029
1007
|
|
|
1030
1008
|
//downloadNodejs
|
|
1031
|
-
|
|
1009
|
+
let downloadNodejs = async(fileId, cbProgress, opt = {}) => {
|
|
1032
1010
|
|
|
1033
1011
|
//send download
|
|
1034
1012
|
let msg = { fileId }
|
|
@@ -1039,7 +1017,7 @@ function WConverhpClient(opt) {
|
|
|
1039
1017
|
}
|
|
1040
1018
|
|
|
1041
1019
|
//downloadBrowser
|
|
1042
|
-
|
|
1020
|
+
let downloadBrowser = async(fileId, cbProgress, opt = {}) => {
|
|
1043
1021
|
//交由瀏覽器下載與管理故無法監聽進度, 不使用cbProgress
|
|
1044
1022
|
|
|
1045
1023
|
//token
|
|
@@ -1076,7 +1054,7 @@ function WConverhpClient(opt) {
|
|
|
1076
1054
|
}
|
|
1077
1055
|
|
|
1078
1056
|
//download
|
|
1079
|
-
|
|
1057
|
+
let download = async(fileId, cbProgress, opt = {}) => {
|
|
1080
1058
|
if (env === 'browser') {
|
|
1081
1059
|
return downloadBrowser(fileId, cbProgress, opt)
|
|
1082
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}`,
|
|
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: {
|