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>
72 lines
2.6 KiB
JavaScript
72 lines
2.6 KiB
JavaScript
import { mkdirSync, readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { openDatabase } from "./db.js";
|
|
import { createApp } from "./app.js";
|
|
import { hashPassword } from "./auth.js";
|
|
import { openProducts } from "./products/db.js";
|
|
import { scheduleProductImports } from "./products/scheduler.js";
|
|
import { createOcr } from "./ocr/engine.js";
|
|
const secret = (name) =>
|
|
process.env[name + "_FILE"]
|
|
? readFileSync(process.env[name + "_FILE"], "utf8").trimEnd()
|
|
: process.env[name];
|
|
const password = secret("CALIO_PASSWORD");
|
|
const passwordHash =
|
|
secret("CALIO_PASSWORD_HASH") || (password && hashPassword(password));
|
|
if (!passwordHash || !/^scrypt:[a-f0-9]{32}:[a-f0-9]{128}$/.test(passwordHash))
|
|
throw new Error(
|
|
"Configure CALIO_PASSWORD_HASH[_FILE] or CALIO_PASSWORD[_FILE]. There are no default credentials.",
|
|
);
|
|
if (password && password.length < 12)
|
|
throw new Error("CALIO_PASSWORD must be at least 12 characters.");
|
|
const origin = process.env.APP_ORIGIN || "http://localhost:3000";
|
|
if (new URL(origin).origin !== origin)
|
|
throw new Error("APP_ORIGIN must be an origin without a trailing slash");
|
|
const secureCookies = process.env.COOKIE_SECURE !== "false";
|
|
if (
|
|
!secureCookies &&
|
|
!["localhost", "127.0.0.1"].includes(new URL(origin).hostname)
|
|
)
|
|
throw new Error(
|
|
"Insecure cookies are allowed only on localhost. Use HTTPS for deployment.",
|
|
);
|
|
const dataDir = resolve(process.env.DATA_DIR || "data");
|
|
mkdirSync(dataDir, { recursive: true });
|
|
const store = openDatabase(resolve(dataDir, "calio.sqlite"));
|
|
const products = openProducts(resolve(dataDir, "products.sqlite"));
|
|
const stopImports = scheduleProductImports(dataDir);
|
|
// Models load in the background so the first label scan doesn't wait.
|
|
const engine = createOcr(resolve(process.env.MODELS_DIR || "models")).catch(
|
|
(error) => {
|
|
console.error("Label scanning is unavailable:", error.message);
|
|
return null;
|
|
},
|
|
);
|
|
const app = createApp({
|
|
store,
|
|
username: process.env.CALIO_USERNAME || "calio",
|
|
passwordHash,
|
|
origin,
|
|
secureCookies,
|
|
products,
|
|
ocr: async (image) => {
|
|
const ocr = await engine;
|
|
if (!ocr)
|
|
throw Object.assign(new Error("OCR models are not loaded"), {
|
|
unavailable: true,
|
|
});
|
|
return ocr.read(image);
|
|
},
|
|
});
|
|
const server = app.listen(Number(process.env.PORT || 3000), "0.0.0.0", () =>
|
|
console.log(`Calio listening at ${origin}`),
|
|
);
|
|
for (const signal of ["SIGTERM", "SIGINT"])
|
|
process.on(signal, () =>
|
|
server.close(() => {
|
|
stopImports();
|
|
products.close();
|
|
store.close();
|
|
process.exit(0);
|
|
}),
|
|
);
|