From 26e326dd1dfa693d4e7a7a38ce1acba8a4c4c7ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=9A=E7=9A=93?= <1736436516@qq.com> Date: Fri, 18 Oct 2024 14:42:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=82=B9=E6=92=AD=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=93=8D=E5=BA=94=E6=8E=A7=E5=88=B6=E5=B1=82=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/boxApi.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/utils/boxApi.ts b/src/utils/boxApi.ts index 6125df8..ed8dfa0 100644 --- a/src/utils/boxApi.ts +++ b/src/utils/boxApi.ts @@ -14,6 +14,8 @@ class BoxApi { private readonly apiAlgorithms: string = "/algorithms"; private readonly apiResetUser: string = "/auth/resetuser"; private readonly apiResetPassword: string = "/auth/reset_password"; + private readonly getMinCamerasApi: string = "/camera/cameras/get_all"; + private readonly getMinCamera: string = "/camera/cameras"; private readonly loginConfig: object = { headers: { @@ -210,6 +212,48 @@ class BoxApi { return await this.getCamerasByUrl(url, token); } + public async getMinCameras(token: string | null = null): Promise { + const url = `${this.getMinCamerasApi}`; + try { + const res = await this.axios.get(url, this._authHeader(token)); + if (res.data.err.ec === 0) { + return res.data.ret; + } else { + throw new Error(res.data.err.msg); + } + } catch (error) { + throw error; + } + } + + public async startCameraStream(token: string | null = null, cameraId: number): Promise { + const url = `${this.getMinCamera}/${cameraId}/start_stream`; + try { + const res = await this.axios.post(url, this._authHeader(token)); + if (res.data.err.ec === 0) { + return res.data.ret; + } else { + throw new Error(res.data.err.msg); + } + } catch (error) { + throw error; + } + } + + public async stopCameraStream(token: string | null = null, cameraId: number): Promise { + const url = `${this.getMinCamera}/${cameraId}/stop_stream`; + try { + const res = await this.axios.post(url, this._authHeader(token)); + if (res.data.err.ec === 0) { + return res.data.ret; + } else { + throw new Error(res.data.err.dm); + } + } catch (error) { + throw error; + } + } + public async getEventsByUrl(url: string, token: string | null = null): Promise { try { const res = await this.axios.get(url, this._authHeader(token));