Skip to content

Commit

Permalink
Merge pull request #99 from Ashesh3/camera-status-remove-validation
Browse files Browse the repository at this point in the history
Remove camerasStatusBodyValidators and fix timeout
  • Loading branch information
mathew-alex authored Sep 15, 2023
2 parents 0b86577 + a9fd3d8 commit c409186
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
24 changes: 0 additions & 24 deletions src/Validators/cameraValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,6 @@ 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,
body("preset")
Expand Down
2 changes: 0 additions & 2 deletions src/router/cameraRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { CameraController } from "../controller/CameraController.js";
import { validate } from "../middleware/validate.js";
import {
baseCameraParamsValidators,
camerasStatusBodyValidators,
setPresetValidators,
baseGetCameraParamsValidators,
camMoveValidator,
Expand Down Expand Up @@ -34,7 +33,6 @@ router.get(

router.post(
"/cameras/status",
validate(camerasStatusBodyValidators),
CameraController.getCameraStatuses
);

Expand Down
10 changes: 5 additions & 5 deletions src/utils/CameraUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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);
Expand Down Expand Up @@ -70,15 +70,15 @@ 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);
}
});
});

static getSnapshotUri = async ({ camParams }) =>
static getSnapshotUri = async ({ camParams }) =>
new Promise((resolve, reject) => {
new Cam(camParams, function (err) {
if (err) return reject(err);
Expand All @@ -95,5 +95,5 @@ export class CameraUtils {




}

0 comments on commit c409186

Please sign in to comment.