w-converhp 2.0.3 → 2.0.5
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 +10 -10
- 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 +16 -12
- package/docs/WConverhpServer.html +3 -3
- package/docs/WConverhpServer.mjs.html +23 -85
- package/docs/index.html +1 -1
- package/package.json +2 -2
- package/scla.mjs +2 -2
- package/sclb.mjs +2 -2
- package/sclc.mjs +2 -2
- package/src/WConverhpClient.mjs +15 -11
- package/src/WConverhpServer.mjs +21 -83
- package/src/mergeFiles.mjs +73 -0
- package/src/mergeFiles.wk.umd.js +1 -0
- package/srv.mjs +13 -7
- package/toolg/gDistRollup.mjs +56 -47
- package/web.html +2 -2
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
|
|
128
128
|
<h5 class="h5-examples">Example</h5>
|
|
129
129
|
|
|
130
|
-
<pre class="prettyprint"><code>import WConverhpClient from 'w-converhp/dist/w-converhp-client.umd.js'
|
|
131
130
|
FormData,
|
|
132
131
|
url: 'http://localhost:8080',
|
|
133
132
|
apiName: 'api',
|
|
134
133
|
//p
|
|
135
134
|
let p = {
|
|
136
135
|
a: 12,
|
|
137
136
|
b: 34.56,
|
|
138
137
|
c: 'test中文',
|
|
139
138
|
d: {
|
|
140
139
|
name,
|
|
141
140
|
u8a,
|
|
142
141
|
},
|
|
143
142
|
}
|
|
144
143
|
console.log('p', p)
|
|
145
144
|
//execute
|
|
146
145
|
await wo.execute('add', { p },
|
|
147
146
|
function (prog, p, m) {
|
|
148
147
|
console.log('client web: execute: prog', prog, p, m)
|
|
149
148
|
})
|
|
150
149
|
.then(function(r) {
|
|
151
150
|
console.log('client web: execute: add', r)
|
|
152
151
|
console.log('r._bin.name', r._bin.name, 'r._bin.u8a', r._bin.u8a)
|
|
153
152
|
// w.downloadFileFromU8Arr(r._bin.name, r._bin.u8a)
|
|
154
153
|
})
|
|
155
154
|
.catch(function (err) {
|
|
156
155
|
console.log('client web: execute: catch', err)
|
|
157
156
|
})
|
|
158
157
|
let core = async() => {
|
|
159
158
|
//u8a
|
|
160
159
|
let u8a = new Uint8Array([66, 97, 115])
|
|
161
160
|
console.log('executeWithU8a u8a', u8a)
|
|
162
161
|
//execute
|
|
163
162
|
await execute('zdata.b1', u8a)
|
|
164
163
|
}
|
|
165
164
|
core()
|
|
166
165
|
let core = async() => {
|
|
167
166
|
//u8a
|
|
168
167
|
let u8a = new Uint8Array(fs.readFileSync('../_data/10mb.7z'))
|
|
169
168
|
console.log('executeWithFile u8a', u8a)
|
|
170
169
|
//execute
|
|
171
170
|
await execute('10mb.7z', u8a)
|
|
172
171
|
}
|
|
173
172
|
core()
|
|
174
173
|
let core = async() => {
|
|
175
174
|
//u8a
|
|
176
175
|
let u8a = new Uint8Array(fs.readFileSync('../_data/1000mb.7z'))
|
|
177
176
|
console.log('u8a.length', u8a.length)
|
|
178
177
|
console.log('uploadLargeFile u8a', u8a)
|
|
179
178
|
await wo.upload('1000mb.7z', u8a,
|
|
180
179
|
function (prog, p, m) {
|
|
181
180
|
console.log('client web: upload: prog', prog, p, m)
|
|
182
181
|
})
|
|
183
182
|
.then(function(res) {
|
|
184
183
|
console.log('client web: upload: then', res)
|
|
185
184
|
})
|
|
186
185
|
.catch(function (err) {
|
|
187
186
|
console.log('client web: upload: catch', err)
|
|
188
187
|
})
|
|
189
188
|
}
|
|
190
189
|
core()
|
|
190
|
+
<pre class="prettyprint"><code>import WConverhpClient from 'w-converhp/dist/w-converhp-client.umd.js'
|
|
191
191
|
FormData,
|
|
192
192
|
url: 'http://localhost:8080',
|
|
193
193
|
apiName: 'api',
|
|
194
194
|
//p
|
|
195
195
|
let p = {
|
|
196
196
|
a: 12,
|
|
197
197
|
b: 34.56,
|
|
198
198
|
c: 'test中文',
|
|
199
199
|
d: {
|
|
200
200
|
name,
|
|
201
201
|
u8a,
|
|
202
202
|
},
|
|
203
203
|
}
|
|
204
204
|
console.log('p', p)
|
|
205
205
|
//execute
|
|
206
206
|
await wo.execute('add', { p },
|
|
207
207
|
function ({ prog, p, m }) {
|
|
208
208
|
console.log('client web: execute: prog', prog, p, m)
|
|
209
209
|
})
|
|
210
210
|
.then(function(r) {
|
|
211
211
|
console.log('client web: execute: add', r)
|
|
212
212
|
console.log('r._bin.name', r._bin.name, 'r._bin.u8a', r._bin.u8a)
|
|
213
213
|
// w.downloadFileFromU8Arr(r._bin.name, r._bin.u8a)
|
|
214
214
|
})
|
|
215
215
|
.catch(function (err) {
|
|
216
216
|
console.log('client web: execute: catch', err)
|
|
217
217
|
})
|
|
218
218
|
let core = async() => {
|
|
219
219
|
//u8a
|
|
220
220
|
let u8a = new Uint8Array([66, 97, 115])
|
|
221
221
|
console.log('executeWithU8a u8a', u8a)
|
|
222
222
|
//execute
|
|
223
223
|
await execute('zdata.b1', u8a)
|
|
224
224
|
}
|
|
225
225
|
core()
|
|
226
226
|
let core = async() => {
|
|
227
227
|
//u8a
|
|
228
228
|
let u8a = new Uint8Array(fs.readFileSync('../_data/10mb.7z'))
|
|
229
229
|
console.log('executeWithFile u8a', u8a)
|
|
230
230
|
//execute
|
|
231
231
|
await execute('10mb.7z', u8a)
|
|
232
232
|
}
|
|
233
233
|
core()
|
|
234
234
|
let core = async() => {
|
|
235
235
|
//u8a
|
|
236
236
|
let u8a = new Uint8Array(fs.readFileSync('../_data/1000mb.7z'))
|
|
237
237
|
console.log('u8a.length', u8a.length)
|
|
238
238
|
console.log('uploadLargeFile u8a', u8a)
|
|
239
239
|
await wo.upload('1000mb.7z', u8a,
|
|
240
240
|
function ({ prog, p, m }) {
|
|
241
241
|
console.log('client web: upload: prog', prog, p, m)
|
|
242
242
|
})
|
|
243
243
|
.then(function(res) {
|
|
244
244
|
console.log('client web: upload: then', res)
|
|
245
245
|
})
|
|
246
246
|
.catch(function (err) {
|
|
247
247
|
console.log('client web: upload: catch', err)
|
|
248
248
|
})
|
|
249
249
|
}
|
|
250
250
|
core()
|
|
251
251
|
|
|
252
252
|
|
|
253
253
|
|
|
@@ -529,7 +529,7 @@
|
|
|
529
529
|
<br class="clear">
|
|
530
530
|
|
|
531
531
|
<footer>
|
|
532
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
532
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Mar 31 2025 23:59:37 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
533
533
|
</footer>
|
|
534
534
|
|
|
535
535
|
<script>prettyPrint();</script>
|
|
@@ -109,7 +109,7 @@ import now2strp from 'wsemi/src/now2strp.mjs'
|
|
|
109
109
|
*
|
|
110
110
|
* //execute
|
|
111
111
|
* await wo.execute('add', { p },
|
|
112
|
-
* function (prog, p, m) {
|
|
112
|
+
* function ({ prog, p, m }) {
|
|
113
113
|
* console.log('client web: execute: prog', prog, p, m)
|
|
114
114
|
* })
|
|
115
115
|
* .then(function(r) {
|
|
@@ -162,7 +162,7 @@ import now2strp from 'wsemi/src/now2strp.mjs'
|
|
|
162
162
|
* console.log('uploadLargeFile u8a', u8a)
|
|
163
163
|
*
|
|
164
164
|
* await wo.upload('1000mb.7z', u8a,
|
|
165
|
-
* function (prog, p, m) {
|
|
165
|
+
* function ({ prog, p, m }) {
|
|
166
166
|
* console.log('client web: upload: prog', prog, p, m)
|
|
167
167
|
* })
|
|
168
168
|
* .then(function(res) {
|
|
@@ -410,7 +410,7 @@ function WConverhpClient(opt) {
|
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
//cbProgress
|
|
413
|
-
cbProgress(Math.floor(r), loaded, 'upload')
|
|
413
|
+
cbProgress({ prog: Math.floor(r), p: loaded, m: 'upload' })
|
|
414
414
|
|
|
415
415
|
},
|
|
416
416
|
onDownloadProgress: function (ev) {
|
|
@@ -426,7 +426,7 @@ function WConverhpClient(opt) {
|
|
|
426
426
|
}
|
|
427
427
|
|
|
428
428
|
//cbProgress
|
|
429
|
-
cbProgress(Math.floor(r), loaded, 'download')
|
|
429
|
+
cbProgress({ prog: Math.floor(r), p: loaded, m: 'download' })
|
|
430
430
|
|
|
431
431
|
},
|
|
432
432
|
}
|
|
@@ -589,8 +589,8 @@ function WConverhpClient(opt) {
|
|
|
589
589
|
catch (err) {}
|
|
590
590
|
}
|
|
591
591
|
if (n === 0) {
|
|
592
|
-
eeEmit('error', `
|
|
593
|
-
return Promise.reject(`
|
|
592
|
+
eeEmit('error', `can not get size of bb`)
|
|
593
|
+
return Promise.reject(`can not get size of bb`)
|
|
594
594
|
}
|
|
595
595
|
// console.log('n', n)
|
|
596
596
|
|
|
@@ -608,20 +608,24 @@ function WConverhpClient(opt) {
|
|
|
608
608
|
// let progWeightMerge = 0.01 //合併階段進度使用1%
|
|
609
609
|
|
|
610
610
|
//cbProgressSlice
|
|
611
|
-
let cbProgressSlice = (
|
|
611
|
+
let cbProgressSlice = (msg) => {
|
|
612
|
+
let perc = msg.prog
|
|
613
|
+
let dir = msg.m
|
|
612
614
|
if (dir === 'upload' && perc === 100) {
|
|
613
615
|
progCount++
|
|
614
616
|
let r = progCount / chunkTotal
|
|
615
617
|
let prog = r * progWeightSlice * 100
|
|
616
618
|
let psiz = r * n
|
|
617
|
-
cbProgress(prog, psiz, 'upload')
|
|
619
|
+
cbProgress({ prog, p: psiz, m: 'upload' })
|
|
618
620
|
}
|
|
619
621
|
}
|
|
620
622
|
|
|
621
623
|
//cbProgressMerge
|
|
622
|
-
let cbProgressMerge = (
|
|
624
|
+
let cbProgressMerge = (msg) => {
|
|
625
|
+
let perc = msg.prog
|
|
626
|
+
let dir = msg.m
|
|
623
627
|
if (dir === 'download' && perc === 100) {
|
|
624
|
-
cbProgress(100, n, 'upload')
|
|
628
|
+
cbProgress({ prog: 100, p: n, m: 'upload' })
|
|
625
629
|
}
|
|
626
630
|
}
|
|
627
631
|
|
|
@@ -652,7 +656,7 @@ function WConverhpClient(opt) {
|
|
|
652
656
|
}
|
|
653
657
|
|
|
654
658
|
//send merge
|
|
655
|
-
console.log(`merging tempId[${tempId}]...`)
|
|
659
|
+
// console.log(`merging tempId[${tempId}]...`)
|
|
656
660
|
let msg = {
|
|
657
661
|
'filename': tempId,
|
|
658
662
|
'chunk-total': chunkTotal,
|
|
@@ -762,7 +766,7 @@ export default WConverhpClient
|
|
|
762
766
|
<br class="clear">
|
|
763
767
|
|
|
764
768
|
<footer>
|
|
765
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
769
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Mar 31 2025 23:59:37 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
766
770
|
</footer>
|
|
767
771
|
|
|
768
772
|
<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#line117">line 117</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
|
funCheck: () => {
|
|
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('execute error', err)
|
|
176
175
|
pm.reject('execute error')
|
|
177
176
|
}
|
|
178
177
|
// console.log(`Server[port:${opt.port}]: handler`, data)
|
|
178
|
+
<pre class="prettyprint"><code>import _ from 'lodash-es'
|
|
179
179
|
port: 8080,
|
|
180
180
|
apiName: 'api',
|
|
181
181
|
pathStaticFiles: '.', //要存取專案資料夾下web.html, 故不能給dist
|
|
182
182
|
funCheck: () => {
|
|
183
183
|
return true
|
|
184
184
|
},
|
|
185
185
|
// console.log(`Server[port:${opt.port}]: execute`, func, input)
|
|
186
186
|
console.log(`Server[port:${opt.port}]: execute`, func)
|
|
187
187
|
try {
|
|
188
188
|
if (func === 'add') {
|
|
189
189
|
if (_.get(input, 'p.d.u8a', null)) {
|
|
190
190
|
console.log('input.p.d.u8a', input.p.d.u8a)
|
|
191
191
|
}
|
|
192
192
|
let r = {
|
|
193
193
|
_add: input.p.a + input.p.b,
|
|
194
194
|
_data: [11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' }],
|
|
195
195
|
_bin: {
|
|
196
196
|
name: 'zdata.b2',
|
|
197
197
|
u8a: new Uint8Array([66, 97, 115]),
|
|
198
198
|
// name: '100mb.7z',
|
|
199
199
|
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\100mb.7z')),
|
|
200
200
|
// name: '500mb.7z',
|
|
201
201
|
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\500mb.7z')),
|
|
202
202
|
// name: '1000mb.7z',
|
|
203
203
|
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\1000mb.7z')),
|
|
204
204
|
},
|
|
205
205
|
}
|
|
206
206
|
pm.resolve(r)
|
|
207
207
|
}
|
|
208
208
|
else {
|
|
209
209
|
console.log('invalid func')
|
|
210
210
|
pm.reject('invalid func')
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
catch (err) {
|
|
214
214
|
console.log('execute error', err)
|
|
215
215
|
pm.reject('execute error')
|
|
216
216
|
}
|
|
217
217
|
console.log(`Server[port:${opt.port}]: upload`, input)
|
|
218
218
|
try {
|
|
219
219
|
let output = input
|
|
220
220
|
pm.resolve(output)
|
|
221
221
|
}
|
|
222
222
|
catch (err) {
|
|
223
223
|
console.log('upload error', err)
|
|
224
224
|
pm.reject('upload error')
|
|
225
225
|
}
|
|
226
226
|
// console.log(`Server[port:${opt.port}]: handler`, data)
|
|
227
227
|
|
|
228
228
|
|
|
229
229
|
|
|
@@ -709,7 +709,7 @@
|
|
|
709
709
|
<br class="clear">
|
|
710
710
|
|
|
711
711
|
<footer>
|
|
712
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
712
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Mar 31 2025 23:59:37 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
713
713
|
</footer>
|
|
714
714
|
|
|
715
715
|
<script>prettyPrint();</script>
|
|
@@ -45,11 +45,10 @@
|
|
|
45
45
|
|
|
46
46
|
<section>
|
|
47
47
|
<article>
|
|
48
|
-
<pre class="prettyprint source linenums"><code>import
|
|
49
|
-
import
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import fs from 'fs'
|
|
49
|
+
import stream from 'stream'
|
|
50
50
|
import Hapi from '@hapi/hapi'
|
|
51
51
|
import Inert from '@hapi/inert' //提供靜態檔案
|
|
52
|
-
import stream from 'stream'
|
|
53
52
|
import get from 'lodash-es/get.js'
|
|
54
53
|
import genPm from 'wsemi/src/genPm.mjs'
|
|
55
54
|
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
@@ -66,8 +65,7 @@ import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
|
|
|
66
65
|
import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
|
|
67
66
|
import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
|
|
68
67
|
import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
|
|
69
|
-
import
|
|
70
|
-
import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
|
|
68
|
+
import mergeFiles from './mergeFiles.wk.umd.js'
|
|
71
69
|
|
|
72
70
|
|
|
73
71
|
/**
|
|
@@ -103,7 +101,7 @@ import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
|
|
|
103
101
|
* //new
|
|
104
102
|
* let wo = new WConverhpServer(opt)
|
|
105
103
|
*
|
|
106
|
-
* wo.on('execute',
|
|
104
|
+
* wo.on('execute', (func, input, pm) => {
|
|
107
105
|
* // console.log(`Server[port:${opt.port}]: execute`, func, input)
|
|
108
106
|
* console.log(`Server[port:${opt.port}]: execute`, func)
|
|
109
107
|
*
|
|
@@ -145,7 +143,7 @@ import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
|
|
|
145
143
|
* }
|
|
146
144
|
*
|
|
147
145
|
* })
|
|
148
|
-
* wo.on('upload',
|
|
146
|
+
* wo.on('upload', (input, pm) => {
|
|
149
147
|
* console.log(`Server[port:${opt.port}]: upload`, input)
|
|
150
148
|
*
|
|
151
149
|
* try {
|
|
@@ -153,12 +151,12 @@ import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
|
|
|
153
151
|
* pm.resolve(output)
|
|
154
152
|
* }
|
|
155
153
|
* catch (err) {
|
|
156
|
-
* console.log('
|
|
157
|
-
* pm.reject('
|
|
154
|
+
* console.log('upload error', err)
|
|
155
|
+
* pm.reject('upload error')
|
|
158
156
|
* }
|
|
159
157
|
*
|
|
160
158
|
* })
|
|
161
|
-
* wo.on('handler',
|
|
159
|
+
* wo.on('handler', (data) => {
|
|
162
160
|
* // console.log(`Server[port:${opt.port}]: handler`, data)
|
|
163
161
|
* })
|
|
164
162
|
*
|
|
@@ -244,6 +242,10 @@ function WConverhpServer(opt = {}) {
|
|
|
244
242
|
//host: 'localhost',
|
|
245
243
|
port,
|
|
246
244
|
routes: {
|
|
245
|
+
timeout: {
|
|
246
|
+
server: false, //關閉伺服器超時
|
|
247
|
+
socket: false, //關閉socket超時
|
|
248
|
+
},
|
|
247
249
|
cors: {
|
|
248
250
|
origin: corsOrigins, //Access-Control-Allow-Origin
|
|
249
251
|
credentials: false, //Access-Control-Allow-Credentials
|
|
@@ -360,8 +362,8 @@ function WConverhpServer(opt = {}) {
|
|
|
360
362
|
parse: false,
|
|
361
363
|
},
|
|
362
364
|
timeout: {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
+
server: false, //關閉伺服器超時
|
|
366
|
+
socket: false, //關閉socket超時
|
|
365
367
|
},
|
|
366
368
|
},
|
|
367
369
|
handler: async function (req, res) {
|
|
@@ -518,8 +520,8 @@ function WConverhpServer(opt = {}) {
|
|
|
518
520
|
parse: false,
|
|
519
521
|
},
|
|
520
522
|
timeout: {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
+
server: false, //關閉伺服器超時
|
|
524
|
+
socket: false, //關閉socket超時
|
|
523
525
|
},
|
|
524
526
|
},
|
|
525
527
|
handler: async function (req, res) {
|
|
@@ -664,8 +666,8 @@ function WConverhpServer(opt = {}) {
|
|
|
664
666
|
parse: true, //前端送obj過來
|
|
665
667
|
},
|
|
666
668
|
timeout: {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
+
server: false, //關閉伺服器超時
|
|
670
|
+
socket: false, //關閉socket超時
|
|
669
671
|
},
|
|
670
672
|
},
|
|
671
673
|
handler: async function (req, res) {
|
|
@@ -739,78 +741,13 @@ function WConverhpServer(opt = {}) {
|
|
|
739
741
|
return res.response({ error: 'invalid packageId in payload' }).code(400)
|
|
740
742
|
}
|
|
741
743
|
|
|
742
|
-
//merge
|
|
743
|
-
let merge = async () => {
|
|
744
|
-
let errTemp = ''
|
|
745
|
-
|
|
746
|
-
//pathFileMerge
|
|
747
|
-
let pathFileMerge = path.join(pathUploadTemp, `${packageId}`)
|
|
748
|
-
// console.log('pathFileMerge', pathFileMerge)
|
|
749
|
-
|
|
750
|
-
//fileStream
|
|
751
|
-
let fileStream = fs.createWriteStream(pathFileMerge)
|
|
752
|
-
// console.log(`merge filename[${filename}] start`)
|
|
753
|
-
|
|
754
|
-
//使用try catch攔截,使stream能完整創造與結束
|
|
755
|
-
try {
|
|
756
|
-
for (let i = 0; i < chunkTotal; i++) {
|
|
757
|
-
// console.log(`merge ${i + 1}/${chunkTotal}`)
|
|
758
|
-
|
|
759
|
-
//chunkIndex
|
|
760
|
-
let chunkIndex = i
|
|
761
|
-
|
|
762
|
-
//pathFileChunk
|
|
763
|
-
let pathFileChunk = path.join(pathUploadTemp, `${packageId}_${chunkIndex}`)
|
|
764
|
-
|
|
765
|
-
//check
|
|
766
|
-
if (!fsIsFile(pathFileChunk)) {
|
|
767
|
-
// console.log(`pathFileChunk[${pathFileChunk}] is not a file`)
|
|
768
|
-
throw new Error(`Missing chunk ${i} of filename[${filename}]`)
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
// console.log(`merging chunk[${chunkIndex + 1}/${chunkTotal}]...`)
|
|
772
|
-
|
|
773
|
-
//chunkData
|
|
774
|
-
let chunkData = fs.readFileSync(pathFileChunk)
|
|
775
|
-
|
|
776
|
-
//write
|
|
777
|
-
fileStream.write(chunkData)
|
|
778
|
-
|
|
779
|
-
//fsDeleteFile
|
|
780
|
-
fsDeleteFile(pathFileChunk)
|
|
781
|
-
|
|
782
|
-
// console.log(`merge chunk[${chunkIndex + 1}/${chunkTotal}] done`)
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
catch (err) {
|
|
786
|
-
errTemp = err.message
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
//end
|
|
790
|
-
fileStream.end()
|
|
791
|
-
// console.log(`merge filename[${filename}] done`)
|
|
792
|
-
|
|
793
|
-
//check
|
|
794
|
-
if (isestr(errTemp)) {
|
|
795
|
-
return Promise.reject(errTemp)
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
//r
|
|
799
|
-
let r = {
|
|
800
|
-
// message: `Merged filename[${filename}] successfully`,
|
|
801
|
-
filename,
|
|
802
|
-
path: pathFileMerge,
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
return r
|
|
806
|
-
}
|
|
807
|
-
|
|
808
744
|
//core
|
|
809
745
|
let core = async() => {
|
|
810
746
|
|
|
811
747
|
//merge
|
|
812
748
|
// console.log('merge start')
|
|
813
|
-
let r = await merge()
|
|
749
|
+
// let r = await merge()
|
|
750
|
+
let r = await mergeFiles(pathUploadTemp, packageId, chunkTotal, filename)
|
|
814
751
|
// console.log('merge done', r)
|
|
815
752
|
|
|
816
753
|
//procUpload
|
|
@@ -886,7 +823,8 @@ function WConverhpServer(opt = {}) {
|
|
|
886
823
|
|
|
887
824
|
//start
|
|
888
825
|
if (get(opt, 'serverHapi')) {
|
|
889
|
-
opt.serverHapi.route([apiMain, apiSlice, apiSliceMerge])
|
|
826
|
+
// opt.serverHapi.route([apiMain, apiSlice, apiSliceMerge])
|
|
827
|
+
server.route([apiMain, apiSlice, apiSliceMerge])
|
|
890
828
|
}
|
|
891
829
|
else {
|
|
892
830
|
startServer()
|
|
@@ -911,7 +849,7 @@ export default WConverhpServer
|
|
|
911
849
|
<br class="clear">
|
|
912
850
|
|
|
913
851
|
<footer>
|
|
914
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
852
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Mar 31 2025 23:59:37 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
915
853
|
</footer>
|
|
916
854
|
|
|
917
855
|
<script>prettyPrint();</script>
|
package/docs/index.html
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
<br class="clear">
|
|
72
72
|
|
|
73
73
|
<footer>
|
|
74
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on
|
|
74
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Mar 31 2025 23:59:37 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
75
75
|
</footer>
|
|
76
76
|
|
|
77
77
|
<script>prettyPrint();</script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w-converhp",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"main": "dist/w-converhp-server.umd.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@hapi/hapi": "^21.4.0",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"form-data": "^4.0.2",
|
|
14
|
-
"w-package-tools": "^1.0.
|
|
14
|
+
"w-package-tools": "^1.0.85"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"@hapi/hapi": "^20.2.1",
|
package/scla.mjs
CHANGED
|
@@ -16,7 +16,7 @@ let opt = {
|
|
|
16
16
|
//new
|
|
17
17
|
let wo = new WConverhpClient(opt)
|
|
18
18
|
|
|
19
|
-
wo.on('error',
|
|
19
|
+
wo.on('error', (err) => {
|
|
20
20
|
console.log(`error`, err)
|
|
21
21
|
})
|
|
22
22
|
|
|
@@ -36,7 +36,7 @@ async function execute(name, u8a) {
|
|
|
36
36
|
|
|
37
37
|
//execute
|
|
38
38
|
await wo.execute('add', { p },
|
|
39
|
-
function (prog, p, m) {
|
|
39
|
+
function ({ prog, p, m }) {
|
|
40
40
|
if (m === 'upload') {
|
|
41
41
|
console.log('client web: execute: prog', prog * 0.5, p, m)
|
|
42
42
|
}
|
package/sclb.mjs
CHANGED
|
@@ -16,7 +16,7 @@ let opt = {
|
|
|
16
16
|
//new
|
|
17
17
|
let wo = new WConverhpClient(opt)
|
|
18
18
|
|
|
19
|
-
wo.on('error',
|
|
19
|
+
wo.on('error', (err) => {
|
|
20
20
|
console.log(`error`, err)
|
|
21
21
|
})
|
|
22
22
|
|
|
@@ -36,7 +36,7 @@ async function execute(name, u8a) {
|
|
|
36
36
|
|
|
37
37
|
//execute
|
|
38
38
|
await wo.execute('add', { p },
|
|
39
|
-
function (prog, p, m) {
|
|
39
|
+
function ({ prog, p, m }) {
|
|
40
40
|
if (m === 'upload') {
|
|
41
41
|
console.log('client web: execute: prog', prog * 0.5, p, m)
|
|
42
42
|
}
|
package/sclc.mjs
CHANGED
|
@@ -16,7 +16,7 @@ let opt = {
|
|
|
16
16
|
//new
|
|
17
17
|
let wo = new WConverhpClient(opt)
|
|
18
18
|
|
|
19
|
-
wo.on('error',
|
|
19
|
+
wo.on('error', (err) => {
|
|
20
20
|
console.log(`error`, err)
|
|
21
21
|
})
|
|
22
22
|
|
|
@@ -29,7 +29,7 @@ function uploadLargeFile() {
|
|
|
29
29
|
console.log('uploadLargeFile u8a', u8a)
|
|
30
30
|
|
|
31
31
|
await wo.upload('1000mb.7z', u8a,
|
|
32
|
-
function (prog, p, m) {
|
|
32
|
+
function ({ prog, p, m }) {
|
|
33
33
|
// console.log('client web: upload: prog', prog, p, m)
|
|
34
34
|
if (m === 'upload') {
|
|
35
35
|
console.log('client web: upload: prog', prog)
|