Add barcode and nutrition label scanning
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m2s
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:
parent
8f6981c8a2
commit
80fc48b9f1
39 changed files with 4434 additions and 33 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { execFileSync, spawnSync } from "node:child_process";
|
||||
import assert from "node:assert/strict";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { emptyNutrients } from "../shared/domain.js";
|
||||
const image = process.argv[2] || "calio:local";
|
||||
const unraid = process.argv.includes("--unraid");
|
||||
|
|
@ -66,19 +67,20 @@ async function start() {
|
|||
);
|
||||
}
|
||||
// In-container probes work on socket-mounted Forgejo runners without published ports.
|
||||
const request = async (path, body, cookie) => {
|
||||
// `image` (base64 PNG) is posted as the raw request body.
|
||||
const request = async (path, body, cookie, image) => {
|
||||
const probe = `let input=''; for await (const chunk of process.stdin) input+=chunk;
|
||||
const {path,body,cookie}=JSON.parse(input);
|
||||
const {path,body,cookie,image}=JSON.parse(input);
|
||||
const response=await fetch('http://127.0.0.1:3000'+path,{
|
||||
method:body===undefined?'GET':'POST',
|
||||
headers:{'Content-Type':'application/json',Origin:'http://localhost:3000','X-Calio-Request':'1',Cookie:cookie||''},
|
||||
body:body===undefined?undefined:JSON.stringify(body)
|
||||
method:body===undefined&&!image?'GET':'POST',
|
||||
headers:{'Content-Type':image?'image/png':'application/json',Origin:'http://localhost:3000','X-Calio-Request':'1',Cookie:cookie||''},
|
||||
body:image?Buffer.from(image,'base64'):body===undefined?undefined:JSON.stringify(body)
|
||||
});
|
||||
console.log(JSON.stringify({status:response.status,cookie:response.headers.get('set-cookie'),body:await response.text()}));`;
|
||||
const result = JSON.parse(
|
||||
docker(
|
||||
["exec", "-i", name, "node", "--input-type=module", "-e", probe],
|
||||
JSON.stringify({ path, body, cookie }),
|
||||
JSON.stringify({ path, body, cookie, image }),
|
||||
),
|
||||
);
|
||||
return {
|
||||
|
|
@ -135,6 +137,28 @@ try {
|
|||
"/icons/apple-touch-icon-v2.png",
|
||||
])
|
||||
assert.equal((await request(path)).status, 200, path);
|
||||
// The bundled OCR models load and read a label inside the image.
|
||||
const label = await request(
|
||||
"/api/label",
|
||||
undefined,
|
||||
cookie,
|
||||
readFileSync(
|
||||
new URL("../tests/fixtures/label.png", import.meta.url),
|
||||
).toString("base64"),
|
||||
);
|
||||
assert.equal(label.status, 200, await label.text());
|
||||
const read = (await label.json()).label;
|
||||
assert.deepEqual(read.nutrients, {
|
||||
calories: 230,
|
||||
fat: 8,
|
||||
sodium: 160,
|
||||
carbs: 37,
|
||||
fiber: 4,
|
||||
sugar: 12,
|
||||
protein: 3,
|
||||
});
|
||||
assert.equal(read.serving, "2/3 cup (55 g)");
|
||||
assert.equal((await request("/api/products", undefined, cookie)).status, 200);
|
||||
const html = await (await request("/")).text();
|
||||
const asset = html.match(/src="(\/assets\/[^\"]+)"/)[1];
|
||||
assert.equal((await request(asset)).status, 200);
|
||||
|
|
@ -147,7 +171,7 @@ try {
|
|||
assert.equal(response.status, 200);
|
||||
assert.deepEqual((await response.json()).records, [record]);
|
||||
console.log(
|
||||
`PASS (${unraid ? "Unraid 99:100" : "default 1000"}): non-root container, production assets, authentication, read-only root, persistent volume and sessions after container recreation.`,
|
||||
`PASS (${unraid ? "Unraid 99:100" : "default 1000"}): non-root container, production assets, authentication, label OCR, read-only root, persistent volume and sessions after container recreation.`,
|
||||
);
|
||||
} finally {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue