1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11 | }) : function(o, v) {
|
12 | o["default"] = v;
|
13 | });
|
14 | var __importStar = (this && this.__importStar) || function (mod) {
|
15 | if (mod && mod.__esModule) return mod;
|
16 | var result = {};
|
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18 | __setModuleDefault(result, mod);
|
19 | return result;
|
20 | };
|
21 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
22 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
23 | return new (P || (P = Promise))(function (resolve, reject) {
|
24 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
27 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
28 | });
|
29 | };
|
30 | Object.defineProperty(exports, "__esModule", { value: true });
|
31 | const bf_types_1 = require("bf-types");
|
32 | const system_1 = __importStar(require("../system"));
|
33 | function multitool() {
|
34 | let api = null;
|
35 | function getApi() {
|
36 | if (!api) {
|
37 | api = system_1.default.getLibModule(system_1.LibModule.API);
|
38 | }
|
39 | return api;
|
40 | }
|
41 | function executeCommand(command) {
|
42 | return __awaiter(this, void 0, void 0, function* () {
|
43 | const results = yield getApi().post('core/multitoolCommand/command/execute', {
|
44 | command,
|
45 | });
|
46 | if (!Array.isArray(results) || results.length < 1) {
|
47 | const result = {
|
48 | action: bf_types_1.MultitoolCommandAction.CREATED,
|
49 | result: bf_types_1.MultitoolCommandResult.FAILED,
|
50 | reason: 'no response was given',
|
51 | };
|
52 | return result;
|
53 | }
|
54 | return results[0];
|
55 | });
|
56 | }
|
57 | function executeCommands(commands) {
|
58 | return __awaiter(this, void 0, void 0, function* () {
|
59 | const results = yield getApi().post('core/multitoolCommand/command/execute', {
|
60 | command: commands.join('\n'),
|
61 | });
|
62 | if (!Array.isArray(results) || results.length < 1) {
|
63 | const result = {
|
64 | action: bf_types_1.MultitoolCommandAction.CREATED,
|
65 | result: bf_types_1.MultitoolCommandResult.FAILED,
|
66 | reason: 'no response was given',
|
67 | };
|
68 | return [result];
|
69 | }
|
70 | return results;
|
71 | });
|
72 | }
|
73 | function isCommandFailedResult(result) {
|
74 | return result.result === bf_types_1.MultitoolCommandResult.FAILED;
|
75 | }
|
76 | function isCommandSuccessResult(result) {
|
77 | return result.result === bf_types_1.MultitoolCommandResult.SUCCESS;
|
78 | }
|
79 | function runScript(script) {
|
80 | return getApi().post('core/multitoolCommand/script/run', {
|
81 | script,
|
82 | });
|
83 | }
|
84 | return Object.freeze({
|
85 | executeCommand,
|
86 | executeCommands,
|
87 | isCommandFailedResult,
|
88 | isCommandSuccessResult,
|
89 | runScript,
|
90 | });
|
91 | }
|
92 | exports.default = system_1.default.sealModule(multitool());
|