<commit_before>var config = require('../config'),
    crypto = require('crypto'),
    db = require('../db'),
    fs = require('fs'),
    path = require('path'),
    pix = require('../server/pix'),
    stackless = require('../server/stackless');

function Recycler() {
	this.tag = 'archive';
	this.y = new db.Yakusoku(this.tag, db.UPKEEP_IDENT);
}

var R = Recycler.prototype;

R.recycle_post = function (post, cb) {
	if (!post.image || !post.image.src || post.hideimg)
		return cb(null);
	var r = this.y.connect();
	var image = post.image
	var src = pix.media_path('src', image.src);
	var toDelete = [];
	if (image.thumb) {
		toDelete.push(src);
		src = pix.media_path('thumb', image.thumb);
	}
	if (image.realthumb) {
		toDelete.push(pix.media_path('thumb', image.realthumb));
	}

	MD5_file(src, function (err, MD5) {
		if (err) {
			if (err.code == 'ENOENT')
				console.warn(src + " doesn't exist.");
			else
				console.error(err);
			return cb(null);
		}
		var dest = MD5 + path.extname(src);
		var dest_path = path.join(config.MEDIA_DIRS.vint, dest);
		pix.mv_file(src, dest_path, function (err) {
			if (err)
				return cb(err);
			var m = r.multi();
			var key = post.op ? 'post:' + post.num
					: 'thread:' + post.num;
			m.hdel(key, 'src');
			m.hdel(key, 'thumb');
			m.hset(key, 'vint', dest);
			m.exec(function (err) {
				if (err) {
					// move it back
					pix.mv_file(dest_path, src,
							function (e) {
						if (e)
							console.error(e);
						return cb(err);
					});
					return;
				}

				toDelete.forEach(function (victim) {
					fs.unlink(victim, function (err) {
						if (err)
							console.error(err);
					});
				});
				if (toDelete.length) {
					var info = post.num + ': del ' +
							toDelete.length;
					console.log(info);
				}

				cb(null);
			});
		});<commit_msg>Use winston in clean.js<commit_after>var config = require('../config'),
    crypto = require('crypto'),
    db = require('../db'),
    fs = require('fs'),
    path = require('path'),
    pix = require('../server/pix'),
    stackless = require('../server/stackless'),
    winston = require('winston');

function Recycler() {
	this.tag = 'archive';
	this.y = new db.Yakusoku(this.tag, db.UPKEEP_IDENT);
}

var R = Recycler.prototype;

R.recycle_post = function (post, cb) {
	if (!post.image || !post.image.src || post.hideimg)
		return cb(null);
	var r = this.y.connect();
	var image = post.image
	var src = pix.media_path('src', image.src);
	var toDelete = [];
	if (image.thumb) {
		toDelete.push(src);
		src = pix.media_path('thumb', image.thumb);
	}
	if (image.realthumb) {
		toDelete.push(pix.media_path('thumb', image.realthumb));
	}

	MD5_file(src, function (err, MD5) {
		if (err) {
			if (err.code == 'ENOENT')
				winston.warn(src + " doesn't exist.");
			else
				winston.error(err);
			return cb(null);
		}
		var dest = MD5 + path.extname(src);
		var dest_path = path.join(config.MEDIA_DIRS.vint, dest);
		pix.mv_file(src, dest_path, function (err) {
			if (err)
				return cb(err);
			var m = r.multi();
			var key = post.op ? 'post:' + post.num
					: 'thread:' + post.num;
			m.hdel(key, 'src');
			m.hdel(key, 'thumb');
			m.hset(key, 'vint', dest);
			m.exec(function (err) {
				if (err) {
					// move it back
					pix.mv_file(dest_path, src,
							function (e) {
						if (e)
							winston.error(e);
						return cb(err);
					});
					return;
				}

				toDelete.forEach(function (victim) {
					fs.unlink(victim, function (err) {
						if (err)
							winston.error(err);
					});
				});
				if (toDelete.length) {
					var info = post.num + ': del ' +
							toDelete.length;
					winston.info(info);
				}

				cb(null);
			});
		});
{'fraction_non_alphanumeric': 0.18615426546742983, 'fraction_numerical': 0.001635322976287817, 'mean_word_length': 2.6773547094188377, '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': '1304346', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1377, 'n_words': 287}