<commit_before>/**
 * GET /
 * Home page.
 */
var Video = require('../models/Video');
var moment = require('moment');
var _ = require('underscore');
var watchlist = require('../config/watchlist');
var Author = require('../models/Author');
var genCaptcha = require('../libs/genCaptcha');
var pageSize = 15;
var homeController = require('./home');

module.exports = function (app) {
    function setget(paths, functions) {
        for (var i = 0; i < paths.length; i++)
            app.get(paths[i], functions);
    }

    function indexQuery(req, res, next) {
        req.query = constructVideoPagingQuery(req.params.page, pageSize);
        next();
    }

    function index(req, res) {
        var videos = req.videos;
        var title = 'Newest';
        if (req.params.groupby) {
            groups = _.groupBy(videos, req.params.groupby);
            title = 'GroupBy' + req.params.groupby;
            res.render("groupbyauthor", {
                title: "Group",
                groups: groups
            });
        } else {
            res.render("home", {
                title: "Newest",
                items: videos
            });
        }
    };
    setget(['/', '/p/:page', '/gby/:groupby', '/gby/:groupby/p/:page'],
           [paramCons,
            setLocals,
            indexQuery,
            doQuery,
            index]);

    // app.get('/',
    //         paramCons,
    //         setLocals,
    //         indexQuery,
    //         doQuery,
    //         index);
    // app.get('/p/:page',
    //         paramCons,
    //         setLocals,
    //         indexQuery,
    //         doQuery,
    //         index);
    // app.get('/gby/:groupby/',
    //         paramCons,
    //         setLocals,
    //         indexQuery,
    //         doQuery,
    //         index);
    // app.get('/gby/:groupby/p/:page',
    //         paramCons,
    //         setLocals,
    //         indexQuery,
    //         doQuery,
    //         index);

    function authorQuery(req, res, next) {
        req.query = constructVideoPagingQuery(req.params.page, pageSize);
        req.query.where('authorName').equals(req.params.authorName);
        next();
    }
    function authorList(req, res) {
        res.render("home", {
            title: "Author",
            items: req.videos,
            currentAuthor: req.params.authorName
        });
    }
    setget(['/author/:authorName/', '/author/:authorName/p/:page'],
           [paramCons,
            setLocals,
            authorQuery,
            doQuery,
            authorList]);
    // app.get('/author/:authorName/',
    //         paramCons,
    //         setLocals,
    //         authorQuery,
    //         doQuery,
    //         authorList);
    // app.get('/author/:authorName/p/:page',
    //         paramCons,
    //         setLocals,
    //         authorQuery,
    //         doQuery,
    //         authorList);

    function followingQuery(req, res, next) {
        req.query = constructVideoPagingQuery(req.params.page, pageSize);
        req.query = req.query.where('authorName').in(req.user.following);
        next();
    }

    function followingChecker(req, res, next) {
        if (!req.user.following) {
            Author.find(function (err, authors) {
                if (err) {
                    res.render('exception', {title: err.toString()});
                    return;
                }
                res.render('authors', {title: 'Following',
                                       authors: authors,
                                       hint: '你还没有关注一个解说哦，快来关注一下吧。',
                                       req: req});
            });
        } else {
            next();
        }
    }
    function setFollowing(req, res, next) {
        req.params.following = true;
        next();
    }
    function followingList(req, res) {
        if (!req.params.groupby) {
            res.render('home', {title: 'Following',
                                items: req.videos
                               });
        } else {
            var groups = _.groupBy(req.videos, 'authorName');
            res.render('groupbyauthor', {title: 'Following',
                                         groups: groups
                                        });
        }
    }
    setget(['/following/', '/following/p/:page', '/following/gby/:groupby/', '/following/gby/:groupby/p/:page'],
           [homeController.checkUser,
            followingChecker,
            setFollowing,
            paramCons,
            setLocals,
            followingQuery,
            doQuery,
            followingList]);
    // app.get('/following/',
    //         homeController.checkUser,
    //         followingChecker,
    //         setFollowing,
    //         paramCons,
    //         setLocals,
    //         followingQuery,
    //         doQuery,
    //         followingList);
    // app.get('/following/p/:page',
    //         homeController.checkUser,
    //         followingChecker,
    //         setFollowing,
    //         paramCons,
    //         setLocals,
    //         followingQuery,
    //         doQuery,
    //         followingList);
    // app.get('/following/gby/:groupby/',
    //         homeController.checkUser,
    //         followingChecker,
    //         setFollowing,
    //         paramCons,
    //         setLocals,
    //         followingQuery,
    //         doQuery,
    //         followingList);
    // app.get('/following/gby/:groupby/p/:page',
    //         homeController.checkUser,
    //         followingChecker,
    //         setFollowing,
    //         paramCons,
    //         setLocals,
    //         followingQuery,
    //         doQuery,
    //         followingList);


    function paramCons(req, res, next) {
        req.params = req.params || {};
        req.params.page = Number(req.params.page || 1);
        if (req.params.groupby) {<commit_msg>cleanup backup comments<commit_after>/**
 * GET /
 * Home page.
 */
var Video = require('../models/Video');
var moment = require('moment');
var _ = require('underscore');
var watchlist = require('../config/watchlist');
var Author = require('../models/Author');
var genCaptcha = require('../libs/genCaptcha');
var pageSize = 15;
var homeController = require('./home');

module.exports = function (app) {
    function setget(paths, functions) {
        for (var i = 0; i < paths.length; i++)
            app.get(paths[i], functions);
    }

    function indexQuery(req, res, next) {
        req.query = constructVideoPagingQuery(req.params.page, pageSize);
        next();
    }

    function index(req, res) {
        var videos = req.videos;
        var title = 'Newest';
        if (req.params.groupby) {
            groups = _.groupBy(videos, req.params.groupby);
            title = 'GroupBy' + req.params.groupby;
            res.render("groupbyauthor", {
                title: "Group",
                groups: groups
            });
        } else {
            res.render("home", {
                title: "Newest",
                items: videos
            });
        }
    };
    setget(['/', '/p/:page', '/gby/:groupby', '/gby/:groupby/p/:page'],
           [paramCons,
            setLocals,
            indexQuery,
            doQuery,
            index]);

    function authorQuery(req, res, next) {
        req.query = constructVideoPagingQuery(req.params.page, pageSize);
        req.query.where('authorName').equals(req.params.authorName);
        next();
    }
    function authorList(req, res) {
        res.render("home", {
            title: "Author",
            items: req.videos,
            currentAuthor: req.params.authorName
        });
    }
    setget(['/author/:authorName/', '/author/:authorName/p/:page'],
           [paramCons,
            setLocals,
            authorQuery,
            doQuery,
            authorList]);

    function followingQuery(req, res, next) {
        req.query = constructVideoPagingQuery(req.params.page, pageSize);
        req.query = req.query.where('authorName').in(req.user.following);
        next();
    }

    function followingChecker(req, res, next) {
        if (!req.user.following) {
            Author.find(function (err, authors) {
                if (err) {
                    res.render('exception', {title: err.toString()});
                    return;
                }
                res.render('authors', {title: 'Following',
                                       authors: authors,
                                       hint: '你还没有关注一个解说哦，快来关注一下吧。',
                                       req: req});
            });
        } else {
            next();
        }
    }
    function setFollowing(req, res, next) {
        req.params.following = true;
        next();
    }
    function followingList(req, res) {
        if (!req.params.groupby) {
            res.render('home', {title: 'Following',
                                items: req.videos
                               });
        } else {
            var groups = _.groupBy(req.videos, 'authorName');
            res.render('groupbyauthor', {title: 'Following',
                                         groups: groups
                                        });
        }
    }
    setget(['/following/', '/following/p/:page', '/following/gby/:groupby/', '/following/gby/:groupby/p/:page'],
           [homeController.checkUser,
            followingChecker,
            setFollowing,
            paramCons,
            setLocals,
            followingQuery,
            doQuery,
            followingList]);

    function paramCons(req, res, next) {
        req.params = req.params || {};
        req.params.page = Number(req.params.page || 1);
        if (req.params.groupby) {
{'fraction_non_alphanumeric': 0.1414639154090956, 'fraction_numerical': 0.0008212709167436608, 'mean_word_length': 1.3407015857760691, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1273619', 'n_tokens_mistral': 2744, 'n_tokens_neox': 2692, 'n_words': 472}