Files
oxmc 13a5674ec1 Add server/: Express + SQLite backend for the library
Implements the device lookup/report API DeviceInfo talks to: search-device
(v1 deprecated but sharing v2's lookup logic internally, v2 exact-match
with optional per-unit CMF color resolution), report-device-info, and the
device-names self-update feed. Includes a migration script for anyone
coming from an older JSON-file version, plus docs/CMF_COLOR.md on why the
color-code table has to be hand-maintained.
2026-09-17 03:58:50 -07:00
..

device-info-server

Backend for AndroidDeviceInfo: device name/image lookup, per-unit color (CMF) resolution, report ingestion, and a self-update feed for the library's bundled device-names database. SQLite-backed via better-sqlite3.

This is a lean reference implementation — no auth, rate limiting, or other deployment hardening. Add what your setup needs before putting it on the public internet.

Quick start

npm install
npm start        # listens on :3000

Coming from the older JSON-file version of this server (a { phones: [...], cmf: {...} } file)?

npm run migrate -- path/to/deviceInfo.json

Schema

  • phones — one row per model: deviceName, manufacturer, model (unique), image (default/fallback photo), count (total reports).
  • phone_codenames — a phone can have more than one Build.DEVICE codename (regional variants), so this is its own table rather than a column.
  • cmf_colors — (model, cmf_code) -> {name, folder, image}. This is the only source of truth for resolving a device's CMF color code to a real color name — there's no public API for it. See docs/CMF_COLOR.md.
  • phone_color_reports — how many reports came in per (model, cmf_code), so two units of the same model can be told apart by actual color.
  • device_names_update — one row: {version, db_path}, served at /api/device-info/updates for the library's DeviceDatabase.checkForUpdates(). Point db_path at a sqlite file built by the library's own gen-db.py.

API

Route Method Notes
/api/device-info/search-device/v1?search_exp= GET Deprecated, kept for older clients. Substring match on deviceName, looser than v2. Built on the same resolveImage() helper as v2 so the two can't drift apart — just use v2 in new code.
/api/device-info/search-device/v2?codename=&model=&manufacturer=&cmfColor= GET Exact match; cmfColor optional, resolves the unit-specific image when known.
/api/device-info/report-device-info POST Body: {deviceName, manufacturer, model, codename, image?, cmfColor?}.
/api/device-info/updates GET {version, url} for the library's self-update check.
/api/device-info/updates/db GET Serves the raw device-names sqlite file.

v1 doesn't fall back to an external lookup (e.g. Wikipedia) on a miss, it just returns {}. Add that yourself in routes/deviceInfo.js if you want it.

Images

server.js serves public/images/<path> statically. Point your image/cmf.image columns at whatever layout you use there — nothing here requires a specific one, but ours is phonedb/<brand>/<model>/<color>/<view>.png, with a jpg/ subfolder under each color holding the pre-cutout originals.