feat: Add SvelteKit web app with scan sessions and import queue

Replaces the Flask/Alpine web app with a SvelteKit 2 + Svelte 5 rewrite
under web/, built on adapter-node and Tailwind v4. Same shape as the
reference b4l budget app — no auth, stateless pass-through to InvenTree.

New "scan session" flow groups mass scans into a session with live
counters (scanned / succeeded / pending / failed). Unknown parts in
import mode are fed to a worker pool that spawns inventree-part-import
(IMPORT_CONCURRENCY, default 3, with 3-retry). Anything that can't be
resolved automatically — parse errors, missing qty, invalid location,
API errors, or imports that exhaust retries — drops into a Failures
panel with a per-item Fix dialog (edit fields / search existing part /
retry import). CSV export on the failure list.

Layout is two-column on lg+: scanner + activity on the left, pending
imports + failures on the right. Light-theme default. SSE on
/api/events streams session and import events to the client.

Barcode parser ported from the Python/JS versions and hardened for
Digi-Key MH10.8.2 barcodes both with and without GS separators (old
parser greedy-matched Q's digits and read "Q6" + "11ZPICK" as 611).
Import worker also now treats a subprocess failure followed by a
successful findPart as a success, so partial imports (part created but
a duplicate parameter trips the DB constraint) no longer land in the
Failures panel.

Deploy artifacts: systemd unit, nginx example (SSE-friendly), and a
step-by-step deploy/README. Requires inventree-part-import >= 1.9.2 on
the server for InvenTree 1.x API compatibility.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-22 15:58:57 +07:00
parent ed9a3307ef
commit 379ed232df
50 changed files with 5517 additions and 1 deletions
+94
View File
@@ -0,0 +1,94 @@
import { parseScan } from '../src/lib/barcode.ts';
const GS = '\x1D';
const RS = '\x1E';
// User's Digi-Key barcode as the scanner actually delivers it (with GS between
// fields and the RS format-envelope after `[)>`).
const digiKey = [
'[)>',
RS,
'06',
GS,
'P2073-USB1035-GF-P-0-B-B-ND',
GS,
'1PUSB1035-GF-P-0-B-B',
GS,
'30P2073-USB1035-GF-P-0-B-B-ND',
GS,
'K',
GS,
'1K9867254010',
GS,
'10K1242607169',
GS,
'D25511',
GS,
'T251215-501',
GS,
'11K1',
GS,
'4LCN',
GS,
'Q6',
GS,
'11ZPICK',
GS,
'12Z1064967213',
GS,
'13Z9999992',
GS,
'20Z' + '0'.repeat(55)
].join('');
const cases = [
{
name: "Digi-Key MH10.8.2 with GS separators (qty=6)",
raw: digiKey,
expected: { partCode: '2073-USB1035-GF-P-0-B-B-ND', quantity: 6 }
},
{
name: "same barcode but scanner stripped all separators (fallback)",
raw: '[)>06P2073-USB1035-GF-P-0-B-B-ND1PUSB1035-GF-P-0-B-B30P2073-USB1035-GF-P-0-B-B-NDK1K9867254010K1242607169D25511T251215-50111K14LCNQ611ZPICK12Z1064967213Z99999920Z0000000000000000000000000000000000000000000000000000000',
expected: { partCode: '2073-USB1035-GF-P-0-B-B-ND', quantity: 6 }
},
{
name: 'GS-separated without MH10.8.2 envelope',
raw: `30PABC${GS}Q15`,
expected: { partCode: 'ABC', quantity: 15 }
},
{
name: 'Quantity legitimately 611 before 11Z (fallback path)',
raw: '[)>06PABC1PXYZQ61111ZPICK',
expected: { partCode: 'ABC', quantity: 611 }
},
{
name: 'MH10.8.2 with separators, only 1P present',
raw: `[)>06${GS}1PMYPART${GS}Q42`,
expected: { partCode: 'MYPART', quantity: 42 }
},
{
name: 'JSON-like',
raw: '{PM:WIDGET-42,QTY:7}',
expected: { partCode: 'WIDGET-42', quantity: 7 }
}
];
let pass = 0;
let fail = 0;
for (const c of cases) {
const got = parseScan(c.raw);
const ok =
got.partCode === c.expected.partCode && got.quantity === c.expected.quantity;
if (ok) {
pass++;
console.log(`ok ${c.name}`);
} else {
fail++;
console.log(`FAIL ${c.name}`);
console.log(` got ${JSON.stringify(got)}`);
console.log(` expected ${JSON.stringify(c.expected)}`);
}
}
console.log(`\n${pass}/${pass + fail} pass`);
process.exit(fail ? 1 : 0);