<commit_before>'use strict';

var joi     = require('joi');
var sharp   = require('sharp');
var path    = require('path');
var images  = path.join(__dirname, '../images');

module.exports = [{

    method  : 'GET',
    path    : '/{width}/{height}',
    handler : function(request, reply) {
        var image = sharp(path.join(images, '1.jpg')).resize(request.params.width | 0, request.params.height | 0);
        if (request.query.gray) image = image.grayscale();
        reply(image).type('image/jpeg');
    },
    config  : {
        validate : {
            params : {
                width   : joi.number().integer().min(1).max(3000).required(),
                height  : joi.number().integer().min(1).max(3000).required()
            },
            query : {
                gray    : joi.boolean().default(false, 'color image').optional()
            }
        }
    }

}];<commit_msg>Insane caching<commit_after>'use strict';

var joi     = require('joi');
var sharp   = require('sharp');
var path    = require('path');
var images  = path.join(__dirname, '../images');

var lastModified = new Date(2016, 3, 5, 2).toUTCString(); // "not modified" since project start

module.exports = [{

    method  : 'GET',
    path    : '/{width}/{height}',
    handler : function(request, reply) {
        var width   = request.params.width;
        var height  = request.params.height;
        var gray    = request.query.gray;
        var key     = ['placetrump', width, height, gray].join('_'); // etag caching

        // load and scale image
        var image = sharp(path.join(images, '1.jpg')).resize(width, height);
        if (gray) image = image.grayscale();

        reply(image).type('image/jpeg').etag(key).header('last-modified', lastModified);
    },
    config  : {
        validate : {
            params : {
                width   : joi.number().integer().min(1).max(3000).required(),
                height  : joi.number().integer().min(1).max(3000).required()
            },
            query : {
                gray    : joi.boolean().default(false, 'color image').optional()
            }
        },
        cache : {
            expiresIn   : 30 * 24 * 60 * 60 * 1000, // 30 days
            privacy     : 'public'
        }
    }

}];
{'fraction_non_alphanumeric': 0.16984478935698447, 'fraction_numerical': 0.019955654101995565, 'mean_word_length': 1.9645203679369252, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4899075', 'n_tokens_mistral': 712, 'n_tokens_neox': 664, 'n_words': 138}