Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blink.js: Add null check in thumbnail loader to avoid process crash #137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/blink.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const STATUS_POLL = 30;
const ARMED_DELAY = 60; // 60s
const MOTION_TRIGGER_DECAY = 90; // 90s

// const OFFLINE_BYTES = fs.readFileSync(`${__dirname}/offline.png`);
const OFFLINE_BYTES = fs.readFileSync(`${__dirname}/offline.png`);
const PRIVACY_BYTES = fs.readFileSync(`${__dirname}/privacy.png`);
const DISABLED_BYTES = fs.readFileSync(`${__dirname}/disabled.png`);
const UNSUPPORTED_BYTES = fs.readFileSync(`${__dirname}/unsupported.png`);
Expand Down Expand Up @@ -303,18 +303,24 @@ class BlinkCamera extends BlinkDevice {

if (this.cacheThumbnail.has(thumbnailUrl)) return this.cacheThumbnail.get(thumbnailUrl);

// legacy thumbnails need a suffix of .jpg appended to the url
const data = await this.blink.getUrl(thumbnailUrl.replace(/\.jpg|$/, '.jpg'));
this.cacheThumbnail.clear(); // avoid memory from getting large
this.cacheThumbnail.set(thumbnailUrl, data);
return data;
if (thumbnailUrl) {
// legacy thumbnails need a suffix of .jpg appended to the url
const data = await this.blink.getUrl(thumbnailUrl.replace(/\.jpg|$/, '.jpg'));
this.cacheThumbnail.clear(); // avoid memory from getting large
this.cacheThumbnail.set(thumbnailUrl, data);
return data;
} else {
// If the thumbnailUrl is null, return a Camera offline image
return BlinkCamera.OFFLINE_BYTES
}
}

async getLiveViewURL(timeout = 30) {
const [data] = await this.blink.getCameraLiveView(this.networkID, this.cameraID, timeout);
return data?.server;
}
}
BlinkCamera.OFFLINE_BYTES = OFFLINE_BYTES;
BlinkCamera.PRIVACY_BYTES = PRIVACY_BYTES;
BlinkCamera.DISABLED_BYTES = DISABLED_BYTES;
BlinkCamera.UNSUPPORTED_BYTES = UNSUPPORTED_BYTES;
Expand Down