add net-level client and helper to apps api

This commit is contained in:
Stewart Allen 2024-05-17 01:04:13 -04:00
commit 7abc9a0426
2 changed files with 16 additions and 1 deletions

16
app.js
View file

@ -13,6 +13,7 @@ const moment = require('moment');
const agent = require('express-useragent');
const license = require_fresh('./src/moto/license.js');
const version = license.VERSION || "rogue";
const netdb = require('@gridspace/net-level-client');
const fileCache = {};
const code_src = {};
@ -42,6 +43,18 @@ const EventEmitter = require('events');
class AppEmitter extends EventEmitter {}
const events = new AppEmitter();
netdb.create = async function(map = {}) {
if (util.isfile(map.conf)) {
Object.assign(map, JSON.parse(fs.readFileSync(map.conf)));
}
const client = new netdb();
if (map.host && map.port) await client.open(map.host, map.port);
if (map.user && map.pass) await client.auth(map.user, map.pass);
if (map.base) await client.use(map.base);
logger.log({ netdb: map.host, user: map.user, base: map.base });
return client;
};
function addonce(array, v) {
if (array.indexOf(v) < 0) {
array.push(v);
@ -318,7 +331,8 @@ function initModule(mod, file, dir) {
env: mod.env,
pkg: {
agent,
moment
moment,
netdb,
},
mod: mods,
util: {

View file

@ -22,6 +22,7 @@
],
"dependencies": {
"@fortawesome/fontawesome-free": "^6.1.1",
"@gridspace/net-level-client": "^0.2.3",
"@tweenjs/tween.js": "^16.6.0",
"base64-js": "^1.5.1",
"buffer-crc32": "^0.2.13",