w-converhp 2.0.40 → 2.0.41

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.
@@ -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 Wed Apr 16 2025 15:43:24 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
532
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 09:18:48 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 Wed Apr 16 2025 15:43:24 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1110
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 09:18:48 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#line197">line 197</a>
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
- &lt;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 Wed Apr 16 2025 15:43:24 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
752
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 09:18:48 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 managerMergeSlices from './managerMergeSlices.mjs'
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)) {
@@ -579,20 +567,24 @@ function WConverhpServer(opt = {}) {
579
567
  chunks.push(chunk)
580
568
  // console.log('chunk.length', chunk.length)
581
569
 
582
- //setTimeout, 延遲觸發cb
583
- setTimeout(() => {
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] finished')
579
+ })
580
+
590
581
  //pipe
591
582
  req.payload.pipe(smw)
592
583
 
593
584
  //end
594
585
  req.payload.on('end', () => {
595
586
  // console.log(`receive payload done`)
587
+ console.log('[req.payload] end')
596
588
 
597
589
  //bb
598
590
  let bb = Buffer.concat(chunks)
@@ -606,6 +598,11 @@ function WConverhpServer(opt = {}) {
606
598
 
607
599
  })
608
600
 
601
+ //close
602
+ req.payload.on('close', () => {
603
+ console.log('[req.payload] close')
604
+ })
605
+
609
606
  //error
610
607
  req.payload.on('error', (err) => {
611
608
  // console.log(`receive payload err`, err)
@@ -1478,7 +1475,7 @@ export default WConverhpServer
1478
1475
  <br class="clear">
1479
1476
 
1480
1477
  <footer>
1481
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Apr 16 2025 15:43:24 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1478
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 09:18:48 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1482
1479
  </footer>
1483
1480
 
1484
1481
  <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 Apr 16 2025 15:43:24 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 Thu Apr 24 2025 09:18: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,6 +1,6 @@
1
1
  {
2
2
  "name": "w-converhp",
3
- "version": "2.0.40",
3
+ "version": "2.0.41",
4
4
  "main": "dist/w-converhp-server.umd.js",
5
5
  "dependencies": {
6
6
  "@hapi/hapi": "^21.4.0",
@@ -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 managerMergeSlices from './managerMergeSlices.mjs'
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)) {
@@ -532,20 +520,24 @@ function WConverhpServer(opt = {}) {
532
520
  chunks.push(chunk)
533
521
  // console.log('chunk.length', chunk.length)
534
522
 
535
- //setTimeout, 延遲觸發cb
536
- setTimeout(() => {
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] finished')
532
+ })
533
+
543
534
  //pipe
544
535
  req.payload.pipe(smw)
545
536
 
546
537
  //end
547
538
  req.payload.on('end', () => {
548
539
  // console.log(`receive payload done`)
540
+ console.log('[req.payload] end')
549
541
 
550
542
  //bb
551
543
  let bb = Buffer.concat(chunks)
@@ -559,6 +551,11 @@ function WConverhpServer(opt = {}) {
559
551
 
560
552
  })
561
553
 
554
+ //close
555
+ req.payload.on('close', () => {
556
+ console.log('[req.payload] close')
557
+ })
558
+
562
559
  //error
563
560
  req.payload.on('error', (err) => {
564
561
  // console.log(`receive payload err`, err)
@@ -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
- //managerMergeSlices
14
- let managerMergeSlices = () => {
13
+ //qPush
14
+ let qPush = (fileHash, chunkTotal, pathUploadTemp) => {
15
15
 
16
- //qPush
17
- let qPush = (fileHash, chunkTotal, pathUploadTemp) => {
16
+ //id, 使用fileHash代表不用佇列儲存, 通過id即可解析反查
17
+ let id = `${now2strp()}|${genID(6)}|${fileHash}`
18
18
 
19
- //id, 使用fileHash代表不用佇列儲存, 通過id即可解析反查
20
- let id = `${now2strp()}|${genID(6)}|${fileHash}`
19
+ //setTimeout, 脫勾觸發
20
+ setTimeout(() => {
21
+ mergeSlices(fileHash, chunkTotal, pathUploadTemp)
22
+ .catch((err) => {
23
+ console.log(err)
24
+ })
25
+ }, 1)
21
26
 
22
- //setTimeout, 脫勾觸發
23
- setTimeout(() => {
24
- mergeSlices(fileHash, chunkTotal, pathUploadTemp)
25
- .catch((err) => {
26
- console.log(err)
27
- })
28
- }, 1)
27
+ return id
28
+ }
29
29
 
30
- return id
31
- }
30
+ //qGet
31
+ let qGet = (id, pathUploadTemp) => {
32
+ let errTemp = ''
32
33
 
33
- //qGet
34
- let qGet = (id, pathUploadTemp) => {
35
- let errTemp = ''
36
-
37
- //check
38
- if (!isestr(id)) {
39
- errTemp = `invalid id[${id}]`
40
- console.log(errTemp)
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
- //fileHash
49
- let s = sep(id, '|')
50
- let fileHash = get(s, 2, '')
51
- if (!isestr(fileHash)) {
52
- errTemp = `can not find fileHash in id[${id}]`
53
- console.log(errTemp)
54
- return {
55
- state: 'error',
56
- msg: errTemp,
57
- path: '',
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
- //fp
62
- let fp = path.resolve(pathUploadTemp, fileHash)
63
- // console.log('fp', fp)
58
+ //fp
59
+ let fp = path.resolve(pathUploadTemp, fileHash)
60
+ // console.log('fp', fp)
64
61
 
65
- //fpd
66
- let fpd = path.resolve(pathUploadTemp, `${fileHash}.done`)
67
- // console.log('fpd', fpd)
62
+ //fpd
63
+ let fpd = path.resolve(pathUploadTemp, `${fileHash}.done`)
64
+ // console.log('fpd', fpd)
68
65
 
69
- //bfp, bfpd, b
70
- let bfp = fsIsFile(fp)
71
- let bfpd = fsIsFile(fpd)
72
- let b = bfp && bfpd //記得要同時偵測fp與fpd, 否則有些已經移動fp但fpd忘記刪, 就會造成誤判
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
- //check, 若有.done檔但沒合併檔, 就代表合併檔已被處理或移動, .done檔須自動刪除
75
- if (!bfp && bfpd) {
76
- fsDeleteFile(fpd)
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
- return {
85
- state: b ? 'success' : 'merging',
86
- msg: '',
87
- path: fp,
88
- }
76
+ //check, 若已經完成任務, 且外部調用get取得完成訊息, 則可自動刪除.done檔, 但因不能保證合併後有完成再處理動作, 例如移動至處理資料夾再處理, 故保留.done檔
77
+ if (b) {
78
+ // fsDeleteFile(fpd)
89
79
  }
90
80
 
91
- //r
92
- let r = {
93
- push: qPush,
94
- get: qGet,
81
+ return {
82
+ state: b ? 'success' : 'merging',
83
+ msg: '',
84
+ path: fp,
95
85
  }
86
+ }
96
87
 
97
- return r
88
+ let r = {
89
+ push: qPush,
90
+ get: qGet,
98
91
  }
99
92
 
100
93
 
101
- export default managerMergeSlices
94
+ export default r