From ec19410e0c2fce757eab6902f128f401b66e3b15 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Tue, 5 Mar 2024 08:44:50 -0800 Subject: [PATCH] snapshot: enforce a 5s timeout for web requests --- plugins/snapshot/package-lock.json | 20 +++++++++----------- plugins/snapshot/package.json | 2 +- plugins/snapshot/src/main.ts | 7 ++++++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/plugins/snapshot/package-lock.json b/plugins/snapshot/package-lock.json index dd12f191f..7a6cc6d24 100644 --- a/plugins/snapshot/package-lock.json +++ b/plugins/snapshot/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/snapshot", - "version": "0.2.38", + "version": "0.2.39", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/snapshot", - "version": "0.2.38", + "version": "0.2.39", "dependencies": { "@types/node": "^20.10.6", "sharp": "^0.33.1", @@ -26,24 +26,23 @@ "dependencies": { "@scrypted/sdk": "file:../sdk", "@scrypted/server": "file:../server", - "http-auth-utils": "^3.0.2", - "node-fetch-commonjs": "^3.1.1", + "http-auth-utils": "^5.0.1", "typescript": "^5.3.3" }, "devDependencies": { - "@types/node": "^20.10.8", + "@types/node": "^20.11.0", "ts-node": "^10.9.2" } }, "../../sdk": { "name": "@scrypted/sdk", - "version": "0.3.4", + "version": "0.3.14", "dev": true, "license": "ISC", "dependencies": { "@babel/preset-typescript": "^7.18.6", "adm-zip": "^0.4.13", - "axios": "^0.21.4", + "axios": "^1.6.5", "babel-loader": "^9.1.0", "babel-plugin-const-enum": "^1.1.0", "esbuild": "^0.15.9", @@ -838,9 +837,8 @@ "requires": { "@scrypted/sdk": "file:../sdk", "@scrypted/server": "file:../server", - "@types/node": "^20.10.8", - "http-auth-utils": "^3.0.2", - "node-fetch-commonjs": "^3.1.1", + "@types/node": "^20.11.0", + "http-auth-utils": "^5.0.1", "ts-node": "^10.9.2", "typescript": "^5.3.3" } @@ -852,7 +850,7 @@ "@types/node": "^18.11.18", "@types/stringify-object": "^4.0.0", "adm-zip": "^0.4.13", - "axios": "^0.21.4", + "axios": "^1.6.5", "babel-loader": "^9.1.0", "babel-plugin-const-enum": "^1.1.0", "esbuild": "^0.15.9", diff --git a/plugins/snapshot/package.json b/plugins/snapshot/package.json index 191b4691f..cef864145 100644 --- a/plugins/snapshot/package.json +++ b/plugins/snapshot/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/snapshot", - "version": "0.2.38", + "version": "0.2.39", "description": "Snapshot Plugin for Scrypted", "scripts": { "scrypted-setup-project": "scrypted-setup-project", diff --git a/plugins/snapshot/src/main.ts b/plugins/snapshot/src/main.ts index 1c4f9facc..dcbc6ca7f 100644 --- a/plugins/snapshot/src/main.ts +++ b/plugins/snapshot/src/main.ts @@ -291,7 +291,7 @@ class SnapshotMixin extends SettingsMixinDeviceBase implements Camera { // the debounce has already triggered a refresh for the next go around. if (periodicSnapshot && this.currentPicture) { const cp = this.currentPicture; - debounced.catch(() => {}); + debounced.catch(() => { }); try { picture = await (options.timeout ? timeoutPromise(options.timeout, debounced) : debounced); } @@ -682,8 +682,13 @@ export class SnapshotPlugin extends AutoenableMixinProvider implements MixinProv const search = new URLSearchParams(pathname.split('?')[1]); const mixin = this.mixinDevices.get(id); let buffer: Buffer; + let timeout = parseInt(search.get('timeout')); + // make web requests timeout after 5 seconds by default. + if (isNaN(timeout)) + timeout = 5000; const rpo: RequestPictureOptions = { reason: search.get('reason') as 'event' | 'periodic', + timeout, picture: { width: parseInt(search.get('width')) || undefined, height: parseInt(search.get('height')) || undefined,