scrypted-detection-trainer 0.1.13 → 0.1.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/plugin.zip CHANGED
Binary file
@@ -1794,11 +1794,11 @@ class DetectionTrainer extends sdk_1.ScryptedDeviceBase {
1794
1794
  const url = new URL(request.url, 'http://localhost');
1795
1795
  const path = url.pathname.replace(request.rootPath, '');
1796
1796
  // Serve browse event image via getVideoClipThumbnail
1797
- if (path === '/api/browse-img') {
1798
- const params = new URL(request.url, 'http://localhost').searchParams;
1799
- const cameraId = params.get('cameraId')?.replace(/[^a-zA-Z0-9_\-]/g, '');
1800
- const thumbnailId = params.get('thumbnailId')?.replace(/[^a-zA-Z0-9_\-:.]/g, '');
1801
- if (!cameraId || !thumbnailId)
1797
+ if (path === '/api/browse-img' && request.body) {
1798
+ const rawBody = request.body;
1799
+ const body = JSON.parse(typeof rawBody === 'string' ? rawBody : Buffer.isBuffer(rawBody) ? rawBody.toString() : String(rawBody));
1800
+ const { cameraId, thumbnailId } = body;
1801
+ if (!cameraId || thumbnailId === undefined)
1802
1802
  return response.send('Missing params', { code: 400 });
1803
1803
  try {
1804
1804
  const cam = systemManager.getDeviceById(cameraId);
@@ -1860,9 +1860,10 @@ class DetectionTrainer extends sdk_1.ScryptedDeviceBase {
1860
1860
  const endTime = Date.now();
1861
1861
  const startTime = endTime - hours * 3600 * 1000;
1862
1862
  const clips = await cam.getVideoClips({ startTime, endTime });
1863
+ const limit = parseInt(params.get('limit') || '100');
1863
1864
  const events = (clips || [])
1864
1865
  .filter((c) => c.detectionClasses?.length && c.thumbnailId)
1865
- .slice(0, 100)
1866
+ .slice(0, limit)
1866
1867
  .map((c) => ({
1867
1868
  clipId: c.id,
1868
1869
  thumbnailId: c.thumbnailId,
@@ -2127,6 +2128,12 @@ class DetectionTrainer extends sdk_1.ScryptedDeviceBase {
2127
2128
  <option value="24" selected>Last 24 hours</option>
2128
2129
  <option value="72">Last 3 days</option>
2129
2130
  </select>
2131
+ <select id="browse-limit" style="padding:8px 12px;background:#222;border:1px solid #444;color:#fff;border-radius:6px;font-size:13px;">
2132
+ <option value="50">50 events</option>
2133
+ <option value="100" selected>100 events</option>
2134
+ <option value="250">250 events</option>
2135
+ <option value="500">500 events</option>
2136
+ </select>
2130
2137
  <button class="export-btn" onclick="loadBrowse()" style="padding:8px 16px;">Load Events</button>
2131
2138
  <span id="browse-status" style="font-size:13px;color:#888;"></span>
2132
2139
  </div>
@@ -2346,6 +2353,7 @@ let browseEvents = [];
2346
2353
  async function loadBrowse() {
2347
2354
  const cameraId = document.getElementById('browse-camera').value;
2348
2355
  const hours = document.getElementById('browse-hours').value;
2356
+ const limit = document.getElementById('browse-limit').value;
2349
2357
  const status = document.getElementById('browse-status');
2350
2358
  const list = document.getElementById('browse-list');
2351
2359
 
@@ -2356,7 +2364,7 @@ async function loadBrowse() {
2356
2364
  browseEvents = [];
2357
2365
 
2358
2366
  try {
2359
- const res = await fetch(BASE + '/api/browse?cameraId=' + cameraId + '&hours=' + hours);
2367
+ const res = await fetch(BASE + '/api/browse?cameraId=' + cameraId + '&hours=' + hours + '&limit=' + limit);
2360
2368
  const events = await res.json();
2361
2369
 
2362
2370
  if (events.error) { status.textContent = 'Error: ' + events.error; return; }
@@ -2416,7 +2424,11 @@ async function loadBrowse() {
2416
2424
  }
2417
2425
 
2418
2426
  function loadBrowseImage(i, ev) {
2419
- fetch(BASE + '/api/browse-img?cameraId=' + ev.cameraId + '&thumbnailId=' + encodeURIComponent(ev.thumbnailId))
2427
+ fetch(BASE + '/api/browse-img', {
2428
+ method: 'POST',
2429
+ headers: { 'Content-Type': 'application/json' },
2430
+ body: JSON.stringify({ cameraId: ev.cameraId, thumbnailId: ev.thumbnailId }),
2431
+ })
2420
2432
  .then(r => r.ok ? r.blob() : null)
2421
2433
  .then(blob => {
2422
2434
  if (!blob) return;