<commit_before>var express = require('express');

var app = express();

var fs = require('fs');

var mkdirp = require('mkdirp');

var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();


app.use(multipartMiddleware);

app.get('/', function(req, res){
    console.log("called /");
    res.send(
            '<form action="/upload" method="post" enctype="multipart/form-data">'+
            '<input type="file" name="source">'+
            '<input type="submit" value="Upload">'+
            '</form>'
    );
});

app.post('/upload/:sid/:username', multipartMiddleware, function(req, res) {
    console.log(req.body, req.files);
    // don't forget to delete all req.files when done
    console.log(req.params.sid, req.params.username);

    var uploadDir = __dirname+"/uploads/" + req.params.sid + "/" + req.params.username + "/";
    var fileName = req.files.source.name;

    console.log(uploadDir);

    mkdirp(__dirname+"/uploads/" + req.params.sid + "/", function (err) {
        if (err){
            console.error(err)
            res.send(400, "Server Writting No Good");
        }
        else{
            mkdirp(uploadDir, function (err) {
                if (err){
                    console.error(err)
                    res.send(400, "Server Writting No Good");
                }
                else{
                    fs.rename(
                        req.files.source.path,
                            uploadDir+fileName,
                        function(err){
                            if(err != null){
                                console.log(err)
                                res.send(400, "Server Writting No Good");
                            } else {
                                res.send("ok!");
                            }
                        }
                    );
                }
            });
        }
    });


});

app.get('/info', function(req, res){
    console.log(__dirname);
    res.send("ok");
});

app.listen(8080);
console.log('connected to localhost....')<commit_msg>upload dir structure changed<commit_after>var express = require('express');

var app = express();

var fs = require('fs');

var mkdirp = require('mkdirp');

var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();


app.use(multipartMiddleware);

app.get('/', function(req, res){
    console.log("called /");
    res.send(
            '<form action="/upload/test/000" method="post" enctype="multipart/form-data">'+
            '<input type="file" name="source">'+
            '<input type="submit" value="Upload">'+
            '</form>'
    );
});

app.post('/upload/:sid/:username', multipartMiddleware, function(req, res) {
    console.log(req.body, req.files);
    // don't forget to delete all req.files when done
    console.log(req.params.sid, req.params.username);

    var uploadDir = "/home/martin/www/uploads/" + req.params.username + "/" + req.params.sid + "/";
    var fileName = req.files.source.name;

    console.log(uploadDir);

    mkdirp("/home/martin/www/uploads/" + req.params.username + "/", function (err) {
        if (err){
            console.error(err)
            res.send(400, "Server Writting No Good");
        }
        else{
            mkdirp(uploadDir, function (err) {
                if (err){
                    console.error(err)
                    res.send(400, "Server Writting No Good");
                }
                else{
                    fs.rename(
                        req.files.source.path,
                            uploadDir+fileName,
                        function(err){
                            if(err != null){
                                console.log(err)
                                res.send(400, "Server Writting No Good");
                            } else {
                                res.send("ok!");
                            }
                        }
                    );
                }
            });
        }
    });


});

app.get('/info', function(req, res){
    console.log(__dirname);
    res.send("ok");
});

app.listen(8080);
console.log('connected to localhost....')

{'fraction_non_alphanumeric': 0.15045519885002395, 'fraction_numerical': 0.006947771921418304, 'mean_word_length': 1.5014979029358897, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6209233', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1140, 'n_words': 218}