@apocaliss92/scrypted-reolink-native 0.2.14 → 0.2.15

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/plugin.zip CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apocaliss92/scrypted-reolink-native",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "Use any reolink camera with Scrypted, even older/unsupported models without HTTP protocol support",
5
5
  "author": "@apocaliss92",
6
6
  "license": "Apache",
package/src/main.ts CHANGED
@@ -32,6 +32,7 @@ class ReolinkNativePlugin extends ScryptedDeviceBase implements DeviceProvider,
32
32
  nvrDeviceId: string;
33
33
  private thumbnailQueue: ThumbnailRequest[] = [];
34
34
  private thumbnailProcessing = false;
35
+ private thumbnailPendingRequests = new Map<string, Promise<MediaObject>>();
35
36
 
36
37
  constructor(nativeId: string) {
37
38
  super(nativeId);
@@ -340,12 +341,23 @@ class ReolinkNativePlugin extends ScryptedDeviceBase implements DeviceProvider,
340
341
  * Add a thumbnail generation request to the queue
341
342
  */
342
343
  async generateThumbnail(request: ThumbnailRequestInput): Promise<MediaObject> {
344
+ // Create a unique key for this request (deviceId:fileId)
345
+ const requestKey = `${request.deviceId}:${request.fileId}`;
346
+
347
+ // Check if this thumbnail is already in queue or being processed
348
+ const existingRequest = this.thumbnailPendingRequests.get(requestKey);
349
+ if (existingRequest) {
350
+ const logger = request.device?.getBaichuanLogger?.() || request.logger || console;
351
+ logger.debug(`[Thumbnail] Request already in queue: fileId=${request.fileId}, reusing existing promise`);
352
+ return existingRequest;
353
+ }
354
+
343
355
  const queueLength = this.thumbnailQueue.length;
344
356
  // Use device logger if available, otherwise fallback to provided logger
345
357
  const logger = request.device?.getBaichuanLogger?.() || request.logger || console;
346
358
  logger.log(`[Thumbnail] Download start: fileId=${request.fileId}, queuePosition=${queueLength + 1}`);
347
359
 
348
- return new Promise((resolve, reject) => {
360
+ const promise = new Promise<MediaObject>((resolve, reject) => {
349
361
  this.thumbnailQueue.push({
350
362
  ...request,
351
363
  resolve,
@@ -353,6 +365,16 @@ class ReolinkNativePlugin extends ScryptedDeviceBase implements DeviceProvider,
353
365
  });
354
366
  this.processThumbnailQueue();
355
367
  });
368
+
369
+ // Track this request
370
+ this.thumbnailPendingRequests.set(requestKey, promise);
371
+
372
+ // Remove from tracking when the promise resolves or rejects
373
+ promise.finally(() => {
374
+ this.thumbnailPendingRequests.delete(requestKey);
375
+ });
376
+
377
+ return promise;
356
378
  }
357
379
 
358
380
  /**