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.
@@ -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[${fileId}]`)
906
+ return responseU8aStreamWithError(res, `can not get file from fileId`)
895
907
  }
896
908
 
897
- //streamRead, fileName, fileSize, fileType
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.response({ error: `invalid fileName` }).code(400)
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 (!isnum(fileSize)) {
906
- return res.response({ error: `invalid fileSize` }).code(400)
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.response({ error: `invalid fileType` }).code(400)
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
@@ -87,7 +87,7 @@ wo.on('download', (input, pm) => {
87
87
  let streamRead = fs.createReadStream(fp)
88
88
 
89
89
  //fileName
90
- let fileName = `1mb.7z`
90
+ let fileName = `1mb中文.7z` //測試支援中文
91
91
 
92
92
  //fileSize
93
93
  let stats = fs.statSync(fp)
@@ -47,7 +47,7 @@ describe('downloadLargeFile', function() {
47
47
  let streamRead = fs.createReadStream(fp) //createReadStream得指定使用test內檔案
48
48
 
49
49
  //fileName
50
- let fileName = `1mb.7z`
50
+ let fileName = `1mb.7z` //測試支援中文
51
51
 
52
52
  //fileSize
53
53
  let stats = fs.statSync(fp)