w-converhp 2.0.13 → 2.0.15
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 +68 -99
- 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 +3 -3
- package/docs/WConverhpClient.mjs.html +104 -120
- package/docs/WConverhpServer.html +43 -3
- package/docs/WConverhpServer.mjs.html +349 -32
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/scld.mjs +5 -5
- package/src/WConverhpClient.mjs +103 -119
- package/src/WConverhpServer.mjs +348 -31
- package/srv.mjs +25 -2
- package/test/downloadLargeFile.test.mjs +12 -13
- package/test/executeWithFile.test.mjs +10 -12
- package/test/executeWithU8a.test.mjs +11 -13
- package/test/uploadLargeFile.test.mjs +10 -14
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
<pre class="prettyprint source linenums"><code>import axios from 'axios'
|
|
49
49
|
import get from 'lodash-es/get.js'
|
|
50
50
|
import isWindow from 'wsemi/src/isWindow.mjs'
|
|
51
|
+
import evem from 'wsemi/src/evem.mjs'
|
|
51
52
|
import genPm from 'wsemi/src/genPm.mjs'
|
|
52
53
|
import genID from 'wsemi/src/genID.mjs'
|
|
53
54
|
import haskey from 'wsemi/src/haskey.mjs'
|
|
@@ -60,7 +61,7 @@ import iseobj from 'wsemi/src/iseobj.mjs'
|
|
|
60
61
|
import ispm from 'wsemi/src/ispm.mjs'
|
|
61
62
|
import cint from 'wsemi/src/cint.mjs'
|
|
62
63
|
import strright from 'wsemi/src/strright.mjs'
|
|
63
|
-
import
|
|
64
|
+
import b642str from 'wsemi/src/b642str.mjs'
|
|
64
65
|
import blob2u8arr from 'wsemi/src/blob2u8arr.mjs'
|
|
65
66
|
import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
|
|
66
67
|
import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
|
|
@@ -82,100 +83,30 @@ import now2strp from 'wsemi/src/now2strp.mjs'
|
|
|
82
83
|
* @returns {Object} 回傳事件物件,可使用函數execute、upload
|
|
83
84
|
* @example
|
|
84
85
|
*
|
|
85
|
-
* import
|
|
86
|
+
* import path from 'path'
|
|
87
|
+
* import fs from 'fs'
|
|
88
|
+
* import _ from 'lodash-es'
|
|
89
|
+
* import w from 'wsemi'
|
|
90
|
+
* import FormData from 'form-data'
|
|
91
|
+
* import WConverhpClient from './src/WConverhpClient.mjs'
|
|
92
|
+
*
|
|
93
|
+
* let ms = []
|
|
86
94
|
*
|
|
87
95
|
* let opt = {
|
|
88
96
|
* FormData,
|
|
89
97
|
* url: 'http://localhost:8080',
|
|
90
98
|
* apiName: 'api',
|
|
99
|
+
* getToken: () => {
|
|
100
|
+
* return 'token-for-test'
|
|
101
|
+
* },
|
|
91
102
|
* }
|
|
92
103
|
*
|
|
93
104
|
* //new
|
|
94
105
|
* let wo = new WConverhpClient(opt)
|
|
95
106
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* let p = {
|
|
100
|
-
* a: 12,
|
|
101
|
-
* b: 34.56,
|
|
102
|
-
* c: 'test中文',
|
|
103
|
-
* d: {
|
|
104
|
-
* name,
|
|
105
|
-
* u8a,
|
|
106
|
-
* },
|
|
107
|
-
* }
|
|
108
|
-
* console.log('p', p)
|
|
109
|
-
*
|
|
110
|
-
* //execute
|
|
111
|
-
* await wo.execute('add', { p },
|
|
112
|
-
* function ({ prog, p, m }) {
|
|
113
|
-
* console.log('client web: execute: prog', prog, p, m)
|
|
114
|
-
* })
|
|
115
|
-
* .then(function(r) {
|
|
116
|
-
* console.log('client web: execute: add', r)
|
|
117
|
-
* console.log('r._bin.name', r._bin.name, 'r._bin.u8a', r._bin.u8a)
|
|
118
|
-
* // w.downloadFileFromU8Arr(r._bin.name, r._bin.u8a)
|
|
119
|
-
* })
|
|
120
|
-
* .catch(function (err) {
|
|
121
|
-
* console.log('client web: execute: catch', err)
|
|
122
|
-
* })
|
|
123
|
-
*
|
|
124
|
-
* }
|
|
125
|
-
*
|
|
126
|
-
* function executeWithU8a() {
|
|
127
|
-
* let core = async() => {
|
|
128
|
-
*
|
|
129
|
-
* //u8a
|
|
130
|
-
* let u8a = new Uint8Array([66, 97, 115])
|
|
131
|
-
* console.log('executeWithU8a u8a', u8a)
|
|
132
|
-
*
|
|
133
|
-
* //execute
|
|
134
|
-
* await execute('zdata.b1', u8a)
|
|
135
|
-
*
|
|
136
|
-
* }
|
|
137
|
-
* core()
|
|
138
|
-
* }
|
|
139
|
-
* executeWithU8a()
|
|
140
|
-
*
|
|
141
|
-
* function executeWithFile() {
|
|
142
|
-
* let core = async() => {
|
|
143
|
-
*
|
|
144
|
-
* //u8a
|
|
145
|
-
* let u8a = new Uint8Array(fs.readFileSync('../_data/10mb.7z'))
|
|
146
|
-
* console.log('executeWithFile u8a', u8a)
|
|
147
|
-
*
|
|
148
|
-
* //execute
|
|
149
|
-
* await execute('10mb.7z', u8a)
|
|
150
|
-
*
|
|
151
|
-
* }
|
|
152
|
-
* core()
|
|
153
|
-
* }
|
|
154
|
-
* executeWithFile()
|
|
155
|
-
*
|
|
156
|
-
* function uploadLargeFile() {
|
|
157
|
-
* let core = async() => {
|
|
158
|
-
*
|
|
159
|
-
* //u8a
|
|
160
|
-
* let u8a = new Uint8Array(fs.readFileSync('../_data/1000mb.7z'))
|
|
161
|
-
* console.log('u8a.length', u8a.length)
|
|
162
|
-
* console.log('uploadLargeFile u8a', u8a)
|
|
163
|
-
*
|
|
164
|
-
* await wo.upload('1000mb.7z', u8a,
|
|
165
|
-
* function ({ prog, p, m }) {
|
|
166
|
-
* console.log('client web: upload: prog', prog, p, m)
|
|
167
|
-
* })
|
|
168
|
-
* .then(function(res) {
|
|
169
|
-
* console.log('client web: upload: then', res)
|
|
170
|
-
* })
|
|
171
|
-
* .catch(function (err) {
|
|
172
|
-
* console.log('client web: upload: catch', err)
|
|
173
|
-
* })
|
|
174
|
-
*
|
|
175
|
-
* }
|
|
176
|
-
* core()
|
|
177
|
-
* }
|
|
178
|
-
* uploadLargeFile()
|
|
107
|
+
* wo.on('error', (err) => {
|
|
108
|
+
* console.log(`error`, err)
|
|
109
|
+
* })
|
|
179
110
|
*
|
|
180
111
|
* function downloadLargeFile() {
|
|
181
112
|
* let core = async() => {
|
|
@@ -188,7 +119,7 @@ import now2strp from 'wsemi/src/now2strp.mjs'
|
|
|
188
119
|
* }
|
|
189
120
|
* },
|
|
190
121
|
* {
|
|
191
|
-
* fdDownload: './',
|
|
122
|
+
* fdDownload: './', //於後端nodejs環境才能提供
|
|
192
123
|
* })
|
|
193
124
|
* .then(function(res) {
|
|
194
125
|
* console.log('client web: download: then', res)
|
|
@@ -270,6 +201,36 @@ function WConverhpClient(opt) {
|
|
|
270
201
|
}, 1)
|
|
271
202
|
}
|
|
272
203
|
|
|
204
|
+
//getUrlUse
|
|
205
|
+
let getUrlUse = (type) => {
|
|
206
|
+
|
|
207
|
+
//urlUse
|
|
208
|
+
let urlUse = ''
|
|
209
|
+
if (type === 'basic') {
|
|
210
|
+
urlUse = url
|
|
211
|
+
}
|
|
212
|
+
else if (type === 'slice') {
|
|
213
|
+
urlUse = `${url}slc`
|
|
214
|
+
}
|
|
215
|
+
else if (type === 'slice-merge') {
|
|
216
|
+
urlUse = `${url}slcm`
|
|
217
|
+
}
|
|
218
|
+
else if (type === 'download-get-filename') {
|
|
219
|
+
urlUse = `${url}dwgfn`
|
|
220
|
+
}
|
|
221
|
+
else if (type === 'download-get') {
|
|
222
|
+
urlUse = `${url}dwgf`
|
|
223
|
+
}
|
|
224
|
+
else if (type === 'download') {
|
|
225
|
+
urlUse = `${url}dw`
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
throw new Error(`invalid type[${type}]`)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return urlUse
|
|
232
|
+
}
|
|
233
|
+
|
|
273
234
|
//res2u8arr
|
|
274
235
|
async function res2u8arr(bb) {
|
|
275
236
|
//blob(in browser) or buffer(in nodejs) to u8a
|
|
@@ -320,22 +281,7 @@ function WConverhpClient(opt) {
|
|
|
320
281
|
}
|
|
321
282
|
|
|
322
283
|
//urlUse
|
|
323
|
-
let urlUse =
|
|
324
|
-
if (type === 'basic') {
|
|
325
|
-
urlUse = url
|
|
326
|
-
}
|
|
327
|
-
else if (type === 'slice') {
|
|
328
|
-
urlUse = `${url}slc`
|
|
329
|
-
}
|
|
330
|
-
else if (type === 'slicemerge') {
|
|
331
|
-
urlUse = `${url}slcm`
|
|
332
|
-
}
|
|
333
|
-
else if (type === 'download') {
|
|
334
|
-
urlUse = `${url}dw`
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
throw new Error(`invalid type[${type}]`)
|
|
338
|
-
}
|
|
284
|
+
let urlUse = getUrlUse(type)
|
|
339
285
|
|
|
340
286
|
//pm
|
|
341
287
|
let pm = genPm()
|
|
@@ -506,6 +452,7 @@ function WConverhpClient(opt) {
|
|
|
506
452
|
|
|
507
453
|
//filename
|
|
508
454
|
let filename = getFilenameByHeader(contentDisposition)
|
|
455
|
+
filename = b642str(filename) //headers內對中文支援度不佳須用base64傳, 此處解析提取後須反轉
|
|
509
456
|
// console.log('filename', filename)
|
|
510
457
|
|
|
511
458
|
//streamRecv
|
|
@@ -513,7 +460,7 @@ function WConverhpClient(opt) {
|
|
|
513
460
|
|
|
514
461
|
if (env === 'browser') {
|
|
515
462
|
|
|
516
|
-
|
|
463
|
+
//browser通過createObjectURL接收stream與a.href+a.click()接收檔案
|
|
517
464
|
try {
|
|
518
465
|
let url = URL.createObjectURL(streamRecv)
|
|
519
466
|
let a = document.createElement('a')
|
|
@@ -533,6 +480,7 @@ function WConverhpClient(opt) {
|
|
|
533
480
|
}
|
|
534
481
|
else {
|
|
535
482
|
|
|
483
|
+
//nodejs通過fs與stream接收檔案, stream出錯只會觸發error事件, 此處try catch為攔截其他非stream程式碼錯誤
|
|
536
484
|
try {
|
|
537
485
|
|
|
538
486
|
//path, fs
|
|
@@ -690,9 +638,7 @@ function WConverhpClient(opt) {
|
|
|
690
638
|
}
|
|
691
639
|
|
|
692
640
|
//send
|
|
693
|
-
// console.log('send bb...')
|
|
694
641
|
let res = await send(type, bb, { dataType: 'blob', cbProgress })
|
|
695
|
-
// console.log('send done', res)
|
|
696
642
|
|
|
697
643
|
return res
|
|
698
644
|
}
|
|
@@ -797,29 +743,23 @@ function WConverhpClient(opt) {
|
|
|
797
743
|
//chunk
|
|
798
744
|
let chunk = bb.slice(start, end)
|
|
799
745
|
|
|
800
|
-
//
|
|
746
|
+
//send slice
|
|
801
747
|
let hd = {
|
|
802
748
|
'chunk-index': i,
|
|
803
749
|
'chunk-total': chunkTotal,
|
|
804
750
|
'package-id': packageId,
|
|
805
751
|
}
|
|
806
|
-
|
|
807
|
-
//send slice
|
|
808
|
-
// console.log(`uploading chunk[${i + 1}/${chunkTotal}] of packageId[${packageId}]...`)
|
|
809
752
|
await send('slice', chunk, { headers: hd, dataType: 'blob', cbProgress: cbProgressSlice })
|
|
810
|
-
// console.log(`upload chunk[${i + 1}/${chunkTotal}] of packageId[${packageId}] done`, res)
|
|
811
753
|
|
|
812
754
|
}
|
|
813
755
|
|
|
814
|
-
//send merge
|
|
815
|
-
// console.log(`merging tempId[${tempId}]...`)
|
|
756
|
+
//send slice-merge
|
|
816
757
|
let msg = {
|
|
817
758
|
'filename': tempId,
|
|
818
759
|
'chunk-total': chunkTotal,
|
|
819
760
|
'package-id': packageId,
|
|
820
761
|
}
|
|
821
|
-
let resMg = await send('
|
|
822
|
-
// console.log(`merge tempId[${tempId}] done`, resMg)
|
|
762
|
+
let resMg = await send('slice-merge', msg, { dataType: 'json', cbProgress: cbProgressMerge })
|
|
823
763
|
|
|
824
764
|
return resMg
|
|
825
765
|
}
|
|
@@ -899,19 +839,63 @@ function WConverhpClient(opt) {
|
|
|
899
839
|
return sendDataSlice(tempId, bb, cbProgress)
|
|
900
840
|
}
|
|
901
841
|
|
|
902
|
-
//
|
|
903
|
-
async function
|
|
904
|
-
|
|
905
|
-
//msg
|
|
906
|
-
let msg = { fileId }
|
|
842
|
+
//downloadNodejs
|
|
843
|
+
async function downloadNodejs(fileId, cbProgress, opt = {}) {
|
|
907
844
|
|
|
908
845
|
//send download
|
|
846
|
+
let msg = { fileId }
|
|
909
847
|
let resMg = await send('download', msg, { ...opt, dataType: 'json', cbProgress })
|
|
910
848
|
// console.log('resMg', resMg)
|
|
911
849
|
|
|
912
850
|
return resMg
|
|
913
851
|
}
|
|
914
852
|
|
|
853
|
+
//downloadBrowser
|
|
854
|
+
async function downloadBrowser(fileId, cbProgress, opt = {}) {
|
|
855
|
+
//交由瀏覽器下載與管理故無法監聽進度, 不使用cbProgress
|
|
856
|
+
|
|
857
|
+
//token
|
|
858
|
+
let token = getToken()
|
|
859
|
+
if (ispm(token)) {
|
|
860
|
+
token = await token
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
//send download-get-filename
|
|
864
|
+
let msg = { fileId }
|
|
865
|
+
let resMg = await send('download-get-filename', msg, { dataType: 'json' })
|
|
866
|
+
// console.log('resMg', resMg)
|
|
867
|
+
|
|
868
|
+
//filename
|
|
869
|
+
let filename = get(resMg, 'filename', '')
|
|
870
|
+
// console.log('filename', filename)
|
|
871
|
+
|
|
872
|
+
//urlUse
|
|
873
|
+
let urlUse = getUrlUse('download-get')
|
|
874
|
+
// console.log('urlUse', urlUse)
|
|
875
|
+
|
|
876
|
+
//url
|
|
877
|
+
let url = `${urlUse}?fileId=${fileId}&token=${token}`
|
|
878
|
+
// console.log('url', url)
|
|
879
|
+
|
|
880
|
+
//透過a元素打url下載, 讓瀏覽器認定為直接下載模式, 由瀏覽器展示下載進度與排入正在下載清單
|
|
881
|
+
let a = document.createElement('a')
|
|
882
|
+
a.href = url
|
|
883
|
+
a.download = filename
|
|
884
|
+
a.click()
|
|
885
|
+
|
|
886
|
+
return filename
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
//download
|
|
890
|
+
async function download(fileId, cbProgress, opt = {}) {
|
|
891
|
+
if (env === 'browser') {
|
|
892
|
+
return downloadBrowser(fileId, cbProgress, opt)
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
return downloadNodejs(fileId, cbProgress, opt)
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
915
899
|
//save
|
|
916
900
|
ee.execute = execute
|
|
917
901
|
ee.upload = upload
|
|
@@ -936,7 +920,7 @@ export default WConverhpClient
|
|
|
936
920
|
<br class="clear">
|
|
937
921
|
|
|
938
922
|
<footer>
|
|
939
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
923
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Apr 09 2025 13:07:53 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
940
924
|
</footer>
|
|
941
925
|
|
|
942
926
|
<script>prettyPrint();</script>
|
|
@@ -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#line203">line 203</a>
|
|
84
84
|
</li></ul></dd>
|
|
85
85
|
|
|
86
86
|
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
|
|
128
128
|
<h5 class="h5-examples">Example</h5>
|
|
129
129
|
|
|
130
|
-
<pre class="prettyprint"><code>import _ from 'lodash-es'
|
|
131
130
|
port: 8080,
|
|
132
131
|
apiName: 'api',
|
|
133
132
|
pathStaticFiles: '.', //要存取專案資料夾下web.html, 故不能給dist
|
|
134
133
|
verifyConn: () => {
|
|
135
134
|
return true
|
|
136
135
|
},
|
|
137
136
|
// console.log(`Server[port:${opt.port}]: execute`, func, input)
|
|
138
137
|
console.log(`Server[port:${opt.port}]: execute`, func)
|
|
139
138
|
try {
|
|
140
139
|
if (func === 'add') {
|
|
141
140
|
if (_.get(input, 'p.d.u8a', null)) {
|
|
142
141
|
console.log('input.p.d.u8a', input.p.d.u8a)
|
|
143
142
|
}
|
|
144
143
|
let r = {
|
|
145
144
|
_add: input.p.a + input.p.b,
|
|
146
145
|
_data: [11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' }],
|
|
147
146
|
_bin: {
|
|
148
147
|
name: 'zdata.b2',
|
|
149
148
|
u8a: new Uint8Array([66, 97, 115]),
|
|
150
149
|
// name: '100mb.7z',
|
|
151
150
|
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\100mb.7z')),
|
|
152
151
|
// name: '500mb.7z',
|
|
153
152
|
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\500mb.7z')),
|
|
154
153
|
// name: '1000mb.7z',
|
|
155
154
|
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\1000mb.7z')),
|
|
156
155
|
},
|
|
157
156
|
}
|
|
158
157
|
pm.resolve(r)
|
|
159
158
|
}
|
|
160
159
|
else {
|
|
161
160
|
console.log('invalid func')
|
|
162
161
|
pm.reject('invalid func')
|
|
163
162
|
}
|
|
164
163
|
}
|
|
165
164
|
catch (err) {
|
|
166
165
|
console.log('execute error', err)
|
|
167
166
|
pm.reject('execute error')
|
|
168
167
|
}
|
|
169
168
|
console.log(`Server[port:${opt.port}]: upload`, input)
|
|
170
169
|
try {
|
|
171
170
|
let output = input
|
|
172
171
|
pm.resolve(output)
|
|
173
172
|
}
|
|
174
173
|
catch (err) {
|
|
175
174
|
console.log('upload error', err)
|
|
176
175
|
pm.reject('upload error')
|
|
177
176
|
}
|
|
178
177
|
console.log(`Server[port:${opt.port}]: download`, input)
|
|
179
178
|
try {
|
|
180
179
|
ms.push({ 'download': input })
|
|
181
180
|
//fp
|
|
182
181
|
let fp = `./test/1mb.7z`
|
|
183
182
|
//streamRead
|
|
184
183
|
let streamRead = fs.createReadStream(fp)
|
|
185
184
|
//fileName
|
|
186
185
|
let fileName = `1mb.7z`
|
|
187
186
|
//fileSize
|
|
188
187
|
let stats = fs.statSync(fp)
|
|
189
188
|
let fileSize = stats.size
|
|
190
189
|
//fileType
|
|
191
190
|
let fileType = 'application/x-7z-compressed'
|
|
192
191
|
//output
|
|
193
192
|
let output = {
|
|
194
193
|
streamRead,
|
|
195
194
|
fileName,
|
|
196
195
|
fileSize,
|
|
197
196
|
fileType,
|
|
198
197
|
}
|
|
199
198
|
pm.resolve(output)
|
|
200
199
|
}
|
|
201
200
|
catch (err) {
|
|
202
201
|
console.log('download error', err)
|
|
203
202
|
pm.reject('download error')
|
|
204
203
|
}
|
|
205
204
|
// console.log(`Server[port:${opt.port}]: handler`, data)
|
|
205
|
+
<pre class="prettyprint"><code>import fs from 'fs'
|
|
206
206
|
port: 8080,
|
|
207
207
|
apiName: 'api',
|
|
208
208
|
pathStaticFiles: '.', //要存取專案資料夾下web.html, 故不能給dist
|
|
209
209
|
verifyConn: async ({ apiType, authorization, headers, query }) => {
|
|
210
210
|
console.log('verifyConn', `apiType[${apiType}]`, `authorization[${authorization}]`)
|
|
211
211
|
let token = w.strdelleft(authorization, 7) //刪除Bearer
|
|
212
212
|
if (!w.isestr(token)) {
|
|
213
213
|
return false
|
|
214
214
|
}
|
|
215
215
|
// await w.delay(3000)
|
|
216
216
|
return true
|
|
217
217
|
},
|
|
218
218
|
// console.log(`Server[port:${opt.port}]: execute`, func, input)
|
|
219
219
|
console.log(`Server[port:${opt.port}]: execute`, func)
|
|
220
220
|
try {
|
|
221
221
|
if (func === 'add') {
|
|
222
222
|
if (_.get(input, 'p.d.u8a', null)) {
|
|
223
223
|
console.log('input.p.d.u8a', input.p.d.u8a)
|
|
224
224
|
ms.push({ 'input.p.d.u8a': input.p.d.u8a })
|
|
225
225
|
}
|
|
226
226
|
let r = {
|
|
227
227
|
_add: input.p.a + input.p.b,
|
|
228
228
|
_data: [11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' }],
|
|
229
229
|
_bin: {
|
|
230
230
|
name: 'zdata.b2',
|
|
231
231
|
u8a: new Uint8Array([52, 66, 97, 115]),
|
|
232
232
|
},
|
|
233
233
|
}
|
|
234
234
|
pm.resolve(r)
|
|
235
235
|
}
|
|
236
236
|
else {
|
|
237
237
|
console.log('invalid func')
|
|
238
238
|
pm.reject('invalid func')
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
catch (err) {
|
|
242
242
|
console.log('execute error', err)
|
|
243
243
|
pm.reject('execute error')
|
|
244
244
|
}
|
|
245
245
|
console.log(`Server[port:${opt.port}]: upload`, input)
|
|
246
246
|
try {
|
|
247
247
|
ms.push({ 'receive and return': input })
|
|
248
248
|
let output = input
|
|
249
249
|
pm.resolve(output)
|
|
250
250
|
}
|
|
251
251
|
catch (err) {
|
|
252
252
|
console.log('upload error', err)
|
|
253
253
|
pm.reject('upload error')
|
|
254
254
|
}
|
|
255
255
|
console.log(`Server[port:${opt.port}]: download-get-filename`, input)
|
|
256
256
|
try {
|
|
257
257
|
ms.push({ 'download': input })
|
|
258
258
|
//filename
|
|
259
259
|
let filename = `1mb中文.7z` //測試支援中文
|
|
260
260
|
//output
|
|
261
261
|
let output = {
|
|
262
262
|
filename
|
|
263
263
|
}
|
|
264
264
|
pm.resolve(output)
|
|
265
265
|
}
|
|
266
266
|
catch (err) {
|
|
267
267
|
console.log('download error', err)
|
|
268
268
|
pm.reject('download error')
|
|
269
269
|
}
|
|
270
270
|
console.log(`Server[port:${opt.port}]: download`, input)
|
|
271
271
|
try {
|
|
272
272
|
ms.push({ 'download': input })
|
|
273
273
|
//fp
|
|
274
274
|
let fp = `./test/1mb.7z`
|
|
275
275
|
//streamRead
|
|
276
276
|
let streamRead = fs.createReadStream(fp)
|
|
277
277
|
//fileName
|
|
278
278
|
let fileName = `1mb中文.7z` //測試支援中文
|
|
279
279
|
//fileSize
|
|
280
280
|
let stats = fs.statSync(fp)
|
|
281
281
|
let fileSize = stats.size
|
|
282
282
|
//fileType
|
|
283
283
|
let fileType = 'application/x-7z-compressed'
|
|
284
284
|
//output
|
|
285
285
|
let output = {
|
|
286
286
|
streamRead,
|
|
287
287
|
fileName,
|
|
288
288
|
fileSize,
|
|
289
289
|
fileType,
|
|
290
290
|
}
|
|
291
291
|
pm.resolve(output)
|
|
292
292
|
}
|
|
293
293
|
catch (err) {
|
|
294
294
|
console.log('download error', err)
|
|
295
295
|
pm.reject('download error')
|
|
296
296
|
}
|
|
297
297
|
console.log(`Server[port:${opt.port}]: error`, err)
|
|
298
298
|
// console.log(`Server[port:${opt.port}]: handler`, data)
|
|
299
299
|
console.log('ms', ms)
|
|
300
300
|
// console.log('ms', JSON.stringify(ms))
|
|
301
301
|
wo.stop()
|
|
302
302
|
|
|
303
303
|
|
|
304
304
|
|
|
@@ -422,6 +422,46 @@
|
|
|
422
422
|
|
|
423
423
|
|
|
424
424
|
|
|
425
|
+
<tr>
|
|
426
|
+
|
|
427
|
+
<td class="name"><code>tokenType</code></td>
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
<td class="type">
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
<span class="param-type">String</span>
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
</td>
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
<td class="attributes">
|
|
442
|
+
|
|
443
|
+
<optional><br>
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
</td>
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
<td class="default">
|
|
454
|
+
|
|
455
|
+
<code>'Bearer'</code>
|
|
456
|
+
|
|
457
|
+
</td>
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
<td class="description last"><p>輸入token類型字串,預設'Bearer'</p></td>
|
|
461
|
+
</tr>
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
425
465
|
<tr>
|
|
426
466
|
|
|
427
467
|
<td class="name"><code>verifyConn</code></td>
|
|
@@ -709,7 +749,7 @@
|
|
|
709
749
|
<br class="clear">
|
|
710
750
|
|
|
711
751
|
<footer>
|
|
712
|
-
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 Wed Apr 09 2025 13:07:53 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
713
753
|
</footer>
|
|
714
754
|
|
|
715
755
|
<script>prettyPrint();</script>
|