Files
MyIP/api/mac-checker.js
T
jason5ng32andClaude Opus 5.5 c29e48687b Refactor(layout): split backend-only code out of common/, group frontend utils
common/ had become the backend's library: 30 of its 41 modules were
imported by nothing in the frontend, so the name no longer said what
belonged there. It now holds only what the frontend or the build imports
too; backend-only code moved to server/, flat except for datasets/ (the
dataset engine and its readers). The *-db/ dataset directories stay in
common/: self-hosting docs and Docker volumes mount those paths.

frontend/utils/ keeps its app-wide modules at the root and gains ip/
(IP / ASN shaping and validation), report/ (the report pipeline) and
features/ (the pure layer of a single feature). Paths only — no logic
changes. The Dockerfile copies server/, and the AGENTS.md files say where
a new module goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:10:02 +08:00

30 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// /api/macchecker?mac= — MAC Lookup against the local IEEE registries
// (server/datasets/oui-db.js). `mac` is a full address or a vendor prefix of 6–12
// hex digits (common/mac-input.js). The answer names the block that covers
// it, its range and the first-octet flags; an address no block covers is
// still a 200 with `found: false`.
import { normalizeMacQuery } from '../common/mac-input.js';
import { lookupMac } from '../server/datasets/oui-db.js';
// `lookup` is injectable so tests can run the handler over fixture registries.
export const createMacChecker = (lookup) => async (req, res) => {
const { mac } = req.query;
if (!mac) {
return res.status(400).json({ error: 'No MAC address provided' });
}
const hex = normalizeMacQuery(String(mac));
if (!hex) {
return res.status(400).json({ error: 'Invalid MAC address' });
}
// Past the boot window (requireOfflineData) only a failed download leaves this empty.
const result = lookup(hex);
if (!result) {
return res.status(503).json({ error: 'MAC database unavailable' });
}
res.json(result);
};
export default createMacChecker(lookupMac);