// Handler for the /cfapi/cli-get-user endpoint

import fs from "node:fs"
import path, { dirname } from "node:path"
import { fileURLToPath } from "node:url"

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const min_version = fs
  .readFileSync(path.join(__dirname, "min_supported_version.txt"), "utf8")
  .trim()

export function getUser(req, res) {
  const cli_version = req.headers.cli_version || "unknown"

  if (cli_version !== "unknown") {
    res.status(200).send({
      userId: req.userId,
      min_version,
    })
  } else {
    res.status(200).send(req.userId)
  }
}
