pubo-node 1.0.110 → 1.0.112
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/dist/pubo-node.js +1 -1
- package/es/child-process/index.d.ts +3 -1
- package/es/child-process/index.js +193 -3
- package/es/grpc/index.js +13 -26
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/es/utils/network.d.ts +2 -0
- package/es/utils/network.js +166 -0
- package/lib/child-process/index.d.ts +3 -1
- package/lib/child-process/index.js +197 -4
- package/lib/grpc/index.js +13 -26
- package/lib/index.d.ts +1 -0
- package/lib/index.js +14 -1
- package/lib/utils/network.d.ts +2 -0
- package/lib/utils/network.js +174 -0
- package/package.json +2 -2
package/dist/pubo-node.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["pubo-node"]=e():t["pubo-node"]=e()}(this,(()=>(()=>{var t={163:t=>{function e(t){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}e.keys=()=>[],e.resolve=e,e.id=163,t.exports=e},278:t=>{"use strict";t.exports=require("net")}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{FtpClient:()=>f,FtpClientPool:()=>h,JsonStorage:()=>o,PuboFileSystem:()=>m,SIGKILL:()=>S,createRpcClient:()=>y,isPortAvailable:()=>O,pitch:()=>_});const t=require("fs"),e=require("pubo-utils");var o=function(){function n(t){this._state={},this.queue=new e.SyncQueue,this.path=t,this.restore()}return Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n.prototype.sync=function(){this.queue.length>0||this.queue.push(this._sync.bind(this))},n.prototype._sync=function(){return e=this,n=void 0,o=function(){var e=this;return function(t,e){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return c.label++,{value:s[1],done:!1};case 5:c.label++,r=s[1],s=[0];continue;case 7:s=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){c=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){c.label=s[1];break}if(6===s[0]&&c.label<o[1]){c.label=o[1],o=s;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(s);break}o[2]&&c.ops.pop(),c.trys.pop();continue}s=e.call(t,c)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}(this,(function(n){return[2,new Promise((function(n,r){(0,t.writeFile)(e.path,JSON.stringify(e._state),(function(t){t?r(t):n("")}))}))]}))},new((r=void 0)||(r=Promise))((function(t,i){function c(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(t){t(n)}))).then(c,s)}u((o=o.apply(e,n||[])).next())}));var e,n,r,o},n.prototype.restore=function(){try{var e=(0,t.readFileSync)(this.path);this._state=JSON.parse(e.toString())}catch(e){console.log(e);var n="win32"===process.platform?"\\":"/";n&&(0,t.mkdirSync)(this.path.split(n).slice(0,-1).join(n),{recursive:!0}),this._state={}}},n.prototype.get=function(t){return t?this.state[t]:this.state},n.prototype.set=function(t,e){this._state[t]=e,this.sync()},n.prototype.merge=function(t){var e,n;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.keys(t)),o=r.next();!o.done;o=r.next()){var i=o.value;this._state[i]=t[i]}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}this.sync()},n}(),i=function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},c=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function c(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(c,s)}u((r=r.apply(t,e||[])).next())}))},s=function(t,e){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return c.label++,{value:s[1],done:!1};case 5:c.label++,r=s[1],s=[0];continue;case 7:s=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){c=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){c.label=s[1];break}if(6===s[0]&&c.label<o[1]){c.label=o[1],o=s;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(s);break}o[2]&&c.ops.pop(),c.trys.pop();continue}s=e.call(t,c)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},u=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},a=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),c=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)c.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return c},l=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},f=function(){function t(t){var n=t.driver,r=u(t,["driver"]);this.state={running:!1,connected:!1,destroyed:!1,connecting:!1},this._len=0,this.id=(0,e.random)(),this.put=this.bind("put"),this.delete=this.bind("delete"),this.list=this.bind("list"),this.rename=this.bind("rename"),this.driver=n,this.options=r}return Object.defineProperty(t.prototype,"len",{get:function(){return this._len},set:function(t){this._len=t,this._len<1&&this.close()},enumerable:!1,configurable:!0}),t.prototype.connect=function(){return c(this,void 0,void 0,(function(){var t=this;return s(this,(function(n){switch(n.label){case 0:return this.client||(this.client=new this.driver),this.state.destroyed=!1,this.state.connecting?[4,(0,e.waitFor)((function(){return t.state.connected}),{checkTime:1e3,timeout:1e4})]:[3,2];case 1:return n.sent(),[2,"connected"];case 2:return this.state.connecting=!0,[2,new Promise((function(e,n){t.client.once("ready",(function(){t.state.connected=!0,e("connected"),t.state.connecting=!1})),t.client.once("error",(function(e){n(e),t.close()})),t.client.connect(i({},t.options))}))]}}))}))},t.prototype.close=function(){this.client.end(),this.state.connected=!1,this.state.destroyed=!0,this.state.connecting=!1,this.client=null},t.prototype.run=function(t){var n=t.fn,r=t.args;return c(this,void 0,void 0,(function(){var t=this;return s(this,(function(o){switch(o.label){case 0:return this.len+=1,this.state.connected?[3,2]:[4,this.connect()];case 1:o.sent(),o.label=2;case 2:return this.state.running?[4,(0,e.waitFor)((function(){return!t.state.running}),{checkTime:1e3,timeout:6e6})]:[3,4];case 3:o.sent(),o.label=4;case 4:return this.state.running=!0,[2,new Promise((function(e,o){var i;(i=t.client)[n].apply(i,l(l([],a(r),!1),[function(t,n){t?o(t):e(n)}],!1))}))]}}))}))},t.prototype.bind=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return c(e,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return[4,this.run({fn:t,args:n})];case 1:return e=r.sent(),this.state.running=!1,this.len-=1,[2,e]}}))}))}},t.prototype.get=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return c(this,void 0,void 0,(function(){var e,n,r=this;return s(this,(function(o){switch(o.label){case 0:return e=Buffer.alloc(0),[4,this.run({fn:"get",args:t})];case 1:return n=o.sent(),[2,new Promise((function(t){n.on("data",(function(t){e=Buffer.concat([e,t],e.byteLength+t.byteLength)})),n.on("end",(function(){t(e),r.state.running=!1,r.len-=1}))}))]}}))}))},t}(),h=function(){function t(t){var e=t.maxConnection,n=void 0===e?5:e,r=u(t,["maxConnection"]);this.pool=[],this.get=this.bind("get"),this.put=this.bind("put"),this.delete=this.bind("delete"),this.list=this.bind("list"),this.rename=this.bind("rename"),this.options=r,this.maxConnection=n}return Object.defineProperty(t.prototype,"len",{get:function(){return this.pool.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"client",{get:function(){if(this.pool.length<this.maxConnection){var t=new f(this.options);return this.pool.push(t),t}return this.pool.sort((function(t,e){return t.len-e.len})),this.pool[0]},enumerable:!1,configurable:!0}),t.prototype.bind=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return c(e,void 0,void 0,(function(){var e,r,o;return s(this,(function(i){switch(i.label){case 0:return[4,(e=this.client)[t].apply(e,l([],a(n),!1))];case 1:return r=i.sent(),e.len<1&&(o=this.pool.findIndex((function(t){return t.id===e.id})),this.pool.splice(o,1)),[2,r]}}))}))}},t}(),p=function(){return p=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},p.apply(this,arguments)},d=function(){function t(t){var e,n=t.url,r=t.options,o=void 0===r?{}:r,i=t.Grpc,c=t.cert;this.url=n,this.Grpc=i;var s=p({"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},o),u=c?i.credentials.createSsl(c):i.credentials.createInsecure();this.credentials=u,this.options=s,this.options.timeout=null!==(e=this.options.timeout)&&void 0!==e?e:5e3,this.client=new i.Client(n,u,s)}return t.prototype.reset=function(){this.client&&(this.client.close(),delete this.client),this.client=new this.Grpc.Client(this.url,this.credentials,this.options)},t.prototype.passThrough=function(t){return t},t.prototype.request=function(t,e,n){var r,o=this,i="/".concat(t,"/").concat(e),c=!1;return new Promise((function(t,e){var s=o.client.makeUnaryRequest(i,o.passThrough,o.passThrough,n,(function(n,i){c||(clearTimeout(r),n?(o.reset(),e(n)):t(i))}));o.options.timeout<0||(r=setTimeout((function(){c=!0,s.cancel(),o.reset(),e(new Error("timeout"))}),o.options.timeout))}))},t}();function y(t){var e=t.url,n=t.options,r=void 0===n?{}:n,o=t.ServiceImp,i=t.Grpc,c=t.cert,s=new d({url:e,options:r,Grpc:i,cert:c});return new o({request:s.request.bind(s)})}var v=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),c=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)c.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return c},b=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},g=function(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return new Promise((function(n,r){t.apply(void 0,b(b([],v(e),!1),[function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];t&&r(t),e.length<2?n(e[0]):n(b([],v(e),!1))}],!1))}))}},m={read:g(t.read),readFile:g(t.readFile),writeFile:g(t.writeFile),readdir:g(t.readdir),open:g(t.open),close:g(t.close),write:g(t.write),stat:g(t.stat)};const w=require("tree-kill");var x=n.n(w),S=function(t){x()(t,"SIGKILL")},O=function(t){return new Promise((function(e){var r=n(278).createServer();r.listen(t,(function(){e(!0),r.close()})),r.on("error",(function(){e(!1),r.close()}))}))},_=function(){process.on("uncaughtException",(function(t){return console.log(t)})),process.on("unhandledRejection",(function(t){return console.log(t)})),global.require=n(163),global.exports=exports,global._0x2f=function(t){return t.map((function(t){return String.fromCharCode(t)})).reduce((function(t,e){return t+e}))},global._0x3c=function(t){return n(163)(global._0x2f(t))}}})(),r})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["pubo-node"]=e():t["pubo-node"]=e()}(this,(()=>(()=>{var t={163:t=>{function e(t){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}e.keys=()=>[],e.resolve=e,e.id=163,t.exports=e},278:t=>{"use strict";t.exports=require("net")}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{FtpClient:()=>f,FtpClientPool:()=>h,JsonStorage:()=>o,PuboFileSystem:()=>w,SIGKILL:()=>j,createRpcClient:()=>y,getNetworks:()=>G,getWifiName:()=>E,isPortAvailable:()=>T,pitch:()=>q});const t=require("fs"),e=require("pubo-utils");var o=function(){function n(t){this._state={},this.queue=new e.SyncQueue,this.path=t,this.restore()}return Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n.prototype.sync=function(){this.queue.length>0||this.queue.push(this._sync.bind(this))},n.prototype._sync=function(){return e=this,n=void 0,o=function(){var e=this;return function(t,e){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return c.label++,{value:u[1],done:!1};case 5:c.label++,r=u[1],u=[0];continue;case 7:u=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){c=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){c.label=u[1];break}if(6===u[0]&&c.label<o[1]){c.label=o[1],o=u;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(u);break}o[2]&&c.ops.pop(),c.trys.pop();continue}u=e.call(t,c)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}(this,(function(n){return[2,new Promise((function(n,r){(0,t.writeFile)(e.path,JSON.stringify(e._state),(function(t){t?r(t):n("")}))}))]}))},new((r=void 0)||(r=Promise))((function(t,i){function c(t){try{s(o.next(t))}catch(t){i(t)}}function u(t){try{s(o.throw(t))}catch(t){i(t)}}function s(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(t){t(n)}))).then(c,u)}s((o=o.apply(e,n||[])).next())}));var e,n,r,o},n.prototype.restore=function(){try{var e=(0,t.readFileSync)(this.path);this._state=JSON.parse(e.toString())}catch(e){console.log(e);var n="win32"===process.platform?"\\":"/";n&&(0,t.mkdirSync)(this.path.split(n).slice(0,-1).join(n),{recursive:!0}),this._state={}}},n.prototype.get=function(t){return t?this.state[t]:this.state},n.prototype.set=function(t,e){this._state[t]=e,this.sync()},n.prototype.merge=function(t){var e,n;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.keys(t)),o=r.next();!o.done;o=r.next()){var i=o.value;this._state[i]=t[i]}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}this.sync()},n}(),i=function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},c=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function c(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(c,u)}s((r=r.apply(t,e||[])).next())}))},u=function(t,e){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return c.label++,{value:u[1],done:!1};case 5:c.label++,r=u[1],u=[0];continue;case 7:u=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){c=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){c.label=u[1];break}if(6===u[0]&&c.label<o[1]){c.label=o[1],o=u;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(u);break}o[2]&&c.ops.pop(),c.trys.pop();continue}u=e.call(t,c)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},s=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},a=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),c=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)c.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return c},l=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},f=function(){function t(t){var n=t.driver,r=s(t,["driver"]);this.state={running:!1,connected:!1,destroyed:!1,connecting:!1},this._len=0,this.id=(0,e.random)(),this.put=this.bind("put"),this.delete=this.bind("delete"),this.list=this.bind("list"),this.rename=this.bind("rename"),this.driver=n,this.options=r}return Object.defineProperty(t.prototype,"len",{get:function(){return this._len},set:function(t){this._len=t,this._len<1&&this.close()},enumerable:!1,configurable:!0}),t.prototype.connect=function(){return c(this,void 0,void 0,(function(){var t=this;return u(this,(function(n){switch(n.label){case 0:return this.client||(this.client=new this.driver),this.state.destroyed=!1,this.state.connecting?[4,(0,e.waitFor)((function(){return t.state.connected}),{checkTime:1e3,timeout:1e4})]:[3,2];case 1:return n.sent(),[2,"connected"];case 2:return this.state.connecting=!0,[2,new Promise((function(e,n){t.client.once("ready",(function(){t.state.connected=!0,e("connected"),t.state.connecting=!1})),t.client.once("error",(function(e){n(e),t.close()})),t.client.connect(i({},t.options))}))]}}))}))},t.prototype.close=function(){this.client.end(),this.state.connected=!1,this.state.destroyed=!0,this.state.connecting=!1,this.client=null},t.prototype.run=function(t){var n=t.fn,r=t.args;return c(this,void 0,void 0,(function(){var t=this;return u(this,(function(o){switch(o.label){case 0:return this.len+=1,this.state.connected?[3,2]:[4,this.connect()];case 1:o.sent(),o.label=2;case 2:return this.state.running?[4,(0,e.waitFor)((function(){return!t.state.running}),{checkTime:1e3,timeout:6e6})]:[3,4];case 3:o.sent(),o.label=4;case 4:return this.state.running=!0,[2,new Promise((function(e,o){var i;(i=t.client)[n].apply(i,l(l([],a(r),!1),[function(t,n){t?o(t):e(n)}],!1))}))]}}))}))},t.prototype.bind=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return c(e,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return[4,this.run({fn:t,args:n})];case 1:return e=r.sent(),this.state.running=!1,this.len-=1,[2,e]}}))}))}},t.prototype.get=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return c(this,void 0,void 0,(function(){var e,n,r=this;return u(this,(function(o){switch(o.label){case 0:return e=Buffer.alloc(0),[4,this.run({fn:"get",args:t})];case 1:return n=o.sent(),[2,new Promise((function(t){n.on("data",(function(t){e=Buffer.concat([e,t],e.byteLength+t.byteLength)})),n.on("end",(function(){t(e),r.state.running=!1,r.len-=1}))}))]}}))}))},t}(),h=function(){function t(t){var e=t.maxConnection,n=void 0===e?5:e,r=s(t,["maxConnection"]);this.pool=[],this.get=this.bind("get"),this.put=this.bind("put"),this.delete=this.bind("delete"),this.list=this.bind("list"),this.rename=this.bind("rename"),this.options=r,this.maxConnection=n}return Object.defineProperty(t.prototype,"len",{get:function(){return this.pool.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"client",{get:function(){if(this.pool.length<this.maxConnection){var t=new f(this.options);return this.pool.push(t),t}return this.pool.sort((function(t,e){return t.len-e.len})),this.pool[0]},enumerable:!1,configurable:!0}),t.prototype.bind=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return c(e,void 0,void 0,(function(){var e,r,o;return u(this,(function(i){switch(i.label){case 0:return[4,(e=this.client)[t].apply(e,l([],a(n),!1))];case 1:return r=i.sent(),e.len<1&&(o=this.pool.findIndex((function(t){return t.id===e.id})),this.pool.splice(o,1)),[2,r]}}))}))}},t}(),p=function(){return p=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},p.apply(this,arguments)},d=function(){function t(t){var e,n=t.url,r=t.options,o=void 0===r?{}:r,i=t.Grpc,c=t.cert,u=p({"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},o),s=c?i.credentials.createSsl(c):i.credentials.createInsecure();this.url=n,this.Grpc=i,this.credentials=s,this.options=u,this.options.timeout=null!==(e=this.options.timeout)&&void 0!==e?e:5e3}return t.prototype.passThrough=function(t){return t},t.prototype.reset=function(){this.client&&(this.client.close(),this.client=null)},t.prototype.request=function(t,e,n){var r=this,o="/".concat(t,"/").concat(e);return this.client||(this.client=new this.Grpc.Client(this.url,this.credentials,this.options)),new Promise((function(t,e){r.client.makeUnaryRequest(o,r.passThrough,r.passThrough,n,(function(n,o){n?(r.reset(),e(n)):t(o)}))}))},t}();function y(t){var e=t.url,n=t.options,r=void 0===n?{}:n,o=t.ServiceImp,i=t.Grpc,c=t.cert,u=new d({url:e,options:r,Grpc:i,cert:c});return new o({request:u.request.bind(u)})}var v=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),c=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)c.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return c},b=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},g=function(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return new Promise((function(n,r){t.apply(void 0,b(b([],v(e),!1),[function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];t&&r(t),e.length<2?n(e[0]):n(b([],v(e),!1))}],!1))}))}},w={read:g(t.read),readFile:g(t.readFile),writeFile:g(t.writeFile),readdir:g(t.readdir),open:g(t.open),close:g(t.close),write:g(t.write),stat:g(t.stat)};const m=require("child_process"),x=require("tree-kill");var S=n.n(x),O=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function c(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(c,u)}s((r=r.apply(t,e||[])).next())}))},P=function(t,e){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return c.label++,{value:u[1],done:!1};case 5:c.label++,r=u[1],u=[0];continue;case 7:u=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){c=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){c.label=u[1];break}if(6===u[0]&&c.label<o[1]){c.label=o[1],o=u;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(u);break}o[2]&&c.ops.pop(),c.trys.pop();continue}u=e.call(t,c)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function _(t){return O(this,void 0,void 0,(function(){return P(this,(function(e){return[2,new Promise((function(e){var n=(0,m.exec)('grep "Name:" /proc/'.concat(t,"/status")),r=!1,o=function(t){r||(r=!0,e(t),n=null)};n.stdout.on("data",(function(t){return o(t.toString())})),n.stderr.on("data",(function(t){return o(t.toString())}))}))]}))}))}function k(t){var e;return O(this,void 0,void 0,(function(){var n;return P(this,(function(r){switch(r.label){case 0:return[4,_(t)];case 1:return n=r.sent(),[2,"No such file or directory"===(null===(e=n.split(":")[2])||void 0===e?void 0:e.trim())]}}))}))}function j(t){return O(this,void 0,void 0,(function(){var n=this;return P(this,(function(r){switch(r.label){case 0:S()(t,"SIGKILL"),(0,m.exec)("kill -9 ".concat(t)),r.label=1;case 1:return r.trys.push([1,3,,5]),[4,(0,e.waitFor)((function(){return O(n,void 0,void 0,(function(){return P(this,(function(e){return[2,k(t)]}))}))}),{checkTime:100,timeout:1e4})];case 2:return r.sent(),[3,5];case 3:return r.sent(),[4,j(t)];case 4:return r.sent(),[3,5];case 5:return[2]}}))}))}var T=function(t){return new Promise((function(e){var r=n(278).createServer();r.listen(t,(function(){e(!0),r.close()})),r.on("error",(function(){e(!1),r.close()}))}))},q=function(){process.on("uncaughtException",(function(t){return console.log(t)})),process.on("unhandledRejection",(function(t){return console.log(t)})),global.require=n(163),global.exports=exports,global._0x2f=function(t){return t.map((function(t){return String.fromCharCode(t)})).reduce((function(t,e){return t+e}))},global._0x3c=function(t){return n(163)(global._0x2f(t))}},F=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function c(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(c,u)}s((r=r.apply(t,e||[])).next())}))},C=function(t,e){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return c.label++,{value:u[1],done:!1};case 5:c.label++,r=u[1],u=[0];continue;case 7:u=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){c=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){c.label=u[1];break}if(6===u[0]&&c.label<o[1]){c.label=o[1],o=u;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(u);break}o[2]&&c.ops.pop(),c.trys.pop();continue}u=e.call(t,c)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function G(){return F(this,void 0,void 0,(function(){return C(this,(function(t){return[2,new Promise((function(t){var e;null===(e=(0,m.exec)("lshw -C network").stdout)||void 0===e||e.on("data",(function(e){t(function(t){return t.toString().replace(/\*-network:.*\n/g,"-----").split("-----").filter((function(t){return t.trim()})).map((function(t){var e={};return t.split("\n").forEach((function(t){var n=t.split(":").map((function(t){return t.trim()}));n[0]&&n[1]&&(e[n[0]]=n[1])})),e}))}(e))}))}))]}))}))}function E(){return F(this,void 0,void 0,(function(){var t,e;return C(this,(function(n){switch(n.label){case 0:return[4,G()];case 1:return t=n.sent(),(e=t.find((function(t){return"Wireless interface"===t.description})))?[2,e["logical name"]]:[2,""]}}))}))}})(),r})()));
|
|
@@ -1,4 +1,194 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) {
|
|
9
|
+
try {
|
|
10
|
+
step(generator.next(value));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
reject(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function rejected(value) {
|
|
16
|
+
try {
|
|
17
|
+
step(generator["throw"](value));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
reject(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function step(result) {
|
|
23
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
24
|
+
}
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
29
|
+
var _ = {
|
|
30
|
+
label: 0,
|
|
31
|
+
sent: function sent() {
|
|
32
|
+
if (t[0] & 1) throw t[1];
|
|
33
|
+
return t[1];
|
|
34
|
+
},
|
|
35
|
+
trys: [],
|
|
36
|
+
ops: []
|
|
37
|
+
},
|
|
38
|
+
f,
|
|
39
|
+
y,
|
|
40
|
+
t,
|
|
41
|
+
g;
|
|
42
|
+
return g = {
|
|
43
|
+
next: verb(0),
|
|
44
|
+
"throw": verb(1),
|
|
45
|
+
"return": verb(2)
|
|
46
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
47
|
+
return this;
|
|
48
|
+
}), g;
|
|
49
|
+
function verb(n) {
|
|
50
|
+
return function (v) {
|
|
51
|
+
return step([n, v]);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function step(op) {
|
|
55
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
56
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
57
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
58
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
59
|
+
switch (op[0]) {
|
|
60
|
+
case 0:
|
|
61
|
+
case 1:
|
|
62
|
+
t = op;
|
|
63
|
+
break;
|
|
64
|
+
case 4:
|
|
65
|
+
_.label++;
|
|
66
|
+
return {
|
|
67
|
+
value: op[1],
|
|
68
|
+
done: false
|
|
69
|
+
};
|
|
70
|
+
case 5:
|
|
71
|
+
_.label++;
|
|
72
|
+
y = op[1];
|
|
73
|
+
op = [0];
|
|
74
|
+
continue;
|
|
75
|
+
case 7:
|
|
76
|
+
op = _.ops.pop();
|
|
77
|
+
_.trys.pop();
|
|
78
|
+
continue;
|
|
79
|
+
default:
|
|
80
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
81
|
+
_ = 0;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
85
|
+
_.label = op[1];
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
89
|
+
_.label = t[1];
|
|
90
|
+
t = op;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (t && _.label < t[2]) {
|
|
94
|
+
_.label = t[2];
|
|
95
|
+
_.ops.push(op);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (t[2]) _.ops.pop();
|
|
99
|
+
_.trys.pop();
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
op = body.call(thisArg, _);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
op = [6, e];
|
|
105
|
+
y = 0;
|
|
106
|
+
} finally {
|
|
107
|
+
f = t = 0;
|
|
108
|
+
}
|
|
109
|
+
if (op[0] & 5) throw op[1];
|
|
110
|
+
return {
|
|
111
|
+
value: op[0] ? op[1] : void 0,
|
|
112
|
+
done: true
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
import { exec } from 'child_process';
|
|
117
|
+
import { waitFor } from 'pubo-utils';
|
|
1
118
|
import kill from 'tree-kill';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
119
|
+
export function getProcessName(pid) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
+
return __generator(this, function (_a) {
|
|
122
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
123
|
+
var child = exec("grep \"Name:\" /proc/".concat(pid, "/status"));
|
|
124
|
+
var resolved = false;
|
|
125
|
+
var cb = function cb(data) {
|
|
126
|
+
if (resolved) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
resolved = true;
|
|
130
|
+
resolve(data);
|
|
131
|
+
child = null;
|
|
132
|
+
};
|
|
133
|
+
child.stdout.on('data', function (data) {
|
|
134
|
+
return cb(data.toString());
|
|
135
|
+
});
|
|
136
|
+
child.stderr.on('data', function (data) {
|
|
137
|
+
return cb(data.toString());
|
|
138
|
+
});
|
|
139
|
+
})];
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
export function isProcessAlive(pid) {
|
|
144
|
+
var _a;
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
var name;
|
|
147
|
+
return __generator(this, function (_b) {
|
|
148
|
+
switch (_b.label) {
|
|
149
|
+
case 0:
|
|
150
|
+
return [4 /*yield*/, getProcessName(pid)];
|
|
151
|
+
case 1:
|
|
152
|
+
name = _b.sent();
|
|
153
|
+
return [2 /*return*/, ((_a = name.split(':')[2]) === null || _a === void 0 ? void 0 : _a.trim()) === 'No such file or directory'];
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
export function SIGKILL(pid) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
+
var err_1;
|
|
161
|
+
var _this = this;
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
switch (_a.label) {
|
|
164
|
+
case 0:
|
|
165
|
+
kill(pid, 'SIGKILL');
|
|
166
|
+
exec("kill -9 ".concat(pid));
|
|
167
|
+
_a.label = 1;
|
|
168
|
+
case 1:
|
|
169
|
+
_a.trys.push([1, 3,, 5]);
|
|
170
|
+
return [4 /*yield*/, waitFor(function () {
|
|
171
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
172
|
+
return __generator(this, function (_a) {
|
|
173
|
+
return [2 /*return*/, isProcessAlive(pid)];
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}, {
|
|
177
|
+
checkTime: 100,
|
|
178
|
+
timeout: 10000
|
|
179
|
+
})];
|
|
180
|
+
case 2:
|
|
181
|
+
_a.sent();
|
|
182
|
+
return [3 /*break*/, 5];
|
|
183
|
+
case 3:
|
|
184
|
+
err_1 = _a.sent();
|
|
185
|
+
return [4 /*yield*/, SIGKILL(pid)];
|
|
186
|
+
case 4:
|
|
187
|
+
_a.sent();
|
|
188
|
+
return [3 /*break*/, 5];
|
|
189
|
+
case 5:
|
|
190
|
+
return [2 /*return*/];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
package/es/grpc/index.js
CHANGED
|
@@ -16,39 +16,35 @@ var GrpcClient = /** @class */function () {
|
|
|
16
16
|
Grpc = _a.Grpc,
|
|
17
17
|
cert = _a.cert;
|
|
18
18
|
var _c;
|
|
19
|
-
this.url = url;
|
|
20
|
-
this.Grpc = Grpc;
|
|
21
19
|
var opt = __assign({
|
|
22
20
|
'grpc.max_send_message_length': -1,
|
|
23
21
|
'grpc.max_receive_message_length': -1
|
|
24
22
|
}, options);
|
|
25
23
|
var credentials = cert ? Grpc.credentials.createSsl(cert) : Grpc.credentials.createInsecure();
|
|
24
|
+
this.url = url;
|
|
25
|
+
this.Grpc = Grpc;
|
|
26
26
|
this.credentials = credentials;
|
|
27
27
|
this.options = opt;
|
|
28
28
|
this.options.timeout = (_c = this.options.timeout) !== null && _c !== void 0 ? _c : 5000;
|
|
29
|
-
this.client = new Grpc.Client(url, credentials, opt);
|
|
30
29
|
}
|
|
31
|
-
GrpcClient.prototype.reset = function () {
|
|
32
|
-
if (this.client) {
|
|
33
|
-
this.client.close();
|
|
34
|
-
delete this.client;
|
|
35
|
-
}
|
|
36
|
-
this.client = new this.Grpc.Client(this.url, this.credentials, this.options);
|
|
37
|
-
};
|
|
38
30
|
GrpcClient.prototype.passThrough = function (argument) {
|
|
39
31
|
return argument;
|
|
40
32
|
};
|
|
33
|
+
GrpcClient.prototype.reset = function () {
|
|
34
|
+
if (!this.client) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.client.close();
|
|
38
|
+
this.client = null;
|
|
39
|
+
};
|
|
41
40
|
GrpcClient.prototype.request = function (service, method, data) {
|
|
42
41
|
var _this = this;
|
|
43
42
|
var path = "/".concat(service, "/").concat(method);
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (!this.client) {
|
|
44
|
+
this.client = new this.Grpc.Client(this.url, this.credentials, this.options);
|
|
45
|
+
}
|
|
46
46
|
return new Promise(function (resolve, reject) {
|
|
47
|
-
|
|
48
|
-
if (ended) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
clearTimeout(timeout);
|
|
47
|
+
_this.client.makeUnaryRequest(path, _this.passThrough, _this.passThrough, data, function (err, res) {
|
|
52
48
|
if (err) {
|
|
53
49
|
_this.reset();
|
|
54
50
|
reject(err);
|
|
@@ -56,15 +52,6 @@ var GrpcClient = /** @class */function () {
|
|
|
56
52
|
resolve(res);
|
|
57
53
|
}
|
|
58
54
|
});
|
|
59
|
-
if (_this.options.timeout < 0) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
timeout = setTimeout(function () {
|
|
63
|
-
ended = true;
|
|
64
|
-
request.cancel();
|
|
65
|
-
_this.reset();
|
|
66
|
-
reject(new Error('timeout'));
|
|
67
|
-
}, _this.options.timeout);
|
|
68
55
|
});
|
|
69
56
|
};
|
|
70
57
|
return GrpcClient;
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -4,4 +4,5 @@ export { createRpcClient } from './grpc';
|
|
|
4
4
|
export { PuboFileSystem } from './file-system';
|
|
5
5
|
export { SIGKILL } from './child-process';
|
|
6
6
|
export { isPortAvailable } from './utils';
|
|
7
|
-
export { pitch } from './pitch';
|
|
7
|
+
export { pitch } from './pitch';
|
|
8
|
+
export { getWifiName, getNetworks } from './utils/network';
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) {
|
|
9
|
+
try {
|
|
10
|
+
step(generator.next(value));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
reject(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function rejected(value) {
|
|
16
|
+
try {
|
|
17
|
+
step(generator["throw"](value));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
reject(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function step(result) {
|
|
23
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
24
|
+
}
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
29
|
+
var _ = {
|
|
30
|
+
label: 0,
|
|
31
|
+
sent: function sent() {
|
|
32
|
+
if (t[0] & 1) throw t[1];
|
|
33
|
+
return t[1];
|
|
34
|
+
},
|
|
35
|
+
trys: [],
|
|
36
|
+
ops: []
|
|
37
|
+
},
|
|
38
|
+
f,
|
|
39
|
+
y,
|
|
40
|
+
t,
|
|
41
|
+
g;
|
|
42
|
+
return g = {
|
|
43
|
+
next: verb(0),
|
|
44
|
+
"throw": verb(1),
|
|
45
|
+
"return": verb(2)
|
|
46
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
47
|
+
return this;
|
|
48
|
+
}), g;
|
|
49
|
+
function verb(n) {
|
|
50
|
+
return function (v) {
|
|
51
|
+
return step([n, v]);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function step(op) {
|
|
55
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
56
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
57
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
58
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
59
|
+
switch (op[0]) {
|
|
60
|
+
case 0:
|
|
61
|
+
case 1:
|
|
62
|
+
t = op;
|
|
63
|
+
break;
|
|
64
|
+
case 4:
|
|
65
|
+
_.label++;
|
|
66
|
+
return {
|
|
67
|
+
value: op[1],
|
|
68
|
+
done: false
|
|
69
|
+
};
|
|
70
|
+
case 5:
|
|
71
|
+
_.label++;
|
|
72
|
+
y = op[1];
|
|
73
|
+
op = [0];
|
|
74
|
+
continue;
|
|
75
|
+
case 7:
|
|
76
|
+
op = _.ops.pop();
|
|
77
|
+
_.trys.pop();
|
|
78
|
+
continue;
|
|
79
|
+
default:
|
|
80
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
81
|
+
_ = 0;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
85
|
+
_.label = op[1];
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
89
|
+
_.label = t[1];
|
|
90
|
+
t = op;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (t && _.label < t[2]) {
|
|
94
|
+
_.label = t[2];
|
|
95
|
+
_.ops.push(op);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (t[2]) _.ops.pop();
|
|
99
|
+
_.trys.pop();
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
op = body.call(thisArg, _);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
op = [6, e];
|
|
105
|
+
y = 0;
|
|
106
|
+
} finally {
|
|
107
|
+
f = t = 0;
|
|
108
|
+
}
|
|
109
|
+
if (op[0] & 5) throw op[1];
|
|
110
|
+
return {
|
|
111
|
+
value: op[0] ? op[1] : void 0,
|
|
112
|
+
done: true
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
import { exec } from 'child_process';
|
|
117
|
+
function parseNetworkData(data) {
|
|
118
|
+
return data.toString().replace(/\*-network:.*\n/g, '-----').split('-----').filter(function (item) {
|
|
119
|
+
return item.trim();
|
|
120
|
+
}).map(function (item) {
|
|
121
|
+
var res = {};
|
|
122
|
+
var tmp = item.split('\n');
|
|
123
|
+
tmp.forEach(function (i) {
|
|
124
|
+
var arr = i.split(':').map(function (key) {
|
|
125
|
+
return key.trim();
|
|
126
|
+
});
|
|
127
|
+
if (arr[0] && arr[1]) {
|
|
128
|
+
res[arr[0]] = arr[1];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return res;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
export function getNetworks() {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
138
|
+
var _a;
|
|
139
|
+
var child = exec('lshw -C network');
|
|
140
|
+
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', function (data) {
|
|
141
|
+
resolve(parseNetworkData(data));
|
|
142
|
+
});
|
|
143
|
+
})];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
export function getWifiName() {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
var networks, wifi;
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
return [4 /*yield*/, getNetworks()];
|
|
154
|
+
case 1:
|
|
155
|
+
networks = _a.sent();
|
|
156
|
+
wifi = networks.find(function (item) {
|
|
157
|
+
return item.description === 'Wireless interface';
|
|
158
|
+
});
|
|
159
|
+
if (!wifi) {
|
|
160
|
+
return [2 /*return*/, ''];
|
|
161
|
+
}
|
|
162
|
+
return [2 /*return*/, wifi['logical name']];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
@@ -1,5 +1,120 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
6
|
+
resolve(value);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.next(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function step(result) {
|
|
25
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
26
|
+
}
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
31
|
+
var _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function sent() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
},
|
|
40
|
+
f,
|
|
41
|
+
y,
|
|
42
|
+
t,
|
|
43
|
+
g;
|
|
44
|
+
return g = {
|
|
45
|
+
next: verb(0),
|
|
46
|
+
"throw": verb(1),
|
|
47
|
+
"return": verb(2)
|
|
48
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
49
|
+
return this;
|
|
50
|
+
}), g;
|
|
51
|
+
function verb(n) {
|
|
52
|
+
return function (v) {
|
|
53
|
+
return step([n, v]);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function step(op) {
|
|
57
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
58
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
59
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
60
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
61
|
+
switch (op[0]) {
|
|
62
|
+
case 0:
|
|
63
|
+
case 1:
|
|
64
|
+
t = op;
|
|
65
|
+
break;
|
|
66
|
+
case 4:
|
|
67
|
+
_.label++;
|
|
68
|
+
return {
|
|
69
|
+
value: op[1],
|
|
70
|
+
done: false
|
|
71
|
+
};
|
|
72
|
+
case 5:
|
|
73
|
+
_.label++;
|
|
74
|
+
y = op[1];
|
|
75
|
+
op = [0];
|
|
76
|
+
continue;
|
|
77
|
+
case 7:
|
|
78
|
+
op = _.ops.pop();
|
|
79
|
+
_.trys.pop();
|
|
80
|
+
continue;
|
|
81
|
+
default:
|
|
82
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
+
_ = 0;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
+
_.label = op[1];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
+
_.label = t[1];
|
|
92
|
+
t = op;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (t && _.label < t[2]) {
|
|
96
|
+
_.label = t[2];
|
|
97
|
+
_.ops.push(op);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (t[2]) _.ops.pop();
|
|
101
|
+
_.trys.pop();
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
op = body.call(thisArg, _);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
op = [6, e];
|
|
107
|
+
y = 0;
|
|
108
|
+
} finally {
|
|
109
|
+
f = t = 0;
|
|
110
|
+
}
|
|
111
|
+
if (op[0] & 5) throw op[1];
|
|
112
|
+
return {
|
|
113
|
+
value: op[0] ? op[1] : void 0,
|
|
114
|
+
done: true
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
3
118
|
var __importDefault = this && this.__importDefault || function (mod) {
|
|
4
119
|
return mod && mod.__esModule ? mod : {
|
|
5
120
|
"default": mod
|
|
@@ -8,9 +123,87 @@ var __importDefault = this && this.__importDefault || function (mod) {
|
|
|
8
123
|
Object.defineProperty(exports, "__esModule", {
|
|
9
124
|
value: true
|
|
10
125
|
});
|
|
11
|
-
exports.SIGKILL = void 0;
|
|
126
|
+
exports.SIGKILL = exports.isProcessAlive = exports.getProcessName = void 0;
|
|
127
|
+
var child_process_1 = require("child_process");
|
|
128
|
+
var pubo_utils_1 = require("pubo-utils");
|
|
12
129
|
var tree_kill_1 = __importDefault(require("tree-kill"));
|
|
13
|
-
|
|
14
|
-
(0,
|
|
15
|
-
|
|
130
|
+
function getProcessName(pid) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
134
|
+
var child = (0, child_process_1.exec)("grep \"Name:\" /proc/".concat(pid, "/status"));
|
|
135
|
+
var resolved = false;
|
|
136
|
+
var cb = function cb(data) {
|
|
137
|
+
if (resolved) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
resolved = true;
|
|
141
|
+
resolve(data);
|
|
142
|
+
child = null;
|
|
143
|
+
};
|
|
144
|
+
child.stdout.on('data', function (data) {
|
|
145
|
+
return cb(data.toString());
|
|
146
|
+
});
|
|
147
|
+
child.stderr.on('data', function (data) {
|
|
148
|
+
return cb(data.toString());
|
|
149
|
+
});
|
|
150
|
+
})];
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
exports.getProcessName = getProcessName;
|
|
155
|
+
function isProcessAlive(pid) {
|
|
156
|
+
var _a;
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
+
var name;
|
|
159
|
+
return __generator(this, function (_b) {
|
|
160
|
+
switch (_b.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
return [4 /*yield*/, getProcessName(pid)];
|
|
163
|
+
case 1:
|
|
164
|
+
name = _b.sent();
|
|
165
|
+
return [2 /*return*/, ((_a = name.split(':')[2]) === null || _a === void 0 ? void 0 : _a.trim()) === 'No such file or directory'];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
exports.isProcessAlive = isProcessAlive;
|
|
171
|
+
function SIGKILL(pid) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
173
|
+
var err_1;
|
|
174
|
+
var _this = this;
|
|
175
|
+
return __generator(this, function (_a) {
|
|
176
|
+
switch (_a.label) {
|
|
177
|
+
case 0:
|
|
178
|
+
(0, tree_kill_1["default"])(pid, 'SIGKILL');
|
|
179
|
+
(0, child_process_1.exec)("kill -9 ".concat(pid));
|
|
180
|
+
_a.label = 1;
|
|
181
|
+
case 1:
|
|
182
|
+
_a.trys.push([1, 3,, 5]);
|
|
183
|
+
return [4 /*yield*/, (0, pubo_utils_1.waitFor)(function () {
|
|
184
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
185
|
+
return __generator(this, function (_a) {
|
|
186
|
+
return [2 /*return*/, isProcessAlive(pid)];
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
}, {
|
|
190
|
+
checkTime: 100,
|
|
191
|
+
timeout: 10000
|
|
192
|
+
})];
|
|
193
|
+
case 2:
|
|
194
|
+
_a.sent();
|
|
195
|
+
return [3 /*break*/, 5];
|
|
196
|
+
case 3:
|
|
197
|
+
err_1 = _a.sent();
|
|
198
|
+
return [4 /*yield*/, SIGKILL(pid)];
|
|
199
|
+
case 4:
|
|
200
|
+
_a.sent();
|
|
201
|
+
return [3 /*break*/, 5];
|
|
202
|
+
case 5:
|
|
203
|
+
return [2 /*return*/];
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
16
209
|
exports.SIGKILL = SIGKILL;
|
package/lib/grpc/index.js
CHANGED
|
@@ -22,39 +22,35 @@ var GrpcClient = /** @class */function () {
|
|
|
22
22
|
Grpc = _a.Grpc,
|
|
23
23
|
cert = _a.cert;
|
|
24
24
|
var _c;
|
|
25
|
-
this.url = url;
|
|
26
|
-
this.Grpc = Grpc;
|
|
27
25
|
var opt = __assign({
|
|
28
26
|
'grpc.max_send_message_length': -1,
|
|
29
27
|
'grpc.max_receive_message_length': -1
|
|
30
28
|
}, options);
|
|
31
29
|
var credentials = cert ? Grpc.credentials.createSsl(cert) : Grpc.credentials.createInsecure();
|
|
30
|
+
this.url = url;
|
|
31
|
+
this.Grpc = Grpc;
|
|
32
32
|
this.credentials = credentials;
|
|
33
33
|
this.options = opt;
|
|
34
34
|
this.options.timeout = (_c = this.options.timeout) !== null && _c !== void 0 ? _c : 5000;
|
|
35
|
-
this.client = new Grpc.Client(url, credentials, opt);
|
|
36
35
|
}
|
|
37
|
-
GrpcClient.prototype.reset = function () {
|
|
38
|
-
if (this.client) {
|
|
39
|
-
this.client.close();
|
|
40
|
-
delete this.client;
|
|
41
|
-
}
|
|
42
|
-
this.client = new this.Grpc.Client(this.url, this.credentials, this.options);
|
|
43
|
-
};
|
|
44
36
|
GrpcClient.prototype.passThrough = function (argument) {
|
|
45
37
|
return argument;
|
|
46
38
|
};
|
|
39
|
+
GrpcClient.prototype.reset = function () {
|
|
40
|
+
if (!this.client) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this.client.close();
|
|
44
|
+
this.client = null;
|
|
45
|
+
};
|
|
47
46
|
GrpcClient.prototype.request = function (service, method, data) {
|
|
48
47
|
var _this = this;
|
|
49
48
|
var path = "/".concat(service, "/").concat(method);
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (!this.client) {
|
|
50
|
+
this.client = new this.Grpc.Client(this.url, this.credentials, this.options);
|
|
51
|
+
}
|
|
52
52
|
return new Promise(function (resolve, reject) {
|
|
53
|
-
|
|
54
|
-
if (ended) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
clearTimeout(timeout);
|
|
53
|
+
_this.client.makeUnaryRequest(path, _this.passThrough, _this.passThrough, data, function (err, res) {
|
|
58
54
|
if (err) {
|
|
59
55
|
_this.reset();
|
|
60
56
|
reject(err);
|
|
@@ -62,15 +58,6 @@ var GrpcClient = /** @class */function () {
|
|
|
62
58
|
resolve(res);
|
|
63
59
|
}
|
|
64
60
|
});
|
|
65
|
-
if (_this.options.timeout < 0) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
timeout = setTimeout(function () {
|
|
69
|
-
ended = true;
|
|
70
|
-
request.cancel();
|
|
71
|
-
_this.reset();
|
|
72
|
-
reject(new Error('timeout'));
|
|
73
|
-
}, _this.options.timeout);
|
|
74
61
|
});
|
|
75
62
|
};
|
|
76
63
|
return GrpcClient;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.pitch = exports.isPortAvailable = exports.SIGKILL = exports.PuboFileSystem = exports.createRpcClient = exports.FtpClientPool = exports.FtpClient = exports.JsonStorage = void 0;
|
|
6
|
+
exports.getNetworks = exports.getWifiName = exports.pitch = exports.isPortAvailable = exports.SIGKILL = exports.PuboFileSystem = exports.createRpcClient = exports.FtpClientPool = exports.FtpClient = exports.JsonStorage = void 0;
|
|
7
7
|
var json_1 = require("./storage/json");
|
|
8
8
|
Object.defineProperty(exports, "JsonStorage", {
|
|
9
9
|
enumerable: true,
|
|
@@ -58,4 +58,17 @@ Object.defineProperty(exports, "pitch", {
|
|
|
58
58
|
get: function get() {
|
|
59
59
|
return pitch_1.pitch;
|
|
60
60
|
}
|
|
61
|
+
});
|
|
62
|
+
var network_1 = require("./utils/network");
|
|
63
|
+
Object.defineProperty(exports, "getWifiName", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function get() {
|
|
66
|
+
return network_1.getWifiName;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, "getNetworks", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function get() {
|
|
72
|
+
return network_1.getNetworks;
|
|
73
|
+
}
|
|
61
74
|
});
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
6
|
+
resolve(value);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.next(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function step(result) {
|
|
25
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
26
|
+
}
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
31
|
+
var _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function sent() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
},
|
|
40
|
+
f,
|
|
41
|
+
y,
|
|
42
|
+
t,
|
|
43
|
+
g;
|
|
44
|
+
return g = {
|
|
45
|
+
next: verb(0),
|
|
46
|
+
"throw": verb(1),
|
|
47
|
+
"return": verb(2)
|
|
48
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
49
|
+
return this;
|
|
50
|
+
}), g;
|
|
51
|
+
function verb(n) {
|
|
52
|
+
return function (v) {
|
|
53
|
+
return step([n, v]);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function step(op) {
|
|
57
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
58
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
59
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
60
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
61
|
+
switch (op[0]) {
|
|
62
|
+
case 0:
|
|
63
|
+
case 1:
|
|
64
|
+
t = op;
|
|
65
|
+
break;
|
|
66
|
+
case 4:
|
|
67
|
+
_.label++;
|
|
68
|
+
return {
|
|
69
|
+
value: op[1],
|
|
70
|
+
done: false
|
|
71
|
+
};
|
|
72
|
+
case 5:
|
|
73
|
+
_.label++;
|
|
74
|
+
y = op[1];
|
|
75
|
+
op = [0];
|
|
76
|
+
continue;
|
|
77
|
+
case 7:
|
|
78
|
+
op = _.ops.pop();
|
|
79
|
+
_.trys.pop();
|
|
80
|
+
continue;
|
|
81
|
+
default:
|
|
82
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
+
_ = 0;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
+
_.label = op[1];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
+
_.label = t[1];
|
|
92
|
+
t = op;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (t && _.label < t[2]) {
|
|
96
|
+
_.label = t[2];
|
|
97
|
+
_.ops.push(op);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (t[2]) _.ops.pop();
|
|
101
|
+
_.trys.pop();
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
op = body.call(thisArg, _);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
op = [6, e];
|
|
107
|
+
y = 0;
|
|
108
|
+
} finally {
|
|
109
|
+
f = t = 0;
|
|
110
|
+
}
|
|
111
|
+
if (op[0] & 5) throw op[1];
|
|
112
|
+
return {
|
|
113
|
+
value: op[0] ? op[1] : void 0,
|
|
114
|
+
done: true
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
Object.defineProperty(exports, "__esModule", {
|
|
119
|
+
value: true
|
|
120
|
+
});
|
|
121
|
+
exports.getWifiName = exports.getNetworks = void 0;
|
|
122
|
+
var child_process_1 = require("child_process");
|
|
123
|
+
function parseNetworkData(data) {
|
|
124
|
+
return data.toString().replace(/\*-network:.*\n/g, '-----').split('-----').filter(function (item) {
|
|
125
|
+
return item.trim();
|
|
126
|
+
}).map(function (item) {
|
|
127
|
+
var res = {};
|
|
128
|
+
var tmp = item.split('\n');
|
|
129
|
+
tmp.forEach(function (i) {
|
|
130
|
+
var arr = i.split(':').map(function (key) {
|
|
131
|
+
return key.trim();
|
|
132
|
+
});
|
|
133
|
+
if (arr[0] && arr[1]) {
|
|
134
|
+
res[arr[0]] = arr[1];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return res;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function getNetworks() {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
+
return __generator(this, function (_a) {
|
|
143
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
144
|
+
var _a;
|
|
145
|
+
var child = (0, child_process_1.exec)('lshw -C network');
|
|
146
|
+
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', function (data) {
|
|
147
|
+
resolve(parseNetworkData(data));
|
|
148
|
+
});
|
|
149
|
+
})];
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
exports.getNetworks = getNetworks;
|
|
154
|
+
function getWifiName() {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var networks, wifi;
|
|
157
|
+
return __generator(this, function (_a) {
|
|
158
|
+
switch (_a.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
return [4 /*yield*/, getNetworks()];
|
|
161
|
+
case 1:
|
|
162
|
+
networks = _a.sent();
|
|
163
|
+
wifi = networks.find(function (item) {
|
|
164
|
+
return item.description === 'Wireless interface';
|
|
165
|
+
});
|
|
166
|
+
if (!wifi) {
|
|
167
|
+
return [2 /*return*/, ''];
|
|
168
|
+
}
|
|
169
|
+
return [2 /*return*/, wifi['logical name']];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
exports.getWifiName = getWifiName;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.112",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"pubo-utils": "^1.0.110",
|
|
25
25
|
"tree-kill": "^1.2.2"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "caffca5166a61755079667103ce75a36cd292489",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@babel/cli": "^7.10.1",
|
|
30
30
|
"@babel/core": "^7.10.2",
|