fix(striker-ui-api): revise accessDB->accessModule to reflect anvil-access-module changes

main
Tsu-ba-me 3 years ago
parent a7a2cc70d7
commit 8310a6edbb
  1. 37
      striker-ui-api/src/lib/accessModule.ts
  2. 2
      striker-ui-api/src/lib/consts/SERVER_PATHS.ts
  3. 2
      striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts
  4. 2
      striker-ui-api/src/routes/file.ts

@ -2,7 +2,7 @@ import { spawnSync, SpawnSyncOptions } from 'child_process';
import SERVER_PATHS from './consts/SERVER_PATHS'; import SERVER_PATHS from './consts/SERVER_PATHS';
const execStrikerAccessDatabase = ( const execAnvilAccessModule = (
args: string[], args: string[],
options: SpawnSyncOptions = { options: SpawnSyncOptions = {
timeout: 10000, timeout: 10000,
@ -10,7 +10,7 @@ const execStrikerAccessDatabase = (
}, },
) => { ) => {
const { error, stdout, stderr } = spawnSync( const { error, stdout, stderr } = spawnSync(
SERVER_PATHS.usr.sbin['striker-access-database'].self, SERVER_PATHS.usr.sbin['anvil-access-module'].self,
args, args,
options, options,
); );
@ -31,7 +31,7 @@ const execStrikerAccessDatabase = (
output = stdout; output = stdout;
console.warn( console.warn(
`Failed to parse striker-access-database output [${output}]; error: [${stdoutParseError}]`, `Failed to parse anvil-access-module output [${output}]; error: [${stdoutParseError}]`,
); );
} }
@ -40,18 +40,30 @@ const execStrikerAccessDatabase = (
}; };
}; };
const execDatabaseModuleSubroutine = ( const execModuleSubroutine = (
subName: string, subName: string,
subParams?: Record<string, unknown>, {
options?: SpawnSyncOptions, spawnSyncOptions,
subModuleName,
subParams,
}: {
spawnSyncOptions?: SpawnSyncOptions;
subModuleName?: string;
subParams?: Record<string, unknown>;
} = {},
) => { ) => {
const args = ['--sub', subName]; const args = ['--sub', subName];
// Defaults to "Database" in anvil-access-module.
if (subModuleName) {
args.push('--sub-module', subModuleName);
}
if (subParams) { if (subParams) {
args.push('--sub-params', JSON.stringify(subParams)); args.push('--sub-params', JSON.stringify(subParams));
} }
const { stdout } = execStrikerAccessDatabase(args, options); const { stdout } = execAnvilAccessModule(args, spawnSyncOptions);
return { return {
stdout: stdout['sub_results'], stdout: stdout['sub_results'],
@ -92,23 +104,22 @@ const dbJobAnvilSyncShared = (
console.log(JSON.stringify(subParams, null, 2)); console.log(JSON.stringify(subParams, null, 2));
return execDatabaseModuleSubroutine('insert_or_update_jobs', subParams) return execModuleSubroutine('insert_or_update_jobs', { subParams }).stdout;
.stdout;
}; };
const dbQuery = (query: string, options?: SpawnSyncOptions) => const dbQuery = (query: string, options?: SpawnSyncOptions) =>
execStrikerAccessDatabase(['--query', query], options); execAnvilAccessModule(['--query', query], options);
const dbSubRefreshTimestamp = () => const dbSubRefreshTimestamp = () =>
execDatabaseModuleSubroutine('refresh_timestamp').stdout; execModuleSubroutine('refresh_timestamp').stdout;
const dbWrite = (query: string, options?: SpawnSyncOptions) => const dbWrite = (query: string, options?: SpawnSyncOptions) =>
execStrikerAccessDatabase(['--query', query, '--mode', 'write'], options); execAnvilAccessModule(['--query', query, '--mode', 'write'], options);
export { export {
dbJobAnvilSyncShared, dbJobAnvilSyncShared,
dbQuery, dbQuery,
execDatabaseModuleSubroutine as dbSub, execModuleSubroutine as sub,
dbSubRefreshTimestamp, dbSubRefreshTimestamp,
dbWrite, dbWrite,
}; };

@ -12,7 +12,7 @@ const EMPTY_SERVER_PATHS: ServerPath = {
}, },
sbin: { sbin: {
'anvil-sync-shared': {}, 'anvil-sync-shared': {},
'striker-access-database': {}, 'anvil-access-module': {},
'striker-parse-os-list': {}, 'striker-parse-os-list': {},
}, },
}, },

@ -1,6 +1,6 @@
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import { dbQuery } from '../accessDB'; import { dbQuery } from '../accessModule';
import call from '../call'; import call from '../call';
const buildGetRequestHandler = const buildGetRequestHandler =

@ -5,7 +5,7 @@ import {
dbQuery, dbQuery,
dbSubRefreshTimestamp, dbSubRefreshTimestamp,
dbWrite, dbWrite,
} from '../lib/accessDB'; } from '../lib/accessModule';
import getFile from '../lib/request_handlers/file/getFile'; import getFile from '../lib/request_handlers/file/getFile';
import getFileDetail from '../lib/request_handlers/file/getFileDetail'; import getFileDetail from '../lib/request_handlers/file/getFileDetail';
import uploadSharedFiles from '../middlewares/uploadSharedFiles'; import uploadSharedFiles from '../middlewares/uploadSharedFiles';

Loading…
Cancel
Save