<commit_before>var FieldType = require('../Type');
var util = require('util');
var utils = require('keystone-utils');

var debug = require('debug')('keystone:fields:file');

/**
 * File FieldType Constructor
 */
function file (list, path, options) {
	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);
}
file.properName = 'File';
util.inherits(file, FieldType);

/**
 * Registers the field on the List's Mongoose Schema.
 */
file.prototype.addToSchema = function (schema) {

	var field = this;

	this.paths = {};
	// add field paths from the storage schema
	Object.keys(this.storage.schema).forEach(function (path) {
		field.paths[path] = field._path.append('.' + path);<commit_msg>FileType: use /files endpoint<commit_after>var FieldType = require('../Type');
var util = require('util');
var assign = require('object-assign');
var utils = require('keystone-utils');

var debug = require('debug')('keystone:fields:file');

/**
 * File FieldType Constructor
 */
function file (list, path, options) {
	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);
}
file.properName = 'File';
util.inherits(file, FieldType);

file.prototype.getData = function (item) {
	var file = item.get(this.path);
	var doc = item;
	while (doc.parent) {
		doc = doc.parent();
		if (!doc) {
			return file;
		}
	}
	var listId = encodeURIComponent(this.list.key);
	var docId = encodeURIComponent(doc._id);
	var fileId = encodeURIComponent(item._id || file.filename);
	if (fileId === docId) {
		fileId = encodeURIComponent(file.filename);
	}
	var name = encodeURIComponent(file.originalname || file.filename);
	return assign(
		{},
		file,
		{ url: '/files/' + listId + '/' + docId + '/' + fileId + '/' + name }
	);
};

/**
 * Registers the field on the List's Mongoose Schema.
 */
file.prototype.addToSchema = function (schema) {

	var field = this;

	this.paths = {};
	// add field paths from the storage schema
	Object.keys(this.storage.schema).forEach(function (path) {
		field.paths[path] = field._path.append('.' + path);
{'fraction_non_alphanumeric': 0.17336977743069112, 'fraction_numerical': 0.0, 'mean_word_length': 4.228571428571429, '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': '4095749', 'n_tokens_mistral': 853, 'n_tokens_neox': 833, 'n_words': 208}