<commit_before>// Load modules

var Boom = require('boom');
var Joi = require('joi');


// Declare internals

var internals = {
    regions: ['left', 'middle', 'right']
};


module.exports = internals.blink = {
    description: 'Does something related to blinking',
    tags: ['api'],
    validate: {
        payload: {
            millis: Joi.number().integer().required(),
            regions: Joi.array().items(Joi.string().valid(internals.regions)).min(1).max(2),
            timeout: Joi.number().integer().required()
        }
    },
    handler: function (request, reply) {

        var millis = request.payload.millis;
        var regions = request.payload.regions;
        var timeout = request.payload.timeout;

        this.logger.log('Got valid blink request. interval: ' + millis + '. regions: ' + regions + '. timeout: ' + timeout);

        if (this.settings.colors_called) {
            return reply(Boom.internal('must call colors before blink!'));
        }

        var Kb = require('msi-keyboard');
        regions ? Kb.blink(regions, millis) : Kb.blink(millis);

        if (timeout) {
            setTimeout(Kb.stopBlink, timeout);
        }

        return reply({ code: 200, message: 'ok!' });
    }
};<commit_msg>removed timeout being required, made blink call return 412 if called too early<commit_after>// Load modules

var Boom = require('boom');
var Joi = require('joi');


// Declare internals

var internals = {
    regions: ['left', 'middle', 'right']
};


module.exports = internals.blink = {
    description: 'Does something related to blinking',
    tags: ['api'],
    validate: {
        payload: {
            millis: Joi.number().integer().required(),
            regions: Joi.array().items(Joi.string().valid(internals.regions)).min(1).max(2),
            timeout: Joi.number().integer()
        }
    },
    handler: function (request, reply) {

        var millis = request.payload.millis;
        var regions = request.payload.regions;
        var timeout = request.payload.timeout;

        this.logger.log('Got valid blink request. interval: ' + millis + '. regions: ' + regions + '. timeout: ' + timeout);

        if (this.settings.colors_called) {
            return reply(Boom.preconditionFailed('must call colors before blink!'));
        }

        var Kb = require('msi-keyboard');
        regions ? Kb.blink(regions, millis) : Kb.blink(millis);

        if (timeout) {
            setTimeout(Kb.stopBlink, timeout);
        }

        return reply({ code: 200, message: 'ok!' });
    }
};
{'fraction_non_alphanumeric': 0.15039370078740158, 'fraction_numerical': 0.005118110236220472, 'mean_word_length': 2.471311475409836, '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': '4592040', 'n_tokens_mistral': 771, 'n_tokens_neox': 740, 'n_words': 178}