dbgate-api 4.7.4-alpha.7 → 4.8.0

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/.env CHANGED
@@ -1,3 +1,15 @@
1
1
  DEVMODE=1
2
+ # PERMISSIONS=~widgets/app,~widgets/plugins
2
3
  # DISABLE_SHELL=1
3
- # HIDE_APP_EDITOR=1
4
+ # HIDE_APP_EDITOR=1
5
+
6
+
7
+ # DEVWEB=1
8
+ # LOGINS=admin,test
9
+
10
+ # LOGIN_PASSWORD_admin=admin
11
+ # LOGIN_PERMISSIONS_admin=*
12
+
13
+ # LOGIN_PASSWORD_test=test
14
+ # LOGIN_PERMISSIONS_test=~*, widgets/database
15
+ # WORKSPACE_DIR=/home/jena/dbgate-data-2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dbgate-api",
3
3
  "main": "src/index.js",
4
- "version": "4.7.4-alpha.7",
4
+ "version": "4.8.0",
5
5
  "homepage": "https://dbgate.org/",
6
6
  "repository": {
7
7
  "type": "git",
@@ -25,9 +25,9 @@
25
25
  "compare-versions": "^3.6.0",
26
26
  "cors": "^2.8.5",
27
27
  "cross-env": "^6.0.3",
28
- "dbgate-query-splitter": "^4.7.4-alpha.7",
29
- "dbgate-sqltree": "^4.7.4-alpha.7",
30
- "dbgate-tools": "^4.7.4-alpha.7",
28
+ "dbgate-query-splitter": "^4.8.0",
29
+ "dbgate-sqltree": "^4.8.0",
30
+ "dbgate-tools": "^4.8.0",
31
31
  "diff": "^5.0.0",
32
32
  "diff2html": "^3.4.13",
33
33
  "eslint": "^6.8.0",
@@ -63,7 +63,7 @@
63
63
  "devDependencies": {
64
64
  "@types/fs-extra": "^9.0.11",
65
65
  "@types/lodash": "^4.14.149",
66
- "dbgate-types": "^4.7.4-alpha.7",
66
+ "dbgate-types": "^4.8.0",
67
67
  "env-cmd": "^10.1.0",
68
68
  "node-loader": "^1.0.2",
69
69
  "nodemon": "^2.0.2",
@@ -3,7 +3,7 @@ const os = require('os');
3
3
  const path = require('path');
4
4
  const axios = require('axios');
5
5
  const { datadir } = require('../utility/directories');
6
- const hasPermission = require('../utility/hasPermission');
6
+ const { hasPermission, getLogins } = require('../utility/hasPermission');
7
7
  const socket = require('../utility/socket');
8
8
  const _ = require('lodash');
9
9
  const AsyncLock = require('async-lock');
@@ -26,20 +26,31 @@ module.exports = {
26
26
  // },
27
27
 
28
28
  get_meta: true,
29
- async get() {
30
- const permissions = process.env.PERMISSIONS ? process.env.PERMISSIONS.split(',') : null;
29
+ async get(_params, req) {
30
+ const logins = getLogins();
31
+ const login = logins ? logins.find(x => x.login == (req.auth && req.auth.user)) : null;
32
+ const permissions = login ? login.permissions : null;
31
33
 
32
34
  return {
33
35
  runAsPortal: !!connections.portalConnections,
34
36
  singleDatabase: connections.singleDatabase,
35
- hideAppEditor: !!process.env.HIDE_APP_EDITOR,
37
+ // hideAppEditor: !!process.env.HIDE_APP_EDITOR,
36
38
  allowShellConnection: platformInfo.allowShellConnection,
37
39
  allowShellScripting: platformInfo.allowShellConnection,
38
40
  permissions,
41
+ login,
39
42
  ...currentVersion,
40
43
  };
41
44
  },
42
45
 
46
+ logout_meta: {
47
+ method: 'get',
48
+ raw: true,
49
+ },
50
+ logout(req, res) {
51
+ res.status(401).send('Logged out<br><a href="../..">Back to DbGate</a>');
52
+ },
53
+
43
54
  platformInfo_meta: true,
44
55
  async platformInfo() {
45
56
  return platformInfo;
@@ -67,8 +78,8 @@ module.exports = {
67
78
  },
68
79
 
69
80
  updateSettings_meta: true,
70
- async updateSettings(values) {
71
- if (!hasPermission(`settings/change`)) return false;
81
+ async updateSettings(values, req) {
82
+ if (!hasPermission(`settings/change`, req)) return false;
72
83
 
73
84
  const res = await lock.acquire('update', async () => {
74
85
  const currentValue = await this.getSettings();
@@ -180,6 +180,11 @@ module.exports = {
180
180
  return this.loadDataCore('loadKeys', { conid, database, root });
181
181
  },
182
182
 
183
+ exportKeys_meta: true,
184
+ async exportKeys({ conid, database, options }) {
185
+ return this.loadDataCore('exportKeys', { conid, database, options });
186
+ },
187
+
183
188
  loadKeyInfo_meta: true,
184
189
  async loadKeyInfo({ conid, database, key }) {
185
190
  return this.loadDataCore('loadKeyInfo', { conid, database, key });
@@ -3,7 +3,7 @@ const fs = require('fs-extra');
3
3
  const path = require('path');
4
4
  const { filesdir, archivedir, resolveArchiveFolder, uploadsdir, appdir } = require('../utility/directories');
5
5
  const getChartExport = require('../utility/getChartExport');
6
- const hasPermission = require('../utility/hasPermission');
6
+ const { hasPermission } = require('../utility/hasPermission');
7
7
  const socket = require('../utility/socket');
8
8
  const scheduler = require('./scheduler');
9
9
  const getDiagramExport = require('../utility/getDiagramExport');
@@ -23,8 +23,8 @@ function deserialize(format, text) {
23
23
 
24
24
  module.exports = {
25
25
  list_meta: true,
26
- async list({ folder }) {
27
- if (!hasPermission(`files/${folder}/read`)) return [];
26
+ async list({ folder }, req) {
27
+ if (!hasPermission(`files/${folder}/read`, req)) return [];
28
28
  const dir = path.join(filesdir(), folder);
29
29
  if (!(await fs.exists(dir))) return [];
30
30
  const files = (await fs.readdir(dir)).map(file => ({ folder, file }));
@@ -32,11 +32,11 @@ module.exports = {
32
32
  },
33
33
 
34
34
  listAll_meta: true,
35
- async listAll() {
35
+ async listAll(_params, req) {
36
36
  const folders = await fs.readdir(filesdir());
37
37
  const res = [];
38
38
  for (const folder of folders) {
39
- if (!hasPermission(`files/${folder}/read`)) continue;
39
+ if (!hasPermission(`files/${folder}/read`, req)) continue;
40
40
  const dir = path.join(filesdir(), folder);
41
41
  const files = (await fs.readdir(dir)).map(file => ({ folder, file }));
42
42
  res.push(...files);
@@ -45,31 +45,34 @@ module.exports = {
45
45
  },
46
46
 
47
47
  delete_meta: true,
48
- async delete({ folder, file }) {
49
- if (!hasPermission(`files/${folder}/write`)) return;
48
+ async delete({ folder, file }, req) {
49
+ if (!hasPermission(`files/${folder}/write`, req)) return false;
50
50
  await fs.unlink(path.join(filesdir(), folder, file));
51
51
  socket.emitChanged(`files-changed-${folder}`);
52
52
  socket.emitChanged(`all-files-changed`);
53
+ return true;
53
54
  },
54
55
 
55
56
  rename_meta: true,
56
- async rename({ folder, file, newFile }) {
57
- if (!hasPermission(`files/${folder}/write`)) return;
57
+ async rename({ folder, file, newFile }, req) {
58
+ if (!hasPermission(`files/${folder}/write`, req)) return false;
58
59
  await fs.rename(path.join(filesdir(), folder, file), path.join(filesdir(), folder, newFile));
59
60
  socket.emitChanged(`files-changed-${folder}`);
60
61
  socket.emitChanged(`all-files-changed`);
62
+ return true;
61
63
  },
62
64
 
63
65
  copy_meta: true,
64
- async copy({ folder, file, newFile }) {
65
- if (!hasPermission(`files/${folder}/write`)) return;
66
+ async copy({ folder, file, newFile }, req) {
67
+ if (!hasPermission(`files/${folder}/write`, req)) return false;
66
68
  await fs.copyFile(path.join(filesdir(), folder, file), path.join(filesdir(), folder, newFile));
67
69
  socket.emitChanged(`files-changed-${folder}`);
68
70
  socket.emitChanged(`all-files-changed`);
71
+ return true;
69
72
  },
70
73
 
71
74
  load_meta: true,
72
- async load({ folder, file, format }) {
75
+ async load({ folder, file, format }, req) {
73
76
  if (folder.startsWith('archive:')) {
74
77
  const text = await fs.readFile(path.join(resolveArchiveFolder(folder.substring('archive:'.length)), file), {
75
78
  encoding: 'utf-8',
@@ -81,20 +84,22 @@ module.exports = {
81
84
  });
82
85
  return deserialize(format, text);
83
86
  } else {
84
- if (!hasPermission(`files/${folder}/read`)) return null;
87
+ if (!hasPermission(`files/${folder}/read`, req)) return null;
85
88
  const text = await fs.readFile(path.join(filesdir(), folder, file), { encoding: 'utf-8' });
86
89
  return deserialize(format, text);
87
90
  }
88
91
  },
89
92
 
90
93
  save_meta: true,
91
- async save({ folder, file, data, format }) {
94
+ async save({ folder, file, data, format }, req) {
92
95
  if (folder.startsWith('archive:')) {
96
+ if (!hasPermission(`archive/write`, req)) return false;
93
97
  const dir = resolveArchiveFolder(folder.substring('archive:'.length));
94
98
  await fs.writeFile(path.join(dir, file), serialize(format, data));
95
99
  socket.emitChanged(`archive-files-changed-${folder.substring('archive:'.length)}`);
96
100
  return true;
97
101
  } else if (folder.startsWith('app:')) {
102
+ if (!hasPermission(`apps/write`, req)) return false;
98
103
  const app = folder.substring('app:'.length);
99
104
  await fs.writeFile(path.join(appdir(), app, file), serialize(format, data));
100
105
  socket.emitChanged(`app-files-changed-${app}`);
@@ -102,7 +107,7 @@ module.exports = {
102
107
  apps.emitChangedDbApp(folder);
103
108
  return true;
104
109
  } else {
105
- if (!hasPermission(`files/${folder}/write`)) return false;
110
+ if (!hasPermission(`files/${folder}/write`, req)) return false;
106
111
  const dir = path.join(filesdir(), folder);
107
112
  if (!(await fs.exists(dir))) {
108
113
  await fs.mkdir(dir);
@@ -123,8 +128,8 @@ module.exports = {
123
128
  },
124
129
 
125
130
  favorites_meta: true,
126
- async favorites() {
127
- if (!hasPermission(`files/favorites/read`)) return [];
131
+ async favorites(_params, req) {
132
+ if (!hasPermission(`files/favorites/read`, req)) return [];
128
133
  const dir = path.join(filesdir(), 'favorites');
129
134
  if (!(await fs.exists(dir))) return [];
130
135
  const files = await fs.readdir(dir);
@@ -7,7 +7,7 @@ const socket = require('../utility/socket');
7
7
  const compareVersions = require('compare-versions');
8
8
  const requirePlugin = require('../shell/requirePlugin');
9
9
  const downloadPackage = require('../utility/downloadPackage');
10
- const hasPermission = require('../utility/hasPermission');
10
+ const { hasPermission } = require('../utility/hasPermission');
11
11
  const _ = require('lodash');
12
12
  const packagedPluginsContent = require('../packagedPluginsContent');
13
13
 
@@ -115,8 +115,8 @@ module.exports = {
115
115
  // },
116
116
 
117
117
  install_meta: true,
118
- async install({ packageName }) {
119
- if (!hasPermission(`plugins/install`)) return;
118
+ async install({ packageName }, req) {
119
+ if (!hasPermission(`plugins/install`, req)) return;
120
120
  const dir = path.join(pluginsdir(), packageName);
121
121
  // @ts-ignore
122
122
  if (!(await fs.exists(dir))) {
@@ -128,8 +128,8 @@ module.exports = {
128
128
  },
129
129
 
130
130
  uninstall_meta: true,
131
- async uninstall({ packageName }) {
132
- if (!hasPermission(`plugins/install`)) return;
131
+ async uninstall({ packageName }, req) {
132
+ if (!hasPermission(`plugins/install`, req)) return;
133
133
  const dir = path.join(pluginsdir(), packageName);
134
134
  await fs.rmdir(dir, { recursive: true });
135
135
  socket.emitChanged(`installed-plugins-changed`);
@@ -138,8 +138,8 @@ module.exports = {
138
138
  },
139
139
 
140
140
  upgrade_meta: true,
141
- async upgrade({ packageName }) {
142
- if (!hasPermission(`plugins/install`)) return;
141
+ async upgrade({ packageName }, req) {
142
+ if (!hasPermission(`plugins/install`, req)) return;
143
143
  const dir = path.join(pluginsdir(), packageName);
144
144
  // @ts-ignore
145
145
  if (await fs.exists(dir)) {
@@ -111,7 +111,7 @@ module.exports = {
111
111
  stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
112
112
  env: {
113
113
  ...process.env,
114
- DBGATE_API: global['API_PACKAGE'] || global['dbgateApiModulePath'] || process.argv[1],
114
+ DBGATE_API: global['API_PACKAGE'] || process.argv[1],
115
115
  ..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, getPluginBackendPath(name)])),
116
116
  },
117
117
  }
@@ -3,7 +3,7 @@ const fs = require('fs-extra');
3
3
  const path = require('path');
4
4
  const cron = require('node-cron');
5
5
  const runners = require('./runners');
6
- const hasPermission = require('../utility/hasPermission');
6
+ const { hasPermission } = require('../utility/hasPermission');
7
7
 
8
8
  const scheduleRegex = /\s*\/\/\s*@schedule\s+([^\n]+)\n/;
9
9
 
@@ -26,8 +26,8 @@ module.exports = {
26
26
  this.tasks.push(task);
27
27
  },
28
28
 
29
- async reload() {
30
- if (!hasPermission('files/shell/read')) return;
29
+ async reload(_params, req) {
30
+ if (!hasPermission('files/shell/read', req)) return;
31
31
  const shellDir = path.join(filesdir(), 'shell');
32
32
  await this.unload();
33
33
  if (!(await fs.exists(shellDir))) return;
@@ -142,6 +142,7 @@ module.exports = {
142
142
  createDatabase_meta: true,
143
143
  async createDatabase({ conid, name }) {
144
144
  const opened = await this.ensureOpened(conid);
145
+ if (opened.connection.isReadOnly) return false;
145
146
  opened.subprocess.send({ msgtype: 'createDatabase', name });
146
147
  return { status: 'ok' };
147
148
  },
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '4.7.4-alpha.7',
4
- buildTime: '2022-03-20T12:32:18.367Z'
3
+ version: '4.8.0',
4
+ buildTime: '2022-03-28T17:32:31.391Z'
5
5
  };
package/src/index.js CHANGED
@@ -8,7 +8,7 @@ if (processArgs.startProcess) {
8
8
  const proc = require('./proc');
9
9
  const module = proc[processArgs.startProcess];
10
10
  module.start();
11
- } else if (!processArgs.checkParent && !global['API_PACKAGE'] && !global['dbgateApiModulePath']) {
11
+ } else if (!processArgs.checkParent && !global['API_PACKAGE']) {
12
12
  const main = require('./main');
13
13
 
14
14
  main.start();
package/src/main.js CHANGED
@@ -29,6 +29,8 @@ const queryHistory = require('./controllers/queryHistory');
29
29
  const { rundir } = require('./utility/directories');
30
30
  const platformInfo = require('./utility/platformInfo');
31
31
  const getExpressPath = require('./utility/getExpressPath');
32
+ const { getLogins } = require('./utility/hasPermission');
33
+ const _ = require('lodash');
32
34
 
33
35
  function start() {
34
36
  // console.log('process.argv', process.argv);
@@ -37,12 +39,11 @@ function start() {
37
39
 
38
40
  const server = http.createServer(app);
39
41
 
40
- if (process.env.LOGIN && process.env.PASSWORD) {
42
+ const logins = getLogins();
43
+ if (logins) {
41
44
  app.use(
42
45
  basicAuth({
43
- users: {
44
- [process.env.LOGIN]: process.env.PASSWORD,
45
- },
46
+ users: _.fromPairs(logins.map(x => [x.login, x.password])),
46
47
  challenge: true,
47
48
  realm: 'DbGate Web App',
48
49
  })
@@ -85,15 +86,11 @@ function start() {
85
86
  if (platformInfo.isDocker) {
86
87
  // server static files inside docker container
87
88
  app.use(getExpressPath('/'), express.static('/home/dbgate-docker/public'));
88
- } else {
89
- if (!platformInfo.isNpmDist) {
90
- app.get(getExpressPath('/'), (req, res) => {
91
- res.send('DbGate API');
92
- });
93
- }
94
- }
95
89
 
96
- if (platformInfo.isNpmDist) {
90
+ const port = process.env.PORT || 3000;
91
+ console.log('DbGate API listening on port (docker build)', port);
92
+ server.listen(port);
93
+ } else if (platformInfo.isNpmDist) {
97
94
  app.use(getExpressPath('/'), express.static(path.join(__dirname, '../../dbgate-web/public')));
98
95
  getPort({
99
96
  port: parseInt(
@@ -102,12 +99,24 @@ function start() {
102
99
  ),
103
100
  }).then(port => {
104
101
  server.listen(port, () => {
105
- console.log(`DbGate API listening on port ${port}`);
102
+ console.log(`DbGate API listening on port ${port} (NPM build)`);
106
103
  });
107
104
  });
105
+ } else if (process.env.DEVWEB) {
106
+ console.log('__dirname', __dirname);
107
+ console.log(path.join(__dirname, '../../web/public/build'));
108
+ app.use(getExpressPath('/'), express.static(path.join(__dirname, '../../web/public')));
109
+
110
+ const port = process.env.PORT || 3000;
111
+ console.log('DbGate API & web listening on port (dev web build)', port);
112
+ server.listen(port);
108
113
  } else {
114
+ app.get(getExpressPath('/'), (req, res) => {
115
+ res.send('DbGate API');
116
+ });
117
+
109
118
  const port = process.env.PORT || 3000;
110
- console.log('DbGate API listening on port', port);
119
+ console.log('DbGate API listening on port (dev API build)', port);
111
120
  server.listen(port);
112
121
  }
113
122
 
@@ -201,12 +201,20 @@ async function handleLoadKeys({ msgid, root }) {
201
201
  return handleDriverDataCore(msgid, driver => driver.loadKeys(systemConnection, root));
202
202
  }
203
203
 
204
+ async function handleExportKeys({ msgid, options }) {
205
+ return handleDriverDataCore(msgid, driver => driver.exportKeys(systemConnection, options));
206
+ }
207
+
204
208
  async function handleLoadKeyInfo({ msgid, key }) {
205
209
  return handleDriverDataCore(msgid, driver => driver.loadKeyInfo(systemConnection, key));
206
210
  }
207
211
 
208
212
  async function handleCallMethod({ msgid, method, args }) {
209
213
  return handleDriverDataCore(msgid, driver => {
214
+ if (storedConnection.isReadOnly) {
215
+ throw new Error('Connection is read only, cannot call custom methods');
216
+ }
217
+
210
218
  ensureExecuteCustomScript(driver);
211
219
  return driver.callMethod(systemConnection, method, args);
212
220
  });
@@ -307,6 +315,7 @@ const messageHandlers = {
307
315
  generateDeploySql: handleGenerateDeploySql,
308
316
  loadFieldValues: handleLoadFieldValues,
309
317
  sqlSelect: handleSqlSelect,
318
+ exportKeys: handleExportKeys,
310
319
  // runCommand: handleRunCommand,
311
320
  };
312
321
 
@@ -3,6 +3,7 @@ const path = require('path');
3
3
  const fs = require('fs');
4
4
  const cleanDirectory = require('./cleanDirectory');
5
5
  const platformInfo = require('./platformInfo');
6
+ const processArgs = require('./processArgs');
6
7
 
7
8
  const createDirectories = {};
8
9
  const ensureDirectory = (dir, clean) => {
@@ -19,8 +20,18 @@ const ensureDirectory = (dir, clean) => {
19
20
  }
20
21
  };
21
22
 
23
+ function datadirCore() {
24
+ if (process.env.WORKSPACE_DIR) {
25
+ return process.env.WORKSPACE_DIR;
26
+ }
27
+ if (processArgs.workspaceDir) {
28
+ return processArgs.workspaceDir;
29
+ }
30
+ return path.join(os.homedir(), 'dbgate-data');
31
+ }
32
+
22
33
  function datadir() {
23
- const dir = path.join(os.homedir(), 'dbgate-data');
34
+ const dir = datadirCore();
24
35
  ensureDirectory(dir);
25
36
 
26
37
  return dir;
@@ -54,7 +65,10 @@ function packagedPluginsDir() {
54
65
  }
55
66
  if (platformInfo.isNpmDist) {
56
67
  // node_modules
57
- return global['dbgateApiPackagedPluginsPath'];
68
+ return global['PLUGINS_DIR'];
69
+ }
70
+ if (processArgs.pluginsDir) {
71
+ return processArgs.pluginsDir;
58
72
  }
59
73
  if (platformInfo.isElectronBundle) {
60
74
  return path.resolve(__dirname, '../../plugins');
@@ -6,6 +6,10 @@ function getJslFileName(jslid) {
6
6
  if (archiveMatch) {
7
7
  return path.join(resolveArchiveFolder(archiveMatch[1]), `${archiveMatch[2]}.jsonl`);
8
8
  }
9
+ const fileMatch = jslid.match(/^file:\/\/(.*)$/);
10
+ if (fileMatch) {
11
+ return fileMatch[1];
12
+ }
9
13
  return path.join(jsldir(), `${jslid}.jsonl`);
10
14
  }
11
15
 
@@ -1,12 +1,56 @@
1
1
  const { compilePermissions, testPermission } = require('dbgate-tools');
2
+ const _ = require('lodash');
2
3
 
3
- let compiled = undefined;
4
+ const userPermissions = {};
4
5
 
5
- function hasPermission(tested) {
6
- if (compiled === undefined) {
7
- compiled = compilePermissions(process.env.PERMISSIONS);
6
+ function hasPermission(tested, req) {
7
+ const { user } = (req && req.auth) || {};
8
+ const key = user || '';
9
+ const logins = getLogins();
10
+ if (!userPermissions[key] && logins) {
11
+ const login = logins.find(x => x.login == user);
12
+ userPermissions[key] = compilePermissions(login ? login.permissions : null);
8
13
  }
9
- return testPermission(tested, compiled);
14
+ return testPermission(tested, userPermissions[key]);
10
15
  }
11
16
 
12
- module.exports = hasPermission;
17
+ let loginsCache = null;
18
+ let loginsLoaded = false;
19
+
20
+ function getLogins() {
21
+ if (loginsLoaded) {
22
+ return loginsCache;
23
+ }
24
+
25
+ const res = [];
26
+ if (process.env.LOGIN && process.env.PASSWORD) {
27
+ res.push({
28
+ login: process.env.LOGIN,
29
+ password: process.env.PASSWORD,
30
+ permissions: process.env.PERMISSIONS,
31
+ });
32
+ }
33
+ if (process.env.LOGINS) {
34
+ const logins = _.compact(process.env.LOGINS.split(',').map(x => x.trim()));
35
+ for (const login of logins) {
36
+ const password = process.env[`LOGIN_PASSWORD_${login}`];
37
+ const permissions = process.env[`LOGIN_PERMISSIONS_${login}`];
38
+ if (password) {
39
+ res.push({
40
+ login,
41
+ password,
42
+ permissions,
43
+ });
44
+ }
45
+ }
46
+ }
47
+
48
+ loginsCache = res.length > 0 ? res : null;
49
+ loginsLoaded = true;
50
+ return loginsCache;
51
+ }
52
+
53
+ module.exports = {
54
+ hasPermission,
55
+ getLogins,
56
+ };
@@ -10,7 +10,7 @@ const isMac = platform === 'darwin';
10
10
  const isLinux = platform === 'linux';
11
11
  const isDocker = fs.existsSync('/home/dbgate-docker/public');
12
12
  const isDevMode = process.env.DEVMODE == '1';
13
- const isNpmDist = !!global['dbgateApiModulePath'];
13
+ const isNpmDist = !!global['IS_NPM_DIST'];
14
14
  const isForkedApi = processArgs.isForkedApi;
15
15
 
16
16
  // function moduleAvailable(name) {
@@ -9,10 +9,18 @@ function getNamedArg(name) {
9
9
  const checkParent = process.argv.includes('--checkParent');
10
10
  const startProcess = getNamedArg('--start-process');
11
11
  const isForkedApi = process.argv.includes('--is-forked-api');
12
+ const pluginsDir = getNamedArg('--plugins-dir');
13
+ const workspaceDir = getNamedArg('--workspace-dir');
12
14
 
13
15
  function getPassArgs() {
14
- if (global['NATIVE_MODULES']) return ['--native-modules', global['NATIVE_MODULES']];
15
- return [];
16
+ const res = [];
17
+ if (global['NATIVE_MODULES']) {
18
+ res.push('--native-modules', global['NATIVE_MODULES']);
19
+ }
20
+ if (global['PLUGINS_DIR']) {
21
+ res.push('--plugins-dir', global['PLUGINS_DIR']);
22
+ }
23
+ return res;
16
24
  }
17
25
 
18
26
  module.exports = {
@@ -20,4 +28,6 @@ module.exports = {
20
28
  startProcess,
21
29
  isForkedApi,
22
30
  getPassArgs,
31
+ pluginsDir,
32
+ workspaceDir,
23
33
  };
@@ -62,7 +62,7 @@ module.exports = function useController(app, electron, route, controller) {
62
62
  // controller._init_called = true;
63
63
  // }
64
64
  try {
65
- let params = [{ ...req.body, ...req.query }];
65
+ let params = [{ ...req.body, ...req.query }, req];
66
66
  if (rawParams) params = [req, res];
67
67
  const data = await controller[key](...params);
68
68
  res.json(data);