w-converhp 2.0.34 → 2.0.36

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 Mon Apr 14 2025 15:05:12 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 Mon Apr 14 2025 17:07:31 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
533
533
  </footer>
534
534
 
535
535
  <script>prettyPrint();</script>
@@ -765,7 +765,7 @@ function WConverhpClient(opt) {
765
765
  //fileSliceHashs
766
766
  let fileSliceHashs = []
767
767
  // let n = Math.max(resCk.slks.length, 1)
768
- // let nr = Math.floor(n / 200)
768
+ // let nr = Math.floor(n / 100)
769
769
  for (let k = 0; k &lt; resCk.slks.length; k++) {
770
770
  // if (k % nr === 0) {
771
771
  // console.log(`calc hash for slices`, round(k / resCk.slks.length * 100, 1), '%')
@@ -1046,7 +1046,7 @@ export default WConverhpClient
1046
1046
  <br class="clear">
1047
1047
 
1048
1048
  <footer>
1049
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Apr 14 2025 15:05:12 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1049
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Apr 14 2025 17:07:31 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1050
1050
  </footer>
1051
1051
 
1052
1052
  <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#line198">line 198</a>
83
+ <a href="WConverhpServer.mjs.html">WConverhpServer.mjs</a>, <a href="WConverhpServer.mjs.html#line194">line 194</a>
84
84
  </li></ul></dd>
85
85
 
86
86
 
@@ -789,7 +789,7 @@
789
789
  <br class="clear">
790
790
 
791
791
  <footer>
792
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Apr 14 2025 15:05:12 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
792
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Apr 14 2025 17:07:31 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
793
793
  </footer>
794
794
 
795
795
  <script>prettyPrint();</script>
@@ -51,8 +51,6 @@ import stream from 'stream'
51
51
  import Hapi from '@hapi/hapi'
52
52
  import Inert from '@hapi/inert' //提供靜態檔案
53
53
  import get from 'lodash-es/get.js'
54
- import each from 'lodash-es/each.js'
55
- import size from 'lodash-es/size.js'
56
54
  import isNumber from 'lodash-es/isNumber.js'
57
55
  import genPm from 'wsemi/src/genPm.mjs'
58
56
  import evem from 'wsemi/src/evem.mjs'
@@ -62,7 +60,6 @@ import isp0int from 'wsemi/src/isp0int.mjs'
62
60
  import ispint from 'wsemi/src/ispint.mjs'
63
61
  import isearr from 'wsemi/src/isearr.mjs'
64
62
  import isbol from 'wsemi/src/isbol.mjs'
65
- import isnum from 'wsemi/src/isnum.mjs'
66
63
  import isfun from 'wsemi/src/isfun.mjs'
67
64
  import ispm from 'wsemi/src/ispm.mjs'
68
65
  import cint from 'wsemi/src/cint.mjs'
@@ -71,15 +68,14 @@ import str2b64 from 'wsemi/src/str2b64.mjs'
71
68
  import haskey from 'wsemi/src/haskey.mjs'
72
69
  import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
73
70
  import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
74
- import fsIsFile from 'wsemi/src/fsIsFile.mjs'
75
71
  import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
76
72
  import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
77
- import fsGetFilesInFolder from 'wsemi/src/fsGetFilesInFolder.mjs'
78
- import getFileXxHash from 'wsemi/src/getFileXxHash.mjs'
79
- // import calcFileHash from './calcFileHash.mjs'
80
- import calcFileHash from './calcFileHash.wk.umd.js'
81
73
  // import mergeFiles from './mergeFiles.mjs'
82
74
  import mergeFiles from './mergeFiles.wk.umd.js'
75
+ // import checkTotalHash from './checkTotalHash.mjs'
76
+ import checkTotalHash from './checkTotalHash.wk.umd.js'
77
+ // import checkSlicesHash from './checkSlicesHash.mjs'
78
+ import checkSlicesHash from './checkSlicesHash.wk.umd.js'
83
79
 
84
80
 
85
81
  //回傳前端stream時(POST或GET皆可), 前端會須等stream傳完才能判斷是否為大檔或錯誤訊息, 此會導致若回傳超大檔, 會需要對超大檔進行解析會有記憶體上限問題, 故需要通過header提供基本成功或失敗訊息, 讓前端能進行解析判斷
@@ -730,181 +726,28 @@ function WConverhpServer(opt = {}) {
730
726
  return responseU8aStreamWithError(res, 'invalid fileHash in payload')
731
727
  }
732
728
 
733
- //checkTotalHash
734
- let checkTotalHash = async () => {
735
-
736
- //pathFile
737
- let pathFile = path.join(pathUploadTemp, fileHash)
738
- // console.log('pathFile', pathFile)
739
-
740
- //bAllExist
741
- let bAllExist = false
742
- if (true) {
743
- // console.log(`check exist for pathFile[${pathFile}]...`)
744
-
745
- bAllExist = fsIsFile(pathFile)
746
-
747
- // console.log(`check exist for pathFile[${pathFile}] done`, bAllExist)
748
- }
729
+ //out
730
+ let out = null
731
+ if (mode === 'check-total-hash') {
749
732
 
750
733
  //fileSize, 從payload接收
751
734
  let fileSize = get(req, 'payload.fileSize', '')
752
735
 
753
- //check
754
- if (!isnum(fileSize)) {
755
- // console.log('invalid fileSize in payload')
756
- let r = {
757
- error: 'invalid fileSize in payload',
758
- }
759
- return r
760
- }
761
-
762
- //bAllSize
763
- let bAllSize = false
764
- if (bAllExist) {
765
- // console.log(`check size for pathFile[${pathFile}]...`)
766
-
767
- //_fileSize
768
- let stats = fs.statSync(pathFile)
769
- let _fileSize = stats.size
770
-
771
- //bAllSize
772
- bAllSize = fileSize === _fileSize
773
-
774
- // console.log(`check size for pathFile[${pathFile}] done`, bAllSize)
775
- }
776
-
777
- //bAllHash
778
- let bAllHash = false
779
- if (bAllExist &amp;&amp; bAllSize) {
780
- // console.log(`check hash for pathFile[${pathFile}]...`)
781
-
782
- //bAllHash
783
- await calcFileHash(pathFile)
784
- .then((_fileHash) => {
785
- bAllHash = fileHash === _fileHash
786
- })
787
- .catch((err) => {
788
- console.log(err)
789
- console.log(`fsIsFile(pathFile)`, pathFile, fsIsFile(pathFile))
790
- bAllHash = false
791
- })
792
-
793
- // console.log(`check hash for pathFile[${pathFile}] done`, bAllHash)
794
- }
795
-
796
- //vfps
797
- let vfps = fsGetFilesInFolder(pathUploadTemp)
798
- // console.log('vfps', vfps)
799
-
800
- //slks
801
- let slks = []
802
- if (true) {
803
- each(vfps, (v, k) => {
804
- let b1 = (v.name).indexOf(`${fileHash}_`) >= 0
805
- let stats = fs.statSync(v.path)
806
- let b2 = stats.size === sizeSlice
807
- let b = b1 &amp;&amp; b2
808
- if (b) {
809
- slks.push(k)
810
- }
811
- })
812
- }
813
- // console.log('slks', slks)
814
-
815
- //bSls
816
- let bSls = size(slks) > 0
817
- // console.log('bSls', bSls)
818
-
819
- //r
820
- let r = {
821
- success: {
822
- path: pathFile,
823
- bAllExist,
824
- bAllSize,
825
- bAllHash,
826
- bSls,
827
- slks,
828
- },
829
- }
736
+ //checkTotalHash
737
+ out = await checkTotalHash(fileSize, sizeSlice, fileHash, pathUploadTemp)
830
738
 
831
- return r
832
739
  }
833
-
834
- //checkSlicesHash
835
- let checkSlicesHash = async() => {
740
+ else if (mode === 'check-slices-hash') {
836
741
 
837
742
  //fileSliceHashs, 從payload接收
838
743
  let fileSliceHashs = get(req, 'payload.fileSliceHashs', [])
839
744
  // console.log('fileSliceHashs', fileSliceHashs)
840
745
 
841
- //check, 前端須檢核, 若之前已回應無切片, 就不能再調用檢測切片hash的API
842
- if (size(fileSliceHashs) === 0) {
843
- let r = {
844
- error: 'no fileSliceHashs',
845
- }
846
- return r
847
- }
848
-
849
- //slksCfm, 已確定hash值一致的切片
850
- // console.log(`check hash for slices fileHash[${fileHash}]...`, fileSliceHashs[0], size(fileSliceHashs))
851
- let slksCfm = []
852
- // let n = Math.max(fileSliceHashs.length, 1)
853
- // let nr = Math.floor(n / 200)
854
- for (let k = 0; k &lt; fileSliceHashs.length; k++) {
855
- // if (k % nr === 0) {
856
- // console.log(`calc hash for slices`, round(k / fileSliceHashs.length * 100, 1), '%')
857
- // }
858
-
859
- //v
860
- let v = fileSliceHashs[k]
861
-
862
- //_pathFile
863
- let _pathFile = path.join(pathUploadTemp, `${fileHash}_${v.i}`)
864
- // console.log('_pathFile', _pathFile)
865
-
866
- //_fileHash
867
- let _fileHash = ''
868
- // await calcFileHash(_pathFile)
869
- await getFileXxHash(new Blob([fs.readFileSync(_pathFile)])) //計算切片因檔案很小, 直接用getFileXxHash速度比較快
870
- .then((res) => {
871
- _fileHash = res
872
- })
873
- .catch((err) => {
874
- console.log(err)
875
- console.log(`fsIsFile(_pathFile)`, _pathFile, fsIsFile(_pathFile))
876
- })
877
- // console.log('_fileHash', _fileHash)
878
-
879
- //check
880
- if (v.h === _fileHash) {
881
- slksCfm.push(v.i)
882
- }
883
- // else {
884
- // console.log(`hash is not equal`, `hash(front)`, v.h, `hash(backend)`, _fileHash)
885
- // }
886
-
887
- }
888
- // console.log(`check hash for slices fileHash[${fileHash}] done`, slksCfm[0], size(slksCfm))
889
-
890
- //r
891
- let r = {
892
- success: {
893
- slks: slksCfm,
894
- },
895
- }
896
-
897
- return r
898
- }
746
+ //checkSlicesHash
747
+ out = await checkSlicesHash(fileSliceHashs, fileHash, pathUploadTemp)
899
748
 
900
- //out
901
- let out = null
902
- if (mode === 'check-total-hash') {
903
- out = await checkTotalHash()
904
- }
905
- else if (mode === 'check-slices-hash') {
906
- out = await checkSlicesHash()
907
749
  }
750
+ // console.log('out', out)
908
751
 
909
752
  if (out.error) {
910
753
  return responseU8aStreamWithError(res, out.error)
@@ -1142,15 +985,15 @@ function WConverhpServer(opt = {}) {
1142
985
 
1143
986
  //merge
1144
987
  // console.log('merge start')
1145
- let r = await mergeFiles(pathUploadTemp, packageId, chunkTotal, filename)
1146
- // console.log('merge done', r)
988
+ let rMerg = await mergeFiles(pathUploadTemp, packageId, chunkTotal, filename)
989
+ // console.log('merge done', rMerg)
1147
990
 
1148
991
  //procUpload
1149
992
  // console.log('procUpload start')
1150
- let rr = await procUpload(r)
1151
- // console.log('procUpload done', rr)
993
+ let rProc = await procUpload(rMerg)
994
+ // console.log('procUpload done', rProc)
1152
995
 
1153
- return rr
996
+ return rProc
1154
997
  }
1155
998
 
1156
999
  //mergeAndPorc
@@ -1396,14 +1239,6 @@ function WConverhpServer(opt = {}) {
1396
1239
  //streamRead
1397
1240
  let streamRead = get(r, 'streamRead')
1398
1241
 
1399
- // //filename
1400
- // let filename = get(r, 'filename')
1401
- // if (!isestr(filename)) {
1402
- // return responseU8aStreamWithError(res, 'invalid filename')
1403
- // }
1404
- // filename = str2b64(filename) //headers內對中文支援度不佳須用base64傳
1405
- // console.log('filename', filename)
1406
-
1407
1242
  //fileSize
1408
1243
  let fileSize = get(r, 'fileSize')
1409
1244
  if (!isNumber(fileSize)) {
@@ -1650,7 +1485,7 @@ export default WConverhpServer
1650
1485
  <br class="clear">
1651
1486
 
1652
1487
  <footer>
1653
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Apr 14 2025 15:05:12 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1488
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Apr 14 2025 17:07:31 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1654
1489
  </footer>
1655
1490
 
1656
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 Mon Apr 14 2025 15:05:12 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 Mon Apr 14 2025 17:07:31 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.34",
3
+ "version": "2.0.36",
4
4
  "main": "dist/w-converhp-server.umd.js",
5
5
  "dependencies": {
6
6
  "@hapi/hapi": "^21.4.0",
package/script.txt CHANGED
@@ -1,10 +1,10 @@
1
- #node --experimental-modules toolg/addVersion.mjs
2
- node --experimental-modules toolg/modifyReadme.mjs
1
+ #node toolg/addVersion.mjs
2
+ node toolg/modifyReadme.mjs
3
3
 
4
- node --experimental-modules toolg/cleanFolder.mjs
4
+ node toolg/cleanFolder.mjs
5
5
  ./node_modules/.bin/jsdoc -c .jsdoc
6
6
 
7
- node --experimental-modules toolg/gDistRollup.mjs
7
+ node toolg/gDistRollup.mjs
8
8
 
9
9
  git add . -A
10
10
  git commit -m 'modify: '
@@ -718,7 +718,7 @@ function WConverhpClient(opt) {
718
718
  //fileSliceHashs
719
719
  let fileSliceHashs = []
720
720
  // let n = Math.max(resCk.slks.length, 1)
721
- // let nr = Math.floor(n / 200)
721
+ // let nr = Math.floor(n / 100)
722
722
  for (let k = 0; k < resCk.slks.length; k++) {
723
723
  // if (k % nr === 0) {
724
724
  // console.log(`calc hash for slices`, round(k / resCk.slks.length * 100, 1), '%')
@@ -4,8 +4,6 @@ import stream from 'stream'
4
4
  import Hapi from '@hapi/hapi'
5
5
  import Inert from '@hapi/inert' //提供靜態檔案
6
6
  import get from 'lodash-es/get.js'
7
- import each from 'lodash-es/each.js'
8
- import size from 'lodash-es/size.js'
9
7
  import isNumber from 'lodash-es/isNumber.js'
10
8
  import genPm from 'wsemi/src/genPm.mjs'
11
9
  import evem from 'wsemi/src/evem.mjs'
@@ -15,7 +13,6 @@ import isp0int from 'wsemi/src/isp0int.mjs'
15
13
  import ispint from 'wsemi/src/ispint.mjs'
16
14
  import isearr from 'wsemi/src/isearr.mjs'
17
15
  import isbol from 'wsemi/src/isbol.mjs'
18
- import isnum from 'wsemi/src/isnum.mjs'
19
16
  import isfun from 'wsemi/src/isfun.mjs'
20
17
  import ispm from 'wsemi/src/ispm.mjs'
21
18
  import cint from 'wsemi/src/cint.mjs'
@@ -24,15 +21,14 @@ import str2b64 from 'wsemi/src/str2b64.mjs'
24
21
  import haskey from 'wsemi/src/haskey.mjs'
25
22
  import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
26
23
  import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
27
- import fsIsFile from 'wsemi/src/fsIsFile.mjs'
28
24
  import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
29
25
  import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
30
- import fsGetFilesInFolder from 'wsemi/src/fsGetFilesInFolder.mjs'
31
- import getFileXxHash from 'wsemi/src/getFileXxHash.mjs'
32
- // import calcFileHash from './calcFileHash.mjs'
33
- import calcFileHash from './calcFileHash.wk.umd.js'
34
26
  // import mergeFiles from './mergeFiles.mjs'
35
27
  import mergeFiles from './mergeFiles.wk.umd.js'
28
+ // import checkTotalHash from './checkTotalHash.mjs'
29
+ import checkTotalHash from './checkTotalHash.wk.umd.js'
30
+ // import checkSlicesHash from './checkSlicesHash.mjs'
31
+ import checkSlicesHash from './checkSlicesHash.wk.umd.js'
36
32
 
37
33
 
38
34
  //回傳前端stream時(POST或GET皆可), 前端會須等stream傳完才能判斷是否為大檔或錯誤訊息, 此會導致若回傳超大檔, 會需要對超大檔進行解析會有記憶體上限問題, 故需要通過header提供基本成功或失敗訊息, 讓前端能進行解析判斷
@@ -683,181 +679,28 @@ function WConverhpServer(opt = {}) {
683
679
  return responseU8aStreamWithError(res, 'invalid fileHash in payload')
684
680
  }
685
681
 
686
- //checkTotalHash
687
- let checkTotalHash = async () => {
688
-
689
- //pathFile
690
- let pathFile = path.join(pathUploadTemp, fileHash)
691
- // console.log('pathFile', pathFile)
692
-
693
- //bAllExist
694
- let bAllExist = false
695
- if (true) {
696
- // console.log(`check exist for pathFile[${pathFile}]...`)
697
-
698
- bAllExist = fsIsFile(pathFile)
699
-
700
- // console.log(`check exist for pathFile[${pathFile}] done`, bAllExist)
701
- }
682
+ //out
683
+ let out = null
684
+ if (mode === 'check-total-hash') {
702
685
 
703
686
  //fileSize, 從payload接收
704
687
  let fileSize = get(req, 'payload.fileSize', '')
705
688
 
706
- //check
707
- if (!isnum(fileSize)) {
708
- // console.log('invalid fileSize in payload')
709
- let r = {
710
- error: 'invalid fileSize in payload',
711
- }
712
- return r
713
- }
714
-
715
- //bAllSize
716
- let bAllSize = false
717
- if (bAllExist) {
718
- // console.log(`check size for pathFile[${pathFile}]...`)
719
-
720
- //_fileSize
721
- let stats = fs.statSync(pathFile)
722
- let _fileSize = stats.size
723
-
724
- //bAllSize
725
- bAllSize = fileSize === _fileSize
726
-
727
- // console.log(`check size for pathFile[${pathFile}] done`, bAllSize)
728
- }
729
-
730
- //bAllHash
731
- let bAllHash = false
732
- if (bAllExist && bAllSize) {
733
- // console.log(`check hash for pathFile[${pathFile}]...`)
734
-
735
- //bAllHash
736
- await calcFileHash(pathFile)
737
- .then((_fileHash) => {
738
- bAllHash = fileHash === _fileHash
739
- })
740
- .catch((err) => {
741
- console.log(err)
742
- console.log(`fsIsFile(pathFile)`, pathFile, fsIsFile(pathFile))
743
- bAllHash = false
744
- })
745
-
746
- // console.log(`check hash for pathFile[${pathFile}] done`, bAllHash)
747
- }
748
-
749
- //vfps
750
- let vfps = fsGetFilesInFolder(pathUploadTemp)
751
- // console.log('vfps', vfps)
752
-
753
- //slks
754
- let slks = []
755
- if (true) {
756
- each(vfps, (v, k) => {
757
- let b1 = (v.name).indexOf(`${fileHash}_`) >= 0
758
- let stats = fs.statSync(v.path)
759
- let b2 = stats.size === sizeSlice
760
- let b = b1 && b2
761
- if (b) {
762
- slks.push(k)
763
- }
764
- })
765
- }
766
- // console.log('slks', slks)
767
-
768
- //bSls
769
- let bSls = size(slks) > 0
770
- // console.log('bSls', bSls)
771
-
772
- //r
773
- let r = {
774
- success: {
775
- path: pathFile,
776
- bAllExist,
777
- bAllSize,
778
- bAllHash,
779
- bSls,
780
- slks,
781
- },
782
- }
689
+ //checkTotalHash
690
+ out = await checkTotalHash(fileSize, sizeSlice, fileHash, pathUploadTemp)
783
691
 
784
- return r
785
692
  }
786
-
787
- //checkSlicesHash
788
- let checkSlicesHash = async() => {
693
+ else if (mode === 'check-slices-hash') {
789
694
 
790
695
  //fileSliceHashs, 從payload接收
791
696
  let fileSliceHashs = get(req, 'payload.fileSliceHashs', [])
792
697
  // console.log('fileSliceHashs', fileSliceHashs)
793
698
 
794
- //check, 前端須檢核, 若之前已回應無切片, 就不能再調用檢測切片hash的API
795
- if (size(fileSliceHashs) === 0) {
796
- let r = {
797
- error: 'no fileSliceHashs',
798
- }
799
- return r
800
- }
801
-
802
- //slksCfm, 已確定hash值一致的切片
803
- // console.log(`check hash for slices fileHash[${fileHash}]...`, fileSliceHashs[0], size(fileSliceHashs))
804
- let slksCfm = []
805
- // let n = Math.max(fileSliceHashs.length, 1)
806
- // let nr = Math.floor(n / 200)
807
- for (let k = 0; k < fileSliceHashs.length; k++) {
808
- // if (k % nr === 0) {
809
- // console.log(`calc hash for slices`, round(k / fileSliceHashs.length * 100, 1), '%')
810
- // }
811
-
812
- //v
813
- let v = fileSliceHashs[k]
814
-
815
- //_pathFile
816
- let _pathFile = path.join(pathUploadTemp, `${fileHash}_${v.i}`)
817
- // console.log('_pathFile', _pathFile)
818
-
819
- //_fileHash
820
- let _fileHash = ''
821
- // await calcFileHash(_pathFile)
822
- await getFileXxHash(new Blob([fs.readFileSync(_pathFile)])) //計算切片因檔案很小, 直接用getFileXxHash速度比較快
823
- .then((res) => {
824
- _fileHash = res
825
- })
826
- .catch((err) => {
827
- console.log(err)
828
- console.log(`fsIsFile(_pathFile)`, _pathFile, fsIsFile(_pathFile))
829
- })
830
- // console.log('_fileHash', _fileHash)
831
-
832
- //check
833
- if (v.h === _fileHash) {
834
- slksCfm.push(v.i)
835
- }
836
- // else {
837
- // console.log(`hash is not equal`, `hash(front)`, v.h, `hash(backend)`, _fileHash)
838
- // }
839
-
840
- }
841
- // console.log(`check hash for slices fileHash[${fileHash}] done`, slksCfm[0], size(slksCfm))
842
-
843
- //r
844
- let r = {
845
- success: {
846
- slks: slksCfm,
847
- },
848
- }
849
-
850
- return r
851
- }
699
+ //checkSlicesHash
700
+ out = await checkSlicesHash(fileSliceHashs, fileHash, pathUploadTemp)
852
701
 
853
- //out
854
- let out = null
855
- if (mode === 'check-total-hash') {
856
- out = await checkTotalHash()
857
- }
858
- else if (mode === 'check-slices-hash') {
859
- out = await checkSlicesHash()
860
702
  }
703
+ // console.log('out', out)
861
704
 
862
705
  if (out.error) {
863
706
  return responseU8aStreamWithError(res, out.error)
@@ -1095,15 +938,15 @@ function WConverhpServer(opt = {}) {
1095
938
 
1096
939
  //merge
1097
940
  // console.log('merge start')
1098
- let r = await mergeFiles(pathUploadTemp, packageId, chunkTotal, filename)
1099
- // console.log('merge done', r)
941
+ let rMerg = await mergeFiles(pathUploadTemp, packageId, chunkTotal, filename)
942
+ // console.log('merge done', rMerg)
1100
943
 
1101
944
  //procUpload
1102
945
  // console.log('procUpload start')
1103
- let rr = await procUpload(r)
1104
- // console.log('procUpload done', rr)
946
+ let rProc = await procUpload(rMerg)
947
+ // console.log('procUpload done', rProc)
1105
948
 
1106
- return rr
949
+ return rProc
1107
950
  }
1108
951
 
1109
952
  //mergeAndPorc
@@ -1349,14 +1192,6 @@ function WConverhpServer(opt = {}) {
1349
1192
  //streamRead
1350
1193
  let streamRead = get(r, 'streamRead')
1351
1194
 
1352
- // //filename
1353
- // let filename = get(r, 'filename')
1354
- // if (!isestr(filename)) {
1355
- // return responseU8aStreamWithError(res, 'invalid filename')
1356
- // }
1357
- // filename = str2b64(filename) //headers內對中文支援度不佳須用base64傳
1358
- // console.log('filename', filename)
1359
-
1360
1195
  //fileSize
1361
1196
  let fileSize = get(r, 'fileSize')
1362
1197
  if (!isNumber(fileSize)) {