UNPKG

camstreamerlib

Version:

Helper library for CamStreamer ACAP applications.

81 lines (80 loc) 3.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CamScripterAPI = void 0; const errors_1 = require("./errors/errors"); const ProxyClient_1 = require("./internal/ProxyClient"); const CamScripterAPI_1 = require("./types/CamScripterAPI"); const common_1 = require("./types/common"); const BASE_PATH = '/local/camscripter'; class CamScripterAPI { client; constructor(client) { this.client = client; } static getProxyPath = () => `${BASE_PATH}/proxy.cgi`; getClient(proxyParams) { return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client; } async checkCameraTime(options) { const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options); return CamScripterAPI_1.cameraTimeResponseSchema.parse(res).state; } async getNetworkCameraList(options) { const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options); return common_1.networkCameraListSchema.parse(res.camera_list); } async getStorageInfo(options) { const res = await this._getJson(`${BASE_PATH}/package/get_storage.cgi`, undefined, options); return CamScripterAPI_1.cameraStorageSchema.parse(res); } async getPackageList(options) { const res = await this._getJson(`${BASE_PATH}/package/list.cgi`, undefined, options); return CamScripterAPI_1.packageInfoListSchema.parse(res); } async installPackages(formData, storage, options) { await this._post(`${BASE_PATH}/package/install.cgi`, formData, { storage: storage }, options); } async uninstallPackage(packageId, options) { await this._getJson(`${BASE_PATH}/package/remove.cgi`, { package_name: packageId }, options); } async importSettings(packageId, formData, options) { await this._post(`${BASE_PATH}/package/data.cgi`, formData, { action: 'IMPORT', package_name: packageId, }, options); } async exportSettings(packageId, formData, options) { await this._post(`${BASE_PATH}/package/data.cgi`, formData, { action: 'EXPORT', package_name: packageId, }, options); } async getNodejsStatus(options) { const res = await this._getJson(`${BASE_PATH}/diagnostics.cgi`, undefined, options); return CamScripterAPI_1.nodeStateSchema.parse(res); } async installNodejs(storage, options) { await this._getJson(`${BASE_PATH}/node_update.cgi`, { storage: storage }, options); } async _getJson(path, parameters, options) { const agent = this.getClient(options?.proxyParams); const res = await agent.get({ path, parameters, timeout: options?.timeout }); if (res.ok) { return await res.json(); } else { throw new errors_1.ErrorWithResponse(res); } } async _post(path, data, parameters, options, headers) { const agent = this.getClient(options?.proxyParams); const res = await agent.post({ path, data, parameters, headers, timeout: options?.timeout }); if (res.ok) { return await res.json(); } else { throw new errors_1.ErrorWithResponse(res); } } } exports.CamScripterAPI = CamScripterAPI;