w-converhp 2.0.47 → 2.0.49
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 +44 -4
- package/docs/WConverhpClient.mjs.html +185 -197
- 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 +184 -196
- package/src/WConverhpServer.mjs +7 -7
- package/srv.mjs +1 -1
|
@@ -495,7 +495,7 @@ function WConverhpServer(opt = {}) {
|
|
|
495
495
|
|
|
496
496
|
//apiMain
|
|
497
497
|
let apiMain = {
|
|
498
|
-
path: `/${apiName}/main`,
|
|
498
|
+
path: `/${apiName}/main`,
|
|
499
499
|
method: 'POST',
|
|
500
500
|
options: {
|
|
501
501
|
payload: {
|
|
@@ -651,7 +651,7 @@ function WConverhpServer(opt = {}) {
|
|
|
651
651
|
|
|
652
652
|
//apiUploadCheck
|
|
653
653
|
let apiUploadCheck = {
|
|
654
|
-
path: `/${apiName}/ulctr`,
|
|
654
|
+
path: `/${apiName}/ulctr`,
|
|
655
655
|
method: 'POST',
|
|
656
656
|
options: {
|
|
657
657
|
payload: {
|
|
@@ -869,7 +869,7 @@ function WConverhpServer(opt = {}) {
|
|
|
869
869
|
|
|
870
870
|
//apiUploadSlice
|
|
871
871
|
let apiUploadSlice = {
|
|
872
|
-
path: `/${apiName}/slc`,
|
|
872
|
+
path: `/${apiName}/slc`,
|
|
873
873
|
method: 'POST',
|
|
874
874
|
options: {
|
|
875
875
|
payload: {
|
|
@@ -1007,7 +1007,7 @@ function WConverhpServer(opt = {}) {
|
|
|
1007
1007
|
// console.log('u8aOut', u8aOut)
|
|
1008
1008
|
|
|
1009
1009
|
// //測試失敗重傳
|
|
1010
|
-
// if (Math.random() < 0.
|
|
1010
|
+
// if (Math.random() < 0.6) {
|
|
1011
1011
|
// out = {
|
|
1012
1012
|
// error: 'force error'
|
|
1013
1013
|
// }
|
|
@@ -1023,7 +1023,7 @@ function WConverhpServer(opt = {}) {
|
|
|
1023
1023
|
|
|
1024
1024
|
//apiDownloadGetFilename
|
|
1025
1025
|
let apiDownloadGetFilename = {
|
|
1026
|
-
path: `/${apiName}/dwgfn`,
|
|
1026
|
+
path: `/${apiName}/dwgfn`,
|
|
1027
1027
|
method: 'POST',
|
|
1028
1028
|
options: {
|
|
1029
1029
|
payload: {
|
|
@@ -1145,7 +1145,7 @@ function WConverhpServer(opt = {}) {
|
|
|
1145
1145
|
|
|
1146
1146
|
//apiDownloadGetFile
|
|
1147
1147
|
let apiDownloadGetFile = {
|
|
1148
|
-
path: `/${apiName}/dwgf`,
|
|
1148
|
+
path: `/${apiName}/dwgf`,
|
|
1149
1149
|
method: 'GET',
|
|
1150
1150
|
options: {
|
|
1151
1151
|
timeout: {
|
|
@@ -1269,7 +1269,7 @@ function WConverhpServer(opt = {}) {
|
|
|
1269
1269
|
|
|
1270
1270
|
//apiDownload
|
|
1271
1271
|
let apiDownload = {
|
|
1272
|
-
path: `/${apiName}/dw`,
|
|
1272
|
+
path: `/${apiName}/dw`,
|
|
1273
1273
|
method: 'POST',
|
|
1274
1274
|
options: {
|
|
1275
1275
|
payload: {
|
|
@@ -1485,7 +1485,7 @@ export default WConverhpServer
|
|
|
1485
1485
|
<br class="clear">
|
|
1486
1486
|
|
|
1487
1487
|
<footer>
|
|
1488
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
1488
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sat May 17 2025 21:33:07 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1489
1489
|
</footer>
|
|
1490
1490
|
|
|
1491
1491
|
<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
|
|
74
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sat May 17 2025 21:33:07 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
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
|
|
|
@@ -31,7 +33,8 @@ import getFileXxHash from 'wsemi/src/getFileXxHash.mjs'
|
|
|
31
33
|
* @param {Function} [opt.getToken=()=>''] 輸入取得使用者token的回調函數,預設()=>''
|
|
32
34
|
* @param {String} [opt.tokenType='Bearer'] 輸入token類型字串,預設'Bearer'
|
|
33
35
|
* @param {Integer} [opt.sizeSlice=1024*1024] 輸入切片上傳檔案之切片檔案大小整數,單位為Byte,預設為1024*1024
|
|
34
|
-
* @param {Integer} [opt.
|
|
36
|
+
* @param {Integer} [opt.timeout=5*60*1000] 輸入最長等待時間整數,單位ms,預設為5*60*1000、為5分鐘
|
|
37
|
+
* @param {Integer} [opt.retry=10] 輸入傳輸失敗重試次數整數,預設為10
|
|
35
38
|
* @returns {Object} 回傳事件物件,可使用函數execute、upload
|
|
36
39
|
* @example
|
|
37
40
|
*
|
|
@@ -133,10 +136,16 @@ function WConverhpClient(opt) {
|
|
|
133
136
|
sizeSlice = 1024 * 1024 //1m
|
|
134
137
|
}
|
|
135
138
|
|
|
139
|
+
//timeout
|
|
140
|
+
let timeout = get(opt, 'timeout')
|
|
141
|
+
if (!isp0int(timeout)) {
|
|
142
|
+
timeout = 5 * 60 * 1000 //5min
|
|
143
|
+
}
|
|
144
|
+
|
|
136
145
|
//retry
|
|
137
146
|
let retry = get(opt, 'retry')
|
|
138
147
|
if (!isp0int(retry)) {
|
|
139
|
-
retry =
|
|
148
|
+
retry = 10
|
|
140
149
|
}
|
|
141
150
|
|
|
142
151
|
//env
|
|
@@ -159,22 +168,22 @@ function WConverhpClient(opt) {
|
|
|
159
168
|
//urlUse
|
|
160
169
|
let urlUse = ''
|
|
161
170
|
if (type === 'basic') {
|
|
162
|
-
urlUse = `${url}/main`
|
|
171
|
+
urlUse = `${url}/main`
|
|
163
172
|
}
|
|
164
173
|
else if (type === 'upload-controller') {
|
|
165
|
-
urlUse = `${url}/ulctr`
|
|
174
|
+
urlUse = `${url}/ulctr`
|
|
166
175
|
}
|
|
167
176
|
else if (type === 'slice') {
|
|
168
|
-
urlUse = `${url}/slc`
|
|
177
|
+
urlUse = `${url}/slc`
|
|
169
178
|
}
|
|
170
179
|
else if (type === 'download-get-filename') {
|
|
171
|
-
urlUse = `${url}/dwgfn`
|
|
180
|
+
urlUse = `${url}/dwgfn`
|
|
172
181
|
}
|
|
173
182
|
else if (type === 'download-get') {
|
|
174
|
-
urlUse = `${url}/dwgf`
|
|
183
|
+
urlUse = `${url}/dwgf`
|
|
175
184
|
}
|
|
176
185
|
else if (type === 'download') {
|
|
177
|
-
urlUse = `${url}/dw`
|
|
186
|
+
urlUse = `${url}/dw`
|
|
178
187
|
}
|
|
179
188
|
else {
|
|
180
189
|
throw new Error(`invalid type[${type}]`)
|
|
@@ -184,7 +193,7 @@ function WConverhpClient(opt) {
|
|
|
184
193
|
}
|
|
185
194
|
|
|
186
195
|
//res2u8arr
|
|
187
|
-
|
|
196
|
+
let res2u8arr = async(bb) => {
|
|
188
197
|
//blob(in browser) or buffer(in nodejs) to u8a
|
|
189
198
|
let u8a
|
|
190
199
|
if (env === 'browser') {
|
|
@@ -197,7 +206,7 @@ function WConverhpClient(opt) {
|
|
|
197
206
|
}
|
|
198
207
|
|
|
199
208
|
//u8arr2bb
|
|
200
|
-
|
|
209
|
+
let u8arr2bb = (u8a) => {
|
|
201
210
|
//u8a to blob(in browser) or buffer(in nodejs)
|
|
202
211
|
let bb
|
|
203
212
|
if (env === 'browser') {
|
|
@@ -210,7 +219,7 @@ function WConverhpClient(opt) {
|
|
|
210
219
|
}
|
|
211
220
|
|
|
212
221
|
//send
|
|
213
|
-
|
|
222
|
+
let send = async(type, pkg, opt = {}) => {
|
|
214
223
|
|
|
215
224
|
//headers
|
|
216
225
|
let headers = get(opt, 'headers')
|
|
@@ -317,54 +326,6 @@ function WConverhpClient(opt) {
|
|
|
317
326
|
token = await token
|
|
318
327
|
}
|
|
319
328
|
|
|
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
329
|
//getFilenameByHeader
|
|
369
330
|
let getFilenameByHeader = (contentDisposition) => {
|
|
370
331
|
let fn = 'unknow'
|
|
@@ -378,7 +339,7 @@ function WConverhpClient(opt) {
|
|
|
378
339
|
}
|
|
379
340
|
|
|
380
341
|
//downloadStream
|
|
381
|
-
let downloadStream = async
|
|
342
|
+
let downloadStream = async(res) => {
|
|
382
343
|
// console.log('res.headers', res.headers)
|
|
383
344
|
|
|
384
345
|
//pm
|
|
@@ -476,61 +437,151 @@ function WConverhpClient(opt) {
|
|
|
476
437
|
return pm
|
|
477
438
|
}
|
|
478
439
|
|
|
479
|
-
//
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
440
|
+
//s
|
|
441
|
+
let s = {
|
|
442
|
+
method: 'POST',
|
|
443
|
+
url: urlUse,
|
|
444
|
+
data: dd,
|
|
445
|
+
headers: {
|
|
446
|
+
Authorization: `${tokenType} ${token}`,
|
|
447
|
+
...ct,
|
|
448
|
+
...headers,
|
|
449
|
+
},
|
|
450
|
+
timeout,
|
|
451
|
+
maxContentLength: Infinity, //1024 * 1024 * 1024, Infinity //axios於nodejs中會限制內容大小故需改為無限
|
|
452
|
+
maxBodyLength: Infinity, //1024 * 1024 * 1024, Infinity //axios於nodejs中會限制內容大小故需改為無限
|
|
453
|
+
responseType: rt,
|
|
454
|
+
onUploadProgress: function(ev) {
|
|
455
|
+
//console.log('onUploadProgress', ev)
|
|
456
|
+
|
|
457
|
+
//r
|
|
458
|
+
let r = 0
|
|
459
|
+
let loaded = ev.loaded
|
|
460
|
+
let total = ev.total
|
|
461
|
+
if (ispint(total)) {
|
|
462
|
+
r = (loaded * 100) / total
|
|
494
463
|
}
|
|
495
464
|
|
|
496
|
-
//
|
|
497
|
-
|
|
498
|
-
// console.log('bb', bb)
|
|
465
|
+
//cbProgress
|
|
466
|
+
cbProgress({ prog: Math.floor(r), p: loaded, m: 'upload' })
|
|
499
467
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
// console.log('
|
|
468
|
+
},
|
|
469
|
+
onDownloadProgress: function (ev) {
|
|
470
|
+
// console.log('onDownloadProgress', ev)
|
|
503
471
|
|
|
504
|
-
//
|
|
505
|
-
let
|
|
506
|
-
|
|
472
|
+
//r
|
|
473
|
+
let r = 0
|
|
474
|
+
let loaded = ev.loaded
|
|
475
|
+
// let total = ev.srcElement.getResponseHeader('Content-length') //若需要得知下載進度, 需於伺服器回傳時提供Content-length
|
|
476
|
+
let total = ev.total
|
|
477
|
+
if (ispint(total)) {
|
|
478
|
+
r = (loaded * 100) / total
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
//cbProgress
|
|
482
|
+
cbProgress({ prog: Math.floor(r), p: loaded, m: 'download' })
|
|
483
|
+
|
|
484
|
+
},
|
|
485
|
+
}
|
|
486
|
+
// console.log('s', s)
|
|
487
|
+
|
|
488
|
+
//callApiCore, 處理axios成功then時訊息, catch時直接向外傳遞
|
|
489
|
+
let callApiCore = async() => {
|
|
490
|
+
|
|
491
|
+
//axios, catch時直接向外傳遞
|
|
492
|
+
let res = await axios(s)
|
|
493
|
+
|
|
494
|
+
//check, download時直接轉由downloadStream處理res, catch時直接向外傳遞
|
|
495
|
+
if (type === 'download') {
|
|
496
|
+
return await downloadStream(res)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
//bb
|
|
500
|
+
let bb = get(res, 'data')
|
|
501
|
+
// console.log('bb', bb)
|
|
502
|
+
|
|
503
|
+
//res2u8arr, catch時直接向外傳遞
|
|
504
|
+
let u8a = await res2u8arr(bb)
|
|
505
|
+
// console.log('u8a', u8a)
|
|
506
|
+
|
|
507
|
+
//u8arr2obj
|
|
508
|
+
let data = u8arr2obj(u8a)
|
|
509
|
+
// console.log('data', data)
|
|
510
|
+
|
|
511
|
+
//check
|
|
512
|
+
if (!iseobj(data)) {
|
|
513
|
+
eeEmit('error', `data is not an effective object`)
|
|
514
|
+
return Promise.reject(`data is not an effective object`)
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
//分離伺服器資料的success或error
|
|
518
|
+
if (haskey(data, 'success')) {
|
|
519
|
+
return Promise.resolve(data.success)
|
|
520
|
+
}
|
|
521
|
+
else if (haskey(data, 'error')) {
|
|
522
|
+
eeEmit('error', data.error)
|
|
523
|
+
return Promise.reject(data.error)
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
eeEmit('error', `data does not contain success or error`)
|
|
527
|
+
return Promise.reject(`data does not contain success or error`)
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
//callApi, 處理callApiCore失敗catch時retry
|
|
533
|
+
let callApi = async() => {
|
|
534
|
+
|
|
535
|
+
//pmConvertResolve
|
|
536
|
+
let fun = pmConvertResolve(callApiCore)
|
|
537
|
+
|
|
538
|
+
//fun
|
|
539
|
+
let r = await fun(s)
|
|
540
|
+
// console.log('r', r)
|
|
541
|
+
|
|
542
|
+
//while
|
|
543
|
+
let maxRetry = 10
|
|
544
|
+
let baseDelay = 1000 //初始延遲為1秒
|
|
545
|
+
let ratio = Math.pow(180000 / baseDelay, 1 / (maxRetry - 1)) //1.888
|
|
546
|
+
let n = 0
|
|
547
|
+
while (r.state === 'error') {
|
|
548
|
+
|
|
549
|
+
//add
|
|
550
|
+
n += 1
|
|
507
551
|
|
|
508
552
|
//check
|
|
509
|
-
if (
|
|
510
|
-
|
|
511
|
-
eeEmit('error', `data is not an effective object`)
|
|
512
|
-
pm.reject(`data is not an effective object`)
|
|
513
|
-
return
|
|
553
|
+
if (n > retry) {
|
|
554
|
+
break
|
|
514
555
|
}
|
|
515
556
|
|
|
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
|
-
}
|
|
557
|
+
//delay
|
|
558
|
+
let t = Math.round(baseDelay * Math.pow(ratio, n - 1))
|
|
559
|
+
console.log(`wait ${dig(t / 1000, 1)}(second) to retry...`)
|
|
560
|
+
await delay(t)
|
|
529
561
|
|
|
562
|
+
//retry
|
|
563
|
+
console.log(`retry n=${n}...`)
|
|
564
|
+
r = await fun(s)
|
|
565
|
+
// console.log(`retry n=${n} done`)
|
|
566
|
+
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (r.state === 'success') {
|
|
570
|
+
return r.msg
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
return Promise.reject(r.msg)
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
//callApi
|
|
578
|
+
await callApi()
|
|
579
|
+
.then((res) => {
|
|
580
|
+
pm.resolve(res)
|
|
530
581
|
})
|
|
531
|
-
.catch(async
|
|
582
|
+
.catch(async(res) => {
|
|
532
583
|
// console.log('axios catch', res.toJSON())
|
|
533
|
-
//Network Error除可能是網路斷線之外, 可能被瀏覽器外掛封鎖阻擋,
|
|
584
|
+
//Network Error除可能是網路斷線之外, 可能被瀏覽器外掛封鎖阻擋, 亦可能因硬碟空間不足無法下載被瀏覽器拒絕
|
|
534
585
|
|
|
535
586
|
//data
|
|
536
587
|
let data = null
|
|
@@ -572,7 +623,7 @@ function WConverhpClient(opt) {
|
|
|
572
623
|
}
|
|
573
624
|
|
|
574
625
|
//sendPkg
|
|
575
|
-
|
|
626
|
+
let sendPkg = async(type, data, cbProgress) => {
|
|
576
627
|
|
|
577
628
|
//bb
|
|
578
629
|
let bb = null
|
|
@@ -597,35 +648,8 @@ function WConverhpClient(opt) {
|
|
|
597
648
|
return res
|
|
598
649
|
}
|
|
599
650
|
|
|
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
651
|
//calcHash
|
|
628
|
-
|
|
652
|
+
let calcHash = async(inp) => {
|
|
629
653
|
|
|
630
654
|
//bb
|
|
631
655
|
let bb = null
|
|
@@ -644,7 +668,7 @@ function WConverhpClient(opt) {
|
|
|
644
668
|
}
|
|
645
669
|
|
|
646
670
|
//sendDataSlice
|
|
647
|
-
|
|
671
|
+
let sendDataSlice = async(fileTotalName, bb, cbProgress) => {
|
|
648
672
|
|
|
649
673
|
//n
|
|
650
674
|
let n = 0
|
|
@@ -816,65 +840,29 @@ function WConverhpClient(opt) {
|
|
|
816
840
|
//chunk
|
|
817
841
|
let chunk = bb.slice(start, end)
|
|
818
842
|
|
|
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
|
|
843
|
+
//hd
|
|
844
|
+
let hd = { //用header傳key與value時, key不分大小寫, 故使用kebabCase
|
|
845
|
+
'chunk-index': i,
|
|
846
|
+
'chunk-total': chunkTotal,
|
|
847
|
+
'package-id': packageId,
|
|
847
848
|
}
|
|
848
849
|
|
|
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
|
|
850
|
+
//send slice
|
|
851
|
+
await send('slice', chunk, {
|
|
852
|
+
headers: hd,
|
|
853
|
+
dataType: 'blob',
|
|
854
|
+
cbProgress: (msg) => {
|
|
855
|
+
// console.log('cbProgress', msg)
|
|
856
|
+
// let perc = msg.prog
|
|
857
|
+
// let dir = msg.m
|
|
858
|
+
// if (dir === 'upload' && perc === 100) {
|
|
859
|
+
// }
|
|
870
860
|
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
}
|
|
874
|
-
}
|
|
861
|
+
})
|
|
862
|
+
// console.log('resSl', resSl)
|
|
875
863
|
|
|
876
|
-
//
|
|
877
|
-
|
|
864
|
+
//cbProgressSlice, 因其內有累加progCount, 實際代表是須成功傳輸後才能計算與回應外部進度, 故不能直接用於send的opt.cbProgress
|
|
865
|
+
cbProgressSlice()
|
|
878
866
|
|
|
879
867
|
}
|
|
880
868
|
|
|
@@ -950,7 +938,7 @@ function WConverhpClient(opt) {
|
|
|
950
938
|
}
|
|
951
939
|
|
|
952
940
|
//execute
|
|
953
|
-
|
|
941
|
+
let execute = async(func, input, cbProgress) => {
|
|
954
942
|
|
|
955
943
|
//msg
|
|
956
944
|
let msg = {
|
|
@@ -960,10 +948,10 @@ function WConverhpClient(opt) {
|
|
|
960
948
|
input,
|
|
961
949
|
}
|
|
962
950
|
|
|
963
|
-
//
|
|
951
|
+
//sendPkg
|
|
964
952
|
let state = ''
|
|
965
953
|
let res = null
|
|
966
|
-
await
|
|
954
|
+
await sendPkg('basic', msg, cbProgress)
|
|
967
955
|
.then((msg) => {
|
|
968
956
|
// console.log('msg', msg)
|
|
969
957
|
|
|
@@ -1016,7 +1004,7 @@ function WConverhpClient(opt) {
|
|
|
1016
1004
|
}
|
|
1017
1005
|
|
|
1018
1006
|
//upload
|
|
1019
|
-
|
|
1007
|
+
let upload = (filename, input, cbProgress) => {
|
|
1020
1008
|
|
|
1021
1009
|
//bb
|
|
1022
1010
|
let bb = input
|
|
@@ -1025,7 +1013,7 @@ function WConverhpClient(opt) {
|
|
|
1025
1013
|
}
|
|
1026
1014
|
|
|
1027
1015
|
//downloadNodejs
|
|
1028
|
-
|
|
1016
|
+
let downloadNodejs = async(fileId, cbProgress, opt = {}) => {
|
|
1029
1017
|
|
|
1030
1018
|
//send download
|
|
1031
1019
|
let msg = { fileId }
|
|
@@ -1036,7 +1024,7 @@ function WConverhpClient(opt) {
|
|
|
1036
1024
|
}
|
|
1037
1025
|
|
|
1038
1026
|
//downloadBrowser
|
|
1039
|
-
|
|
1027
|
+
let downloadBrowser = async(fileId, cbProgress, opt = {}) => {
|
|
1040
1028
|
//交由瀏覽器下載與管理故無法監聽進度, 不使用cbProgress
|
|
1041
1029
|
|
|
1042
1030
|
//token
|
|
@@ -1073,7 +1061,7 @@ function WConverhpClient(opt) {
|
|
|
1073
1061
|
}
|
|
1074
1062
|
|
|
1075
1063
|
//download
|
|
1076
|
-
|
|
1064
|
+
let download = async(fileId, cbProgress, opt = {}) => {
|
|
1077
1065
|
if (env === 'browser') {
|
|
1078
1066
|
return downloadBrowser(fileId, cbProgress, opt)
|
|
1079
1067
|
}
|