UNPKG

camstreamerlib

Version:

Helper library for CamStreamer ACAP applications.

61 lines (60 loc) 2.3 kB
import { responseStringify } from './internal/utils'; import { packageInfoListSchema, storageSchema, } from './types/CamScripterAPI'; import { networkCameraListSchema } from './types/common'; export class CamScripterAPI { client; constructor(client) { this.client = client; } async checkCameraTime() { return (await this.get('/local/camscripter/camera_time.cgi')).state; } async getStorageInfo() { const data = await this.get(`/local/camscripter/package/get_storage.cgi`); return storageSchema.parse(data); } async getNetworkCameraList() { const response = await this.get('/local/camscripter/network_camera_list.cgi'); return networkCameraListSchema.parse(response.camera_list); } async getPackageList() { const data = await this.get('/local/camscripter/package/list.cgi'); return packageInfoListSchema.parse(data); } async installPackages(formData, storage) { await this.post(`/local/camscripter/package/install.cgi?storage=${storage}`, formData); } async uninstallPackage(packageId) { await this.get(`/local/camscripter/package/remove.cgi?package_name=${packageId}`); } async importSettings(packageId, formData) { await this.post(`/local/camscripter/package/data.cgi?action=IMPORT&package_name=${packageId}`, formData); } async exportSettings(packageId, formData) { await this.post(`/local/camscripter/package/data.cgi?action=EXPORT&package_name=${packageId}`, formData); } async getNodejsStatus() { return (await this.get('/local/camscripter/diagnostics.cgi')).node_state; } async installNodejs(storage) { await this.get(`/local/camscripter/node_update.cgi?storage=${storage}`); } async get(path, params) { const res = await this.client.get(path, params); if (res.ok) { return await res.json(); } else { throw new Error(await responseStringify(res)); } } async post(path, data, params) { const res = await this.client.post(path, data, params); if (res.ok) { return await res.json(); } else { throw new Error(await responseStringify(res)); } } }