@mega-yfue/eufy-sdk 0.4.0-beta.13 → 0.4.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +23 -2
- package/dist/index.js.map +3 -3
- package/dist/transport/stored-image-cache.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24364,6 +24364,7 @@ var MEDIA_FAILURE_REASONS = [
|
|
|
24364
24364
|
// dist/transport/stored-image-cache.js
|
|
24365
24365
|
var MAX_JPEG_BYTES = 10 * 1024 * 1024;
|
|
24366
24366
|
var MAX_REMEMBERED_URLS = 64;
|
|
24367
|
+
var NOT_YET_PUBLISHED_RETRY_MS = [2e3, 4e3];
|
|
24367
24368
|
var DIAGNOSTIC_INTERVAL_MS = 6e4;
|
|
24368
24369
|
var StoredImageCache = class {
|
|
24369
24370
|
downloader;
|
|
@@ -24401,6 +24402,8 @@ var StoredImageCache = class {
|
|
|
24401
24402
|
if (state.seenUrls.has(url))
|
|
24402
24403
|
return;
|
|
24403
24404
|
state.seenUrls.add(url);
|
|
24405
|
+
clearTimeout(state.retrying);
|
|
24406
|
+
state.retrying = void 0;
|
|
24404
24407
|
while (state.seenUrls.size > MAX_REMEMBERED_URLS) {
|
|
24405
24408
|
const oldest = state.seenUrls.values().next();
|
|
24406
24409
|
if (oldest.done)
|
|
@@ -24412,14 +24415,15 @@ var StoredImageCache = class {
|
|
|
24412
24415
|
url,
|
|
24413
24416
|
sequence: ++state.nextSequence,
|
|
24414
24417
|
observedAt: this.clock(),
|
|
24415
|
-
generation: this.generation
|
|
24418
|
+
generation: this.generation,
|
|
24419
|
+
retries: 0
|
|
24416
24420
|
};
|
|
24417
24421
|
this.pump();
|
|
24418
24422
|
}
|
|
24419
24423
|
/** Return retained bytes without starting or awaiting network work. */
|
|
24420
24424
|
snapshotStored(deviceKey) {
|
|
24421
24425
|
const state = this.devices.get(deviceKey);
|
|
24422
|
-
const reason = state?.queued || state?.inFlight ? "pending" : state?.reason ?? "not-observed";
|
|
24426
|
+
const reason = state?.queued || state?.inFlight || state?.retrying ? "pending" : state?.reason ?? "not-observed";
|
|
24423
24427
|
if (reason !== "pending" && state?.lifecycleError)
|
|
24424
24428
|
return Promise.reject(state.lifecycleError);
|
|
24425
24429
|
if (state?.retained)
|
|
@@ -24453,6 +24457,8 @@ var StoredImageCache = class {
|
|
|
24453
24457
|
if (error !== void 0 && this.isLifecycleError(error)) {
|
|
24454
24458
|
state.lifecycleError = error;
|
|
24455
24459
|
state.reason = void 0;
|
|
24460
|
+
} else if (image === void 0 && this.retryLater(state, candidate, error)) {
|
|
24461
|
+
state.lifecycleError = void 0;
|
|
24456
24462
|
} else if (image === void 0) {
|
|
24457
24463
|
state.lifecycleError = void 0;
|
|
24458
24464
|
state.reason = "download-failed";
|
|
@@ -24469,6 +24475,21 @@ var StoredImageCache = class {
|
|
|
24469
24475
|
}
|
|
24470
24476
|
this.pump();
|
|
24471
24477
|
}
|
|
24478
|
+
/** Schedule the next attempt after a 404; answers whether one was scheduled. */
|
|
24479
|
+
retryLater(state, candidate, error) {
|
|
24480
|
+
const delay = NOT_YET_PUBLISHED_RETRY_MS[candidate.retries];
|
|
24481
|
+
const tag2 = mediaFailureTag(error);
|
|
24482
|
+
if (delay === void 0 || tag2.cause !== "http-status" || tag2.status !== 404 || state.queued)
|
|
24483
|
+
return false;
|
|
24484
|
+
const timer = setTimeout(() => {
|
|
24485
|
+
state.retrying = void 0;
|
|
24486
|
+
state.queued = { ...candidate, retries: candidate.retries + 1 };
|
|
24487
|
+
this.pump();
|
|
24488
|
+
}, delay);
|
|
24489
|
+
timer.unref?.();
|
|
24490
|
+
state.retrying = timer;
|
|
24491
|
+
return true;
|
|
24492
|
+
}
|
|
24472
24493
|
isValidJpeg(image) {
|
|
24473
24494
|
return Buffer.isBuffer(image) && image.length > 0 && image.length <= MAX_JPEG_BYTES && image.length >= 5 && image[0] === 255 && image[1] === 216 && image[2] === 255 && image[image.length - 2] === 255 && image[image.length - 1] === 217;
|
|
24474
24495
|
}
|