Пример #1
0
function s3file(list, path, options) {
	grappling.mixin(this)
		.allowHooks('pre:upload');
	this._underscoreMethods = ['format', 'uploadFile'];
	this._fixedSize = 'full';

	// TODO: implement filtering, usage disabled for now
	options.nofilter = true;

	// TODO: implement initial form, usage disabled for now
	if (options.initial) {
		throw new Error('Invalid Configuration\n\n' +
			'S3File fields (' + list.key + '.' + path + ') do not currently support being used as initial fields.\n');
	}

	s3file.super_.call(this, list, path, options);

	// validate s3 config (has to happen after super_.call)
	if (!this.s3config) {
		throw new Error('Invalid Configuration\n\n' +
			'S3File fields (' + list.key + '.' + path + ') require the "s3 config" option to be set.\n\n' +
			'See http://keystonejs.com/docs/configuration/#services-amazons3 for more information.\n');
	}

	// Could be more pre- hooks, just upload for now
	if (options.pre && options.pre.upload) {
		this.pre('upload', options.pre.upload);
	}

}
Пример #2
0
/**
 * localfile FieldType Constructor
 * @extends Field
 * @api public
 */
function localfile (list, path, options) {

	if (!loggedWarning) {
		loggedWarning = true;
		console.warn('The LocalFile field type has been deprecated and will be removed '
			+ 'very soon. Please see https://github.com/keystonejs/keystone/issues/3228');
	}

	grappling.mixin(this).allowHooks('move');
	this._underscoreMethods = ['format', 'uploadFile'];
	this._fixedSize = 'full';
	this.autoCleanup = options.autoCleanup || false;

	if (options.overwrite !== false) {
		options.overwrite = true;
	}

	localfile.super_.call(this, list, path, options);

	// validate destination dir
	if (!options.dest) {
		throw new Error('Invalid Configuration\n\n'
			+ 'localfile fields (' + list.key + '.' + path + ') require the "dest" option to be set.');
	}
	// Allow hook into before and after
	if (options.pre && options.pre.move) {
		this.pre('move', options.pre.move);
	}

	if (options.post && options.post.move) {
		this.post('move', options.post.move);
	}

}
Пример #3
0
/**
 * localfiles FieldType Constructor
 * @extends Field
 * @api public
 */
function localfiles (list, path, options) {
	grappling.mixin(this).allowHooks('move');
	this._underscoreMethods = ['format', 'uploadFiles'];
	this._fixedSize = 'full';

	// TODO: implement filtering, usage disabled for now
	options.nofilter = true;

	// TODO: implement initial form, usage disabled for now
	if (options.initial) {
		throw new Error('Invalid Configuration\n\n'
			+ 'localfiles fields (' + list.key + '.' + path + ') do not currently support being used as initial fields.\n');
	}

	if (options.overwrite !== false) {
		options.overwrite = true;
	}

	localfiles.super_.call(this, list, path, options);

	// validate destination dir
	if (!options.dest) {
		throw new Error('Invalid Configuration\n\n'
			+ 'localfiles fields (' + list.key + '.' + path + ') require the "dest" option to be set.');
	}

	// Allow hook into before and after
	if (options.pre && options.pre.move) {
		this.pre('move', options.pre.move);
	}

	if (options.post && options.post.move) {
		this.post('move', options.post.move);
	}
}
Пример #4
0
/**
 * File FieldType Constructor
 */
function file (list, path, options) {
	grappling.mixin(this).allowHooks('pre:upload');
	this._underscoreMethods = ['format', 'upload', 'remove', 'reset'];
	this._fixedSize = 'full';

	if (!options.storage) {
		throw new Error('Invalid Configuration\n\n'
		+ 'File fields (' + list.key + '.' + path + ') require storage to be provided.');
	}
	this.storage = options.storage;
	file.super_.call(this, list, path, options);
}
Пример #5
0
/**
 * AzureFile FieldType Constructor
 * @extends Field
 * @api public
 */
function azurefile (list, path, options) {

	if (!loggedWarning) {
		loggedWarning = true;
		console.warn('The AzureFile field type has been deprecated and will be removed '
			+ 'very soon. Please see https://github.com/keystonejs/keystone/issues/3228');
	}

	grappling.mixin(this).allowHooks('pre:upload');

	this._underscoreMethods = ['format', 'uploadFile'];
	this._fixedSize = 'full';

	// TODO: implement filtering, usage disabled for now
	options.nofilter = true;

	// TODO: implement initial form, usage disabled for now
	if (options.initial) {
		throw new Error('Invalid Configuration\n\nAzureFile fields (' + list.key + '.' + path + ') do not currently support being used as initial fields.\n');
	}

	var self = this;
	options.filenameFormatter = options.filenameFormatter || function (item, filename) { return filename; };
	options.containerFormatter = options.containerFormatter || function (item, filename) { return self.azurefileconfig.container; };// eslint-disable-line no-unused-vars

	azurefile.super_.call(this, list, path, options);

	// validate azurefile config (has to happen after super_.call)
	if (!this.azurefileconfig) {
		throw new Error('Invalid Configuration\n\n'
			+ 'AzureFile fields (' + list.key + '.' + path + ') require the "azurefile config" option to be set.\n\n'
			+ 'See http://keystonejs.com/docs/configuration/#services-azure for more information.\n');
	}

	// TODO; this is really bad, we shouldn't be overwriting global env!
	process.env.AZURE_STORAGE_ACCOUNT = this.azurefileconfig.account;
	process.env.AZURE_STORAGE_ACCESS_KEY = this.azurefileconfig.key;

	this.azurefileconfig.container = this.azurefileconfig.container || 'keystone';

	// Could be more pre- hooks, just upload for now
	if (options.pre && options.pre.upload) {
		this.pre('upload', options.pre.upload);
	}

}
Пример #6
0
/**
 * localfiles FieldType Constructor
 * @extends Field
 * @api public
 */
function localfiles (list, path, options) {

	if (!loggedWarning) {
		loggedWarning = true;
		console.warn('The LocalFiles field type has been deprecated and will be removed '
			+ 'very soon. Please see https://github.com/keystonejs/keystone/issues/3228');
	}

	grappling.mixin(this).allowHooks('move');
	this._underscoreMethods = ['format', 'uploadFiles'];
	this._fixedSize = 'full';

	// TODO: implement filtering, usage disabled for now
	options.nofilter = true;

	// TODO: implement initial form, usage disabled for now
	if (options.initial) {
		throw new Error('Invalid Configuration\n\n'
			+ 'localfiles fields (' + list.key + '.' + path + ') do not currently support being used as initial fields.\n');
	}

	if (options.overwrite !== false) {
		options.overwrite = true;
	}

	localfiles.super_.call(this, list, path, options);

	// validate destination dir
	if (!options.dest) {
		throw new Error('Invalid Configuration\n\n'
			+ 'localfiles fields (' + list.key + '.' + path + ') require the "dest" option to be set.');
	}

	// Allow hook into before and after
	if (options.pre && options.pre.move) {
		this.pre('move', options.pre.move);
	}

	if (options.post && options.post.move) {
		this.post('move', options.post.move);
	}
}
Пример #7
0
function azurefile(list, path, options) {
	grappling.mixin(this)
		.allowHooks('pre:upload');

	this._underscoreMethods = ['format', 'uploadFile'];
	this._fixedSize = 'full';

	// TODO: implement filtering, usage disabled for now
	options.nofilter = true;

	// TODO: implement initial form, usage disabled for now
	if (options.initial) {
		throw new Error('Invalid Configuration\n\nAzureFile fields (' + list.key + '.' + path + ') do not currently support being used as initial fields.\n');
	}

	azurefile.super_.call(this, list, path, options);

	// validate azurefile config (has to happen after super_.call)
	if (!this.azurefileconfig) {
		throw new Error('Invalid Configuration\n\n' +
			'AzureFile fields (' + list.key + '.' + path + ') require the "azurefile config" option to be set.\n\n' +
			'See http://keystonejs.com/docs/configuration/#services-azure for more information.\n');
	}

	process.env.AZURE_STORAGE_ACCOUNT = this.azurefileconfig.account;
	process.env.AZURE_STORAGE_ACCESS_KEY = this.azurefileconfig.key;

	this.azurefileconfig.container = this.azurefileconfig.container || 'keystone';

	var self = this;
	options.filenameFormatter = options.filenameFormatter || function(item, filename) { return filename; };
	options.containerFormatter = options.containerFormatter || function(item, filename) { return self.azurefileconfig.container; };

	// Could be more pre- hooks, just upload for now
	if (options.pre && options.pre.upload) {
		this.pre('upload', options.pre.upload);
	}

}
Пример #8
0
function gcsimage(list, path, options) {
    grappling.mixin(this)
        .allowHooks('pre:upload');
    this._underscoreMethods = ['format', 'uploadFile'];
    this._fixedSize = 'full';

    // TODO: implement filtering, usage disabled for now
    options.nofilter = true;

    gcsimage.super_.call(this, list, path, options);

    // validate gcs config (has to happen after super_.call)
    if (!keystone.get('gcs config')) {
        throw new Error('Invalid Configuration\n\n' + 'gcsimage fields (' + list.key + '.' + path + ') require the "gcs config" option to be set.\n\n' + 'See http://keystonejs.com/docs/configuration/#services-gcsimage for more information.\n');
    }

    // Could be more pre- hooks, just upload for now
    if (options.pre && options.pre.upload) {
        this.pre('upload', options.pre.upload);
    }

}
Пример #9
0
var Keystone = function () {
	grappling.mixin(this).allowHooks('pre:static', 'pre:bodyparser', 'pre:session', 'pre:logger', 'pre:admin', 'pre:routes', 'pre:render', 'updates', 'signin', 'signout');
	this.lists = {};
	this.fieldTypes = {};
	this.paths = {};
	this._options = {
		'name': 'Keystone',
		'brand': 'Keystone',
		'admin path': 'keystone',
		'compress': true,
		'headless': false,
		'logger': ':method :url :status :response-time ms',
		'auto update': false,
		'model prefix': null,
		'module root': moduleRoot,
		'frame guard': 'sameorigin',
	};
	this._redirects = {};

	// expose express
	this.express = express;

	// init environment defaults
	this.set('env', process.env.NODE_ENV || 'development');

	this.set('port', process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT);
	this.set('host', process.env.HOST || process.env.IP || process.env.OPENSHIFT_NODEJS_IP);
	this.set('listen', process.env.LISTEN);

	this.set('ssl', process.env.SSL);
	this.set('ssl port', process.env.SSL_PORT);
	this.set('ssl host', process.env.SSL_HOST || process.env.SSL_IP);
	this.set('ssl key', process.env.SSL_KEY);
	this.set('ssl cert', process.env.SSL_CERT);

	this.set('cookie secret', process.env.COOKIE_SECRET);
	this.set('cookie signin', (this.get('env') === 'development') ? true : false);

	this.set('embedly api key', process.env.EMBEDLY_API_KEY || process.env.EMBEDLY_APIKEY);
	this.set('mandrill api key', process.env.MANDRILL_API_KEY || process.env.MANDRILL_APIKEY);
	this.set('mandrill username', process.env.MANDRILL_USERNAME);
	this.set('google api key', process.env.GOOGLE_BROWSER_KEY);
	this.set('google server api key', process.env.GOOGLE_SERVER_KEY);
	this.set('ga property', process.env.GA_PROPERTY);
	this.set('ga domain', process.env.GA_DOMAIN);
	this.set('chartbeat property', process.env.CHARTBEAT_PROPERTY);
	this.set('chartbeat domain', process.env.CHARTBEAT_DOMAIN);
	this.set('allowed ip ranges', process.env.ALLOWED_IP_RANGES);

	if (process.env.S3_BUCKET && process.env.S3_KEY && process.env.S3_SECRET) {
		this.set('s3 config', { bucket: process.env.S3_BUCKET, key: process.env.S3_KEY, secret: process.env.S3_SECRET, region: process.env.S3_REGION });
	}

	if (process.env.AZURE_STORAGE_ACCOUNT && process.env.AZURE_STORAGE_ACCESS_KEY) {
		this.set('azurefile config', { account: process.env.AZURE_STORAGE_ACCOUNT, key: process.env.AZURE_STORAGE_ACCESS_KEY });
	}

	if (process.env.CLOUDINARY_URL) {
		// process.env.CLOUDINARY_URL is processed by the cloudinary package when this is set
		this.set('cloudinary config', true);
	}

	// init mongoose
	this.set('mongoose', require('mongoose'));
	this.mongoose.Promise = require('es6-promise').Promise;

	// Attach middleware packages, bound to this instance
	this.middleware = {
		api: require('./lib/middleware/api')(this),
		cors: require('./lib/middleware/cors')(this),
	};
};