hh-shipments 0.3.14 → 0.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/app.js +13 -2
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "test": "node test/run-tests.js && node test/run-carriers-tests.js"
19
19
  },
20
20
  "type": "commonjs",
21
- "version": "0.3.14",
21
+ "version": "0.3.15",
22
22
  "bin": {
23
23
  "hh-shipments": "server.js"
24
24
  },
package/public/app.js CHANGED
@@ -180,7 +180,7 @@ async function handlePhotoFile(f) {
180
180
  target.innerHTML = `<div class="review"><img src="${url}" style="max-width:100%;border-radius:10px"><p class="muted" id="ocr-live-photo">📷 Scanning barcode…</p></div>`;
181
181
  const live = $('ocr-live-photo');
182
182
  const barcode = await decodeBarcode(f);
183
- let text, preset;
183
+ let text, preset, topText = null;
184
184
  if (barcode) {
185
185
  text = barcode;
186
186
  if (live) live.textContent = '📷 Barcode read — reading sender…';
@@ -188,7 +188,7 @@ async function handlePhotoFile(f) {
188
188
  fd.append('image', f);
189
189
  const upPromise = fetchTimeout('/api/intake/image', { method: 'POST', body: fd }, 60000)
190
190
  .catch(() => { throw new Error('upload timed out — check your connection and try again'); });
191
- const topText = await ocrTopStrip(f, $('ocr-status'));
191
+ topText = await ocrTopStrip(f, $('ocr-status'));
192
192
  const up = await upPromise;
193
193
  if (!up.ok) throw new Error('upload failed');
194
194
  preset = topText ? { labelText: topText } : undefined;
@@ -204,6 +204,7 @@ async function handlePhotoFile(f) {
204
204
  if (!up.ok) throw new Error('upload failed');
205
205
  }
206
206
  const r = await runQuick(text, $('photo-result'), preset);
207
+ if (looksLikeAppScreenshot(topText || text)) $('photo-result').insertAdjacentHTML('afterbegin', '<p class="warn">⚠️ This looks like a screenshot of the app itself — choose the label photo directly for best results.</p>');
207
208
  if (barcode && r && r.added.length) $('photo-result').insertAdjacentHTML('afterbegin', '<p class="muted">📷 Read from the barcode — checksum verified.</p>');
208
209
  if (r && !r.added.length && !r.needs_review.length && !r.duplicates.length) showOcrRead($('photo-result'), text);
209
210
  loadPending();
@@ -342,6 +343,14 @@ async function decodeBarcode(file) {
342
343
  } finally { bmp.close(); }
343
344
  return null;
344
345
  }
346
+ // Detect when the pasted image is a screenshot OF THE APP itself (its own
347
+ // header/buttons/tab bar get OCR'd) — the label inside is too small to read
348
+ // well, and UI words pollute the results.
349
+ function looksLikeAppScreenshot(text) {
350
+ const t = String(text || '').toLowerCase();
351
+ return /paste a screenshot|extract from text|finding tracking number|reading screenshot|mark received|open carrier tracking|hh shipments/.test(t);
352
+ }
353
+
345
354
  async function handlePastedImageFile(f) {
346
355
  const target = $('quick-result');
347
356
  try {
@@ -367,6 +376,7 @@ async function handlePastedImageFile(f) {
367
376
  if (!up.ok) throw new Error('upload failed');
368
377
  if (live) live.textContent = '🔍 Finding tracking number…';
369
378
  const r = await runQuick(text, target, topText ? { labelText: topText } : undefined);
379
+ if (looksLikeAppScreenshot(topText)) target.insertAdjacentHTML('afterbegin', '<p class="warn">⚠️ This looks like a screenshot of the app itself — paste the label photo directly for best results.</p>');
370
380
  if (r && r.added.length) target.insertAdjacentHTML('afterbegin', '<p class="muted">📷 Read from the barcode — checksum verified.</p>');
371
381
  if (r && !r.added.length && !r.needs_review.length && !r.duplicates.length) showOcrRead(target, text);
372
382
  return;
@@ -383,6 +393,7 @@ async function handlePastedImageFile(f) {
383
393
  if (!up.ok) throw new Error('upload failed');
384
394
  if (live) live.textContent = '🔍 Finding tracking number…';
385
395
  const r = await runQuick(text, target);
396
+ if (looksLikeAppScreenshot(text)) target.insertAdjacentHTML('afterbegin', '<p class="warn">⚠️ This looks like a screenshot of the app itself — paste the label photo directly for best results.</p>');
386
397
  if (r && !r.added.length && !r.needs_review.length && !r.duplicates.length) showOcrRead(target, text);
387
398
  } catch (err) { $('ocr-status-paste').textContent = ''; target.innerHTML = `<p class="error">${esc(err.message)}</p>`; }
388
399
  }