w-converhp 2.0.14 → 2.0.16
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 +58 -104
- 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 +102 -119
- package/docs/WConverhpServer.html +43 -3
- package/docs/WConverhpServer.mjs.html +330 -35
- package/docs/index.html +1 -1
- package/package.json +2 -2
- package/scld.mjs +4 -4
- package/src/WConverhpClient.mjs +101 -118
- package/src/WConverhpServer.mjs +329 -34
- package/srv.mjs +15 -7
- package/test/downloadLargeFile.test.mjs +24 -19
- package/test/executeWithFile.test.mjs +10 -12
- package/test/executeWithU8a.test.mjs +11 -13
- package/test/uploadLargeFile.test.mjs +10 -14
|
@@ -83,100 +83,30 @@ import now2strp from 'wsemi/src/now2strp.mjs'
|
|
|
83
83
|
* @returns {Object} 回傳事件物件,可使用函數execute、upload
|
|
84
84
|
* @example
|
|
85
85
|
*
|
|
86
|
-
* 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 = []
|
|
87
94
|
*
|
|
88
95
|
* let opt = {
|
|
89
96
|
* FormData,
|
|
90
97
|
* url: 'http://localhost:8080',
|
|
91
98
|
* apiName: 'api',
|
|
99
|
+
* getToken: () => {
|
|
100
|
+
* return 'token-for-test'
|
|
101
|
+
* },
|
|
92
102
|
* }
|
|
93
103
|
*
|
|
94
104
|
* //new
|
|
95
105
|
* let wo = new WConverhpClient(opt)
|
|
96
106
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* let p = {
|
|
101
|
-
* a: 12,
|
|
102
|
-
* b: 34.56,
|
|
103
|
-
* c: 'test中文',
|
|
104
|
-
* d: {
|
|
105
|
-
* name,
|
|
106
|
-
* u8a,
|
|
107
|
-
* },
|
|
108
|
-
* }
|
|
109
|
-
* console.log('p', p)
|
|
110
|
-
*
|
|
111
|
-
* //execute
|
|
112
|
-
* await wo.execute('add', { p },
|
|
113
|
-
* function ({ prog, p, m }) {
|
|
114
|
-
* console.log('client web: execute: prog', prog, p, m)
|
|
115
|
-
* })
|
|
116
|
-
* .then(function(r) {
|
|
117
|
-
* console.log('client web: execute: add', r)
|
|
118
|
-
* console.log('r._bin.name', r._bin.name, 'r._bin.u8a', r._bin.u8a)
|
|
119
|
-
* // w.downloadFileFromU8Arr(r._bin.name, r._bin.u8a)
|
|
120
|
-
* })
|
|
121
|
-
* .catch(function (err) {
|
|
122
|
-
* console.log('client web: execute: catch', err)
|
|
123
|
-
* })
|
|
124
|
-
*
|
|
125
|
-
* }
|
|
126
|
-
*
|
|
127
|
-
* function executeWithU8a() {
|
|
128
|
-
* let core = async() => {
|
|
129
|
-
*
|
|
130
|
-
* //u8a
|
|
131
|
-
* let u8a = new Uint8Array([66, 97, 115])
|
|
132
|
-
* console.log('executeWithU8a u8a', u8a)
|
|
133
|
-
*
|
|
134
|
-
* //execute
|
|
135
|
-
* await execute('zdata.b1', u8a)
|
|
136
|
-
*
|
|
137
|
-
* }
|
|
138
|
-
* core()
|
|
139
|
-
* }
|
|
140
|
-
* executeWithU8a()
|
|
141
|
-
*
|
|
142
|
-
* function executeWithFile() {
|
|
143
|
-
* let core = async() => {
|
|
144
|
-
*
|
|
145
|
-
* //u8a
|
|
146
|
-
* let u8a = new Uint8Array(fs.readFileSync('../_data/10mb.7z'))
|
|
147
|
-
* console.log('executeWithFile u8a', u8a)
|
|
148
|
-
*
|
|
149
|
-
* //execute
|
|
150
|
-
* await execute('10mb.7z', u8a)
|
|
151
|
-
*
|
|
152
|
-
* }
|
|
153
|
-
* core()
|
|
154
|
-
* }
|
|
155
|
-
* executeWithFile()
|
|
156
|
-
*
|
|
157
|
-
* function uploadLargeFile() {
|
|
158
|
-
* let core = async() => {
|
|
159
|
-
*
|
|
160
|
-
* //u8a
|
|
161
|
-
* let u8a = new Uint8Array(fs.readFileSync('../_data/1000mb.7z'))
|
|
162
|
-
* console.log('u8a.length', u8a.length)
|
|
163
|
-
* console.log('uploadLargeFile u8a', u8a)
|
|
164
|
-
*
|
|
165
|
-
* await wo.upload('1000mb.7z', u8a,
|
|
166
|
-
* function ({ prog, p, m }) {
|
|
167
|
-
* console.log('client web: upload: prog', prog, p, m)
|
|
168
|
-
* })
|
|
169
|
-
* .then(function(res) {
|
|
170
|
-
* console.log('client web: upload: then', res)
|
|
171
|
-
* })
|
|
172
|
-
* .catch(function (err) {
|
|
173
|
-
* console.log('client web: upload: catch', err)
|
|
174
|
-
* })
|
|
175
|
-
*
|
|
176
|
-
* }
|
|
177
|
-
* core()
|
|
178
|
-
* }
|
|
179
|
-
* uploadLargeFile()
|
|
107
|
+
* wo.on('error', (err) => {
|
|
108
|
+
* console.log(`error`, err)
|
|
109
|
+
* })
|
|
180
110
|
*
|
|
181
111
|
* function downloadLargeFile() {
|
|
182
112
|
* let core = async() => {
|
|
@@ -189,7 +119,7 @@ import now2strp from 'wsemi/src/now2strp.mjs'
|
|
|
189
119
|
* }
|
|
190
120
|
* },
|
|
191
121
|
* {
|
|
192
|
-
* fdDownload: './',
|
|
122
|
+
* fdDownload: './', //於後端nodejs環境才能提供
|
|
193
123
|
* })
|
|
194
124
|
* .then(function(res) {
|
|
195
125
|
* console.log('client web: download: then', res)
|
|
@@ -271,6 +201,36 @@ function WConverhpClient(opt) {
|
|
|
271
201
|
}, 1)
|
|
272
202
|
}
|
|
273
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
|
+
|
|
274
234
|
//res2u8arr
|
|
275
235
|
async function res2u8arr(bb) {
|
|
276
236
|
//blob(in browser) or buffer(in nodejs) to u8a
|
|
@@ -321,22 +281,7 @@ function WConverhpClient(opt) {
|
|
|
321
281
|
}
|
|
322
282
|
|
|
323
283
|
//urlUse
|
|
324
|
-
let urlUse =
|
|
325
|
-
if (type === 'basic') {
|
|
326
|
-
urlUse = url
|
|
327
|
-
}
|
|
328
|
-
else if (type === 'slice') {
|
|
329
|
-
urlUse = `${url}slc`
|
|
330
|
-
}
|
|
331
|
-
else if (type === 'slicemerge') {
|
|
332
|
-
urlUse = `${url}slcm`
|
|
333
|
-
}
|
|
334
|
-
else if (type === 'download') {
|
|
335
|
-
urlUse = `${url}dw`
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
throw new Error(`invalid type[${type}]`)
|
|
339
|
-
}
|
|
284
|
+
let urlUse = getUrlUse(type)
|
|
340
285
|
|
|
341
286
|
//pm
|
|
342
287
|
let pm = genPm()
|
|
@@ -515,7 +460,7 @@ function WConverhpClient(opt) {
|
|
|
515
460
|
|
|
516
461
|
if (env === 'browser') {
|
|
517
462
|
|
|
518
|
-
|
|
463
|
+
//browser通過createObjectURL接收stream與a.href+a.click()接收檔案
|
|
519
464
|
try {
|
|
520
465
|
let url = URL.createObjectURL(streamRecv)
|
|
521
466
|
let a = document.createElement('a')
|
|
@@ -535,6 +480,7 @@ function WConverhpClient(opt) {
|
|
|
535
480
|
}
|
|
536
481
|
else {
|
|
537
482
|
|
|
483
|
+
//nodejs通過fs與stream接收檔案, stream出錯只會觸發error事件, 此處try catch為攔截其他非stream程式碼錯誤
|
|
538
484
|
try {
|
|
539
485
|
|
|
540
486
|
//path, fs
|
|
@@ -692,9 +638,7 @@ function WConverhpClient(opt) {
|
|
|
692
638
|
}
|
|
693
639
|
|
|
694
640
|
//send
|
|
695
|
-
// console.log('send bb...')
|
|
696
641
|
let res = await send(type, bb, { dataType: 'blob', cbProgress })
|
|
697
|
-
// console.log('send done', res)
|
|
698
642
|
|
|
699
643
|
return res
|
|
700
644
|
}
|
|
@@ -799,29 +743,23 @@ function WConverhpClient(opt) {
|
|
|
799
743
|
//chunk
|
|
800
744
|
let chunk = bb.slice(start, end)
|
|
801
745
|
|
|
802
|
-
//
|
|
746
|
+
//send slice
|
|
803
747
|
let hd = {
|
|
804
748
|
'chunk-index': i,
|
|
805
749
|
'chunk-total': chunkTotal,
|
|
806
750
|
'package-id': packageId,
|
|
807
751
|
}
|
|
808
|
-
|
|
809
|
-
//send slice
|
|
810
|
-
// console.log(`uploading chunk[${i + 1}/${chunkTotal}] of packageId[${packageId}]...`)
|
|
811
752
|
await send('slice', chunk, { headers: hd, dataType: 'blob', cbProgress: cbProgressSlice })
|
|
812
|
-
// console.log(`upload chunk[${i + 1}/${chunkTotal}] of packageId[${packageId}] done`, res)
|
|
813
753
|
|
|
814
754
|
}
|
|
815
755
|
|
|
816
|
-
//send merge
|
|
817
|
-
// console.log(`merging tempId[${tempId}]...`)
|
|
756
|
+
//send slice-merge
|
|
818
757
|
let msg = {
|
|
819
758
|
'filename': tempId,
|
|
820
759
|
'chunk-total': chunkTotal,
|
|
821
760
|
'package-id': packageId,
|
|
822
761
|
}
|
|
823
|
-
let resMg = await send('
|
|
824
|
-
// console.log(`merge tempId[${tempId}] done`, resMg)
|
|
762
|
+
let resMg = await send('slice-merge', msg, { dataType: 'json', cbProgress: cbProgressMerge })
|
|
825
763
|
|
|
826
764
|
return resMg
|
|
827
765
|
}
|
|
@@ -901,19 +839,64 @@ function WConverhpClient(opt) {
|
|
|
901
839
|
return sendDataSlice(tempId, bb, cbProgress)
|
|
902
840
|
}
|
|
903
841
|
|
|
904
|
-
//
|
|
905
|
-
async function
|
|
906
|
-
|
|
907
|
-
//msg
|
|
908
|
-
let msg = { fileId }
|
|
842
|
+
//downloadNodejs
|
|
843
|
+
async function downloadNodejs(fileId, cbProgress, opt = {}) {
|
|
909
844
|
|
|
910
845
|
//send download
|
|
846
|
+
let msg = { fileId }
|
|
911
847
|
let resMg = await send('download', msg, { ...opt, dataType: 'json', cbProgress })
|
|
912
848
|
// console.log('resMg', resMg)
|
|
913
849
|
|
|
914
850
|
return resMg
|
|
915
851
|
}
|
|
916
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
|
+
console.log('token', token)
|
|
863
|
+
|
|
864
|
+
//send download-get-filename
|
|
865
|
+
let msg = { fileId }
|
|
866
|
+
let resMg = await send('download-get-filename', msg, { dataType: 'json' })
|
|
867
|
+
console.log('resMg', resMg)
|
|
868
|
+
|
|
869
|
+
//filename
|
|
870
|
+
let filename = get(resMg, 'filename', '')
|
|
871
|
+
console.log('filename', filename)
|
|
872
|
+
|
|
873
|
+
//urlUse
|
|
874
|
+
let urlUse = getUrlUse('download-get')
|
|
875
|
+
console.log('urlUse', urlUse)
|
|
876
|
+
|
|
877
|
+
//url
|
|
878
|
+
let url = `${urlUse}?fileId=${fileId}&token=${token}`
|
|
879
|
+
console.log('url', url)
|
|
880
|
+
|
|
881
|
+
//透過a元素打url下載, 讓瀏覽器認定為直接下載模式, 由瀏覽器展示下載進度與排入正在下載清單
|
|
882
|
+
let a = document.createElement('a')
|
|
883
|
+
a.href = url
|
|
884
|
+
a.download = filename
|
|
885
|
+
a.click()
|
|
886
|
+
|
|
887
|
+
return filename
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
//download
|
|
891
|
+
async function download(fileId, cbProgress, opt = {}) {
|
|
892
|
+
if (env === 'browser') {
|
|
893
|
+
return downloadBrowser(fileId, cbProgress, opt)
|
|
894
|
+
}
|
|
895
|
+
else {
|
|
896
|
+
return downloadNodejs(fileId, cbProgress, opt)
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
|
|
917
900
|
//save
|
|
918
901
|
ee.execute = execute
|
|
919
902
|
ee.upload = upload
|
|
@@ -938,7 +921,7 @@ export default WConverhpClient
|
|
|
938
921
|
<br class="clear">
|
|
939
922
|
|
|
940
923
|
<footer>
|
|
941
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
924
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Apr 09 2025 14:36:52 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
942
925
|
</footer>
|
|
943
926
|
|
|
944
927
|
<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#line188">line 188</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`, input)
|
|
256
256
|
let streamRead = null
|
|
257
257
|
try {
|
|
258
258
|
ms.push({ 'download': input })
|
|
259
259
|
//fp
|
|
260
260
|
let fp = `./test/1mb.7z`
|
|
261
261
|
//check, 檔案存在才往下
|
|
262
262
|
//fileSize
|
|
263
263
|
let stats = fs.statSync(fp)
|
|
264
264
|
let fileSize = stats.size
|
|
265
265
|
//streamRead
|
|
266
266
|
streamRead = fs.createReadStream(fp)
|
|
267
267
|
//filename
|
|
268
268
|
let filename = `1mb中文.7z` //測試支援中文
|
|
269
269
|
//fileType
|
|
270
270
|
let fileType = 'application/x-7z-compressed'
|
|
271
271
|
//output
|
|
272
272
|
let output = {
|
|
273
273
|
streamRead,
|
|
274
274
|
filename,
|
|
275
275
|
fileSize,
|
|
276
276
|
fileType,
|
|
277
277
|
}
|
|
278
278
|
pm.resolve(output)
|
|
279
279
|
}
|
|
280
280
|
catch (err) {
|
|
281
281
|
console.log('download error', err)
|
|
282
282
|
// try {
|
|
283
283
|
// streamRead.destroy() //若fs.createReadStream早於fs.statSync執行, 但fs.statSync發生錯誤時, stream得要destroy
|
|
284
284
|
// }
|
|
285
285
|
// catch (err) {}
|
|
286
286
|
pm.reject('download error')
|
|
287
287
|
}
|
|
288
288
|
console.log(`Server[port:${opt.port}]: error`, err)
|
|
289
289
|
// console.log(`Server[port:${opt.port}]: handler`, data)
|
|
290
290
|
console.log('ms', ms)
|
|
291
291
|
// console.log('ms', JSON.stringify(ms))
|
|
292
292
|
wo.stop()
|
|
293
293
|
|
|
294
294
|
|
|
295
295
|
|
|
@@ -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 14:36:52 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
713
753
|
</footer>
|
|
714
754
|
|
|
715
755
|
<script>prettyPrint();</script>
|