<commit_before>/*!
 * Module dependencies.
 */

var _ = require('underscore'),
	keystone = require('../../'),
	util = require('util'),
	cloudinary = require('cloudinary'),
	utils = require('../utils'),
	super_ = require('../field');

/**
 * CloudinaryImage FieldType Constructor
 * @extends Field
 * @api public
 */

function cloudinaryimage(list, path, options) {
	this._underscoreMethods = ['format'];
	// TODO: implement filtering, hard-coded as disabled for now
	options.nofilter = true;
	cloudinaryimage.super_.call(this, list, path, options);
};

/*!
 * Inherit from Field
 */
 
util.inherits(cloudinaryimage, super_);


/**
 * Registers the field on the List's Mongoose Schema.
 * 
 * @api public
 */

cloudinaryimage.prototype.addToSchema = function() {
	
	var field = this,
		schema = this.list.schema;
	
	var paths = this.paths = {
		// cloudinary fields
		public_id: 		this._path.append('.public_id'),
		version: 		this._path.append('.version'),
		signature: 		this._path.append('.signature'),
		format: 		this._path.append('.format'),
		resource_type: 	this._path.append('.resource_type'),
		url: 			this._path.append('.url'),
		width: 			this._path.append('.width'),
		height: 		this._path.append('.height'),
		secure_url: 	this._path.append('.secure_url'),
		// virtuals
		exists: 		this._path.append('.exists'),
		upload: 		this._path.append('_upload'),
		action: 		this._path.append('_action')
	};
	
	schema.nested[this.path] = true;
	schema.add({
		public_id:		String,
		version:		Number,
		signature:		String,
		format:			String,
		resource_type:	String,
		url:			String,
		width:			Number,
		height:			Number,
		secure_url:		String
	}, this.path + '.');
	
	var exists = function(item) {
		return (item.get(paths.public_id) ? true : false);
	}
	
	var src = function(item, options) {
		
		if (!exists(item)) {
			return '';
		}
		
		options = ('object' == typeof options) ? options : {};
		
		if (keystone.get('cloudinary webp') !== false) {
			options.fetch_format = "auto";
		}
		
		if (keystone.get('cloudinary secure')) {
			options.secure = true;
		}
		
		return cloudinary.url(item.get(paths.public_id) + '.' + item.get(paths.format), options);
		
	}
	
	var reset = function(item) {
		item.set(field.path, {
			public_id: '',
			version: 0,
			signature: '',
			format: '',
			resource_type: '',
			url: '',
			width: 0,
			height: 0,
			secure_url: ''<commit_msg>Adding progressive option to cloudinary images<commit_after>/*!
 * Module dependencies.
 */

var _ = require('underscore'),
	keystone = require('../../'),
	util = require('util'),
	cloudinary = require('cloudinary'),
	utils = require('../utils'),
	super_ = require('../field');

/**
 * CloudinaryImage FieldType Constructor
 * @extends Field
 * @api public
 */

function cloudinaryimage(list, path, options) {
	this._underscoreMethods = ['format'];
	// TODO: implement filtering, hard-coded as disabled for now
	options.nofilter = true;
	cloudinaryimage.super_.call(this, list, path, options);
};

/*!
 * Inherit from Field
 */
 
util.inherits(cloudinaryimage, super_);


/**
 * Registers the field on the List's Mongoose Schema.
 * 
 * @api public
 */

cloudinaryimage.prototype.addToSchema = function() {
	
	var field = this,
		schema = this.list.schema;
	
	var paths = this.paths = {
		// cloudinary fields
		public_id: 		this._path.append('.public_id'),
		version: 		this._path.append('.version'),
		signature: 		this._path.append('.signature'),
		format: 		this._path.append('.format'),
		resource_type: 	this._path.append('.resource_type'),
		url: 			this._path.append('.url'),
		width: 			this._path.append('.width'),
		height: 		this._path.append('.height'),
		secure_url: 	this._path.append('.secure_url'),
		// virtuals
		exists: 		this._path.append('.exists'),
		upload: 		this._path.append('_upload'),
		action: 		this._path.append('_action')
	};
	
	schema.nested[this.path] = true;
	schema.add({
		public_id:		String,
		version:		Number,
		signature:		String,
		format:			String,
		resource_type:	String,
		url:			String,
		width:			Number,
		height:			Number,
		secure_url:		String
	}, this.path + '.');
	
	var exists = function(item) {
		return (item.get(paths.public_id) ? true : false);
	}
	
	var src = function(item, options) {
		
		if (!exists(item)) {
			return '';
		}
		
		options = ('object' == typeof options) ? options : {};
		
		if (keystone.get('cloudinary webp') !== false) {
			options.fetch_format = "auto";
		}
		
		if (keystone.get('cloudinary progressive') !== false) {
			options.progressive = true;
		}
		
		if (keystone.get('cloudinary secure')) {
			options.secure = true;
		}
		
		return cloudinary.url(item.get(paths.public_id) + '.' + item.get(paths.format), options);
		
	}
	
	var reset = function(item) {
		item.set(field.path, {
			public_id: '',
			version: 0,
			signature: '',
			format: '',
			resource_type: '',
			url: '',
			width: 0,
			height: 0,
			secure_url: ''
{'fraction_non_alphanumeric': 0.169895982051805, 'fraction_numerical': 0.0012237405669997961, 'mean_word_length': 3.3864042933810374, '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': '648563', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1649, 'n_words': 343}