camstreamerlib
Version:
Helper library for CamStreamer ACAP applications.
55 lines (54 loc) • 2.48 kB
JavaScript
import { BasicAPI } from './internal/BasicAPI';
import { cameraTimeResponseSchema, nodeStateSchema, packageInfoListSchema, cameraStorageSchema, } from './types/CamScripterAPI';
import { networkCameraListSchema } from './types/common';
const BASE_PATH = '/local/camscripter';
export class CamScripterAPI extends BasicAPI {
static getProxyPath = () => `${BASE_PATH}/proxy.cgi`;
async checkAPIAvailable(options) {
await this._getJson(`${BASE_PATH}/api_check.cgi`, undefined, options);
}
async checkCameraTime(options) {
const res = await this._getJson(`${BASE_PATH}/camera_time.cgi`, undefined, options);
return cameraTimeResponseSchema.parse(res).state;
}
async getNetworkCameraList(options) {
const res = await this._getJson(`${BASE_PATH}/network_camera_list.cgi`, undefined, options);
return networkCameraListSchema.parse(res.camera_list);
}
async getStorageInfo(options) {
const res = await this._getJson(`${BASE_PATH}/package/get_storage.cgi`, undefined, options);
return cameraStorageSchema.parse(res);
}
async getPackageList(options) {
const res = await this._getJson(`${BASE_PATH}/package/list.cgi`, undefined, options);
return 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 nodeStateSchema.parse(res);
}
async installNodejs(storage, options) {
await this._getJson(`${BASE_PATH}/node_update.cgi`, { storage: storage }, options);
}
downloadReport(options) {
return this._getText(`${BASE_PATH}/report.cgi`, undefined, options);
}
}