<commit_before>'use strict';

const fs = require('fs');
const http = require('http');
const https = require('https');
const path = require('path');
const awsConfig = require('./aws-config');
const Rekognition = require('aws-sdk/clients/rekognition');
const r = new Rekognition(awsConfig);
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const oratio = require('@orat.io/integration-sdk');
const PORT = process.env.NOTHOTDOG_PORT || 8082;
const botToken = '';

app.set('trust proxy', 1);
app.set('x-powered-by', false);

app.disable('etag');
app.disable('view cache');

app.use(bodyParser.json());
app.use(oratio());

function random(len) {
    let rdmString = "";
    for (; rdmString.length < len; rdmString += Math.random().toString(36).substr(2))
;
    return rdmString.substr(0, len);
}

function getRandomFile() {
    const downloads = path.join(__dirname, 'downloads');
    if(!fs.existsSync(downloads)) {
        fs.mkdirSync(downloads);
    }
    return path.join(downloads, random(32));
}

app.post('/nohotdog', (req, res) => {
    console.log(req.body);

    if(req.body.message.type === 'image') {
        (req.body.message.content.startsWith('https') ? https : http)
        .get(req.body.message.content, (result) => {
            const imageFile = getRandomFile();

            result.pipe(fs.createWriteStream(imageFile))
            .on('finish', () => {
                const params = {
                    Image: {
                        Bytes: new Buffer(fs.readFileSync(imageFile))
                    },
                    MaxLabels: 5,
                    MinConfidence: 80
                };

                r.detectLabels(params, (err, data) => {
                    if(err) {
                        console.log(err);
                    }
                    else {
                        if(data.Labels.filter((label => {
                            return label.Name === 'Hot Dog';
                        })).length > 0) {
                            res.sendText('Hotdog');
                        }
                        else {
                            res.sendText('No Hotdog');
                        }
                    }
                });
            });
        });
    }
    else {
        res.sendText('Only Hotdogs!');
    }
});

app.listen(PORT, () => {
    console.log(`Server is listening on port ${PORT}`);
});<commit_msg>I Promised Everything<commit_after>'use strict';

const fs = require('fs');
const http = require('http');
const https = require('https');
const path = require('path');
const awsConfig = require('./aws-config');
const Rekognition = require('aws-sdk/clients/rekognition');
const r = new Rekognition(awsConfig);
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const oratio = require('@orat.io/integration-sdk');
const PORT = process.env.NOTHOTDOG_PORT || 8082;
const botToken = '';

app.set('trust proxy', 1);
app.set('x-powered-by', false);

app.disable('etag');
app.disable('view cache');

app.use(bodyParser.json());
app.use(oratio());

function random(len) {
    let rdmString = "";
    for (; rdmString.length < len; rdmString += Math.random().toString(36).substr(2))
;
    return rdmString.substr(0, len);
}

function getRandomFile() {
    const downloads = path.join(__dirname, 'downloads');
    if(!fs.existsSync(downloads)) {
        fs.mkdirSync(downloads);
    }
    return path.join(downloads, random(32));
}

app.post('/nothotdog', (req, res) => {
    console.log(req.body);

    if(req.body.message.type === 'image') {
        new Promise((resolve, reject) => {
            (req.body.message.content.startsWith('https') ? https : http)
            .get(req.body.message.content, (result) => {
                const imageFile = getRandomFile();
                result.pipe(fs.createWriteStream(imageFile))
                .on('finish', () => {
                    resolve(imageFile);
                });
            });
        })
        .then((imageFile) => {
            return new Promise((resolve, reject) => {
                fs.readFile(imageFile, (err, data) => {
                    if(err) reject(err);
                    else resolve(data);
                });
            });
        })
        .then((imageData) => {
            return new Promise((resolve, reject) => {
                const params = {
                    Image: {
                        Bytes: new Buffer(imageData)
                    },
                    MaxLabels: 5,
                    MinConfidence: 80
                };
                r.detectLabels(params, (err, data) => {
                    if(err) {
                        reject(err);
                    }
                    else {
                        const len = data.Labels.filter((label => {return label.Name === 'Hot Dog'})).length;
                        resolve(len > 0);
                    }
                });
            });
        })
        .then((isHotdog) => {
            res.sendText(isHotdog ? 'Hotdog' : 'Not Hotdog');
        });
    }
    else {
        res.sendText('Only Hotdogs!');
    }
});

app.listen(PORT, () => {
    console.log(`Server is listening on port ${PORT}`);
});
{'fraction_non_alphanumeric': 0.15747432483834156, 'fraction_numerical': 0.005705591479650057, 'mean_word_length': 1.7664387164650184, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2285796', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1466, 'n_words': 282}