UNPKG

volxitcloud

Version:

CLI tool for VolxitCloud. See Volxit.com for more details.

38 lines 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Constants_1 = require("../utils/Constants"); const StorageHelper_1 = require("../utils/StorageHelper"); const ApiManager_1 = require("./ApiManager"); function hashCode(str) { let hash = 0; let i; let chr; if (str.length === 0) { return hash; } for (i = 0; i < str.length; i++) { chr = str.charCodeAt(i); hash = (hash << 5) - hash + chr; hash |= 0; // Convert to 32bit integer } return hash; } class CliApiManager { static get(volxMachine) { const hashKey = 'v' + hashCode(volxMachine.baseUrl); if (!CliApiManager.instances[hashKey]) { CliApiManager.instances[hashKey] = new ApiManager_1.default(volxMachine.baseUrl + Constants_1.default.BASE_API_PATH, volxMachine.appToken, function (token) { volxMachine.authToken = token; if (volxMachine.name) { StorageHelper_1.default.get().saveMachine(volxMachine); } return Promise.resolve(); }); } CliApiManager.instances[hashKey].setAuthToken(volxMachine.authToken); return CliApiManager.instances[hashKey]; } } exports.default = CliApiManager; CliApiManager.instances = {}; //# sourceMappingURL=CliApiManager.js.map