Add barcode and nutrition label scanning
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m2s

Barcode scanning
- Scan barcode in the food sheet reads UPC-A/E and EAN-13/8 live from
  the camera with ZXing WebAssembly (bundled, precached, CSP allows
  wasm), with photo and typed-digit fallbacks
- Lookups check saved foods first (offline), then local copies of USDA
  FoodData Central Branded Foods and Open Food Facts, then the live
  Open Food Facts API; API answers and misses are cached
- Server imports refresh in a low-priority child process: USDA when a
  new archive is published, Open Food Facts weekly by streaming its CSV
  export; each import builds a new table and swaps it in atomically
- Every available nutrient is kept: foods and entries gain optional
  barcode (GTIN-14) and extra nutrients, shown under More nutrients and
  included in JSON exports
- Settings shows the size, date and any error for each product copy

Label scanning
- Scan label sends a downscaled photo to the server, read with
  PaddleOCR PP-OCRv5 (server detection, English recognition) on ONNX
  Runtime CPU, about 1.3 s median
- Parser handles US/Canadian, linear, Spanish and EU per-100 g panels,
  tilted photos, OCR misspellings and %DV cross-checks
- Models are pinned and checksum-verified at image build time

Container
- Runtime moves to Debian slim for ONNX Runtime's glibc build; other
  platforms' binaries are pruned
- Smoke tests now read a fixture label inside the container
- README and Unraid docs cover disk use, network access and refresh

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-10-22 13:41:44 -07:00
parent 8f6981c8a2
commit 80fc48b9f1
39 changed files with 4434 additions and 33 deletions

View file

@ -11,11 +11,12 @@ import {
Moon,
Monitor,
ArrowUpRight,
ScanBarcode,
} from "lucide-react";
import type { JournalRecord, Metric, Settings as SettingsData } from "./types";
import { metrics } from "./types";
import { downloadExport, offsetDay, today } from "./utils";
import { logout, saveRecord, sync, useSyncStatus } from "./store";
import { api, logout, saveRecord, sync, useSyncStatus } from "./store";
import {
accentPalette,
accentPresets,
@ -23,6 +24,63 @@ import {
} from "../shared/theme.js";
import { useTilt } from "./useTilt";
type ProductSource = {
source: "usda" | "off";
imported_at: string | null;
rows: number | null;
error: string | null;
};
const sourceNames = {
usda: "USDA FoodData Central",
off: "Open Food Facts",
};
// Status of the server's product databases, refreshed in the background.
function ProductDatabases() {
const [sources, setSources] = useState<ProductSource[] | null>(null);
const [failed, setFailed] = useState(false);
useEffect(() => {
api("/products")
.then((data) => setSources(data.sources))
.catch(() => setFailed(true));
}, []);
return (
<section className="card settings-card">
<div className="card-title">
<div>
<span className="eyebrow">SCAN AND GO</span>
<h2>Barcode database</h2>
</div>
<ScanBarcode size={22} className="muted" />
</div>
{(["usda", "off"] as const).map((key) => {
const source = sources?.find((item) => item.source === key);
return (
<div className="status-detail" key={key}>
<div>
<strong>{sourceNames[key]}</strong>
<small>
{failed
? "Status unavailable while offline."
: !sources
? "Checking…"
: source?.imported_at
? `${(source.rows ?? 0).toLocaleString()} products · updated ${new Date(source.imported_at).toLocaleDateString()}`
: source?.error
? `Download failed: ${source.error}`
: "First download in progress on the server."}
</small>
</div>
</div>
);
})}
<p className="small muted">
Scans check your saved foods first, then these copies on your server,
then Open Food Facts online. Both copies refresh automatically.
</p>
</section>
);
}
// Edits a number locally and commits once it is valid: after a short pause, on
// blur, or on Enter. External changes (sync) apply only while it is not focused.
function NumberField({
@ -580,6 +638,7 @@ export function Settings({
</button>
)}
</section>
<ProductDatabases />
<section className="account-row">
<div>
<ShieldCheck size={20} />