<commit_before>'use strict';

var Promise = require('bluebird');
var UPYUN = require('upyun');
var moment = require('moment');
var util = require('util');
var BaseAdapter = require('ghost-storage-base');


function UpyunAdapter(config) {
	BaseAdapter.call(this);
	this.options = config || {};
}

util.inherits(UpyunAdapter, BaseAdapter);

// ### Save
// Saves the image to Upyun
// - image is the express image object
// - returns a promise which ultimately returns the full url to the uploaded image
UpyunAdapter.prototype.save = function(image) {
	var _this = this;

	var upyun = new UPYUN (this.options.bucket, this.options.operator, this.options.password, 'v0.api.upyun.com', {apiVersion: 'v2'});

	return new Promise (function (resolve, reject) {
		var remotePath = _this.getRemotePath(image);
		var remoteURL = _this.options.domain;
		upyun.putFile(remotePath, image.path, null, false, {}, function (err, result) {
			if (err || result.statusCode !== 200) {
				reject('[' + result.data.code + '] ' + result.data.msg);
			} else {
				if (_this.options.imageVersion !== undefined) {
					resolve(remoteURL + remotePath + _this.options.imageVersion);
				} else {
					resolve(remoteURL + remotePath);
				}
			}
		});
	});
};

// middleware for serving the files
UpyunAdapter.prototype.serve = function () {
	// a no-op, these are absolute URLs
	return function (req, res, next) {
		next();
	};
};

UpyunAdapter.prototype.exists = function () {
	// Server side will automatically replace the file.
	return;
};

UpyunAdapter.prototype.delete = function (target) {
	//For backup and security purposes there is no way to delete files
	//whatever on local or server side through Ghost, please do it manually.
	return;
};

UpyunAdapter.prototype.getRemotePath = function (image) {
	var folder = moment().format(this.options.folder || 'YYYY/MM/').replace(/^\//, '');

	return '/' + this.options.prefix + folder + image.name;
};

module.exports = UpyunAdapter;<commit_msg>Use class instead of inherits<commit_after>'use strict';

const Promise = require('bluebird');
const yun = require('upyun');
const moment = require('moment');
const BaseAdapter = require('ghost-storage-base');


class UpyunAdapter extends BaseAdapter {

  constructor(options) {
    super(options);
    this.options = options || {};
  }

  exists() {
  	return false;
  }

  save(image) {

		const _this = this;
		const upyun = new yun(this.options.bucket, this.options.operator, this.options.password, 'v0.api.upyun.com', {apiVersion: 'v2'});

		return new Promise (function(resolve, reject) {
			const remotePath = _this.getRemotePath(image);
			const remoteURL = _this.options.domain;
			upyun.putFile(remotePath, image.path, null, false, {}, function (err, result) {
				if (err || result.statusCode !== 200) {
					reject('[' + result.data.code + '] ' + result.data.msg);
				} else {
					if (_this.options.imageVersion !== undefined) {
						resolve(remoteURL + remotePath + _this.options.imageVersion);
					} else {
						resolve(remoteURL + remotePath);
					}
				}
			});
		});
  }

  getRemotePath(image) {
    const folder = moment().format(this.options.folder || 'YYYY/MM/').replace(/^\//, '');
    return '/' + this.options.prefix + folder + image.name;
  }

  serve() {
    return function(req, res, next) {
      next();
    };
  }

  delete() {
  	return true;
  }
}

module.exports = UpyunAdapter;
{'fraction_non_alphanumeric': 0.15230224321133412, 'fraction_numerical': 0.0029515938606847697, 'mean_word_length': 3.66162310866575, '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': '1125606', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1071, 'n_words': 266}