<commit_before>const async  = require('async'),
      fs     = require('fs'),
      multer = require('multer'),
      path   = require('path'),
      uuidv4 = require('uuid/v4');

const constants = require('./constants'),
      nodebb    = require('./nodebb');

const nconf   = nodebb.nconf,
      plugins = nodebb.plugins;

let files = {};

(function (Uploads) {
    // Multer File Object - https://github.com/expressjs/multer#multer-file-object

    Uploads.init = function (router, middleware, done) {
        async.waterfall([
            async.apply(createTemporalStorage),
            function (storage, next) {
                addRoute(storage, router, middleware, next);
            }
        ], done);
    };

    function addRoute(storage, router, middleware, done) {
        let route = path.join(
            constants.API_PATH,
            constants.PLUGIN_PATH,
            constants.IMAGE_SERVICE_PATH
        );
        let fileMiddleware = multer({storage: storage}).single('award');

        router.post(route, [fileMiddleware, middleware.applyCSRF, middleware.authenticate], function (req, res, next) {
            let saveDidComplete = (error, file) => {
                let entityId = req.headers['x-ns-award-entity-id'];

                if (error) {
                    return res.status(500).json(error);
                }

                fs.unlink(file.path, function (error) {
                    if (error) {
                        return res.status(500).json(error);
                    }

                    files[entityId] = file;

                    res.json({
                        entityId: entityId,
                        file    : file,
                        storage : Uploads.isLocalFile(file) ? constants.FILE_LOCAL : constants.FILE_REMOTE
                    });
                });
            };

            if (plugins.hasListeners('filter:uploadImage')) {
                storeCloud(req.file, req.user, saveDidComplete);
            } else {
                storeLocal(req.file, saveDidComplete);
            }
        });

        done(null);
    }<commit_msg>fix(compatibility): no more `middleware.authenticate`<commit_after>const async  = require('async'),
      fs     = require('fs'),
      multer = require('multer'),
      path   = require('path'),
      uuidv4 = require('uuid/v4');

const constants = require('./constants'),
      nodebb    = require('./nodebb');

const nconf   = nodebb.nconf,
      plugins = nodebb.plugins;

let files = {};

(function (Uploads) {
    // Multer File Object - https://github.com/expressjs/multer#multer-file-object

    Uploads.init = function (router, middleware, done) {
        async.waterfall([
            async.apply(createTemporalStorage),
            function (storage, next) {
                addRoute(storage, router, middleware, next);
            }
        ], done);
    };

    function addRoute(storage, router, middleware, done) {
        let route = path.join(
            constants.API_PATH,
            constants.PLUGIN_PATH,
            constants.IMAGE_SERVICE_PATH
        );
        let fileMiddleware = multer({storage: storage}).single('award');

        router.post(route, [fileMiddleware, middleware.applyCSRF, middleware.authenticateRequest, middleware.ensureLoggedIn], function (req, res, next) {
            let saveDidComplete = (error, file) => {
                let entityId = req.headers['x-ns-award-entity-id'];

                if (error) {
                    return res.status(500).json(error);
                }

                fs.unlink(file.path, function (error) {
                    if (error) {
                        return res.status(500).json(error);
                    }

                    files[entityId] = file;

                    res.json({
                        entityId: entityId,
                        file    : file,
                        storage : Uploads.isLocalFile(file) ? constants.FILE_LOCAL : constants.FILE_REMOTE
                    });
                });
            };

            if (plugins.hasListeners('filter:uploadImage')) {
                storeCloud(req.file, req.user, saveDidComplete);
            } else {
                storeLocal(req.file, saveDidComplete);
            }
        });

        done(null);
    }
{'fraction_non_alphanumeric': 0.1204091120409112, 'fraction_numerical': 0.003719200371920037, 'mean_word_length': 1.603145795523291, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '7440935', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1127, 'n_words': 214}