← back to Domain Sniper

owned-check.js

30 lines

// owned-check.js — shared lookup against data/owned.json.
//
// data/owned.json is the single-source-of-truth for "domains Steve already
// owns". Both register.js (refuse re-registration) and honeypot-v2.js (refuse
// to use as bait) consult this. File may not exist yet — that's a clean
// "nothing owned" answer, not an error. Tolerates both shapes:
//   ["foo.com", "bar.app"]                   (bare array)
//   { "domains": ["foo.com", "bar.app"] }    (wrapped object)

const fs = require('fs');
const path = require('path');

const OWNED_FILE = path.join(__dirname, 'data', 'owned.json');

function loadOwned() {
  if (!fs.existsSync(OWNED_FILE)) return [];
  try {
    const j = JSON.parse(fs.readFileSync(OWNED_FILE, 'utf8'));
    const list = Array.isArray(j) ? j : (Array.isArray(j.domains) ? j.domains : []);
    return list.filter((d) => typeof d === 'string').map((d) => d.toLowerCase());
  } catch { return []; }
}

function isOwned(domain) {
  const owned = loadOwned();
  return owned.includes(domain.toLowerCase());
}

module.exports = { loadOwned, isOwned, OWNED_FILE };