<commit_before>var md5 = require("crypto-js/md5");
var uuid = require("node-uuid");
var atob = require("atob");
var minutes = 1000*60;
var hours = 60*minutes;
var sessionExpiration = 3*hours;


var sessions = {};

function deleteAfterExpiration(session) {
    clearTimeout(session.timeoutHandler);
    session.timeoutHandler = setTimeout(function() {
        delete sessions[session.id];
    }, sessionExpiration);
}

function userFromAuth(auth) {
    return atob(auth).split(":")[0];
}

function getSession(id, auth) {
    if (id && sessions[id]) {
        deleteAfterExpiration(sessions[id]);
        return sessions[id];
    }
    var session = {
        id: uuid.v4(),
        expires: sessionExpiration,
        user: userFromAuth(auth)
    }

    sessions[session.id] = session;

    deleteAfterExpiration(session);

    return session;
}

module.exports = {
    middleware: function() {
        return function(req, res, next) {
            var auth = "<PASSWORD>";
            res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
            res.setHeader("Pragma", "no-cache");
            res.setHeader("Expires", "0");

            if(req.query.shared && req.method === "GET") {
                req.query.select="description";
                const tmp = res.end.bind(res);
                res.end = function(f) {
                    const description = JSON.parse(f).description;
                    res.setHeader("Content-Length", description.length);
                    res.setHeader("Content-Type", "text/markdown; charset=UTF-8");
                    return tmp("" + description || "no data");
                }
                return next();
            };
            if ((md5(req.headers.authorization).toString() !== auth) && (typeof sessions[req.headers["x-session-id"]] === "undefined")) {
                return res.status(401).send("not logged in").end();
            } else {
                const session = getSession(req.headers["x-session-id"], req.headers.authorization);
                res.setHeader("x-session-id", "" + session.id);
                req.session = session;
                return next();
            }
        }
    },
    logout: function(session) {
        delete sessions[session.id];
    }
};<commit_msg>remove content-type from shared link<commit_after>var md5 = require("crypto-js/md5");
var uuid = require("node-uuid");
var atob = require("atob");
var minutes = 1000*60;
var hours = 60*minutes;
var sessionExpiration = 3*hours;


var sessions = {};

function deleteAfterExpiration(session) {
    clearTimeout(session.timeoutHandler);
    session.timeoutHandler = setTimeout(function() {
        delete sessions[session.id];
    }, sessionExpiration);
}

function userFromAuth(auth) {
    return atob(auth).split(":")[0];
}

function getSession(id, auth) {
    if (id && sessions[id]) {
        deleteAfterExpiration(sessions[id]);
        return sessions[id];
    }
    var session = {
        id: uuid.v4(),
        expires: sessionExpiration,
        user: userFromAuth(auth)
    }

    sessions[session.id] = session;

    deleteAfterExpiration(session);

    return session;
}

module.exports = {
    middleware: function() {
        return function(req, res, next) {
            var auth = "<PASSWORD>";
            res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
            res.setHeader("Pragma", "no-cache");
            res.setHeader("Expires", "0");

            if(req.query.shared && req.method === "GET") {
                req.query.select="description";
                const tmp = res.end.bind(res);
                res.end = function(f) {
                    const description = JSON.parse(f).description;
                    res.setHeader("Content-Length", description.length);
                    res.setHeader("Content-Type", "text/markdown; charset=UTF-8");
                    res.setHeader("Content-Type", null);
                    return tmp("" + description || "no data");
                }
                return next();
            };
            if ((md5(req.headers.authorization).toString() !== auth) && (typeof sessions[req.headers["x-session-id"]] === "undefined")) {
                return res.status(401).send("not logged in").end();
            } else {
                const session = getSession(req.headers["x-session-id"], req.headers.authorization);
                res.setHeader("x-session-id", "" + session.id);
                req.session = session;
                return next();
            }
        }
    },
    logout: function(session) {
        delete sessions[session.id];
    }
};
{'fraction_non_alphanumeric': 0.14844425237683664, 'fraction_numerical': 0.008210890233362144, 'mean_word_length': 2.144701086956522, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '5167226', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1279, 'n_words': 248}