w-converhp 2.0.12 → 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 +5 -7
- 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/scla.mjs +2 -0
- package/sclb.mjs +2 -0
- package/sclc.mjs +2 -0
- package/scld.mjs +4 -1
- package/src/WConverhpClient.mjs +4 -6
- package/src/WConverhpServer.mjs +30 -7
- package/srv.mjs +2 -2
- package/test/downloadLargeFile.test.mjs +1 -1
package/scld.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import _ from 'lodash-es'
|
|
1
4
|
import w from 'wsemi'
|
|
2
5
|
import FormData from 'form-data'
|
|
3
6
|
import WConverhpClient from './src/WConverhpClient.mjs'
|
|
@@ -32,7 +35,7 @@ function downloadLargeFile() {
|
|
|
32
35
|
}
|
|
33
36
|
},
|
|
34
37
|
{
|
|
35
|
-
fdDownload: './',
|
|
38
|
+
fdDownload: './', //於後端nodejs環境才能提供
|
|
36
39
|
})
|
|
37
40
|
.then(function(res) {
|
|
38
41
|
console.log('client web: download: then', res)
|
package/src/WConverhpClient.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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 evem from 'wsemi/src/evem.mjs'
|
|
4
5
|
import genPm from 'wsemi/src/genPm.mjs'
|
|
5
6
|
import genID from 'wsemi/src/genID.mjs'
|
|
6
7
|
import haskey from 'wsemi/src/haskey.mjs'
|
|
@@ -13,14 +14,12 @@ import iseobj from 'wsemi/src/iseobj.mjs'
|
|
|
13
14
|
import ispm from 'wsemi/src/ispm.mjs'
|
|
14
15
|
import cint from 'wsemi/src/cint.mjs'
|
|
15
16
|
import strright from 'wsemi/src/strright.mjs'
|
|
16
|
-
import
|
|
17
|
+
import b642str from 'wsemi/src/b642str.mjs'
|
|
17
18
|
import blob2u8arr from 'wsemi/src/blob2u8arr.mjs'
|
|
18
19
|
import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
|
|
19
20
|
import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
|
|
20
21
|
import pmConvertResolve from 'wsemi/src/pmConvertResolve.mjs'
|
|
21
22
|
import now2strp from 'wsemi/src/now2strp.mjs'
|
|
22
|
-
import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
|
|
23
|
-
import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
/**
|
|
@@ -461,6 +460,7 @@ function WConverhpClient(opt) {
|
|
|
461
460
|
|
|
462
461
|
//filename
|
|
463
462
|
let filename = getFilenameByHeader(contentDisposition)
|
|
463
|
+
filename = b642str(filename) //headers內對中文支援度不佳須用base64傳, 此處解析提取後須反轉
|
|
464
464
|
// console.log('filename', filename)
|
|
465
465
|
|
|
466
466
|
//streamRecv
|
|
@@ -496,9 +496,7 @@ function WConverhpClient(opt) {
|
|
|
496
496
|
|
|
497
497
|
//fdDownload, 只有後端下載才使用fdDownload
|
|
498
498
|
let fdDownload = get(opt, 'fdDownload', '')
|
|
499
|
-
|
|
500
|
-
fsCreateFolder(fdDownload)
|
|
501
|
-
}
|
|
499
|
+
fs.mkdirSync(fdDownload, { recursive: true }) //須使用mkdirSync, 不要用fsIsFolder與fsCreateFolder避免編譯
|
|
502
500
|
// console.log('fdDownload', fdDownload)
|
|
503
501
|
|
|
504
502
|
//fp
|
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
|
@@ -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
|
|
90
|
+
let fileName = `1mb中文.7z` //測試支援中文
|
|
91
91
|
|
|
92
92
|
//fileSize
|
|
93
93
|
let stats = fs.statSync(fp)
|
|
@@ -123,7 +123,7 @@ setTimeout(() => {
|
|
|
123
123
|
console.log('ms', ms)
|
|
124
124
|
// console.log('ms', JSON.stringify(ms))
|
|
125
125
|
wo.stop()
|
|
126
|
-
},
|
|
126
|
+
}, 1113000)
|
|
127
127
|
|
|
128
128
|
|
|
129
129
|
//node --experimental-modules srv.mjs
|