w-converhp 2.0.40 → 2.0.42
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 +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 +1 -1
- package/docs/WConverhpClient.mjs.html +1 -1
- package/docs/WConverhpServer.html +2 -42
- package/docs/WConverhpServer.mjs.html +17 -21
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/WConverhpServer.mjs +16 -20
- package/src/managerMergeSlices.mjs +62 -69
|
@@ -529,7 +529,7 @@
|
|
|
529
529
|
<br class="clear">
|
|
530
530
|
|
|
531
531
|
<footer>
|
|
532
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
532
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 10:08:13 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
533
533
|
</footer>
|
|
534
534
|
|
|
535
535
|
<script>prettyPrint();</script>
|
|
@@ -1107,7 +1107,7 @@ export default WConverhpClient
|
|
|
1107
1107
|
<br class="clear">
|
|
1108
1108
|
|
|
1109
1109
|
<footer>
|
|
1110
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
1110
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 10:08:13 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1111
1111
|
</footer>
|
|
1112
1112
|
|
|
1113
1113
|
<script>prettyPrint();</script>
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
|
|
81
81
|
<dt class="tag-source">Source:</dt>
|
|
82
82
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
83
|
-
<a href="WConverhpServer.mjs.html">WConverhpServer.mjs</a>, <a href="WConverhpServer.mjs.html#
|
|
83
|
+
<a href="WConverhpServer.mjs.html">WConverhpServer.mjs</a>, <a href="WConverhpServer.mjs.html#line192">line 192</a>
|
|
84
84
|
</li></ul></dd>
|
|
85
85
|
|
|
86
86
|
|
|
@@ -582,46 +582,6 @@
|
|
|
582
582
|
|
|
583
583
|
|
|
584
584
|
|
|
585
|
-
<tr>
|
|
586
|
-
|
|
587
|
-
<td class="name"><code>delayForBasic</code></td>
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
<td class="type">
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
<span class="param-type">Integer</span>
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
</td>
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
<td class="attributes">
|
|
602
|
-
|
|
603
|
-
<optional><br>
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
</td>
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
<td class="default">
|
|
614
|
-
|
|
615
|
-
<code>0</code>
|
|
616
|
-
|
|
617
|
-
</td>
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
<td class="description last"><p>輸入基本API用延遲響應時間,單位ms,預設0</p></td>
|
|
621
|
-
</tr>
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
585
|
<tr>
|
|
626
586
|
|
|
627
587
|
<td class="name"><code>delayForSlice</code></td>
|
|
@@ -789,7 +749,7 @@
|
|
|
789
749
|
<br class="clear">
|
|
790
750
|
|
|
791
751
|
<footer>
|
|
792
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
752
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 10:08:13 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
793
753
|
</footer>
|
|
794
754
|
|
|
795
755
|
<script>prettyPrint();</script>
|
|
@@ -70,7 +70,7 @@ import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
|
|
|
70
70
|
import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
|
|
71
71
|
import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
|
|
72
72
|
import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
|
|
73
|
-
import
|
|
73
|
+
import mmg from './managerMergeSlices.mjs'
|
|
74
74
|
// import checkTotalHash from './checkTotalHash.mjs'
|
|
75
75
|
import checkTotalHash from './checkTotalHash.wk.umd.js'
|
|
76
76
|
// import checkSlicesHash from './checkSlicesHash.mjs'
|
|
@@ -82,10 +82,6 @@ import checkSlicesHash from './checkSlicesHash.wk.umd.js'
|
|
|
82
82
|
//回傳前端(browser)時, 針對超大檔, 可用POST並用stream回傳但還要處理進度條, 若要交由瀏覽器下載器處理, 只能用GET並用stream回傳, 且前端只能用window.location.href或a.href+a.click()下載
|
|
83
83
|
|
|
84
84
|
|
|
85
|
-
//mmg
|
|
86
|
-
let mmg = managerMergeSlices()
|
|
87
|
-
|
|
88
|
-
|
|
89
85
|
/**
|
|
90
86
|
* 建立Hapi伺服器
|
|
91
87
|
*
|
|
@@ -100,7 +96,6 @@ let mmg = managerMergeSlices()
|
|
|
100
96
|
* @param {Integer} [opt.sizeSlice=1024*1024] 輸入切片上傳檔案之切片檔案大小整數,單位為Byte,預設為1024*1024
|
|
101
97
|
* @param {Function} [opt.verifyConn=()=>{return true}] 輸入呼叫API時檢測函數,預設()=>{return true}
|
|
102
98
|
* @param {Array} [opt.corsOrigins=['*']] 輸入允許跨域網域陣列,若給予['*']代表允許全部,預設['*']
|
|
103
|
-
* @param {Integer} [opt.delayForBasic=0] 輸入基本API用延遲響應時間,單位ms,預設0
|
|
104
99
|
* @param {Integer} [opt.delayForSlice=100] 輸入切片上傳檔案API用延遲響應時間,單位ms,預設100
|
|
105
100
|
* @param {Boolean} [opt.serverHapi=null] 輸入外部提供Hapi伺服器物件,預設null
|
|
106
101
|
* @returns {Object} 回傳事件物件,可監聽事件execute、upload、handler
|
|
@@ -302,13 +297,6 @@ function WConverhpServer(opt = {}) {
|
|
|
302
297
|
corsOrigins = ['*']
|
|
303
298
|
}
|
|
304
299
|
|
|
305
|
-
//delayForBasic
|
|
306
|
-
let delayForBasic = get(opt, 'delayForBasic', '')
|
|
307
|
-
if (!isp0int(delayForBasic)) {
|
|
308
|
-
delayForBasic = 0
|
|
309
|
-
}
|
|
310
|
-
delayForBasic = cint(delayForBasic)
|
|
311
|
-
|
|
312
300
|
//delayForSlice
|
|
313
301
|
let delayForSlice = get(opt, 'delayForSlice', '')
|
|
314
302
|
if (!isp0int(delayForSlice)) {
|
|
@@ -573,26 +561,29 @@ function WConverhpServer(opt = {}) {
|
|
|
573
561
|
let chunks = []
|
|
574
562
|
let smw = new stream.Writable({
|
|
575
563
|
write(chunk, encoding, cb) {
|
|
576
|
-
// console.log('receive payload', chunk)
|
|
564
|
+
// console.log('smw receive payload', chunk)
|
|
577
565
|
|
|
578
566
|
//push
|
|
579
567
|
chunks.push(chunk)
|
|
580
568
|
// console.log('chunk.length', chunk.length)
|
|
581
569
|
|
|
582
|
-
//
|
|
583
|
-
|
|
584
|
-
cb()
|
|
585
|
-
}, delayForBasic)
|
|
570
|
+
//cb
|
|
571
|
+
cb()
|
|
586
572
|
|
|
587
573
|
}
|
|
588
574
|
})
|
|
589
575
|
|
|
576
|
+
//finish
|
|
577
|
+
smw.on('finish', () => {
|
|
578
|
+
// console.log(`smw finish`)
|
|
579
|
+
})
|
|
580
|
+
|
|
590
581
|
//pipe
|
|
591
582
|
req.payload.pipe(smw)
|
|
592
583
|
|
|
593
584
|
//end
|
|
594
585
|
req.payload.on('end', () => {
|
|
595
|
-
// console.log(`
|
|
586
|
+
// console.log(`req.payload end`)
|
|
596
587
|
|
|
597
588
|
//bb
|
|
598
589
|
let bb = Buffer.concat(chunks)
|
|
@@ -606,9 +597,14 @@ function WConverhpServer(opt = {}) {
|
|
|
606
597
|
|
|
607
598
|
})
|
|
608
599
|
|
|
600
|
+
//close
|
|
601
|
+
req.payload.on('close', () => {
|
|
602
|
+
// console.log(`req.payload close`)
|
|
603
|
+
})
|
|
604
|
+
|
|
609
605
|
//error
|
|
610
606
|
req.payload.on('error', (err) => {
|
|
611
|
-
// console.log(`
|
|
607
|
+
// console.log(`req.payload error`, err)
|
|
612
608
|
eeEmit('error', `receive payload err`)
|
|
613
609
|
pm.reject(err.message)
|
|
614
610
|
})
|
|
@@ -1478,7 +1474,7 @@ export default WConverhpServer
|
|
|
1478
1474
|
<br class="clear">
|
|
1479
1475
|
|
|
1480
1476
|
<footer>
|
|
1481
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
1477
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 10:08:13 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1482
1478
|
</footer>
|
|
1483
1479
|
|
|
1484
1480
|
<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 Thu Apr 24 2025 10:08:13 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/WConverhpServer.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
|
|
|
23
23
|
import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
|
|
24
24
|
import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
|
|
25
25
|
import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
|
|
26
|
-
import
|
|
26
|
+
import mmg from './managerMergeSlices.mjs'
|
|
27
27
|
// import checkTotalHash from './checkTotalHash.mjs'
|
|
28
28
|
import checkTotalHash from './checkTotalHash.wk.umd.js'
|
|
29
29
|
// import checkSlicesHash from './checkSlicesHash.mjs'
|
|
@@ -35,10 +35,6 @@ import checkSlicesHash from './checkSlicesHash.wk.umd.js'
|
|
|
35
35
|
//回傳前端(browser)時, 針對超大檔, 可用POST並用stream回傳但還要處理進度條, 若要交由瀏覽器下載器處理, 只能用GET並用stream回傳, 且前端只能用window.location.href或a.href+a.click()下載
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
//mmg
|
|
39
|
-
let mmg = managerMergeSlices()
|
|
40
|
-
|
|
41
|
-
|
|
42
38
|
/**
|
|
43
39
|
* 建立Hapi伺服器
|
|
44
40
|
*
|
|
@@ -53,7 +49,6 @@ let mmg = managerMergeSlices()
|
|
|
53
49
|
* @param {Integer} [opt.sizeSlice=1024*1024] 輸入切片上傳檔案之切片檔案大小整數,單位為Byte,預設為1024*1024
|
|
54
50
|
* @param {Function} [opt.verifyConn=()=>{return true}] 輸入呼叫API時檢測函數,預設()=>{return true}
|
|
55
51
|
* @param {Array} [opt.corsOrigins=['*']] 輸入允許跨域網域陣列,若給予['*']代表允許全部,預設['*']
|
|
56
|
-
* @param {Integer} [opt.delayForBasic=0] 輸入基本API用延遲響應時間,單位ms,預設0
|
|
57
52
|
* @param {Integer} [opt.delayForSlice=100] 輸入切片上傳檔案API用延遲響應時間,單位ms,預設100
|
|
58
53
|
* @param {Boolean} [opt.serverHapi=null] 輸入外部提供Hapi伺服器物件,預設null
|
|
59
54
|
* @returns {Object} 回傳事件物件,可監聽事件execute、upload、handler
|
|
@@ -255,13 +250,6 @@ function WConverhpServer(opt = {}) {
|
|
|
255
250
|
corsOrigins = ['*']
|
|
256
251
|
}
|
|
257
252
|
|
|
258
|
-
//delayForBasic
|
|
259
|
-
let delayForBasic = get(opt, 'delayForBasic', '')
|
|
260
|
-
if (!isp0int(delayForBasic)) {
|
|
261
|
-
delayForBasic = 0
|
|
262
|
-
}
|
|
263
|
-
delayForBasic = cint(delayForBasic)
|
|
264
|
-
|
|
265
253
|
//delayForSlice
|
|
266
254
|
let delayForSlice = get(opt, 'delayForSlice', '')
|
|
267
255
|
if (!isp0int(delayForSlice)) {
|
|
@@ -526,26 +514,29 @@ function WConverhpServer(opt = {}) {
|
|
|
526
514
|
let chunks = []
|
|
527
515
|
let smw = new stream.Writable({
|
|
528
516
|
write(chunk, encoding, cb) {
|
|
529
|
-
// console.log('receive payload', chunk)
|
|
517
|
+
// console.log('smw receive payload', chunk)
|
|
530
518
|
|
|
531
519
|
//push
|
|
532
520
|
chunks.push(chunk)
|
|
533
521
|
// console.log('chunk.length', chunk.length)
|
|
534
522
|
|
|
535
|
-
//
|
|
536
|
-
|
|
537
|
-
cb()
|
|
538
|
-
}, delayForBasic)
|
|
523
|
+
//cb
|
|
524
|
+
cb()
|
|
539
525
|
|
|
540
526
|
}
|
|
541
527
|
})
|
|
542
528
|
|
|
529
|
+
//finish
|
|
530
|
+
smw.on('finish', () => {
|
|
531
|
+
// console.log(`smw finish`)
|
|
532
|
+
})
|
|
533
|
+
|
|
543
534
|
//pipe
|
|
544
535
|
req.payload.pipe(smw)
|
|
545
536
|
|
|
546
537
|
//end
|
|
547
538
|
req.payload.on('end', () => {
|
|
548
|
-
// console.log(`
|
|
539
|
+
// console.log(`req.payload end`)
|
|
549
540
|
|
|
550
541
|
//bb
|
|
551
542
|
let bb = Buffer.concat(chunks)
|
|
@@ -559,9 +550,14 @@ function WConverhpServer(opt = {}) {
|
|
|
559
550
|
|
|
560
551
|
})
|
|
561
552
|
|
|
553
|
+
//close
|
|
554
|
+
req.payload.on('close', () => {
|
|
555
|
+
// console.log(`req.payload close`)
|
|
556
|
+
})
|
|
557
|
+
|
|
562
558
|
//error
|
|
563
559
|
req.payload.on('error', (err) => {
|
|
564
|
-
// console.log(`
|
|
560
|
+
// console.log(`req.payload error`, err)
|
|
565
561
|
eeEmit('error', `receive payload err`)
|
|
566
562
|
pm.reject(err.message)
|
|
567
563
|
})
|
|
@@ -10,92 +10,85 @@ import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
|
|
|
10
10
|
import mergeSlices from './mergeSlices.wk.umd.js'
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
let
|
|
13
|
+
//qPush
|
|
14
|
+
let qPush = (fileHash, chunkTotal, pathUploadTemp) => {
|
|
15
15
|
|
|
16
|
-
//
|
|
17
|
-
let
|
|
16
|
+
//id, 使用fileHash代表不用佇列儲存, 通過id即可解析反查
|
|
17
|
+
let id = `${now2strp()}|${genID(6)}|${fileHash}`
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
//setTimeout, 脫勾觸發
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
mergeSlices(fileHash, chunkTotal, pathUploadTemp)
|
|
22
|
+
.catch((err) => {
|
|
23
|
+
console.log(err)
|
|
24
|
+
})
|
|
25
|
+
}, 1)
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
mergeSlices(fileHash, chunkTotal, pathUploadTemp)
|
|
25
|
-
.catch((err) => {
|
|
26
|
-
console.log(err)
|
|
27
|
-
})
|
|
28
|
-
}, 1)
|
|
27
|
+
return id
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
//qGet
|
|
31
|
+
let qGet = (id, pathUploadTemp) => {
|
|
32
|
+
let errTemp = ''
|
|
32
33
|
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
errTemp
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
state: 'error',
|
|
43
|
-
msg: errTemp,
|
|
44
|
-
path: '',
|
|
45
|
-
}
|
|
34
|
+
//check
|
|
35
|
+
if (!isestr(id)) {
|
|
36
|
+
errTemp = `invalid id[${id}]`
|
|
37
|
+
console.log(errTemp)
|
|
38
|
+
return {
|
|
39
|
+
state: 'error',
|
|
40
|
+
msg: errTemp,
|
|
41
|
+
path: '',
|
|
46
42
|
}
|
|
43
|
+
}
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
45
|
+
//fileHash
|
|
46
|
+
let s = sep(id, '|')
|
|
47
|
+
let fileHash = get(s, 2, '')
|
|
48
|
+
if (!isestr(fileHash)) {
|
|
49
|
+
errTemp = `can not find fileHash in id[${id}]`
|
|
50
|
+
console.log(errTemp)
|
|
51
|
+
return {
|
|
52
|
+
state: 'error',
|
|
53
|
+
msg: errTemp,
|
|
54
|
+
path: '',
|
|
59
55
|
}
|
|
56
|
+
}
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
//fp
|
|
59
|
+
let fp = path.resolve(pathUploadTemp, fileHash)
|
|
60
|
+
// console.log('fp', fp)
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
//fpd
|
|
63
|
+
let fpd = path.resolve(pathUploadTemp, `${fileHash}.done`)
|
|
64
|
+
// console.log('fpd', fpd)
|
|
68
65
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
//bfp, bfpd, b
|
|
67
|
+
let bfp = fsIsFile(fp)
|
|
68
|
+
let bfpd = fsIsFile(fpd)
|
|
69
|
+
let b = bfp && bfpd //記得要同時偵測fp與fpd, 否則有些已經移動fp但fpd忘記刪, 就會造成誤判
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
//check, 若已經完成任務, 且外部調用get取得完成訊息, 則可自動刪除.done檔, 但因不能保證合併後有完成再處理動作, 例如移動至處理資料夾再處理, 故保留.done檔
|
|
80
|
-
if (b) {
|
|
81
|
-
// fsDeleteFile(fpd)
|
|
82
|
-
}
|
|
71
|
+
//check, 若有.done檔但沒合併檔, 就代表合併檔已被處理或移動, .done檔須自動刪除
|
|
72
|
+
if (!bfp && bfpd) {
|
|
73
|
+
fsDeleteFile(fpd)
|
|
74
|
+
}
|
|
83
75
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
path: fp,
|
|
88
|
-
}
|
|
76
|
+
//check, 若已經完成任務, 且外部調用get取得完成訊息, 則可自動刪除.done檔, 但因不能保證合併後有完成再處理動作, 例如移動至處理資料夾再處理, 故保留.done檔
|
|
77
|
+
if (b) {
|
|
78
|
+
// fsDeleteFile(fpd)
|
|
89
79
|
}
|
|
90
80
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
81
|
+
return {
|
|
82
|
+
state: b ? 'success' : 'merging',
|
|
83
|
+
msg: '',
|
|
84
|
+
path: fp,
|
|
95
85
|
}
|
|
86
|
+
}
|
|
96
87
|
|
|
97
|
-
|
|
88
|
+
let r = {
|
|
89
|
+
push: qPush,
|
|
90
|
+
get: qGet,
|
|
98
91
|
}
|
|
99
92
|
|
|
100
93
|
|
|
101
|
-
export default
|
|
94
|
+
export default r
|