<commit_before>import { RequestHandler } from 'express'
import { create, CreateHost } from './db'

const handler: RequestHandler = async (req, res) => {
  const hostname = req.body.hostname || ''
  const vanityHostname = req.body.hostname || hostname || 'localhost'
  const dockerPort = req.body.dockerPort || 2375
  const proxyIp = req.body.proxyIp || ''
  const sshPort = req.body.sshPort || 22
  const capacity = req.body.capacity || 5
  let credentialsId: number | null = Number(req.body.credentialsId)
  if (credentialsId < 1) {
    credentialsId = null
  }

  const hasHostname = !!hostname.length

  if (hasHostname) {
    res.status(400).json({
      message: 'Invalid SSH username provided: Must provided credentials if providing a hostname'
    })
    return
  }

  const body: CreateHost = {
    hostname,
    dockerPort,
    sshPort,
    capacity,
    vanityHostname,
    proxyIp,
    credentialsId
  }

  try {
    const result = await create(body)
    res.json({ ...body, id: result[0] })
  } catch (ex) {
    res.status(500)
    res.json({ message: ex.message || ex })
  }
}

export default handler<commit_msg>Remove ssh username check when providing hostname<commit_after>import { RequestHandler } from 'express'
import { create, CreateHost } from './db'

const handler: RequestHandler = async (req, res) => {
  const hostname = req.body.hostname || ''
  const vanityHostname = req.body.hostname || hostname || 'localhost'
  const dockerPort = req.body.dockerPort || 2375
  const proxyIp = req.body.proxyIp || ''
  const sshPort = req.body.sshPort || 22
  const capacity = req.body.capacity || 5
  let credentialsId: number | null = Number(req.body.credentialsId)
  if (credentialsId < 1) {
    credentialsId = null
  }

  const body: CreateHost = {
    hostname,
    dockerPort,
    sshPort,
    capacity,
    vanityHostname,
    proxyIp,
    credentialsId
  }

  try {
    const result = await create(body)
    res.json({ ...body, id: result[0] })
  } catch (ex) {
    res.status(500)
    res.json({ message: ex.message || ex })
  }
}

export default handler
{'fraction_non_alphanumeric': 0.12235067437379576, 'fraction_numerical': 0.01300578034682081, 'mean_word_length': 3.1790744466800804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '321073', 'n_tokens_mistral': 686, 'n_tokens_neox': 652, 'n_words': 178}