{"size": 951, "ext": "js", "max_stars_repo_path": "api/controllers/home/homeController.js", "max_stars_repo_name": "jozsefsallai/fastbin", "max_stars_repo_stars_event_min_datetime": "2020-02-09T03:19:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-01T07:32:27.000Z", "max_issues_repo_path": "api/controllers/home/homeController.js", "max_issues_repo_name": "jozsefsallai/fastbin", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "api/controllers/home/homeController.js", "max_forks_repo_name": "jozsefsallai/fastbin", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.1951219512, "max_line_length": 67, "alphanum_fraction": 0.6056782334}
const fs = require('fs');
const path = require('path');
const config = require('../../config');

module.exports.index = function (req, res) {
  if (config.auth.key && !req.session.auth) {
    return res.redirect('/login');
  }

  if ([ 'phone', 'tablet' ].includes(req.device.type)) {
    return res.render('mobile');
  }

  return res.render('index');
};

module.exports.about = function (req, res) {
  const readmePath = path.join(__dirname, '../../..', 'README.md');
  const readme = fs.readFileSync(readmePath, { encoding: 'utf8' });

  return res.json({
    ok: true,
    contents: readme
  });
};

module.exports.snippet = function (req, res) {
  if ([ 'phone', 'tablet' ].includes(req.device.type)) {
    const { key } = req.params;
    const keyComponents = key.split('.');

    if (keyComponents.length > 1) {
      keyComponents.pop();
    }

    return res.redirect(`/raw/${keyComponents.join('.')}`);
  }

  return res.render('index');
};
