w-converhp 2.0.45 → 2.0.47

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 Thu Apr 24 2025 10:55:27 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 Fri May 16 2025 14:05:37 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
533
533
  </footer>
534
534
 
535
535
  <script>prettyPrint();</script>
@@ -206,25 +206,22 @@ function WConverhpClient(opt) {
206
206
  //urlUse
207
207
  let urlUse = ''
208
208
  if (type === 'basic') {
209
- urlUse = url
210
- }
211
- else if (type === 'slice') {
212
- urlUse = `${url}slc`
209
+ urlUse = `${url}/main` //bbb
213
210
  }
214
211
  else if (type === 'upload-controller') {
215
- urlUse = `${url}ulctr`
212
+ urlUse = `${url}/ulctr` //bbb
213
+ }
214
+ else if (type === 'slice') {
215
+ urlUse = `${url}/slc` //bbb
216
216
  }
217
- // else if (type === 'slice-merge') {
218
- // urlUse = `${url}slcm`
219
- // }
220
217
  else if (type === 'download-get-filename') {
221
- urlUse = `${url}dwgfn`
218
+ urlUse = `${url}/dwgfn` //bbb
222
219
  }
223
220
  else if (type === 'download-get') {
224
- urlUse = `${url}dwgf`
221
+ urlUse = `${url}/dwgf` //bbb
225
222
  }
226
223
  else if (type === 'download') {
227
- urlUse = `${url}dw`
224
+ urlUse = `${url}/dw` //bbb
228
225
  }
229
226
  else {
230
227
  throw new Error(`invalid type[${type}]`)
@@ -485,9 +482,11 @@ function WConverhpClient(opt) {
485
482
  //nodejs通過fs與stream接收檔案, stream出錯只會觸發error事件, 此處try catch為攔截其他非stream程式碼錯誤
486
483
  try {
487
484
 
488
- //path, fs, 使用動態import供nodejs使用, 否則會被webpack偵測報錯
489
- let path = await import('path')
490
- let fs = await import('fs')
485
+ //path, fs, 使用動態import供nodejs使用, 須用變數字串給予載入套件, 否則用於前端時會被webpack偵測而報錯
486
+ let cImPath = 'path'
487
+ let cImFs = 'fs'
488
+ let path = await import(cImPath)
489
+ let fs = await import(cImFs)
491
490
 
492
491
  //fdDownload, 只有nodejs下載才使用fdDownload
493
492
  let fdDownload = get(opt, 'fdDownload', '')
@@ -729,17 +728,13 @@ function WConverhpClient(opt) {
729
728
  let progWeightSlice = 0.99 //上傳階段進度使用99%
730
729
  // let progWeightMerge = 0.01 //合併階段進度使用1%
731
730
 
732
- //cbProgressSlice
733
- let cbProgressSlice = (msg) => {
734
- let perc = msg.prog
735
- let dir = msg.m
736
- if (dir === 'upload' &amp;&amp; perc === 100) {
737
- progCount++
738
- let r = progCount / chunkTotal
739
- let prog = r * progWeightSlice * 100
740
- let psiz = r * fileTotalSize
741
- cbProgress({ prog, p: psiz, m: 'upload' })
742
- }
731
+ //cbProgressSlice, 以累積機制計算進度, 累積片數配合總切片數量即可算出進度, 故不須輸入msg
732
+ let cbProgressSlice = () => {
733
+ progCount++
734
+ let r = progCount / chunkTotal
735
+ let prog = r * progWeightSlice * 100
736
+ let psiz = r * fileTotalSize
737
+ cbProgress({ prog, p: psiz, m: 'upload' })
743
738
  }
744
739
 
745
740
  //cbProgressMerge
@@ -855,7 +850,7 @@ function WConverhpClient(opt) {
855
850
  //check
856
851
  if (resUpCkt.slks.indexOf(i) >= 0) {
857
852
  // console.log('已有上傳切片檔')
858
- cbProgressSlice({ prog: 100, m: 'upload' }) //直接觸發更新進度
853
+ cbProgressSlice() //直接觸發更新進度
859
854
  continue
860
855
  }
861
856
 
@@ -868,14 +863,65 @@ function WConverhpClient(opt) {
868
863
  //chunk
869
864
  let chunk = bb.slice(start, end)
870
865
 
871
- //send slice
872
- let hd = { //用header傳key與value時, key不分大小寫, 故使用kebabCase
873
- 'chunk-index': i,
874
- 'chunk-total': chunkTotal,
875
- 'package-id': packageId,
866
+ //sendDataSlice
867
+ let sendDataSlice = async() => {
868
+
869
+ //hd
870
+ let hd = { //用header傳key與value時, key不分大小寫, 故使用kebabCase
871
+ 'chunk-index': i,
872
+ 'chunk-total': chunkTotal,
873
+ 'package-id': packageId,
874
+ }
875
+
876
+ //send slice
877
+ let resSl = await send('slice', chunk, {
878
+ headers: hd,
879
+ dataType: 'blob',
880
+ cbProgress: (msg) => {
881
+ // console.log('cbProgress', msg)
882
+ // let perc = msg.prog
883
+ // let dir = msg.m
884
+ // if (dir === 'upload' &amp;&amp; perc === 100) {
885
+ // }
886
+ }
887
+ })
888
+ // console.log('resSl', resSl)
889
+
890
+ //cbProgressSlice, 因其內有累加progCount, 實際代表是須成功傳輸後才能計算與回應外部進度, 故不能直接用於send的opt.cbProgress
891
+ cbProgressSlice()
892
+
893
+ return resSl
894
+ }
895
+
896
+ //sendDataSliceRetry
897
+ let sendDataSliceRetry = async() => {
898
+
899
+ //fun
900
+ let fun = pmConvertResolve(sendDataSlice)
901
+
902
+ //sendPkg
903
+ let r = await fun()
904
+
905
+ let n = 0
906
+ while (r.state === 'error') {
907
+ n += 1
908
+ if (n > retry) {
909
+ break
910
+ }
911
+ console.log(`retry n=${n}`)
912
+ r = await fun()
913
+ }
914
+
915
+ if (r.state === 'success') {
916
+ return r.msg
917
+ }
918
+ else {
919
+ return Promise.reject(r.msg)
920
+ }
876
921
  }
877
- await send('slice', chunk, { headers: hd, dataType: 'blob', cbProgress: cbProgressSlice })
878
- // console.log('resSl', resSl)
922
+
923
+ //sendDataSliceRetry
924
+ await sendDataSliceRetry()
879
925
 
880
926
  }
881
927
 
@@ -1107,7 +1153,7 @@ export default WConverhpClient
1107
1153
  <br class="clear">
1108
1154
 
1109
1155
  <footer>
1110
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 10:55:27 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1156
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri May 16 2025 14:05:37 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1111
1157
  </footer>
1112
1158
 
1113
1159
  <script>prettyPrint();</script>
@@ -749,7 +749,7 @@
749
749
  <br class="clear">
750
750
 
751
751
  <footer>
752
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 10:55:27 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 Fri May 16 2025 14:05:37 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
753
753
  </footer>
754
754
 
755
755
  <script>prettyPrint();</script>
@@ -495,7 +495,7 @@ function WConverhpServer(opt = {}) {
495
495
 
496
496
  //apiMain
497
497
  let apiMain = {
498
- path: `/${apiName}`,
498
+ path: `/${apiName}/main`, //bbb
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`, //bbb
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`, //bbb
873
873
  method: 'POST',
874
874
  options: {
875
875
  payload: {
@@ -1006,13 +1006,24 @@ function WConverhpServer(opt = {}) {
1006
1006
  let u8aOut = obj2u8arr(out)
1007
1007
  // console.log('u8aOut', u8aOut)
1008
1008
 
1009
+ // //測試失敗重傳
1010
+ // if (Math.random() &lt; 0.9) {
1011
+ // out = {
1012
+ // error: 'force error'
1013
+ // }
1014
+ // returnType = 'error'
1015
+ // returnMsg = 'force error'
1016
+ // // console.log('out', out)
1017
+ // u8aOut = obj2u8arr(out)
1018
+ // }
1019
+
1009
1020
  return responseU8aStream(res, u8aOut, { returnType, returnMsg })
1010
1021
  },
1011
1022
  }
1012
1023
 
1013
1024
  //apiDownloadGetFilename
1014
1025
  let apiDownloadGetFilename = {
1015
- path: `/${apiName}dwgfn`,
1026
+ path: `/${apiName}/dwgfn`, //bbb
1016
1027
  method: 'POST',
1017
1028
  options: {
1018
1029
  payload: {
@@ -1134,7 +1145,7 @@ function WConverhpServer(opt = {}) {
1134
1145
 
1135
1146
  //apiDownloadGetFile
1136
1147
  let apiDownloadGetFile = {
1137
- path: `/${apiName}dwgf`,
1148
+ path: `/${apiName}/dwgf`, //bbb
1138
1149
  method: 'GET',
1139
1150
  options: {
1140
1151
  timeout: {
@@ -1258,7 +1269,7 @@ function WConverhpServer(opt = {}) {
1258
1269
 
1259
1270
  //apiDownload
1260
1271
  let apiDownload = {
1261
- path: `/${apiName}dw`,
1272
+ path: `/${apiName}/dw`, //bbb
1262
1273
  method: 'POST',
1263
1274
  options: {
1264
1275
  payload: {
@@ -1474,7 +1485,7 @@ export default WConverhpServer
1474
1485
  <br class="clear">
1475
1486
 
1476
1487
  <footer>
1477
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Apr 24 2025 10:55:27 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 Fri May 16 2025 14:05:37 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1478
1489
  </footer>
1479
1490
 
1480
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 Thu Apr 24 2025 10:55:27 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 Fri May 16 2025 14:05:37 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,17 +1,17 @@
1
1
  {
2
2
  "name": "w-converhp",
3
- "version": "2.0.45",
3
+ "version": "2.0.47",
4
4
  "main": "dist/w-converhp-server.umd.js",
5
5
  "dependencies": {
6
6
  "@hapi/hapi": "^21.4.0",
7
7
  "@hapi/inert": "^7.1.0",
8
- "axios": "^1.8.4",
8
+ "axios": "^1.9.0",
9
9
  "lodash-es": "^4.17.21",
10
- "wsemi": "^1.7.89"
10
+ "wsemi": "^1.7.90"
11
11
  },
12
12
  "devDependencies": {
13
13
  "form-data": "^4.0.2",
14
- "w-package-tools": "^1.0.87"
14
+ "w-package-tools": "^1.0.90"
15
15
  },
16
16
  "scripts": {
17
17
  "@hapi/hapi": "^20.2.1",
@@ -159,25 +159,22 @@ function WConverhpClient(opt) {
159
159
  //urlUse
160
160
  let urlUse = ''
161
161
  if (type === 'basic') {
162
- urlUse = url
163
- }
164
- else if (type === 'slice') {
165
- urlUse = `${url}slc`
162
+ urlUse = `${url}/main` //bbb
166
163
  }
167
164
  else if (type === 'upload-controller') {
168
- urlUse = `${url}ulctr`
165
+ urlUse = `${url}/ulctr` //bbb
166
+ }
167
+ else if (type === 'slice') {
168
+ urlUse = `${url}/slc` //bbb
169
169
  }
170
- // else if (type === 'slice-merge') {
171
- // urlUse = `${url}slcm`
172
- // }
173
170
  else if (type === 'download-get-filename') {
174
- urlUse = `${url}dwgfn`
171
+ urlUse = `${url}/dwgfn` //bbb
175
172
  }
176
173
  else if (type === 'download-get') {
177
- urlUse = `${url}dwgf`
174
+ urlUse = `${url}/dwgf` //bbb
178
175
  }
179
176
  else if (type === 'download') {
180
- urlUse = `${url}dw`
177
+ urlUse = `${url}/dw` //bbb
181
178
  }
182
179
  else {
183
180
  throw new Error(`invalid type[${type}]`)
@@ -438,9 +435,11 @@ function WConverhpClient(opt) {
438
435
  //nodejs通過fs與stream接收檔案, stream出錯只會觸發error事件, 此處try catch為攔截其他非stream程式碼錯誤
439
436
  try {
440
437
 
441
- //path, fs, 使用動態import供nodejs使用, 否則會被webpack偵測報錯
442
- let path = await import('path')
443
- let fs = await import('fs')
438
+ //path, fs, 使用動態import供nodejs使用, 須用變數字串給予載入套件, 否則用於前端時會被webpack偵測而報錯
439
+ let cImPath = 'path'
440
+ let cImFs = 'fs'
441
+ let path = await import(cImPath)
442
+ let fs = await import(cImFs)
444
443
 
445
444
  //fdDownload, 只有nodejs下載才使用fdDownload
446
445
  let fdDownload = get(opt, 'fdDownload', '')
@@ -682,17 +681,13 @@ function WConverhpClient(opt) {
682
681
  let progWeightSlice = 0.99 //上傳階段進度使用99%
683
682
  // let progWeightMerge = 0.01 //合併階段進度使用1%
684
683
 
685
- //cbProgressSlice
686
- let cbProgressSlice = (msg) => {
687
- let perc = msg.prog
688
- let dir = msg.m
689
- if (dir === 'upload' && perc === 100) {
690
- progCount++
691
- let r = progCount / chunkTotal
692
- let prog = r * progWeightSlice * 100
693
- let psiz = r * fileTotalSize
694
- cbProgress({ prog, p: psiz, m: 'upload' })
695
- }
684
+ //cbProgressSlice, 以累積機制計算進度, 累積片數配合總切片數量即可算出進度, 故不須輸入msg
685
+ let cbProgressSlice = () => {
686
+ progCount++
687
+ let r = progCount / chunkTotal
688
+ let prog = r * progWeightSlice * 100
689
+ let psiz = r * fileTotalSize
690
+ cbProgress({ prog, p: psiz, m: 'upload' })
696
691
  }
697
692
 
698
693
  //cbProgressMerge
@@ -808,7 +803,7 @@ function WConverhpClient(opt) {
808
803
  //check
809
804
  if (resUpCkt.slks.indexOf(i) >= 0) {
810
805
  // console.log('已有上傳切片檔')
811
- cbProgressSlice({ prog: 100, m: 'upload' }) //直接觸發更新進度
806
+ cbProgressSlice() //直接觸發更新進度
812
807
  continue
813
808
  }
814
809
 
@@ -821,14 +816,65 @@ function WConverhpClient(opt) {
821
816
  //chunk
822
817
  let chunk = bb.slice(start, end)
823
818
 
824
- //send slice
825
- let hd = { //用header傳key與value時, key不分大小寫, 故使用kebabCase
826
- 'chunk-index': i,
827
- 'chunk-total': chunkTotal,
828
- 'package-id': packageId,
819
+ //sendDataSlice
820
+ let sendDataSlice = async() => {
821
+
822
+ //hd
823
+ let hd = { //用header傳key與value時, key不分大小寫, 故使用kebabCase
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
847
+ }
848
+
849
+ //sendDataSliceRetry
850
+ let sendDataSliceRetry = async() => {
851
+
852
+ //fun
853
+ let fun = pmConvertResolve(sendDataSlice)
854
+
855
+ //sendPkg
856
+ let r = await fun()
857
+
858
+ let n = 0
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
870
+ }
871
+ else {
872
+ return Promise.reject(r.msg)
873
+ }
829
874
  }
830
- await send('slice', chunk, { headers: hd, dataType: 'blob', cbProgress: cbProgressSlice })
831
- // console.log('resSl', resSl)
875
+
876
+ //sendDataSliceRetry
877
+ await sendDataSliceRetry()
832
878
 
833
879
  }
834
880
 
@@ -448,7 +448,7 @@ function WConverhpServer(opt = {}) {
448
448
 
449
449
  //apiMain
450
450
  let apiMain = {
451
- path: `/${apiName}`,
451
+ path: `/${apiName}/main`, //bbb
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`, //bbb
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`, //bbb
826
826
  method: 'POST',
827
827
  options: {
828
828
  payload: {
@@ -959,13 +959,24 @@ function WConverhpServer(opt = {}) {
959
959
  let u8aOut = obj2u8arr(out)
960
960
  // console.log('u8aOut', u8aOut)
961
961
 
962
+ // //測試失敗重傳
963
+ // if (Math.random() < 0.9) {
964
+ // out = {
965
+ // error: 'force error'
966
+ // }
967
+ // returnType = 'error'
968
+ // returnMsg = 'force error'
969
+ // // console.log('out', out)
970
+ // u8aOut = obj2u8arr(out)
971
+ // }
972
+
962
973
  return responseU8aStream(res, u8aOut, { returnType, returnMsg })
963
974
  },
964
975
  }
965
976
 
966
977
  //apiDownloadGetFilename
967
978
  let apiDownloadGetFilename = {
968
- path: `/${apiName}dwgfn`,
979
+ path: `/${apiName}/dwgfn`, //bbb
969
980
  method: 'POST',
970
981
  options: {
971
982
  payload: {
@@ -1087,7 +1098,7 @@ function WConverhpServer(opt = {}) {
1087
1098
 
1088
1099
  //apiDownloadGetFile
1089
1100
  let apiDownloadGetFile = {
1090
- path: `/${apiName}dwgf`,
1101
+ path: `/${apiName}/dwgf`, //bbb
1091
1102
  method: 'GET',
1092
1103
  options: {
1093
1104
  timeout: {
@@ -1211,7 +1222,7 @@ function WConverhpServer(opt = {}) {
1211
1222
 
1212
1223
  //apiDownload
1213
1224
  let apiDownload = {
1214
- path: `/${apiName}dw`,
1225
+ path: `/${apiName}/dw`, //bbb
1215
1226
  method: 'POST',
1216
1227
  options: {
1217
1228
  payload: {