From 079720dae20315fbb6e1543e29609154ec56565c Mon Sep 17 00:00:00 2001 From: Ashesh <3626859+Ashesh3@users.noreply.github.com> Date: Fri, 15 Sep 2023 03:40:51 +0000 Subject: [PATCH 1/2] Remove camerasStatusBodyValidators --- src/Validators/cameraValidators.js | 24 +----------------------- src/router/cameraRouter.js | 2 -- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/src/Validators/cameraValidators.js b/src/Validators/cameraValidators.js index 28ecfdf..143ca35 100644 --- a/src/Validators/cameraValidators.js +++ b/src/Validators/cameraValidators.js @@ -46,29 +46,7 @@ export const baseGetCameraParamsValidators = [ .withMessage("port must be integer."), ]; -export const camerasStatusBodyValidators = [ - body().isArray().withMessage("body must be a valid array."), - body("*.hostname") - .exists({ checkFalsy: true }) - .withMessage("hostname is required.") - .isString() - .withMessage("hostname must be string."), - body("*.username") - .exists({ checkFalsy: true }) - .withMessage("username is required.") - .isString() - .withMessage("username must be string."), - body("*.password") - .exists({ checkFalsy: true }) - .withMessage("password is required.") - .isString() - .withMessage("password must be string."), - body("*.port") - .exists({ checkFalsy: true }) - .withMessage("port is required.") - .isInt() - .withMessage("port must be integer."), -]; + export const gotoPresetValidator = [ ...baseCameraParamsValidators, diff --git a/src/router/cameraRouter.js b/src/router/cameraRouter.js index 221be98..3f59e27 100644 --- a/src/router/cameraRouter.js +++ b/src/router/cameraRouter.js @@ -5,7 +5,6 @@ import { CameraController } from "../controller/CameraController.js"; import { validate } from "../middleware/validate.js"; import { baseCameraParamsValidators, - camerasStatusBodyValidators, setPresetValidators, baseGetCameraParamsValidators, camMoveValidator, @@ -34,7 +33,6 @@ router.get( router.post( "/cameras/status", - validate(camerasStatusBodyValidators), CameraController.getCameraStatuses ); From a9fd3d8fdac3537c5f88aa574b8a717abfc465bc Mon Sep 17 00:00:00 2001 From: Ashesh <3626859+Ashesh3@users.noreply.github.com> Date: Fri, 15 Sep 2023 04:07:06 +0000 Subject: [PATCH 2/2] Fix timeout --- src/Validators/cameraValidators.js | 2 -- src/utils/CameraUtils.js | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Validators/cameraValidators.js b/src/Validators/cameraValidators.js index 143ca35..9934158 100644 --- a/src/Validators/cameraValidators.js +++ b/src/Validators/cameraValidators.js @@ -46,8 +46,6 @@ export const baseGetCameraParamsValidators = [ .withMessage("port must be integer."), ]; - - export const gotoPresetValidator = [ ...baseCameraParamsValidators, body("preset") diff --git a/src/utils/CameraUtils.js b/src/utils/CameraUtils.js index bc916e2..0603c45 100644 --- a/src/utils/CameraUtils.js +++ b/src/utils/CameraUtils.js @@ -3,7 +3,7 @@ import * as onvif from "onvif"; const Cam = onvif.Cam; export class CameraUtils { - constructor() {} + constructor() { } static gotoPreset = async ({ camParams, preset }) => new Promise((resolve, reject) => { @@ -30,7 +30,7 @@ export class CameraUtils { static getStatus = async ({ camParams }) => new Promise( (resolve, reject) => - new Cam(camParams, function (err) { + new Cam({ ...camParams, timeout: 5000 }, function (err) { if (err) return reject(err); this.getStatus({}, (error, status) => { if (error) return reject(error); @@ -70,7 +70,7 @@ export class CameraUtils { new Cam(camParams, function (err) { if (err) return reject(err); try { - const result = this.setPreset({ presetName }, () => {}); + const result = this.setPreset({ presetName }, () => { }); resolve(result); } catch (error) { reject(error); @@ -78,7 +78,7 @@ export class CameraUtils { }); }); - static getSnapshotUri = async ({ camParams }) => + static getSnapshotUri = async ({ camParams }) => new Promise((resolve, reject) => { new Cam(camParams, function (err) { if (err) return reject(err); @@ -95,5 +95,5 @@ export class CameraUtils { - + }