w-converhp 2.0.13 → 2.0.14
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 +4 -2
- package/docs/WConverhpServer.html +2 -2
- package/docs/WConverhpServer.mjs.html +31 -8
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/scld.mjs +1 -1
- package/src/WConverhpClient.mjs +3 -1
- package/src/WConverhpServer.mjs +30 -7
- package/srv.mjs +1 -1
- package/test/downloadLargeFile.test.mjs +1 -1
package/src/WConverhpServer.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import stream from 'stream'
|
|
|
3
3
|
import Hapi from '@hapi/hapi'
|
|
4
4
|
import Inert from '@hapi/inert' //提供靜態檔案
|
|
5
5
|
import get from 'lodash-es/get.js'
|
|
6
|
+
import isNumber from 'lodash-es/isNumber.js'
|
|
6
7
|
import genPm from 'wsemi/src/genPm.mjs'
|
|
7
8
|
import evem from 'wsemi/src/evem.mjs'
|
|
8
9
|
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
@@ -12,9 +13,10 @@ import ispint from 'wsemi/src/ispint.mjs'
|
|
|
12
13
|
import isearr from 'wsemi/src/isearr.mjs'
|
|
13
14
|
import isbol from 'wsemi/src/isbol.mjs'
|
|
14
15
|
import isfun from 'wsemi/src/isfun.mjs'
|
|
15
|
-
import isnum from 'wsemi/src/isnum.mjs'
|
|
16
16
|
import ispm from 'wsemi/src/ispm.mjs'
|
|
17
17
|
import cint from 'wsemi/src/cint.mjs'
|
|
18
|
+
import cstr from 'wsemi/src/cstr.mjs'
|
|
19
|
+
import str2b64 from 'wsemi/src/str2b64.mjs'
|
|
18
20
|
import haskey from 'wsemi/src/haskey.mjs'
|
|
19
21
|
import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
|
|
20
22
|
import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
|
|
@@ -387,12 +389,22 @@ function WConverhpServer(opt = {}) {
|
|
|
387
389
|
//responseU8aStreamWithError
|
|
388
390
|
function responseU8aStreamWithError(res, msg) {
|
|
389
391
|
|
|
392
|
+
//check
|
|
393
|
+
if (!isestr(msg)) {
|
|
394
|
+
console.log('msg', msg)
|
|
395
|
+
console.log(`msg is not an effective string, set msg=''`)
|
|
396
|
+
msg = ''
|
|
397
|
+
}
|
|
398
|
+
|
|
390
399
|
//u8aOut
|
|
391
400
|
let u8aOut = obj2u8arr({
|
|
392
401
|
error: msg,
|
|
393
402
|
})
|
|
394
403
|
// console.log('download u8aOut', u8aOut)
|
|
395
404
|
|
|
405
|
+
//str2b64
|
|
406
|
+
// msg = str2b64(msg) //預期程式內調用皆為英文, 不須轉base64來支援中文
|
|
407
|
+
|
|
396
408
|
return responseU8aStream(res, u8aOut, { returnType: 'error', returnMsg: msg })
|
|
397
409
|
}
|
|
398
410
|
|
|
@@ -891,24 +903,35 @@ function WConverhpServer(opt = {}) {
|
|
|
891
903
|
//return
|
|
892
904
|
if (haskey(out, 'error')) {
|
|
893
905
|
// console.log('out.error', out.error)
|
|
894
|
-
return responseU8aStreamWithError(res, `can not get file from fileId
|
|
906
|
+
return responseU8aStreamWithError(res, `can not get file from fileId`)
|
|
895
907
|
}
|
|
896
908
|
|
|
897
|
-
//
|
|
909
|
+
//r
|
|
898
910
|
let r = get(out, 'success')
|
|
911
|
+
|
|
912
|
+
//streamRead
|
|
899
913
|
let streamRead = get(r, 'streamRead')
|
|
914
|
+
|
|
915
|
+
//fileName
|
|
900
916
|
let fileName = get(r, 'fileName')
|
|
901
917
|
if (!isestr(fileName)) {
|
|
902
|
-
return res
|
|
918
|
+
return responseU8aStreamWithError(res, 'invalid fileName')
|
|
903
919
|
}
|
|
920
|
+
fileName = str2b64(fileName) //headers內對中文支援度不佳須用base64傳
|
|
921
|
+
|
|
922
|
+
//fileSize
|
|
904
923
|
let fileSize = get(r, 'fileSize')
|
|
905
|
-
if (!
|
|
906
|
-
return res
|
|
924
|
+
if (!isNumber(fileSize)) {
|
|
925
|
+
return responseU8aStreamWithError(res, 'invalid fileSize')
|
|
907
926
|
}
|
|
927
|
+
// fileSize = cstr(fileSize)
|
|
928
|
+
|
|
929
|
+
//fileType
|
|
908
930
|
let fileType = get(r, 'fileType')
|
|
909
931
|
if (!isestr(fileType)) {
|
|
910
|
-
return res
|
|
932
|
+
return responseU8aStreamWithError(res, 'invalid fileType')
|
|
911
933
|
}
|
|
934
|
+
fileType = cstr(fileType)
|
|
912
935
|
|
|
913
936
|
return res.response(streamRead)
|
|
914
937
|
.type(fileType)
|
package/srv.mjs
CHANGED