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.
@@ -62,7 +62,7 @@ import now2strp from 'wsemi/src/now2strp.mjs'
62
62
  *
63
63
  * //execute
64
64
  * await wo.execute('add', { p },
65
- * function (prog, p, m) {
65
+ * function ({ prog, p, m }) {
66
66
  * console.log('client web: execute: prog', prog, p, m)
67
67
  * })
68
68
  * .then(function(r) {
@@ -115,7 +115,7 @@ import now2strp from 'wsemi/src/now2strp.mjs'
115
115
  * console.log('uploadLargeFile u8a', u8a)
116
116
  *
117
117
  * await wo.upload('1000mb.7z', u8a,
118
- * function (prog, p, m) {
118
+ * function ({ prog, p, m }) {
119
119
  * console.log('client web: upload: prog', prog, p, m)
120
120
  * })
121
121
  * .then(function(res) {
@@ -363,7 +363,7 @@ function WConverhpClient(opt) {
363
363
  }
364
364
 
365
365
  //cbProgress
366
- cbProgress(Math.floor(r), loaded, 'upload')
366
+ cbProgress({ prog: Math.floor(r), p: loaded, m: 'upload' })
367
367
 
368
368
  },
369
369
  onDownloadProgress: function (ev) {
@@ -379,7 +379,7 @@ function WConverhpClient(opt) {
379
379
  }
380
380
 
381
381
  //cbProgress
382
- cbProgress(Math.floor(r), loaded, 'download')
382
+ cbProgress({ prog: Math.floor(r), p: loaded, m: 'download' })
383
383
 
384
384
  },
385
385
  }
@@ -542,8 +542,8 @@ function WConverhpClient(opt) {
542
542
  catch (err) {}
543
543
  }
544
544
  if (n === 0) {
545
- eeEmit('error', `Can not get size of bb`)
546
- return Promise.reject(`Can not get size of bb`)
545
+ eeEmit('error', `can not get size of bb`)
546
+ return Promise.reject(`can not get size of bb`)
547
547
  }
548
548
  // console.log('n', n)
549
549
 
@@ -561,20 +561,24 @@ function WConverhpClient(opt) {
561
561
  // let progWeightMerge = 0.01 //合併階段進度使用1%
562
562
 
563
563
  //cbProgressSlice
564
- let cbProgressSlice = (perc, _psiz, dir) => {
564
+ let cbProgressSlice = (msg) => {
565
+ let perc = msg.prog
566
+ let dir = msg.m
565
567
  if (dir === 'upload' && perc === 100) {
566
568
  progCount++
567
569
  let r = progCount / chunkTotal
568
570
  let prog = r * progWeightSlice * 100
569
571
  let psiz = r * n
570
- cbProgress(prog, psiz, 'upload')
572
+ cbProgress({ prog, p: psiz, m: 'upload' })
571
573
  }
572
574
  }
573
575
 
574
576
  //cbProgressMerge
575
- let cbProgressMerge = (perc, _psiz, dir) => {
577
+ let cbProgressMerge = (msg) => {
578
+ let perc = msg.prog
579
+ let dir = msg.m
576
580
  if (dir === 'download' && perc === 100) {
577
- cbProgress(100, n, 'upload')
581
+ cbProgress({ prog: 100, p: n, m: 'upload' })
578
582
  }
579
583
  }
580
584
 
@@ -605,7 +609,7 @@ function WConverhpClient(opt) {
605
609
  }
606
610
 
607
611
  //send merge
608
- console.log(`merging tempId[${tempId}]...`)
612
+ // console.log(`merging tempId[${tempId}]...`)
609
613
  let msg = {
610
614
  'filename': tempId,
611
615
  'chunk-total': chunkTotal,
@@ -1,8 +1,7 @@
1
- import path from 'path'
2
1
  import fs from 'fs'
2
+ import stream from 'stream'
3
3
  import Hapi from '@hapi/hapi'
4
4
  import Inert from '@hapi/inert' //提供靜態檔案
5
- import stream from 'stream'
6
5
  import get from 'lodash-es/get.js'
7
6
  import genPm from 'wsemi/src/genPm.mjs'
8
7
  import iseobj from 'wsemi/src/iseobj.mjs'
@@ -19,8 +18,7 @@ import obj2u8arr from 'wsemi/src/obj2u8arr.mjs'
19
18
  import u8arr2obj from 'wsemi/src/u8arr2obj.mjs'
20
19
  import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
21
20
  import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
22
- import fsIsFile from 'wsemi/src/fsIsFile.mjs'
23
- import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
21
+ import mergeFiles from './mergeFiles.wk.umd.js'
24
22
 
25
23
 
26
24
  /**
@@ -56,7 +54,7 @@ import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
56
54
  * //new
57
55
  * let wo = new WConverhpServer(opt)
58
56
  *
59
- * wo.on('execute', function(func, input, pm) {
57
+ * wo.on('execute', (func, input, pm) => {
60
58
  * // console.log(`Server[port:${opt.port}]: execute`, func, input)
61
59
  * console.log(`Server[port:${opt.port}]: execute`, func)
62
60
  *
@@ -98,7 +96,7 @@ import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
98
96
  * }
99
97
  *
100
98
  * })
101
- * wo.on('upload', function(input, pm) {
99
+ * wo.on('upload', (input, pm) => {
102
100
  * console.log(`Server[port:${opt.port}]: upload`, input)
103
101
  *
104
102
  * try {
@@ -106,12 +104,12 @@ import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
106
104
  * pm.resolve(output)
107
105
  * }
108
106
  * catch (err) {
109
- * console.log('execute error', err)
110
- * pm.reject('execute error')
107
+ * console.log('upload error', err)
108
+ * pm.reject('upload error')
111
109
  * }
112
110
  *
113
111
  * })
114
- * wo.on('handler', function(data) {
112
+ * wo.on('handler', (data) => {
115
113
  * // console.log(`Server[port:${opt.port}]: handler`, data)
116
114
  * })
117
115
  *
@@ -197,6 +195,10 @@ function WConverhpServer(opt = {}) {
197
195
  //host: 'localhost',
198
196
  port,
199
197
  routes: {
198
+ timeout: {
199
+ server: false, //關閉伺服器超時
200
+ socket: false, //關閉socket超時
201
+ },
200
202
  cors: {
201
203
  origin: corsOrigins, //Access-Control-Allow-Origin
202
204
  credentials: false, //Access-Control-Allow-Credentials
@@ -313,8 +315,8 @@ function WConverhpServer(opt = {}) {
313
315
  parse: false,
314
316
  },
315
317
  timeout: {
316
- socket: false, //避免socket自動關閉
317
- server: false,
318
+ server: false, //關閉伺服器超時
319
+ socket: false, //關閉socket超時
318
320
  },
319
321
  },
320
322
  handler: async function (req, res) {
@@ -471,8 +473,8 @@ function WConverhpServer(opt = {}) {
471
473
  parse: false,
472
474
  },
473
475
  timeout: {
474
- socket: false, //避免socket自動關閉
475
- server: false,
476
+ server: false, //關閉伺服器超時
477
+ socket: false, //關閉socket超時
476
478
  },
477
479
  },
478
480
  handler: async function (req, res) {
@@ -617,8 +619,8 @@ function WConverhpServer(opt = {}) {
617
619
  parse: true, //前端送obj過來
618
620
  },
619
621
  timeout: {
620
- socket: false, //避免socket自動關閉
621
- server: false,
622
+ server: false, //關閉伺服器超時
623
+ socket: false, //關閉socket超時
622
624
  },
623
625
  },
624
626
  handler: async function (req, res) {
@@ -692,78 +694,13 @@ function WConverhpServer(opt = {}) {
692
694
  return res.response({ error: 'invalid packageId in payload' }).code(400)
693
695
  }
694
696
 
695
- //merge
696
- let merge = async () => {
697
- let errTemp = ''
698
-
699
- //pathFileMerge
700
- let pathFileMerge = path.join(pathUploadTemp, `${packageId}`)
701
- // console.log('pathFileMerge', pathFileMerge)
702
-
703
- //fileStream
704
- let fileStream = fs.createWriteStream(pathFileMerge)
705
- // console.log(`merge filename[${filename}] start`)
706
-
707
- //使用try catch攔截,使stream能完整創造與結束
708
- try {
709
- for (let i = 0; i < chunkTotal; i++) {
710
- // console.log(`merge ${i + 1}/${chunkTotal}`)
711
-
712
- //chunkIndex
713
- let chunkIndex = i
714
-
715
- //pathFileChunk
716
- let pathFileChunk = path.join(pathUploadTemp, `${packageId}_${chunkIndex}`)
717
-
718
- //check
719
- if (!fsIsFile(pathFileChunk)) {
720
- // console.log(`pathFileChunk[${pathFileChunk}] is not a file`)
721
- throw new Error(`Missing chunk ${i} of filename[${filename}]`)
722
- }
723
-
724
- // console.log(`merging chunk[${chunkIndex + 1}/${chunkTotal}]...`)
725
-
726
- //chunkData
727
- let chunkData = fs.readFileSync(pathFileChunk)
728
-
729
- //write
730
- fileStream.write(chunkData)
731
-
732
- //fsDeleteFile
733
- fsDeleteFile(pathFileChunk)
734
-
735
- // console.log(`merge chunk[${chunkIndex + 1}/${chunkTotal}] done`)
736
- }
737
- }
738
- catch (err) {
739
- errTemp = err.message
740
- }
741
-
742
- //end
743
- fileStream.end()
744
- // console.log(`merge filename[${filename}] done`)
745
-
746
- //check
747
- if (isestr(errTemp)) {
748
- return Promise.reject(errTemp)
749
- }
750
-
751
- //r
752
- let r = {
753
- // message: `Merged filename[${filename}] successfully`,
754
- filename,
755
- path: pathFileMerge,
756
- }
757
-
758
- return r
759
- }
760
-
761
697
  //core
762
698
  let core = async() => {
763
699
 
764
700
  //merge
765
701
  // console.log('merge start')
766
- let r = await merge()
702
+ // let r = await merge()
703
+ let r = await mergeFiles(pathUploadTemp, packageId, chunkTotal, filename)
767
704
  // console.log('merge done', r)
768
705
 
769
706
  //procUpload
@@ -839,7 +776,8 @@ function WConverhpServer(opt = {}) {
839
776
 
840
777
  //start
841
778
  if (get(opt, 'serverHapi')) {
842
- opt.serverHapi.route([apiMain, apiSlice, apiSliceMerge])
779
+ // opt.serverHapi.route([apiMain, apiSlice, apiSliceMerge])
780
+ server.route([apiMain, apiSlice, apiSliceMerge])
843
781
  }
844
782
  else {
845
783
  startServer()
@@ -0,0 +1,73 @@
1
+ import path from 'path' //native lib要用動態import加載
2
+ import fs from 'fs' //native lib要用動態import加載
3
+ import isestr from 'wsemi/src/isestr.mjs'
4
+ import fsIsFile from 'wsemi/src/fsIsFile.mjs'
5
+ import fsDeleteFile from 'wsemi/src/fsDeleteFile.mjs'
6
+
7
+
8
+ let mergeFiles = async (pathUploadTemp, packageId, chunkTotal, filename) => {
9
+ let errTemp = ''
10
+
11
+ //pathFileMerge
12
+ let pathFileMerge = path.join(pathUploadTemp, packageId)
13
+ // console.log('pathFileMerge', pathFileMerge)
14
+
15
+ //fileStream
16
+ let fileStream = fs.createWriteStream(pathFileMerge)
17
+ // console.log(`merge filename[${filename}] start`)
18
+
19
+ //使用try catch攔截,使stream能完整創造與結束
20
+ try {
21
+ for (let i = 0; i < chunkTotal; i++) {
22
+ // console.log(`merge ${i + 1}/${chunkTotal}`)
23
+
24
+ //chunkIndex
25
+ let chunkIndex = i
26
+
27
+ //pathFileChunk
28
+ let pathFileChunk = path.join(pathUploadTemp, `${packageId}_${chunkIndex}`)
29
+
30
+ //check
31
+ if (!fsIsFile(pathFileChunk)) {
32
+ // console.log(`pathFileChunk[${pathFileChunk}] is not a file`)
33
+ throw new Error(`missing chunk ${i} of filename[${filename}]`)
34
+ }
35
+
36
+ // console.log(`merging chunk[${chunkIndex + 1}/${chunkTotal}]...`)
37
+
38
+ //chunkData
39
+ let chunkData = fs.readFileSync(pathFileChunk)
40
+
41
+ //write
42
+ fileStream.write(chunkData)
43
+
44
+ //fsDeleteFile
45
+ fsDeleteFile(pathFileChunk)
46
+
47
+ // console.log(`merge chunk[${chunkIndex + 1}/${chunkTotal}] done`)
48
+ }
49
+ }
50
+ catch (err) {
51
+ errTemp = err.message
52
+ }
53
+
54
+ //end
55
+ fileStream.end()
56
+ // console.log(`merge filename[${filename}] done`)
57
+
58
+ //check
59
+ if (isestr(errTemp)) {
60
+ return Promise.reject(errTemp)
61
+ }
62
+
63
+ //r
64
+ let r = {
65
+ // message: `Merged filename[${filename}] successfully`,
66
+ filename,
67
+ path: pathFileMerge,
68
+ }
69
+
70
+ return r
71
+ }
72
+
73
+ export default mergeFiles
@@ -0,0 +1 @@
1
+ !function(g,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("worker_threads")):"function"==typeof define&&define.amd?define(["worker_threads"],e):(g="undefined"!=typeof globalThis?globalThis:g||self).mergeFiles=e(g.worker_threads)}(this,(function(g){"use strict";"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var e={};!function(e,C){e.exports=function(g){var e={};!function(g){var e=Object.prototype.hasOwnProperty,C="~";function I(){}function t(g,e,C){this.fn=g,this.context=e,this.once=C||!1}function n(g,e,I,n,A){if("function"!=typeof I)throw new TypeError("The listener must be a function");var o=new t(I,n||g,A),c=C?C+e:e;return g._events[c]?g._events[c].fn?g._events[c]=[g._events[c],o]:g._events[c].push(o):(g._events[c]=o,g._eventsCount++),g}function A(g,e){0==--g._eventsCount?g._events=new I:delete g._events[e]}function o(){this._events=new I,this._eventsCount=0}Object.create&&(I.prototype=Object.create(null),(new I).__proto__||(C=!1)),o.prototype.eventNames=function(){var g,I,t=[];if(0===this._eventsCount)return t;for(I in g=this._events)e.call(g,I)&&t.push(C?I.slice(1):I);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(g)):t},o.prototype.listeners=function(g){var e=C?C+g:g,I=this._events[e];if(!I)return[];if(I.fn)return[I.fn];for(var t=0,n=I.length,A=new Array(n);t<n;t++)A[t]=I[t].fn;return A},o.prototype.listenerCount=function(g){var e=C?C+g:g,I=this._events[e];return I?I.fn?1:I.length:0},o.prototype.emit=function(g,e,I,t,n,A){var o=C?C+g:g;if(!this._events[o])return!1;var c,i,r=this._events[o],l=arguments.length;if(r.fn){switch(r.once&&this.removeListener(g,r.fn,void 0,!0),l){case 1:return r.fn.call(r.context),!0;case 2:return r.fn.call(r.context,e),!0;case 3:return r.fn.call(r.context,e,I),!0;case 4:return r.fn.call(r.context,e,I,t),!0;case 5:return r.fn.call(r.context,e,I,t,n),!0;case 6:return r.fn.call(r.context,e,I,t,n,A),!0}for(i=1,c=new Array(l-1);i<l;i++)c[i-1]=arguments[i];r.fn.apply(r.context,c)}else{var s,u=r.length;for(i=0;i<u;i++)switch(r[i].once&&this.removeListener(g,r[i].fn,void 0,!0),l){case 1:r[i].fn.call(r[i].context);break;case 2:r[i].fn.call(r[i].context,e);break;case 3:r[i].fn.call(r[i].context,e,I);break;case 4:r[i].fn.call(r[i].context,e,I,t);break;default:if(!c)for(s=1,c=new Array(l-1);s<l;s++)c[s-1]=arguments[s];r[i].fn.apply(r[i].context,c)}}return!0},o.prototype.on=function(g,e,C){return n(this,g,e,C,!1)},o.prototype.once=function(g,e,C){return n(this,g,e,C,!0)},o.prototype.removeListener=function(g,e,I,t){var n=C?C+g:g;if(!this._events[n])return this;if(!e)return A(this,n),this;var o=this._events[n];if(o.fn)o.fn!==e||t&&!o.once||I&&o.context!==I||A(this,n);else{for(var c=0,i=[],r=o.length;c<r;c++)(o[c].fn!==e||t&&!o[c].once||I&&o[c].context!==I)&&i.push(o[c]);i.length?this._events[n]=1===i.length?i[0]:i:A(this,n)}return this},o.prototype.removeAllListeners=function(g){var e;return g?(e=C?C+g:g,this._events[e]&&A(this,e)):(this._events=new I,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=C,o.EventEmitter=o,g.exports=o}({get exports(){return e},set exports(g){e=g}});var C=e;let I;!function(){if("nodejs"!=("undefined"!=typeof window&&void 0!==window.document?"browser":"nodejs"))return null;let e=(t="CgogICAgICAgIC8vaW1wb3J0IHsgcGFyZW50UG9ydCB9IGZyb20gJ3dvcmtlcl90aHJlYWRzJwogICAgICAgIGxldCB7IHBhcmVudFBvcnQgfSA9IHJlcXVpcmUoJ3dvcmtlcl90aHJlYWRzJykgLy/lm6BwYWNrYWdlLmpzb27kuI3ntaZ0eXBlPW1vZHVsZeaVheeEoeazleaUr+aPtGVzNiBpbXBvcnQsIOW+l+S9v+eUqHJlcXVpcmUKICAgICAgICAvL+iLpeimgeaWvG5vZGVqcyB3b3JrZXLlhafkvb/nlKjnhKHms5Xnt6jora/nmoTljp/nlJ/lpZfku7bkvovlpoJmcywg6YG/5YWN5L2/55So6aCC5bGkaW1wb3J05Yqg6LyJ5L2/55SoLCDlm6DnhKHms5Xnt6jora/mnIPnm7TmjqXkv53nlZkKICAgICAgICAvL+S4puWboGltcG9ydOS9jeaWvHdvcmtlcuWkluWxpOmZkOWumueCunJlcXVpcmXljYAocGFja2FnZS5qc29u5LiN57WmdHlwZT1tb2R1bGUpLCDmlYXlh7rnj77pjK/oqqTnhKHms5Xnt6jora8KICAgICAgICAKCiJ1c2Ugc3RyaWN0Ijt2YXIgZT1yZXF1aXJlKCJwYXRoIiksdD1yZXF1aXJlKCJmcyIpO2Z1bmN0aW9uIHIoZSl7cmV0dXJuISghZnVuY3Rpb24oZSl7cmV0dXJuIltvYmplY3QgU3RyaW5nXSI9PT1PYmplY3QucHJvdG90eXBlLnRvU3RyaW5nLmNhbGwoZSl9KGUpfHwiIj09PWUpfWZ1bmN0aW9uIG4oZSl7cmV0dXJuISF0LmV4aXN0c1N5bmMoZSkmJighdC5sc3RhdFN5bmMoZSkuaXNEaXJlY3RvcnkoKSYmIXQubHN0YXRTeW5jKGUpLmlzU3ltYm9saWNMaW5rKCkpfWZ1bmN0aW9uIGkoZSl7aWYoIXQuZXhpc3RzU3luYyhlKSlyZXR1cm57c3VjY2VzczoiZmlsZSBkb2VzIG5vdCBleGlzdDogIitlfTtpZighbihlKSlyZXR1cm57ZXJyb3I6ImlucHV0IHBhdGggaXMgbm90IGEgZmlsZTogIitlfTt0cnl7dC51bmxpbmtTeW5jKGUpfWNhdGNoKGUpe3JldHVybntlcnJvcjplfX1yZXR1cm57c3VjY2VzczoiZG9uZTogIitlfX1sZXQgbWVyZ2VGaWxlcz1hc3luYyhjLHMsbyx1KT0+e2xldCBhPSIiLGw9ZS5qb2luKGMscyksZj10LmNyZWF0ZVdyaXRlU3RyZWFtKGwpO3RyeXtmb3IobGV0IHI9MDtyPG87cisrKXtsZXQgbz1yLGE9ZS5qb2luKGMsYCR7c31fJHtvfWApO2lmKCFuKGEpKXRocm93IG5ldyBFcnJvcihgbWlzc2luZyBjaHVuayAke3J9IG9mIGZpbGVuYW1lWyR7dX1dYCk7bGV0IGw9dC5yZWFkRmlsZVN5bmMoYSk7Zi53cml0ZShsKSxpKGEpfX1jYXRjaChlKXthPWUubWVzc2FnZX1yZXR1cm4gZi5lbmQoKSxyKGEpP1Byb21pc2UucmVqZWN0KGEpOntmaWxlbmFtZTp1LHBhdGg6bH19OwoKCmxldCBpbnN0YW5jZSA9IG51bGwKZnVuY3Rpb24gaW5pdChpbnB1dCl7CgogICAgLy9pbml0CiAgICBsZXQgcgogICAgCiAgICAgICAgciA9IHsKICAgICAgICAgICAgbWFpbjogbWVyZ2VGaWxlcwogICAgICAgIH0KICAgICAgICAKCiAgICAvL29uCiAgICAKCiAgICAvL3NhdmUKICAgIGluc3RhbmNlID0gcgoKfQoKZnVuY3Rpb24gc2VuZE1lc3NhZ2UoZGF0YSkgewogICAgCiAgICAgICAgcGFyZW50UG9ydC5wb3N0TWVzc2FnZShkYXRhKQogICAgICAgIAp9Cgphc3luYyBmdW5jdGlvbiBydW4oZGF0YSkgewogICAgLy8gY29uc29sZS5sb2coJ2lubmVyIHdvcmtlciBydW4nLGRhdGEpCgogICAgLy9tb2RlCiAgICBsZXQgbW9kZSA9IGRhdGEubW9kZQoKICAgIC8vY2hlY2sKICAgIGlmKG1vZGUgIT09ICdpbml0JyAmJiBtb2RlICE9PSAnY2FsbCcpewogICAgICAgIHJldHVybgogICAgfQoKICAgIC8vaW5pdAogICAgaWYobW9kZSA9PT0gJ2luaXQnKXsKICAgICAgICAKICAgICAgICB0cnl7CgogICAgICAgICAgICAvL3R5cGUKICAgICAgICAgICAgbGV0IHR5cGUgPSBkYXRhLnR5cGUKCiAgICAgICAgICAgIC8vaW5wdXQKICAgICAgICAgICAgbGV0IGlucHV0ID0gZGF0YS5pbnB1dAogICAgCiAgICAgICAgICAgIC8vaW5zdGFuY2UKICAgICAgICAgICAgaWYodHlwZSA9PT0gJ2Z1bmN0aW9uJyl7CiAgICAgICAgICAgICAgICBpbml0KC4uLmlucHV0KQogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYodHlwZSA9PT0gJ29iamVjdCcpewogICAgICAgICAgICAgICAgaW5zdGFuY2UgPSBtZXJnZUZpbGVzCiAgICAgICAgICAgIH0KCiAgICAgICAgfQogICAgICAgIGNhdGNoKGVycil7CiAgICAgICAgCiAgICAgICAgICAgIC8vc2VuZE1lc3NhZ2UKICAgICAgICAgICAgbGV0IHJlcyA9IHsKICAgICAgICAgICAgICAgIG1vZGU6ICdlbWl0JywKICAgICAgICAgICAgICAgIGV2TmFtZTogJ2Vycm9yJywKICAgICAgICAgICAgICAgIG1zZzogZXJyLAogICAgICAgICAgICB9CiAgICAgICAgICAgIHNlbmRNZXNzYWdlKHJlcykKCiAgICAgICAgfQogICAgICAgICAgICAKICAgIH0KCiAgICAvL2NoZWNrCiAgICBpZihtb2RlID09PSAnY2FsbCcpewogICAgICAgIGxldCBzdGF0ZSA9ICcnCiAgICAgICAgbGV0IG1zZyA9IG51bGwKCiAgICAgICAgdHJ5ewoKICAgICAgICAgICAgLy9mdW4KICAgICAgICAgICAgbGV0IGZ1biA9IGluc3RhbmNlW2RhdGEuZnVuXQoKICAgICAgICAgICAgLy9pbnB1dAogICAgICAgICAgICBsZXQgaW5wdXQgPSBkYXRhLmlucHV0CgogICAgICAgICAgICAvL2V4ZWMKICAgICAgICAgICAgYXdhaXQgZnVuKC4uLmlucHV0KQogICAgICAgICAgICAgICAgLnRoZW4oKHN1YykgPT4gewogICAgICAgICAgICAgICAgICAgIHN0YXRlPSdzdWNjZXNzJwogICAgICAgICAgICAgICAgICAgIG1zZz1zdWMKICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgICAuY2F0Y2goKGVycikgPT4gewogICAgICAgICAgICAgICAgICAgIHN0YXRlPSdlcnJvcicKICAgICAgICAgICAgICAgICAgICBtc2c9ZXJyCiAgICAgICAgICAgICAgICB9KQoKICAgICAgICB9CiAgICAgICAgY2F0Y2goZXJyKXsKICAgICAgICAgICAgc3RhdGUgPSAnZXJyb3InCiAgICAgICAgICAgIG1zZyA9IGVycgogICAgICAgIH0KICAgICAgICAKICAgICAgICAvL3NlbmRNZXNzYWdlCiAgICAgICAgbGV0IHJlcyA9IHsKICAgICAgICAgICAgbW9kZTogJ3JldHVybicsCiAgICAgICAgICAgIGlkOiBkYXRhLmlkLAogICAgICAgICAgICBmdW46IGRhdGEuZnVuLAogICAgICAgICAgICBzdGF0ZSwKICAgICAgICAgICAgbXNnLAogICAgICAgIH0KICAgICAgICBzZW5kTWVzc2FnZShyZXMpCgogICAgfQoKfQoKZnVuY3Rpb24gcmVjdk1lc3NhZ2UoZGF0YSkgewogICAgLy8gY29uc29sZS5sb2coJ2lubmVyIHdvcmtlciByZWN2OicsIGRhdGEpCgogICAgLy9kYXRhUmVjdgogICAgbGV0IGRhdGFSZWN2ID0gZGF0YQoKICAgIC8vcnVuCiAgICBydW4oZGF0YVJlY3YpCgp9CgoKICAgICAgICBwYXJlbnRQb3J0Lm9uKCdtZXNzYWdlJywgcmVjdk1lc3NhZ2UpCiAgICAgICAgCgp0cnl7CiAgICBwcm9jZXNzLm9uKCd1bmhhbmRsZWRSZWplY3Rpb24nLCAoZXJyKSA9PiB7CiAgICAgICAgY29uc29sZS5sb2coJ2lubmVyOnVuaGFuZGxlZFJlamVjdGlvbicsIGVycikKICAgIH0pCiAgICBwcm9jZXNzLm9uKCd1bmNhdWdodEV4Y2VwdGlvbicsIChlcnIpID0+IHsKICAgICAgICBjb25zb2xlLmxvZygnaW5uZXI6dW5jYXVnaHRFeGNlcHRpb24nLCBlcnIpCiAgICB9KQogICAgcHJvY2Vzcy5vbigndW5jYXVnaHRFeGNlcHRpb25Nb25pdG9yJywgKGVycikgPT4gewogICAgICAgIGNvbnNvbGUubG9nKCdpbm5lcjp1bmNhdWdodEV4Y2VwdGlvbk1vbml0b3InLCBlcnIpCiAgICB9KQp9CmNhdGNoKGVycil7fQoK",Buffer.from(t,"base64").toString("utf8"));var t;function n(){let I=new C,t=function(e){try{return new g.Worker(e,{eval:!0})}catch(g){A(g)}}(e);if(!t)return A("invalid worker"),null;function n(){let g=function(){let g,e,C=new Promise((function(){g=arguments[0],e=arguments[1]}));return C.resolve=g,C.reject=e,C}(),e=function(){let g=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,e=[],C="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),I=C.length;for(let t=0;t<g;t++)e[t]=C[0|Math.random()*I];return e.join("")}(),C={mode:"call",id:e,fun:"main",input:[...arguments]};return t.postMessage(C),I.once(e,(e=>{"success"===e.state?g.resolve(e.msg):g.reject(e.msg)})),g}function A(g){I.emit("error",g)}return t.on("message",(function(g){let e=g,C=e.mode;"emit"!==C&&"return"!==C||("emit"===C&&I.emit(e.evName,e.msg),"return"===C&&I.emit(e.id,e))})),t.on("error",A),t.on("exit",(g=>{1!==g&&A("exit code["+g+"] !== 1")})),function(){let g={mode:"init",type:"function",input:[...arguments]};t.postMessage(g)}([...arguments]),I.main=n,I.main=n,I.terminate=function(){t?(t.terminate(),t=void 0):A("worker has been terminated")},I}I=async function(){let g=[...arguments],e=n();return await e.main(...g).finally((()=>{e.terminate()}))}}();try{process.on("unhandledRejection",(g=>{console.log("outer:unhandledRejection",g)})),process.on("uncaughtException",(g=>{console.log("outer:uncaughtException",g)})),process.on("uncaughtExceptionMonitor",(g=>{console.log("outer:uncaughtExceptionMonitor",g)}))}catch(g){}return I}(g)}({get exports(){return e},set exports(g){e=g}});var C=e,I={};!function(g,e){g.exports=function(){const g="function"==typeof Buffer,e="function"==typeof TextDecoder?new TextDecoder:void 0,C=(g=>{let e={};return g.forEach(((g,C)=>e[g]=C)),e})(("function"==typeof TextEncoder&&new TextEncoder,Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="))),I=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,t=String.fromCharCode.bind(String),n="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):g=>new Uint8Array(Array.prototype.slice.call(g,0)),A=g=>g.replace(/[^A-Za-z0-9\+\/]/g,""),o=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,c=g=>{switch(g.length){case 4:var e=((7&g.charCodeAt(0))<<18|(63&g.charCodeAt(1))<<12|(63&g.charCodeAt(2))<<6|63&g.charCodeAt(3))-65536;return t(55296+(e>>>10))+t(56320+(1023&e));case 3:return t((15&g.charCodeAt(0))<<12|(63&g.charCodeAt(1))<<6|63&g.charCodeAt(2));default:return t((31&g.charCodeAt(0))<<6|63&g.charCodeAt(1))}},i=g=>g.replace(o,c),r=g=>{if(g=g.replace(/\s+/g,""),!I.test(g))throw new TypeError("malformed base64.");g+="==".slice(2-(3&g.length));let e,n,A,o="";for(let I=0;I<g.length;)e=C[g.charAt(I++)]<<18|C[g.charAt(I++)]<<12|(n=C[g.charAt(I++)])<<6|(A=C[g.charAt(I++)]),o+=64===n?t(e>>16&255):64===A?t(e>>16&255,e>>8&255):t(e>>16&255,e>>8&255,255&e);return o},l="function"==typeof atob?g=>atob(A(g)):g?g=>Buffer.from(g,"base64").toString("binary"):r,s=g?g=>n(Buffer.from(g,"base64")):g=>n(l(g).split("").map((g=>g.charCodeAt(0)))),u=g?g=>Buffer.from(g,"base64").toString("utf8"):e?g=>e.decode(s(g)):g=>i(l(g)),a=g=>A(g.replace(/[-_]/g,(g=>"-"==g?"+":"/"))),d=g=>u(a(g)),p=d;var b={};!function(g){var e=Object.prototype.hasOwnProperty,C="~";function I(){}function t(g,e,C){this.fn=g,this.context=e,this.once=C||!1}function n(g,e,I,n,A){if("function"!=typeof I)throw new TypeError("The listener must be a function");var o=new t(I,n||g,A),c=C?C+e:e;return g._events[c]?g._events[c].fn?g._events[c]=[g._events[c],o]:g._events[c].push(o):(g._events[c]=o,g._eventsCount++),g}function A(g,e){0==--g._eventsCount?g._events=new I:delete g._events[e]}function o(){this._events=new I,this._eventsCount=0}Object.create&&(I.prototype=Object.create(null),(new I).__proto__||(C=!1)),o.prototype.eventNames=function(){var g,I,t=[];if(0===this._eventsCount)return t;for(I in g=this._events)e.call(g,I)&&t.push(C?I.slice(1):I);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(g)):t},o.prototype.listeners=function(g){var e=C?C+g:g,I=this._events[e];if(!I)return[];if(I.fn)return[I.fn];for(var t=0,n=I.length,A=new Array(n);t<n;t++)A[t]=I[t].fn;return A},o.prototype.listenerCount=function(g){var e=C?C+g:g,I=this._events[e];return I?I.fn?1:I.length:0},o.prototype.emit=function(g,e,I,t,n,A){var o=C?C+g:g;if(!this._events[o])return!1;var c,i,r=this._events[o],l=arguments.length;if(r.fn){switch(r.once&&this.removeListener(g,r.fn,void 0,!0),l){case 1:return r.fn.call(r.context),!0;case 2:return r.fn.call(r.context,e),!0;case 3:return r.fn.call(r.context,e,I),!0;case 4:return r.fn.call(r.context,e,I,t),!0;case 5:return r.fn.call(r.context,e,I,t,n),!0;case 6:return r.fn.call(r.context,e,I,t,n,A),!0}for(i=1,c=new Array(l-1);i<l;i++)c[i-1]=arguments[i];r.fn.apply(r.context,c)}else{var s,u=r.length;for(i=0;i<u;i++)switch(r[i].once&&this.removeListener(g,r[i].fn,void 0,!0),l){case 1:r[i].fn.call(r[i].context);break;case 2:r[i].fn.call(r[i].context,e);break;case 3:r[i].fn.call(r[i].context,e,I);break;case 4:r[i].fn.call(r[i].context,e,I,t);break;default:if(!c)for(s=1,c=new Array(l-1);s<l;s++)c[s-1]=arguments[s];r[i].fn.apply(r[i].context,c)}}return!0},o.prototype.on=function(g,e,C){return n(this,g,e,C,!1)},o.prototype.once=function(g,e,C){return n(this,g,e,C,!0)},o.prototype.removeListener=function(g,e,I,t){var n=C?C+g:g;if(!this._events[n])return this;if(!e)return A(this,n),this;var o=this._events[n];if(o.fn)o.fn!==e||t&&!o.once||I&&o.context!==I||A(this,n);else{for(var c=0,i=[],r=o.length;c<r;c++)(o[c].fn!==e||t&&!o[c].once||I&&o[c].context!==I)&&i.push(o[c]);i.length?this._events[n]=1===i.length?i[0]:i:A(this,n)}return this},o.prototype.removeAllListeners=function(g){var e;return g?(e=C?C+g:g,this._events[e]&&A(this,e)):(this._events=new I,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=C,o.EventEmitter=o,g.exports=o}({get exports(){return b},set exports(g){b=g}});var m=b;let f;!function(){if("browser"!=("undefined"!=typeof window&&void 0!==window.document?"browser":"nodejs"))return null;let g=p("CgoKInVzZSBzdHJpY3QiO3ZhciBlPXJlcXVpcmUoInBhdGgiKSx0PXJlcXVpcmUoImZzIik7ZnVuY3Rpb24gcihlKXtyZXR1cm4hKCFmdW5jdGlvbihlKXtyZXR1cm4iW29iamVjdCBTdHJpbmddIj09PU9iamVjdC5wcm90b3R5cGUudG9TdHJpbmcuY2FsbChlKX0oZSl8fCIiPT09ZSl9ZnVuY3Rpb24gbihlKXtyZXR1cm4hIXQuZXhpc3RzU3luYyhlKSYmKCF0LmxzdGF0U3luYyhlKS5pc0RpcmVjdG9yeSgpJiYhdC5sc3RhdFN5bmMoZSkuaXNTeW1ib2xpY0xpbmsoKSl9ZnVuY3Rpb24gaShlKXtpZighdC5leGlzdHNTeW5jKGUpKXJldHVybntzdWNjZXNzOiJmaWxlIGRvZXMgbm90IGV4aXN0OiAiK2V9O2lmKCFuKGUpKXJldHVybntlcnJvcjoiaW5wdXQgcGF0aCBpcyBub3QgYSBmaWxlOiAiK2V9O3RyeXt0LnVubGlua1N5bmMoZSl9Y2F0Y2goZSl7cmV0dXJue2Vycm9yOmV9fXJldHVybntzdWNjZXNzOiJkb25lOiAiK2V9fWxldCBtZXJnZUZpbGVzPWFzeW5jKGMscyxvLHUpPT57bGV0IGE9IiIsbD1lLmpvaW4oYyxzKSxmPXQuY3JlYXRlV3JpdGVTdHJlYW0obCk7dHJ5e2ZvcihsZXQgcj0wO3I8bztyKyspe2xldCBvPXIsYT1lLmpvaW4oYyxgJHtzfV8ke299YCk7aWYoIW4oYSkpdGhyb3cgbmV3IEVycm9yKGBtaXNzaW5nIGNodW5rICR7cn0gb2YgZmlsZW5hbWVbJHt1fV1gKTtsZXQgbD10LnJlYWRGaWxlU3luYyhhKTtmLndyaXRlKGwpLGkoYSl9fWNhdGNoKGUpe2E9ZS5tZXNzYWdlfXJldHVybiBmLmVuZCgpLHIoYSk/UHJvbWlzZS5yZWplY3QoYSk6e2ZpbGVuYW1lOnUscGF0aDpsfX07CgoKbGV0IGluc3RhbmNlID0gbnVsbApmdW5jdGlvbiBpbml0KGlucHV0KXsKCiAgICAvL2luaXQKICAgIGxldCByCiAgICAKICAgICAgICByID0gewogICAgICAgICAgICBtYWluOiBtZXJnZUZpbGVzCiAgICAgICAgfQogICAgICAgIAoKICAgIC8vb24KICAgIAoKICAgIC8vc2F2ZQogICAgaW5zdGFuY2UgPSByCgp9CgpmdW5jdGlvbiBzZW5kTWVzc2FnZShkYXRhKSB7CiAgICAKICAgICAgICBzZWxmLnBvc3RNZXNzYWdlKGRhdGEpCiAgICAgICAgCn0KCmFzeW5jIGZ1bmN0aW9uIHJ1bihkYXRhKSB7CiAgICAvLyBjb25zb2xlLmxvZygnaW5uZXIgd29ya2VyIHJ1bicsZGF0YSkKCiAgICAvL21vZGUKICAgIGxldCBtb2RlID0gZGF0YS5tb2RlCgogICAgLy9jaGVjawogICAgaWYobW9kZSAhPT0gJ2luaXQnICYmIG1vZGUgIT09ICdjYWxsJyl7CiAgICAgICAgcmV0dXJuCiAgICB9CgogICAgLy9pbml0CiAgICBpZihtb2RlID09PSAnaW5pdCcpewogICAgICAgIAogICAgICAgIHRyeXsKCiAgICAgICAgICAgIC8vdHlwZQogICAgICAgICAgICBsZXQgdHlwZSA9IGRhdGEudHlwZQoKICAgICAgICAgICAgLy9pbnB1dAogICAgICAgICAgICBsZXQgaW5wdXQgPSBkYXRhLmlucHV0CiAgICAKICAgICAgICAgICAgLy9pbnN0YW5jZQogICAgICAgICAgICBpZih0eXBlID09PSAnZnVuY3Rpb24nKXsKICAgICAgICAgICAgICAgIGluaXQoLi4uaW5wdXQpCiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZih0eXBlID09PSAnb2JqZWN0Jyl7CiAgICAgICAgICAgICAgICBpbnN0YW5jZSA9IG1lcmdlRmlsZXMKICAgICAgICAgICAgfQoKICAgICAgICB9CiAgICAgICAgY2F0Y2goZXJyKXsKICAgICAgICAKICAgICAgICAgICAgLy9zZW5kTWVzc2FnZQogICAgICAgICAgICBsZXQgcmVzID0gewogICAgICAgICAgICAgICAgbW9kZTogJ2VtaXQnLAogICAgICAgICAgICAgICAgZXZOYW1lOiAnZXJyb3InLAogICAgICAgICAgICAgICAgbXNnOiBlcnIsCiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2VuZE1lc3NhZ2UocmVzKQoKICAgICAgICB9CiAgICAgICAgICAgIAogICAgfQoKICAgIC8vY2hlY2sKICAgIGlmKG1vZGUgPT09ICdjYWxsJyl7CiAgICAgICAgbGV0IHN0YXRlID0gJycKICAgICAgICBsZXQgbXNnID0gbnVsbAoKICAgICAgICB0cnl7CgogICAgICAgICAgICAvL2Z1bgogICAgICAgICAgICBsZXQgZnVuID0gaW5zdGFuY2VbZGF0YS5mdW5dCgogICAgICAgICAgICAvL2lucHV0CiAgICAgICAgICAgIGxldCBpbnB1dCA9IGRhdGEuaW5wdXQKCiAgICAgICAgICAgIC8vZXhlYwogICAgICAgICAgICBhd2FpdCBmdW4oLi4uaW5wdXQpCiAgICAgICAgICAgICAgICAudGhlbigoc3VjKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGU9J3N1Y2Nlc3MnCiAgICAgICAgICAgICAgICAgICAgbXNnPXN1YwogICAgICAgICAgICAgICAgfSkKICAgICAgICAgICAgICAgIC5jYXRjaCgoZXJyKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGU9J2Vycm9yJwogICAgICAgICAgICAgICAgICAgIG1zZz1lcnIKICAgICAgICAgICAgICAgIH0pCgogICAgICAgIH0KICAgICAgICBjYXRjaChlcnIpewogICAgICAgICAgICBzdGF0ZSA9ICdlcnJvcicKICAgICAgICAgICAgbXNnID0gZXJyCiAgICAgICAgfQogICAgICAgIAogICAgICAgIC8vc2VuZE1lc3NhZ2UKICAgICAgICBsZXQgcmVzID0gewogICAgICAgICAgICBtb2RlOiAncmV0dXJuJywKICAgICAgICAgICAgaWQ6IGRhdGEuaWQsCiAgICAgICAgICAgIGZ1bjogZGF0YS5mdW4sCiAgICAgICAgICAgIHN0YXRlLAogICAgICAgICAgICBtc2csCiAgICAgICAgfQogICAgICAgIHNlbmRNZXNzYWdlKHJlcykKCiAgICB9Cgp9CgpmdW5jdGlvbiByZWN2TWVzc2FnZShkYXRhKSB7CiAgICAvLyBjb25zb2xlLmxvZygnaW5uZXIgd29ya2VyIHJlY3Y6JywgZGF0YSkKCiAgICAvL2RhdGFSZWN2CiAgICBsZXQgZGF0YVJlY3YgPSBkYXRhCgogICAgLy9ydW4KICAgIHJ1bihkYXRhUmVjdikKCn0KCgogICAgICAgIHNlbGYub25tZXNzYWdlID0gZnVuY3Rpb24gKGUpIHsKICAgICAgICAgICAgcmVjdk1lc3NhZ2UoZS5kYXRhKQogICAgICAgIH0KICAgICAgICAKCnRyeXsKICAgIHByb2Nlc3Mub24oJ3VuaGFuZGxlZFJlamVjdGlvbicsIChlcnIpID0+IHsKICAgICAgICBjb25zb2xlLmxvZygnaW5uZXI6dW5oYW5kbGVkUmVqZWN0aW9uJywgZXJyKQogICAgfSkKICAgIHByb2Nlc3Mub24oJ3VuY2F1Z2h0RXhjZXB0aW9uJywgKGVycikgPT4gewogICAgICAgIGNvbnNvbGUubG9nKCdpbm5lcjp1bmNhdWdodEV4Y2VwdGlvbicsIGVycikKICAgIH0pCiAgICBwcm9jZXNzLm9uKCd1bmNhdWdodEV4Y2VwdGlvbk1vbml0b3InLCAoZXJyKSA9PiB7CiAgICAgICAgY29uc29sZS5sb2coJ2lubmVyOnVuY2F1Z2h0RXhjZXB0aW9uTW9uaXRvcicsIGVycikKICAgIH0pCn0KY2F0Y2goZXJyKXt9Cgo=");function e(){let e=new m,C=function(g){try{let e=new Blob([g]),C=window.URL||window.webkitURL;return new Worker(C.createObjectURL(e))}catch(g){t(g)}}(g);if(!C)return t("invalid worker"),null;function I(){let g=function(){let g,e,C=new Promise((function(){g=arguments[0],e=arguments[1]}));return C.resolve=g,C.reject=e,C}(),I=function(){let g=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,e=[],C="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),I=C.length;for(let t=0;t<g;t++)e[t]=C[0|Math.random()*I];return e.join("")}(),t={mode:"call",id:I,fun:"main",input:[...arguments]};return C.postMessage(t),e.once(I,(e=>{"success"===e.state?g.resolve(e.msg):g.reject(e.msg)})),g}function t(g){e.emit("error",g)}return C.onmessage=function(g){!function(g){let C=g,I=C.mode;"emit"!==I&&"return"!==I||("emit"===I&&e.emit(C.evName,C.msg),"return"===I&&e.emit(C.id,C))}(g.data)},C.onerror=t,C.onmessageerror=function(g){t(g.data)},function(){let g={mode:"init",type:"function",input:[...arguments]};C.postMessage(g)}([...arguments]),e.main=I,e.main=I,e.terminate=function(){C?(C.terminate(),C=void 0):t("worker has been terminated")},e}f=async function(){let g=[...arguments],C=e();return await C.main(...g).finally((()=>{C.terminate()}))}}();try{process.on("unhandledRejection",(g=>{console.log("outer:unhandledRejection",g)})),process.on("uncaughtException",(g=>{console.log("outer:uncaughtException",g)})),process.on("uncaughtExceptionMonitor",(g=>{console.log("outer:uncaughtExceptionMonitor",g)}))}catch(g){}return f}()}({get exports(){return I},set exports(g){I=g}});var t=I;let n;return n="undefined"!=typeof window&&void 0!==window.document?t:C,n}));
package/srv.mjs CHANGED
@@ -1,13 +1,19 @@
1
1
  import fs from 'fs'
2
2
  import _ from 'lodash-es'
3
+ import w from 'wsemi'
3
4
  import WConverhpServer from './src/WConverhpServer.mjs'
4
5
 
5
6
  let opt = {
6
7
  port: 8080,
7
8
  apiName: 'api',
8
9
  pathStaticFiles: '.', //要存取專案資料夾下web.html, 故不能給dist
9
- funCheck: ({ apiType, authorization, headers, query }) => {
10
+ funCheck: async ({ apiType, authorization, headers, query }) => {
10
11
  console.log('funCheck', `apiType[${apiType}]`, `authorization[${authorization}]`)
12
+ let token = w.strdelleft(authorization, 7) //刪除Bearer
13
+ if (!w.isestr(token)) {
14
+ return false
15
+ }
16
+ // await w.delay(3000)
11
17
  return true
12
18
  },
13
19
  }
@@ -15,7 +21,7 @@ let opt = {
15
21
  //new
16
22
  let wo = new WConverhpServer(opt)
17
23
 
18
- wo.on('execute', function(func, input, pm) {
24
+ wo.on('execute', (func, input, pm) => {
19
25
  // console.log(`Server[port:${opt.port}]: execute`, func, input)
20
26
  console.log(`Server[port:${opt.port}]: execute`, func)
21
27
 
@@ -57,7 +63,7 @@ wo.on('execute', function(func, input, pm) {
57
63
  }
58
64
 
59
65
  })
60
- wo.on('upload', function(input, pm) {
66
+ wo.on('upload', (input, pm) => {
61
67
  console.log(`Server[port:${opt.port}]: upload`, input)
62
68
 
63
69
  try {
@@ -65,15 +71,15 @@ wo.on('upload', function(input, pm) {
65
71
  pm.resolve(output)
66
72
  }
67
73
  catch (err) {
68
- console.log('execute error', err)
69
- pm.reject('execute error')
74
+ console.log('upload error', err)
75
+ pm.reject('upload error')
70
76
  }
71
77
 
72
78
  })
73
- wo.on('error', function(err) {
79
+ wo.on('error', (err) => {
74
80
  console.log(`Server[port:${opt.port}]: error`, err)
75
81
  })
76
- wo.on('handler', function(data) {
82
+ wo.on('handler', (data) => {
77
83
  // console.log(`Server[port:${opt.port}]: handler`, data)
78
84
  })
79
85
 
@@ -1,54 +1,63 @@
1
+ import path from 'path'
1
2
  import rollupFiles from 'w-package-tools/src/rollupFiles.mjs'
2
- import getFiles from 'w-package-tools/src/getFiles.mjs'
3
- import w from 'wsemi'
3
+ import rollupWorker from 'w-package-tools/src/rollupWorker.mjs'
4
4
 
5
5
 
6
6
  let fdSrc = './src'
7
7
  let fdTar = './dist'
8
- let fns = getFiles(fdSrc)
9
- fns = fns.filter((v) => {
10
- return w.strleft(v, 1) === 'W'
11
- })
12
8
 
13
- rollupFiles({
14
- fns,
15
- fdSrc,
16
- fdTar,
17
- nameDistType: 'kebabCase',
18
- globals: {
19
- '@hapi/hapi': '@hapi/hapi',
20
- '@hapi/inert': '@hapi/inert',
21
- 'events': 'events',
22
- 'stream': 'stream',
23
- // 'form-data': 'FormData',
24
- 'crypto': 'crypto', //因crypto-js修改使用內建crypto方式, 會偵測nodejs並使用require內建的crypto, 故需剔除
25
- // 'combined-stream': 'combined-stream',
26
- // 'util': 'util',
27
- // 'fs': 'fs',
28
- // 'path': 'path',
29
- // 'http': 'http',
30
- // 'https': 'https',
31
- // 'url': 'url',
32
- // 'mime-types': 'mime-types',
33
- // 'asynckit': 'asynckit',
34
- },
35
- external: [
36
- '@hapi/hapi',
37
- '@hapi/inert',
38
- 'events',
39
- 'stream',
40
- // 'form-data',
41
- 'crypto',
42
- // 'combined-stream',
43
- // 'util',
44
- // 'path',
45
- // 'http',
46
- // 'https',
47
- // 'url',
48
- // 'fs',
49
- // 'stream',
50
- // 'mime-types',
51
- // 'asynckit',
52
- ],
53
- })
54
9
 
10
+ async function core() {
11
+
12
+ //因為WConverhpServer會import mergeFiles.wk.umd.js故得先編譯
13
+ await rollupWorker({
14
+ name: 'mergeFiles', //原模組名稱, 將來會掛於winodw下或於node引入使用
15
+ type: 'function', //原模組輸出為函數, 可傳入參數初始化
16
+ // execFunctionByInstance: true, //default, 原模組為計算函數回傳結果
17
+ fpSrc: path.resolve(fdSrc, 'mergeFiles.mjs'), //原始檔案路徑
18
+ fpTar: path.resolve(fdSrc, 'mergeFiles.wk.umd.js'), //檔案輸出路徑
19
+ formatOut: 'umd',
20
+ // bMinify: false,
21
+ globals: {
22
+ 'path': 'path',
23
+ 'fs': 'fs',
24
+ },
25
+ external: [
26
+ 'path',
27
+ 'fs',
28
+ ],
29
+ })
30
+ .catch((err) => {
31
+ console.log(err)
32
+ })
33
+
34
+ await rollupFiles({
35
+ fns: ['WConverhpServer.mjs', 'WConverhpClient.mjs'],
36
+ fdSrc,
37
+ fdTar,
38
+ nameDistType: 'kebabCase',
39
+ globals: {
40
+ 'path': 'path',
41
+ 'fs': 'fs',
42
+ 'stream': 'stream',
43
+ 'crypto': 'crypto', //因crypto-js修改使用內建crypto方式, 會偵測nodejs並使用require內建的crypto, 故需剔除
44
+ '@hapi/hapi': '@hapi/hapi',
45
+ '@hapi/inert': '@hapi/inert',
46
+ // 'form-data': 'FormData',
47
+ },
48
+ external: [
49
+ 'path',
50
+ 'fs',
51
+ 'stream',
52
+ 'crypto',
53
+ '@hapi/hapi',
54
+ '@hapi/inert',
55
+ // 'form-data',
56
+ ],
57
+ })
58
+
59
+ }
60
+ core()
61
+ .catch((err) => {
62
+ console.log(err)
63
+ })
package/web.html CHANGED
@@ -50,7 +50,7 @@
50
50
 
51
51
  //execute
52
52
  await wo.execute('add', { p },
53
- function (prog, p, m) {
53
+ function ({ prog, p, m }) {
54
54
  console.log('client web: execute: prog', prog, p, m)
55
55
  })
56
56
  .then(function(r) {
@@ -132,7 +132,7 @@
132
132
 
133
133
  //upload
134
134
  await wo.upload(file.name, file,
135
- function (prog, p, m) {
135
+ function ({ prog, p, m }) {
136
136
  console.log('client web: upload: prog', prog, p, m)
137
137
  })
138
138
  .then(function(res) {