<commit_before>'use strict';

const AbstractController = require('./AbstractController');
const ReleaseNotesLoader = require('@release-notes/node/lib/ReleaseNotesLoader');
const multer = require('multer');

const releaseNotesLoader = new ReleaseNotesLoader();
const uploadHandler = multer();

class IndexController extends AbstractController {
  indexAction(req, res, next) {
    res.render('index/index', {});
  }

  showReleaseNotesAction(req, res, next) {
    if (!req.file) {
      return void res.render('index/index', {
        err: new Error('No release-notes.yml file was uploaded.')
      });
    }

    releaseNotesLoader.loadReleaseNotes(req.file.buffer, (err, releaseNotes) => {
      if (err) {
        res.statusCode = 400;
      }

      res.render('index/index', {
        err,
        releaseNotes,
      })
    });
  }

  getRoutes() {
    return {
      '/': [{
        handler: (req, res, next) => this.indexAction(req, res, next)
      }, {
        method: 'post',
        handler: [
          uploadHandler.single('release-notes'),
          (req, res, next) => this.showReleaseNotesAction(req, res, next),
        ]
      }],
    }<commit_msg>Load the latest 6 release notes to the start page.<commit_after>'use strict';

const AbstractController = require('./AbstractController');

class IndexController extends AbstractController {
  indexAction(req, res, next) {
    this.serviceManager.get('releaseNotesRepository').findNewest(
      6, (err, releaseNotesList) => {
        if (err) {
          return void next(err);
        }

        res.render('index/index', {
          newest: releaseNotesList,
        });
      }
    );
  }

  getRoutes() {
    return {
      '/': [{
        handler: (req, res, next) => this.indexAction(req, res, next)
      }],
    }
{'fraction_non_alphanumeric': 0.14429530201342283, 'fraction_numerical': 0.002796420581655481, 'mean_word_length': 2.6288032454361057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '6486885', 'n_tokens_mistral': 543, 'n_tokens_neox': 517, 'n_words': 112}