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.
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
// Reference server for the AndroidDeviceInfo library.
|
|
//
|
|
// Provides device name/image lookup, CMF color resolution, report ingestion,
|
|
// and a self-update feed for the library's bundled device-names database.
|
|
// SQLite-backed (better-sqlite3) -- see db.js for schema, routes/deviceInfo.js
|
|
// for the API. Run `npm run migrate -- path/to/deviceInfo.json` once to
|
|
// import data from the older JSON-file version of this server, if you have one.
|
|
|
|
const express = require('express');
|
|
const path = require('path');
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
// Serves phonedb/<brand>/<model>/<color>/<view>.png (and the jpg/ originals)
|
|
// out of ./public. Point this at your own image set -- see README.md for the
|
|
// expected folder layout.
|
|
app.use('/images', express.static(path.join(__dirname, 'public', 'images')));
|
|
|
|
app.use('/api/device-info', require('./routes/deviceInfo'));
|
|
|
|
app.get('/', (req, res) => {
|
|
res.type('text/plain').send('device-info-server is running. See /api/device-info/*.');
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`device-info-server listening on :${PORT}`);
|
|
});
|