<commit_before>var request = require('request');
// request.debug=true;
var urls = require("./urls");
var fs = require("fs");
var authentication = require("./authentication");
var randomip = require("random-ip");

// Schemas
var Account = require("../db/schemas/account").Account;
var Skin = require("../db/schemas/skin").Skin;
var Traffic = require("../db/schemas/traffic").Traffic;

module.exports = {};

module.exports.findExistingSkin = function (hash, name, model, visibility, cb) {
    Skin.findOne({hash: hash, name: name, model: model, visibility: visibility}).exec(function (err, skin) {
        if (err) return console.log(err);
        if (skin) {
            skin.duplicate += 1;
            skin.save(function (err, skin) {
                if (err) return console.log(err);
                cb(skin);
            })
        } else {
            cb();
        }
    })
};

module.exports.getAvailableAccount = function (req, res, cb) {
    var time = Date.now() / 1000;
    Account.findOne({enabled: true, lastUsed: {'$lt': (time - 30)}}).sort({lastUsed: 1, errorCounter: 1}).exec(function (err, account) {
        if (err) return console.log(err);<commit_msg>only use accounts that are already authenticated by the current server<commit_after>var request = require('request');
// request.debug=true;
var urls = require("./urls");
var fs = require("fs");
var authentication = require("./authentication");
var randomip = require("random-ip");

var config = require("../config");

// Schemas
var Account = require("../db/schemas/account").Account;
var Skin = require("../db/schemas/skin").Skin;
var Traffic = require("../db/schemas/traffic").Traffic;

module.exports = {};

module.exports.findExistingSkin = function (hash, name, model, visibility, cb) {
    Skin.findOne({hash: hash, name: name, model: model, visibility: visibility}).exec(function (err, skin) {
        if (err) return console.log(err);
        if (skin) {
            skin.duplicate += 1;
            skin.save(function (err, skin) {
                if (err) return console.log(err);
                cb(skin);
            })
        } else {
            cb();
        }
    })
};

module.exports.getAvailableAccount = function (req, res, cb) {
    var time = Date.now() / 1000;
    Account.findOne({enabled: true, requestServer: {$in: [null, config.server]}, lastUsed: {'$lt': (time - 30)}}).sort({lastUsed: 1, errorCounter: 1}).exec(function (err, account) {
        if (err) return console.log(err);
{'fraction_non_alphanumeric': 0.17298387096774193, 'fraction_numerical': 0.007258064516129033, 'mean_word_length': 2.963258785942492, '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': '1647553', 'n_tokens_mistral': 769, 'n_tokens_neox': 739, 'n_words': 188}