<commit_before>exports.init = function(db) {
    return {
        pageOne: function(req, res) {
            var collection = db.get('content_html');
            safeFind(collection, {},function(docs) {
                render(res, 'template_pageOne', {'template_pageOne': docs});
            });
        },
        pageTwo: function(req, res) {
            var collection = db.get('content_html');
            safeFind(collection, {},function(docs) {
                render(res, 'template_pageTwo', {'template_pageTwo': docs});
            });
        },
        write: function(req, res) {
            // Get our form values. These rely on the "name" attributes
            var dateCreated = req.body.dateCreated;
            var categoryId = req.body.catID;
            var categoryName = req.body.catName;
            var articleName = req.body.articleName;
            var html = req.body.myHtml;

            // Set our collection
            var collection = db.get('content_html');

            // Submit to the DB
            collection.insert({
                "created" : dateCreated,
                "categoryId" : categoryId,
                "categoryName" : categoryName,
                "wikiName" : articleName,
                "html" : html
                }, function (err, doc) {
                    if (err) {
                        // If it failed, return error
                        res.send("There was a problem adding the information to the database.");
                    }
                    else {
                        //set the header so the address bar doesn't still say /adduser
                        res.location("/two");
                        // If it worked, forward to success page
                        res.redirect("/two");
                    }
                }
            );
        },

        /**
         * Attempts to retrieve the wiki data for the requested page
         */
        showWikiPage: function(req, res) {
            var pagename = req.params.page || '';

            var collection = db.get('content_html');

            safeFind(collection, {name: pagename}, function(results) {
                var data = results[0] || null;
                if (data) {
                    console.log(data);
                    res.send('Found ' + pagename);
                }
                else {
                    res.send('404: ' + pagename);
                }
            });
        }
    };
};

var safeFind = function(collection, criteria, callback) {
    collection.find(criteria, function(e, docs) {
        if (e) throw e;
        callback(docs);
    });
};

var render = function(res, title, variables) {
    variables = variables || {};

    res.render(title, variables);
};<commit_msg>Updated the 404 response when a wiki page is not in the database<commit_after>exports.init = function(db) {
    return {
        pageOne: function(req, res) {
            var collection = db.get('content_html');
            safeFind(collection, {},function(docs) {
                render(res, 'template_pageOne', {'template_pageOne': docs});
            });
        },
        pageTwo: function(req, res) {
            var collection = db.get('content_html');
            safeFind(collection, {},function(docs) {
                render(res, 'template_pageTwo', {'template_pageTwo': docs});
            });
        },
        write: function(req, res) {
            // Get our form values. These rely on the "name" attributes
            var dateCreated = req.body.dateCreated;
            var categoryId = req.body.catID;
            var categoryName = req.body.catName;
            var articleName = req.body.articleName;
            var html = req.body.myHtml;

            // Set our collection
            var collection = db.get('content_html');

            // Submit to the DB
            collection.insert({
                "created" : dateCreated,
                "categoryId" : categoryId,
                "categoryName" : categoryName,
                "wikiName" : articleName,
                "html" : html
                }, function (err, doc) {
                    if (err) {
                        // If it failed, return error
                        res.send("There was a problem adding the information to the database.");
                    }
                    else {
                        //set the header so the address bar doesn't still say /adduser
                        res.location("/two");
                        // If it worked, forward to success page
                        res.redirect("/two");
                    }
                }
            );
        },

        /**
         * Attempts to retrieve the wiki data for the requested page
         */
        showWikiPage: function(req, res) {
            var pagename = req.params.page || '';

            var collection = db.get('content_html');

            safeFind(collection, {name: pagename}, function(results) {
                var data = results[0] || null;
                if (data) {
                    res.send('Found ' + pagename);
                }
                else {
                    res.status(404).send('<h1>404 Not Found</h1><p>Unable to find wiki page <b>' + pagename + '</b>.</p>');
                }
            });
        }
    };
};

var safeFind = function(collection, criteria, callback) {
    collection.find(criteria, function(e, docs) {
        if (e) throw e;
        callback(docs);
    });
};

var render = function(res, title, variables) {
    variables = variables || {};

    res.render(title, variables);
};
{'fraction_non_alphanumeric': 0.11402569593147752, 'fraction_numerical': 0.0028551034975017845, 'mean_word_length': 1.3530646515533165, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4205028', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1352, 'n_words': 367}