<commit_before>"use strict";

/**
 * Module dependencies.
 */

const AWS = require('aws-sdk');
const fs = require('fs');
const config = require('config');
const Subtitle = require('./subtitle.js');

AWS.config.loadFromPath('./config.json');
const s3 = new AWS.S3({ apiVersion: '2006-03-01' });

/**
 * AWS S3 Bucket client
 *
 */
class Storage {
	/**
     * Storage constructor.
     *
     * @param {Subtitle} subtitle
     * @api private
     */
	constructor(subtitle) {
		this.subtitle = subtitle;
		this.fileName = Subtitle.getFileName(this.subtitle);
	}

	/**
		 * Checks if an object exists on S3
		 *
		 * @param {Function} callback
		 * @api public
		 */
	exists(callback) {
		let params = {
			Bucket: config.get('S3.bucket'),
			Key: this.fileName
		};

		s3.headObject(params, function(err, data) {
			if (err)  {
				callback();
			} else {
				console.log(`object found on S3: ${this.fileName}`);
			}
		});
	}

	/**
     * Uploads a file to the S3 bucket
     *
     * @param {Function} callback
     * @api public
     */
	upload(callback) {
		let headParams = {
			Bucket: config.get('S3.bucket'),
			Key: this.fileName
		};
		let uploadParams = {
			Bucket: config.get('S3.bucket'),
			Key: this.fileName,
			Body: ''
		};

		let fileStream = fs.createReadStream('/tmp/' + this.fileName);
		fileStream.on('error', (err) => {
			console.log('File Error', err);
		});

		uploadParams.Body = fileStream;
		s3.headObject(headParams, function(err, data) {
			if (err)  {
				s3.upload(uploadParams, (err, data) => {
					if (err) {
						console.log("Error", err);
					} if (data) {
						console.log("Upload Success", data.Location);
						callback();
					}
				});
			} else {
				console.log(`object found on S3: ${headParams.Key}`);
			}
		});
	}
}

/**
 * Module exports.
 */

module.exports = Storage;
<commit_msg>Message is not sent to Engine when subtitle already exists on S3 (#63)<commit_after>"use strict";

/**
 * Module dependencies.
 */

const AWS = require('aws-sdk');
const fs = require('fs');
const config = require('config');
const Subtitle = require('./subtitle.js');

AWS.config.loadFromPath('./config.json');
const s3 = new AWS.S3({ apiVersion: '2006-03-01' });

/**
 * AWS S3 Bucket client
 *
 */
class Storage {
	/**
     * Storage constructor.
     *
     * @param {Subtitle} subtitle
     * @api private
     */
	constructor(subtitle) {
		this.subtitle = subtitle;
		this.fileName = Subtitle.getFileName(this.subtitle);
	}

	/**
		 * Checks if an object exists on S3
		 *
		 * @param {Function} callback
		 * @api public
		 */
	exists(callback) {
		let params = {
			Bucket: config.get('S3.bucket'),
			Key: this.fileName
		};

		s3.headObject(params, function(err, data) {
			if (err)  {
				callback();
			} else {
				console.log(`object found on S3: ${this.fileName}`);
			}
		});
	}

	/**
     * Uploads a file to the S3 bucket
     *
     * @param {Function} callback
     * @api public
     */
	upload(callback) {
		let headParams = {
			Bucket: config.get('S3.bucket'),
			Key: this.fileName
		};
		let uploadParams = {
			Bucket: config.get('S3.bucket'),
			Key: this.fileName,
			Body: ''
		};

		let fileStream = fs.createReadStream('/tmp/' + this.fileName);
		fileStream.on('error', (err) => {
			console.log('File Error', err);
		});

		uploadParams.Body = fileStream;
		s3.headObject(headParams, function(err, data) {
			if (err)  {
				s3.upload(uploadParams, (err, data) => {
					if (err) {
						console.log("Error", err);
					} if (data) {
						console.log("Upload Success", data.Location);
						callback();
					}
				});
			} else {
				console.log(`object found on S3: ${headParams.Key}`);
                callback();
			}
		});
	}
}

/**
 * Module exports.
 */

module.exports = Storage;

{'fraction_non_alphanumeric': 0.17159605648814283, 'fraction_numerical': 0.011990407673860911, 'mean_word_length': 2.6731898238747553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5193821', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1287, 'n_words': 287}