w-converhp 2.0.30 → 2.0.32
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 +2 -2
- package/dist/w-converhp-server.umd.js.map +1 -1
- package/docs/WConverhpClient.html +2 -2
- package/docs/WConverhpClient.mjs.html +27 -40
- package/docs/WConverhpServer.html +2 -2
- package/docs/WConverhpServer.mjs.html +42 -16
- package/docs/index.html +1 -1
- package/package.json +2 -2
- package/sclc.mjs +2 -2
- package/src/WConverhpClient.mjs +26 -39
- package/src/WConverhpServer.mjs +41 -15
- package/src/calcFileHash.mjs +10 -0
- package/src/calcFileHash.wk.umd.js +1 -0
- package/srv.mjs +1 -1
- package/toolg/gDistRollup.mjs +22 -2
|
@@ -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#line193">line 193</a>
|
|
84
84
|
</li></ul></dd>
|
|
85
85
|
|
|
86
86
|
|
|
@@ -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
|
|
752
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Apr 13 2025 11:30:23 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
753
753
|
</footer>
|
|
754
754
|
|
|
755
755
|
<script>prettyPrint();</script>
|
|
@@ -60,6 +60,7 @@ import isp0int from 'wsemi/src/isp0int.mjs'
|
|
|
60
60
|
import ispint from 'wsemi/src/ispint.mjs'
|
|
61
61
|
import isearr from 'wsemi/src/isearr.mjs'
|
|
62
62
|
import isbol from 'wsemi/src/isbol.mjs'
|
|
63
|
+
import isnum from 'wsemi/src/isnum.mjs'
|
|
63
64
|
import isfun from 'wsemi/src/isfun.mjs'
|
|
64
65
|
import ispm from 'wsemi/src/ispm.mjs'
|
|
65
66
|
import cint from 'wsemi/src/cint.mjs'
|
|
@@ -71,9 +72,10 @@ import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
|
|
|
71
72
|
import fsIsFile from 'wsemi/src/fsIsFile.mjs'
|
|
72
73
|
import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
|
|
73
74
|
import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
|
|
74
|
-
import
|
|
75
|
-
import
|
|
75
|
+
// import calcFileHash from './calcFileHash.mjs'
|
|
76
|
+
import calcFileHash from './calcFileHash.wk.umd.js'
|
|
76
77
|
// import mergeFiles from './mergeFiles.mjs'
|
|
78
|
+
import mergeFiles from './mergeFiles.wk.umd.js'
|
|
77
79
|
|
|
78
80
|
|
|
79
81
|
//回傳前端stream時(POST或GET皆可), 前端會須等stream傳完才能判斷是否為大檔或錯誤訊息, 此會導致若回傳超大檔, 會需要對超大檔進行解析會有記憶體上限問題, 故需要通過header提供基本成功或失敗訊息, 讓前端能進行解析判斷
|
|
@@ -647,9 +649,9 @@ function WConverhpServer(opt = {}) {
|
|
|
647
649
|
},
|
|
648
650
|
}
|
|
649
651
|
|
|
650
|
-
//
|
|
651
|
-
let
|
|
652
|
-
path: `/${apiName}
|
|
652
|
+
//apiUploadCheck
|
|
653
|
+
let apiUploadCheck = {
|
|
654
|
+
path: `/${apiName}ulck`,
|
|
653
655
|
method: 'POST',
|
|
654
656
|
options: {
|
|
655
657
|
payload: {
|
|
@@ -686,7 +688,7 @@ function WConverhpServer(opt = {}) {
|
|
|
686
688
|
if (true) {
|
|
687
689
|
|
|
688
690
|
//verifyConn
|
|
689
|
-
let m = verifyConn({ apiType: 'upload-check
|
|
691
|
+
let m = verifyConn({ apiType: 'upload-check', authorization, headers, query })
|
|
690
692
|
if (ispm(m)) {
|
|
691
693
|
m = await m
|
|
692
694
|
}
|
|
@@ -700,15 +702,17 @@ function WConverhpServer(opt = {}) {
|
|
|
700
702
|
|
|
701
703
|
//eeEmit
|
|
702
704
|
eeEmit('handler', {
|
|
703
|
-
api: '
|
|
705
|
+
api: 'apiUploadCheck',
|
|
704
706
|
headers,
|
|
705
707
|
query,
|
|
706
708
|
})
|
|
707
709
|
|
|
708
|
-
//filename, fileHash, 從payload接收
|
|
710
|
+
//filename, fileSize, fileHash, 從payload接收
|
|
709
711
|
let filename = get(req, 'payload.filename', '')
|
|
712
|
+
let fileSize = get(req, 'payload.fileSize', '')
|
|
710
713
|
let fileHash = get(req, 'payload.fileHash', '')
|
|
711
714
|
// console.log('filename', filename)
|
|
715
|
+
// console.log('fileSize', fileSize)
|
|
712
716
|
// console.log('fileHash', fileHash)
|
|
713
717
|
|
|
714
718
|
//check
|
|
@@ -717,6 +721,12 @@ function WConverhpServer(opt = {}) {
|
|
|
717
721
|
return responseU8aStreamWithError(res, 'invalid filename in payload')
|
|
718
722
|
}
|
|
719
723
|
|
|
724
|
+
//check
|
|
725
|
+
if (!isnum(fileSize)) {
|
|
726
|
+
// console.log('invalid fileSize in payload')
|
|
727
|
+
return responseU8aStreamWithError(res, 'invalid fileSize in payload')
|
|
728
|
+
}
|
|
729
|
+
|
|
720
730
|
//check
|
|
721
731
|
if (!isestr(fileHash)) {
|
|
722
732
|
// console.log('invalid fileHash in payload')
|
|
@@ -739,19 +749,35 @@ function WConverhpServer(opt = {}) {
|
|
|
739
749
|
return responseU8aStream(res, u8aOut, { returnType: 'success', returnMsg: 'need to parse' })
|
|
740
750
|
}
|
|
741
751
|
|
|
742
|
-
//
|
|
743
|
-
let
|
|
752
|
+
//_fileSize
|
|
753
|
+
let stats = fs.statSync(pathFile)
|
|
754
|
+
let _fileSize = stats.size
|
|
755
|
+
|
|
756
|
+
//check
|
|
757
|
+
if (fileSize !== _fileSize) {
|
|
758
|
+
let out = {
|
|
759
|
+
success: {
|
|
760
|
+
existed: false,
|
|
761
|
+
msg: 'not equal size',
|
|
762
|
+
},
|
|
763
|
+
}
|
|
764
|
+
let u8aOut = obj2u8arr(out)
|
|
765
|
+
return responseU8aStream(res, u8aOut, { returnType: 'success', returnMsg: 'need to parse' })
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
//_fileHash
|
|
769
|
+
let _fileHash = await calcFileHash(pathFile)
|
|
744
770
|
// console.log('path', pathFile)
|
|
745
771
|
// console.log('hash(front)', fileHash)
|
|
746
|
-
// console.log('hash(backend)',
|
|
772
|
+
// console.log('hash(backend)', _fileHash)
|
|
747
773
|
// console.log('')
|
|
748
774
|
|
|
749
775
|
//check
|
|
750
|
-
if (fileHash !==
|
|
776
|
+
if (fileHash !== _fileHash) {
|
|
751
777
|
let out = {
|
|
752
778
|
success: {
|
|
753
779
|
existed: false,
|
|
754
|
-
msg: 'not equal',
|
|
780
|
+
msg: 'not equal hash',
|
|
755
781
|
},
|
|
756
782
|
}
|
|
757
783
|
let u8aOut = obj2u8arr(out)
|
|
@@ -1453,7 +1479,7 @@ function WConverhpServer(opt = {}) {
|
|
|
1453
1479
|
apiRoutes = [
|
|
1454
1480
|
...apiRoutes,
|
|
1455
1481
|
apiMain,
|
|
1456
|
-
|
|
1482
|
+
apiUploadCheck,
|
|
1457
1483
|
apiUploadSlice,
|
|
1458
1484
|
apiUploadSliceMerge,
|
|
1459
1485
|
apiDownloadGetFilename,
|
|
@@ -1474,7 +1500,7 @@ function WConverhpServer(opt = {}) {
|
|
|
1474
1500
|
|
|
1475
1501
|
//start
|
|
1476
1502
|
if (get(opt, 'serverHapi')) {
|
|
1477
|
-
server.route([apiMain,
|
|
1503
|
+
server.route([apiMain, apiUploadCheck, apiUploadSlice, apiUploadSliceMerge, apiDownloadGetFilename, apiDownloadGetFile, apiDownload])
|
|
1478
1504
|
}
|
|
1479
1505
|
else {
|
|
1480
1506
|
startServer()
|
|
@@ -1507,7 +1533,7 @@ export default WConverhpServer
|
|
|
1507
1533
|
<br class="clear">
|
|
1508
1534
|
|
|
1509
1535
|
<footer>
|
|
1510
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
1536
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Apr 13 2025 11:30:23 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1511
1537
|
</footer>
|
|
1512
1538
|
|
|
1513
1539
|
<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 Sun Apr 13 2025 11:30:23 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,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w-converhp",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.32",
|
|
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
8
|
"axios": "^1.8.4",
|
|
9
9
|
"lodash-es": "^4.17.21",
|
|
10
|
-
"wsemi": "^1.7.
|
|
10
|
+
"wsemi": "^1.7.88"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"form-data": "^4.0.2",
|
package/sclc.mjs
CHANGED
|
@@ -27,10 +27,10 @@ wo.on('error', (err) => {
|
|
|
27
27
|
function uploadLargeFile() {
|
|
28
28
|
let core = async() => {
|
|
29
29
|
|
|
30
|
-
let fsz = '
|
|
30
|
+
let fsz = '1000mb' //0mb 10mb 100mb 1000mb
|
|
31
31
|
|
|
32
32
|
//u8a
|
|
33
|
-
let u8a =
|
|
33
|
+
let u8a = fs.readFileSync(`../_data/${fsz}.7z`) //用fs讀有檔案大小上限
|
|
34
34
|
console.log('u8a.length', u8a.length)
|
|
35
35
|
// console.log('uploadLargeFile u8a', u8a)
|
|
36
36
|
ms.push({ 'upload u8a.length': u8a.length })
|
package/src/WConverhpClient.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
2
|
import get from 'lodash-es/get.js'
|
|
3
3
|
import isWindow from 'wsemi/src/isWindow.mjs'
|
|
4
|
-
import getGlobal from 'wsemi/src/getGlobal.mjs'
|
|
5
4
|
import evem from 'wsemi/src/evem.mjs'
|
|
6
5
|
import genPm from 'wsemi/src/genPm.mjs'
|
|
7
6
|
import haskey from 'wsemi/src/haskey.mjs'
|
|
@@ -19,7 +18,7 @@ import blob2u8arr from 'wsemi/src/blob2u8arr.mjs'
|
|
|
19
18
|
import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
|
|
20
19
|
import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
|
|
21
20
|
import pmConvertResolve from 'wsemi/src/pmConvertResolve.mjs'
|
|
22
|
-
|
|
21
|
+
import getFileXxHash from 'wsemi/src/getFileXxHash.mjs'
|
|
23
22
|
|
|
24
23
|
|
|
25
24
|
/**
|
|
@@ -165,8 +164,8 @@ function WConverhpClient(opt) {
|
|
|
165
164
|
else if (type === 'slice') {
|
|
166
165
|
urlUse = `${url}slc`
|
|
167
166
|
}
|
|
168
|
-
else if (type === 'upload-check
|
|
169
|
-
urlUse = `${url}
|
|
167
|
+
else if (type === 'upload-check') {
|
|
168
|
+
urlUse = `${url}ulck`
|
|
170
169
|
}
|
|
171
170
|
else if (type === 'slice-merge') {
|
|
172
171
|
urlUse = `${url}slcm`
|
|
@@ -628,37 +627,21 @@ function WConverhpClient(opt) {
|
|
|
628
627
|
|
|
629
628
|
//calcHash
|
|
630
629
|
async function calcHash(inp) {
|
|
631
|
-
let pm = genPm()
|
|
632
|
-
if (env === 'browser') {
|
|
633
|
-
//於browser時, 因是給予blob或file上傳, 且使用非同步async版計算hash, 可支援大檔
|
|
634
|
-
|
|
635
|
-
//crypto, 須通過global取得crypto, 否則會被舊版webpack偵測報錯
|
|
636
|
-
let g = getGlobal()
|
|
637
|
-
let crypto = get(g, 'crypto')
|
|
638
630
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
let hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('')
|
|
644
|
-
|
|
645
|
-
pm.resolve(hashHex)
|
|
631
|
+
//bb
|
|
632
|
+
let bb = null
|
|
633
|
+
if (env === 'browser') {
|
|
634
|
+
bb = inp
|
|
646
635
|
}
|
|
647
636
|
else {
|
|
648
|
-
//於nodejs時, 因尚無法提供檔名上傳, 故會是readFileSync讀入的buffer,
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
let key = 'crypto'
|
|
652
|
-
let crypto = await import(key)
|
|
637
|
+
//於nodejs時, 因尚無法提供檔名上傳, 故會是readFileSync讀入的buffer, 再轉成new Blob([buffer]), 供getFileXxHash使用
|
|
638
|
+
bb = new Blob([inp])
|
|
639
|
+
}
|
|
653
640
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
hash.update(inp, 'utf8')
|
|
657
|
-
let hashHex = hash.digest('hex')
|
|
641
|
+
//hash
|
|
642
|
+
let hash = await getFileXxHash(bb)
|
|
658
643
|
|
|
659
|
-
|
|
660
|
-
}
|
|
661
|
-
return pm
|
|
644
|
+
return hash
|
|
662
645
|
}
|
|
663
646
|
|
|
664
647
|
//sendDataSlice
|
|
@@ -675,7 +658,7 @@ function WConverhpClient(opt) {
|
|
|
675
658
|
}
|
|
676
659
|
if (n === 0) {
|
|
677
660
|
try {
|
|
678
|
-
n = bb.length //for
|
|
661
|
+
n = bb.length //for ArrayBuffer //nodejs用fs讀有檔案大小上限, 除非改傳入檔名用stream讀, 否則無法支援超大檔
|
|
679
662
|
n = cint(n)
|
|
680
663
|
}
|
|
681
664
|
catch (err) {}
|
|
@@ -687,27 +670,30 @@ function WConverhpClient(opt) {
|
|
|
687
670
|
}
|
|
688
671
|
// console.log('n', n)
|
|
689
672
|
|
|
690
|
-
//
|
|
673
|
+
//fileTotalSize
|
|
674
|
+
let fileTotalSize = n
|
|
675
|
+
|
|
676
|
+
//fileTotalHash
|
|
691
677
|
let fileTotalHash = await calcHash(bb)
|
|
692
678
|
// console.log('fileTotalHash', fileTotalHash)
|
|
693
679
|
|
|
694
680
|
//ckh
|
|
695
|
-
let ckh = async({ filename, fileHash }) => {
|
|
681
|
+
let ckh = async({ filename, fileSize, fileHash }) => {
|
|
696
682
|
|
|
697
|
-
//send upload-check
|
|
698
|
-
let resCk = await send('upload-check
|
|
683
|
+
//send upload-check
|
|
684
|
+
let resCk = await send('upload-check', { filename, fileSize, fileHash }, { dataType: 'json' })
|
|
699
685
|
// console.log('resCk', resCk)
|
|
700
686
|
|
|
701
687
|
return resCk
|
|
702
688
|
}
|
|
703
689
|
|
|
704
690
|
//rAll
|
|
705
|
-
let rAll = await ckh({ filename: fileTotalHash, fileHash: fileTotalHash })
|
|
691
|
+
let rAll = await ckh({ filename: fileTotalHash, fileSize: fileTotalSize, fileHash: fileTotalHash })
|
|
706
692
|
// console.log('rAll', rAll)
|
|
707
693
|
|
|
708
694
|
//check
|
|
709
695
|
if (rAll.existed) {
|
|
710
|
-
|
|
696
|
+
// console.log('已有上傳大檔')
|
|
711
697
|
let resMg = {
|
|
712
698
|
filename: fileTotalName,
|
|
713
699
|
path: rAll.path,
|
|
@@ -771,7 +757,7 @@ function WConverhpClient(opt) {
|
|
|
771
757
|
// console.log('fileSliceHash', fileSliceHash)
|
|
772
758
|
|
|
773
759
|
//rChunk
|
|
774
|
-
let rChunk = await ckh({ filename: fileSliceName, fileHash: fileSliceHash })
|
|
760
|
+
let rChunk = await ckh({ filename: fileSliceName, fileSize: sizeSlice, fileHash: fileSliceHash })
|
|
775
761
|
// console.log('fileSliceName', fileSliceName)
|
|
776
762
|
// console.log('fileSliceHash', fileSliceHash)
|
|
777
763
|
// console.log('rChunk', rChunk)
|
|
@@ -779,7 +765,8 @@ function WConverhpClient(opt) {
|
|
|
779
765
|
|
|
780
766
|
//check
|
|
781
767
|
if (rChunk.existed) {
|
|
782
|
-
|
|
768
|
+
// console.log('已有上傳切片檔')
|
|
769
|
+
cbProgressSlice({ prog: 100, m: 'upload' }) //直接觸發更新進度
|
|
783
770
|
continue
|
|
784
771
|
}
|
|
785
772
|
|
package/src/WConverhpServer.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import isp0int from 'wsemi/src/isp0int.mjs'
|
|
|
13
13
|
import ispint from 'wsemi/src/ispint.mjs'
|
|
14
14
|
import isearr from 'wsemi/src/isearr.mjs'
|
|
15
15
|
import isbol from 'wsemi/src/isbol.mjs'
|
|
16
|
+
import isnum from 'wsemi/src/isnum.mjs'
|
|
16
17
|
import isfun from 'wsemi/src/isfun.mjs'
|
|
17
18
|
import ispm from 'wsemi/src/ispm.mjs'
|
|
18
19
|
import cint from 'wsemi/src/cint.mjs'
|
|
@@ -24,9 +25,10 @@ import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
|
|
|
24
25
|
import fsIsFile from 'wsemi/src/fsIsFile.mjs'
|
|
25
26
|
import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
|
|
26
27
|
import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
|
|
27
|
-
import
|
|
28
|
-
import
|
|
28
|
+
// import calcFileHash from './calcFileHash.mjs'
|
|
29
|
+
import calcFileHash from './calcFileHash.wk.umd.js'
|
|
29
30
|
// import mergeFiles from './mergeFiles.mjs'
|
|
31
|
+
import mergeFiles from './mergeFiles.wk.umd.js'
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
//回傳前端stream時(POST或GET皆可), 前端會須等stream傳完才能判斷是否為大檔或錯誤訊息, 此會導致若回傳超大檔, 會需要對超大檔進行解析會有記憶體上限問題, 故需要通過header提供基本成功或失敗訊息, 讓前端能進行解析判斷
|
|
@@ -600,9 +602,9 @@ function WConverhpServer(opt = {}) {
|
|
|
600
602
|
},
|
|
601
603
|
}
|
|
602
604
|
|
|
603
|
-
//
|
|
604
|
-
let
|
|
605
|
-
path: `/${apiName}
|
|
605
|
+
//apiUploadCheck
|
|
606
|
+
let apiUploadCheck = {
|
|
607
|
+
path: `/${apiName}ulck`,
|
|
606
608
|
method: 'POST',
|
|
607
609
|
options: {
|
|
608
610
|
payload: {
|
|
@@ -639,7 +641,7 @@ function WConverhpServer(opt = {}) {
|
|
|
639
641
|
if (true) {
|
|
640
642
|
|
|
641
643
|
//verifyConn
|
|
642
|
-
let m = verifyConn({ apiType: 'upload-check
|
|
644
|
+
let m = verifyConn({ apiType: 'upload-check', authorization, headers, query })
|
|
643
645
|
if (ispm(m)) {
|
|
644
646
|
m = await m
|
|
645
647
|
}
|
|
@@ -653,15 +655,17 @@ function WConverhpServer(opt = {}) {
|
|
|
653
655
|
|
|
654
656
|
//eeEmit
|
|
655
657
|
eeEmit('handler', {
|
|
656
|
-
api: '
|
|
658
|
+
api: 'apiUploadCheck',
|
|
657
659
|
headers,
|
|
658
660
|
query,
|
|
659
661
|
})
|
|
660
662
|
|
|
661
|
-
//filename, fileHash, 從payload接收
|
|
663
|
+
//filename, fileSize, fileHash, 從payload接收
|
|
662
664
|
let filename = get(req, 'payload.filename', '')
|
|
665
|
+
let fileSize = get(req, 'payload.fileSize', '')
|
|
663
666
|
let fileHash = get(req, 'payload.fileHash', '')
|
|
664
667
|
// console.log('filename', filename)
|
|
668
|
+
// console.log('fileSize', fileSize)
|
|
665
669
|
// console.log('fileHash', fileHash)
|
|
666
670
|
|
|
667
671
|
//check
|
|
@@ -670,6 +674,12 @@ function WConverhpServer(opt = {}) {
|
|
|
670
674
|
return responseU8aStreamWithError(res, 'invalid filename in payload')
|
|
671
675
|
}
|
|
672
676
|
|
|
677
|
+
//check
|
|
678
|
+
if (!isnum(fileSize)) {
|
|
679
|
+
// console.log('invalid fileSize in payload')
|
|
680
|
+
return responseU8aStreamWithError(res, 'invalid fileSize in payload')
|
|
681
|
+
}
|
|
682
|
+
|
|
673
683
|
//check
|
|
674
684
|
if (!isestr(fileHash)) {
|
|
675
685
|
// console.log('invalid fileHash in payload')
|
|
@@ -692,19 +702,35 @@ function WConverhpServer(opt = {}) {
|
|
|
692
702
|
return responseU8aStream(res, u8aOut, { returnType: 'success', returnMsg: 'need to parse' })
|
|
693
703
|
}
|
|
694
704
|
|
|
695
|
-
//
|
|
696
|
-
let
|
|
705
|
+
//_fileSize
|
|
706
|
+
let stats = fs.statSync(pathFile)
|
|
707
|
+
let _fileSize = stats.size
|
|
708
|
+
|
|
709
|
+
//check
|
|
710
|
+
if (fileSize !== _fileSize) {
|
|
711
|
+
let out = {
|
|
712
|
+
success: {
|
|
713
|
+
existed: false,
|
|
714
|
+
msg: 'not equal size',
|
|
715
|
+
},
|
|
716
|
+
}
|
|
717
|
+
let u8aOut = obj2u8arr(out)
|
|
718
|
+
return responseU8aStream(res, u8aOut, { returnType: 'success', returnMsg: 'need to parse' })
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
//_fileHash
|
|
722
|
+
let _fileHash = await calcFileHash(pathFile)
|
|
697
723
|
// console.log('path', pathFile)
|
|
698
724
|
// console.log('hash(front)', fileHash)
|
|
699
|
-
// console.log('hash(backend)',
|
|
725
|
+
// console.log('hash(backend)', _fileHash)
|
|
700
726
|
// console.log('')
|
|
701
727
|
|
|
702
728
|
//check
|
|
703
|
-
if (fileHash !==
|
|
729
|
+
if (fileHash !== _fileHash) {
|
|
704
730
|
let out = {
|
|
705
731
|
success: {
|
|
706
732
|
existed: false,
|
|
707
|
-
msg: 'not equal',
|
|
733
|
+
msg: 'not equal hash',
|
|
708
734
|
},
|
|
709
735
|
}
|
|
710
736
|
let u8aOut = obj2u8arr(out)
|
|
@@ -1406,7 +1432,7 @@ function WConverhpServer(opt = {}) {
|
|
|
1406
1432
|
apiRoutes = [
|
|
1407
1433
|
...apiRoutes,
|
|
1408
1434
|
apiMain,
|
|
1409
|
-
|
|
1435
|
+
apiUploadCheck,
|
|
1410
1436
|
apiUploadSlice,
|
|
1411
1437
|
apiUploadSliceMerge,
|
|
1412
1438
|
apiDownloadGetFilename,
|
|
@@ -1427,7 +1453,7 @@ function WConverhpServer(opt = {}) {
|
|
|
1427
1453
|
|
|
1428
1454
|
//start
|
|
1429
1455
|
if (get(opt, 'serverHapi')) {
|
|
1430
|
-
server.route([apiMain,
|
|
1456
|
+
server.route([apiMain, apiUploadCheck, apiUploadSlice, apiUploadSliceMerge, apiDownloadGetFilename, apiDownloadGetFile, apiDownload])
|
|
1431
1457
|
}
|
|
1432
1458
|
else {
|
|
1433
1459
|
startServer()
|