w-converhp 2.0.14 → 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 +101 -119
- package/docs/WConverhpServer.html +43 -3
- package/docs/WConverhpServer.mjs.html +319 -25
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/scld.mjs +4 -4
- package/src/WConverhpClient.mjs +100 -118
- package/src/WConverhpServer.mjs +318 -24
- package/srv.mjs +24 -1
- package/test/downloadLargeFile.test.mjs +11 -12
- package/test/executeWithFile.test.mjs +10 -12
- package/test/executeWithU8a.test.mjs +11 -13
- package/test/uploadLargeFile.test.mjs +10 -14
package/README.md
CHANGED
|
@@ -21,16 +21,28 @@ To view documentation or get support, visit [docs](https://yuda-lyu.github.io/w-
|
|
|
21
21
|
```alias
|
|
22
22
|
npm i w-converhp
|
|
23
23
|
```
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
#### Example for w-converhp-server in nodejs:
|
|
25
26
|
> **Link:** [[dev source code](https://github.com/yuda-lyu/w-converhp/blob/master/srv.mjs)]
|
|
26
27
|
```alias
|
|
27
|
-
import
|
|
28
|
+
import fs from 'fs'
|
|
29
|
+
import _ from 'lodash-es'
|
|
30
|
+
import w from 'wsemi'
|
|
31
|
+
import WConverhpServer from './src/WConverhpServer.mjs'
|
|
32
|
+
|
|
33
|
+
let ms = []
|
|
28
34
|
|
|
29
35
|
let opt = {
|
|
30
36
|
port: 8080,
|
|
31
37
|
apiName: 'api',
|
|
32
38
|
pathStaticFiles: '.', //要存取專案資料夾下web.html, 故不能給dist
|
|
33
|
-
verifyConn: () => {
|
|
39
|
+
verifyConn: async ({ apiType, authorization, headers, query }) => {
|
|
40
|
+
console.log('verifyConn', `apiType[${apiType}]`, `authorization[${authorization}]`)
|
|
41
|
+
let token = w.strdelleft(authorization, 7) //刪除Bearer
|
|
42
|
+
if (!w.isestr(token)) {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
// await w.delay(3000)
|
|
34
46
|
return true
|
|
35
47
|
},
|
|
36
48
|
}
|
|
@@ -48,6 +60,7 @@ wo.on('execute', (func, input, pm) => {
|
|
|
48
60
|
|
|
49
61
|
if (_.get(input, 'p.d.u8a', null)) {
|
|
50
62
|
console.log('input.p.d.u8a', input.p.d.u8a)
|
|
63
|
+
ms.push({ 'input.p.d.u8a': input.p.d.u8a })
|
|
51
64
|
}
|
|
52
65
|
|
|
53
66
|
let r = {
|
|
@@ -55,13 +68,7 @@ wo.on('execute', (func, input, pm) => {
|
|
|
55
68
|
_data: [11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' }],
|
|
56
69
|
_bin: {
|
|
57
70
|
name: 'zdata.b2',
|
|
58
|
-
u8a: new Uint8Array([66, 97, 115]),
|
|
59
|
-
// name: '100mb.7z',
|
|
60
|
-
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\100mb.7z')),
|
|
61
|
-
// name: '500mb.7z',
|
|
62
|
-
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\500mb.7z')),
|
|
63
|
-
// name: '1000mb.7z',
|
|
64
|
-
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\1000mb.7z')),
|
|
71
|
+
u8a: new Uint8Array([52, 66, 97, 115]),
|
|
65
72
|
},
|
|
66
73
|
}
|
|
67
74
|
|
|
@@ -84,6 +91,7 @@ wo.on('upload', (input, pm) => {
|
|
|
84
91
|
console.log(`Server[port:${opt.port}]: upload`, input)
|
|
85
92
|
|
|
86
93
|
try {
|
|
94
|
+
ms.push({ 'receive and return': input })
|
|
87
95
|
let output = input
|
|
88
96
|
pm.resolve(output)
|
|
89
97
|
}
|
|
@@ -92,6 +100,28 @@ wo.on('upload', (input, pm) => {
|
|
|
92
100
|
pm.reject('upload error')
|
|
93
101
|
}
|
|
94
102
|
|
|
103
|
+
})
|
|
104
|
+
wo.on('download-get-filename', (input, pm) => {
|
|
105
|
+
console.log(`Server[port:${opt.port}]: download-get-filename`, input)
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
ms.push({ 'download': input })
|
|
109
|
+
|
|
110
|
+
//filename
|
|
111
|
+
let filename = `1mb中文.7z` //測試支援中文
|
|
112
|
+
|
|
113
|
+
//output
|
|
114
|
+
let output = {
|
|
115
|
+
filename
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
pm.resolve(output)
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
console.log('download error', err)
|
|
122
|
+
pm.reject('download error')
|
|
123
|
+
}
|
|
124
|
+
|
|
95
125
|
})
|
|
96
126
|
wo.on('download', (input, pm) => {
|
|
97
127
|
console.log(`Server[port:${opt.port}]: download`, input)
|
|
@@ -106,7 +136,7 @@ wo.on('download', (input, pm) => {
|
|
|
106
136
|
let streamRead = fs.createReadStream(fp)
|
|
107
137
|
|
|
108
138
|
//fileName
|
|
109
|
-
let fileName = `1mb
|
|
139
|
+
let fileName = `1mb中文.7z` //測試支援中文
|
|
110
140
|
|
|
111
141
|
//fileSize
|
|
112
142
|
let stats = fs.statSync(fp)
|
|
@@ -131,108 +161,44 @@ wo.on('download', (input, pm) => {
|
|
|
131
161
|
}
|
|
132
162
|
|
|
133
163
|
})
|
|
164
|
+
wo.on('error', (err) => {
|
|
165
|
+
console.log(`Server[port:${opt.port}]: error`, err)
|
|
166
|
+
})
|
|
134
167
|
wo.on('handler', (data) => {
|
|
135
168
|
// console.log(`Server[port:${opt.port}]: handler`, data)
|
|
136
169
|
})
|
|
137
170
|
|
|
171
|
+
setTimeout(() => {
|
|
172
|
+
console.log('ms', ms)
|
|
173
|
+
// console.log('ms', JSON.stringify(ms))
|
|
174
|
+
wo.stop()
|
|
175
|
+
}, 3000)
|
|
176
|
+
|
|
138
177
|
```
|
|
139
|
-
|
|
178
|
+
|
|
179
|
+
#### Example for w-converhp-client in nodejs:
|
|
140
180
|
> **Link:** [[dev source code](https://github.com/yuda-lyu/w-converhp/blob/master/scla.mjs)]
|
|
141
181
|
```alias
|
|
142
|
-
import
|
|
182
|
+
import FormData from 'form-data'
|
|
183
|
+
import WConverhpClient from './src/WConverhpClient.mjs'
|
|
184
|
+
|
|
185
|
+
let ms = []
|
|
143
186
|
|
|
144
187
|
let opt = {
|
|
145
188
|
FormData,
|
|
146
189
|
url: 'http://localhost:8080',
|
|
147
190
|
apiName: 'api',
|
|
191
|
+
getToken: () => {
|
|
192
|
+
return 'token-for-test'
|
|
193
|
+
},
|
|
148
194
|
}
|
|
149
195
|
|
|
150
196
|
//new
|
|
151
197
|
let wo = new WConverhpClient(opt)
|
|
152
198
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
let p = {
|
|
157
|
-
a: 12,
|
|
158
|
-
b: 34.56,
|
|
159
|
-
c: 'test中文',
|
|
160
|
-
d: {
|
|
161
|
-
name,
|
|
162
|
-
u8a,
|
|
163
|
-
},
|
|
164
|
-
}
|
|
165
|
-
console.log('p', p)
|
|
166
|
-
|
|
167
|
-
//execute
|
|
168
|
-
await wo.execute('add', { p },
|
|
169
|
-
function ({ prog, p, m }) {
|
|
170
|
-
console.log('client web: execute: prog', prog, p, m)
|
|
171
|
-
})
|
|
172
|
-
.then(function(r) {
|
|
173
|
-
console.log('client web: execute: add', r)
|
|
174
|
-
console.log('r._bin.name', r._bin.name, 'r._bin.u8a', r._bin.u8a)
|
|
175
|
-
// w.downloadFileFromU8Arr(r._bin.name, r._bin.u8a)
|
|
176
|
-
})
|
|
177
|
-
.catch(function (err) {
|
|
178
|
-
console.log('client web: execute: catch', err)
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function executeWithU8a() {
|
|
184
|
-
let core = async() => {
|
|
185
|
-
|
|
186
|
-
//u8a
|
|
187
|
-
let u8a = new Uint8Array([66, 97, 115])
|
|
188
|
-
console.log('executeWithU8a u8a', u8a)
|
|
189
|
-
|
|
190
|
-
//execute
|
|
191
|
-
await execute('zdata.b1', u8a)
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
core()
|
|
195
|
-
}
|
|
196
|
-
executeWithU8a()
|
|
197
|
-
|
|
198
|
-
function executeWithFile() {
|
|
199
|
-
let core = async() => {
|
|
200
|
-
|
|
201
|
-
//u8a
|
|
202
|
-
let u8a = new Uint8Array(fs.readFileSync('../_data/10mb.7z'))
|
|
203
|
-
console.log('executeWithFile u8a', u8a)
|
|
204
|
-
|
|
205
|
-
//execute
|
|
206
|
-
await execute('10mb.7z', u8a)
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
core()
|
|
210
|
-
}
|
|
211
|
-
executeWithFile()
|
|
212
|
-
|
|
213
|
-
function uploadLargeFile() {
|
|
214
|
-
let core = async() => {
|
|
215
|
-
|
|
216
|
-
//u8a
|
|
217
|
-
let u8a = new Uint8Array(fs.readFileSync('../_data/1000mb.7z'))
|
|
218
|
-
console.log('u8a.length', u8a.length)
|
|
219
|
-
console.log('uploadLargeFile u8a', u8a)
|
|
220
|
-
|
|
221
|
-
await wo.upload('1000mb.7z', u8a,
|
|
222
|
-
function ({ prog, p, m }) {
|
|
223
|
-
console.log('client web: upload: prog', prog, p, m)
|
|
224
|
-
})
|
|
225
|
-
.then(function(res) {
|
|
226
|
-
console.log('client web: upload: then', res)
|
|
227
|
-
})
|
|
228
|
-
.catch(function (err) {
|
|
229
|
-
console.log('client web: upload: catch', err)
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
core()
|
|
234
|
-
}
|
|
235
|
-
uploadLargeFile()
|
|
199
|
+
wo.on('error', (err) => {
|
|
200
|
+
console.log(`error`, err)
|
|
201
|
+
})
|
|
236
202
|
|
|
237
203
|
function downloadLargeFile() {
|
|
238
204
|
let core = async() => {
|
|
@@ -245,7 +211,7 @@ function downloadLargeFile() {
|
|
|
245
211
|
}
|
|
246
212
|
},
|
|
247
213
|
{
|
|
248
|
-
fdDownload: './',
|
|
214
|
+
fdDownload: './', //於後端nodejs環境才能提供
|
|
249
215
|
})
|
|
250
216
|
.then(function(res) {
|
|
251
217
|
console.log('client web: download: then', res)
|
|
@@ -260,7 +226,9 @@ function downloadLargeFile() {
|
|
|
260
226
|
}
|
|
261
227
|
core()
|
|
262
228
|
}
|
|
229
|
+
|
|
263
230
|
downloadLargeFile()
|
|
231
|
+
|
|
264
232
|
```
|
|
265
233
|
|
|
266
234
|
### In a browser(UMD module):
|
|
@@ -268,9 +236,10 @@ downloadLargeFile()
|
|
|
268
236
|
|
|
269
237
|
[Necessary] Add script for w-converhp-client.
|
|
270
238
|
```alias
|
|
271
|
-
<script src="https://cdn.jsdelivr.net/npm/w-converhp@2.0.
|
|
239
|
+
<script src="https://cdn.jsdelivr.net/npm/w-converhp@2.0.15/dist/w-converhp-client.umd.js"></script>
|
|
272
240
|
```
|
|
273
|
-
|
|
241
|
+
|
|
242
|
+
#### Example for w-converhp-client in browser:
|
|
274
243
|
> **Link:** [[dev source code](https://github.com/yuda-lyu/w-converhp/blob/master/web.html)]
|
|
275
244
|
```alias
|
|
276
245
|
|