hh-shipments 0.3.15 → 0.3.16
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/package.json +1 -1
- package/public/app.js +18 -12
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -175,6 +175,7 @@ async function ocrFile(file, statusEl) {
|
|
|
175
175
|
async function handlePhotoFile(f) {
|
|
176
176
|
const target = $('photo-result');
|
|
177
177
|
try {
|
|
178
|
+
const orig = f;
|
|
178
179
|
f = await shrinkImage(f);
|
|
179
180
|
const url = URL.createObjectURL(f);
|
|
180
181
|
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>`;
|
|
@@ -188,7 +189,7 @@ async function handlePhotoFile(f) {
|
|
|
188
189
|
fd.append('image', f);
|
|
189
190
|
const upPromise = fetchTimeout('/api/intake/image', { method: 'POST', body: fd }, 60000)
|
|
190
191
|
.catch(() => { throw new Error('upload timed out — check your connection and try again'); });
|
|
191
|
-
topText = await ocrTopStrip(
|
|
192
|
+
topText = await ocrTopStrip(orig, $('ocr-status'));
|
|
192
193
|
const up = await upPromise;
|
|
193
194
|
if (!up.ok) throw new Error('upload failed');
|
|
194
195
|
preset = topText ? { labelText: topText } : undefined;
|
|
@@ -275,17 +276,21 @@ function loadZxing() {
|
|
|
275
276
|
}
|
|
276
277
|
|
|
277
278
|
// OCR just the top strip of a label (sender block) for the seller name.
|
|
278
|
-
//
|
|
279
|
-
|
|
279
|
+
// Works from the ORIGINAL full-resolution image, upscaled — small text
|
|
280
|
+
// reads far better than on the shrunk copy. Returns text or null.
|
|
281
|
+
async function ocrTopStrip(origFile, statusEl) {
|
|
280
282
|
try {
|
|
281
|
-
const bmp = await createImageBitmap(
|
|
282
|
-
const sh = Math.max(60, Math.round(bmp.height * 0.
|
|
283
|
+
const bmp = await createImageBitmap(origFile);
|
|
284
|
+
const sw = bmp.width, sh = Math.max(60, Math.round(bmp.height * 0.35));
|
|
285
|
+
const targetW = 1400, scale = targetW / sw;
|
|
283
286
|
const canvas = document.createElement('canvas');
|
|
284
|
-
canvas.width =
|
|
285
|
-
canvas.height = sh;
|
|
286
|
-
canvas.getContext('2d')
|
|
287
|
+
canvas.width = targetW;
|
|
288
|
+
canvas.height = Math.max(60, Math.round(sh * scale));
|
|
289
|
+
const ctx = canvas.getContext('2d');
|
|
290
|
+
ctx.imageSmoothingEnabled = true;
|
|
291
|
+
ctx.drawImage(bmp, 0, 0, sw, sh, 0, 0, targetW, canvas.height);
|
|
287
292
|
bmp.close();
|
|
288
|
-
const blob = await new Promise((res) => canvas.toBlob(res, 'image/jpeg', 0.
|
|
293
|
+
const blob = await new Promise((res) => canvas.toBlob(res, 'image/jpeg', 0.92));
|
|
289
294
|
if (!blob) return null;
|
|
290
295
|
const p = ocrFile(new File([blob], 'top.jpg', { type: 'image/jpeg' }), statusEl);
|
|
291
296
|
return await Promise.race([p, new Promise((_, rej) => setTimeout(() => rej(new Error('top-strip timeout')), 25000))]);
|
|
@@ -355,6 +360,7 @@ async function handlePastedImageFile(f) {
|
|
|
355
360
|
const target = $('quick-result');
|
|
356
361
|
try {
|
|
357
362
|
// Instant feedback: show a thumbnail + progress the moment the image lands
|
|
363
|
+
const orig = f;
|
|
358
364
|
f = await shrinkImage(f);
|
|
359
365
|
const url = URL.createObjectURL(f);
|
|
360
366
|
target.innerHTML = `<div class="review"><img src="${url}" style="max-width:100%;border-radius:10px"><p class="muted" id="ocr-live">📷 Scanning barcode…</p></div>`;
|
|
@@ -365,13 +371,13 @@ async function handlePastedImageFile(f) {
|
|
|
365
371
|
if (barcode) {
|
|
366
372
|
text = barcode;
|
|
367
373
|
if (live) live.textContent = '📷 Barcode read — reading sender…';
|
|
368
|
-
// Number is verified; OCR
|
|
369
|
-
// name, in parallel with the upload.
|
|
374
|
+
// Number is verified; OCR the top strip of the ORIGINAL full-res
|
|
375
|
+
// image (sender block) for the name, in parallel with the upload.
|
|
370
376
|
const fd = new FormData();
|
|
371
377
|
fd.append('image', f);
|
|
372
378
|
const upPromise = fetchTimeout('/api/intake/image', { method: 'POST', body: fd }, 60000)
|
|
373
379
|
.catch(() => { throw new Error('upload timed out — check your connection and try again'); });
|
|
374
|
-
const topText = await ocrTopStrip(
|
|
380
|
+
const topText = await ocrTopStrip(orig, $('ocr-status-paste'));
|
|
375
381
|
const up = await upPromise;
|
|
376
382
|
if (!up.ok) throw new Error('upload failed');
|
|
377
383
|
if (live) live.textContent = '🔍 Finding tracking number…';
|