Fix OC.FileInfo to copy all properties

This makes it possible to also store custom properties passed through
the data object like tags or shareOwner.
This commit is contained in:
Vincent Petry 2015-11-18 15:42:35 +01:00 committed by Lukas Reschke
parent 358858c9e3
commit 7ec83fc9fb

View File

@ -19,39 +19,31 @@
* @since 8.2 * @since 8.2
*/ */
var FileInfo = function(data) { var FileInfo = function(data) {
if (!_.isUndefined(data.id)) { var self = this;
_.each(data, function(value, key) {
if (!_.isFunction(value)) {
self[key] = value;
}
});
if (!_.isUndefined(this.id)) {
this.id = parseInt(data.id, 10); this.id = parseInt(data.id, 10);
} }
// TODO: normalize path // TODO: normalize path
this.path = data.path || ''; this.path = data.path || '';
this.name = data.name;
this.mtime = data.mtime; if (this.type === 'dir') {
this.etag = data.etag; this.mimetype = 'httpd/unix-directory';
this.permissions = data.permissions;
this.size = data.size;
this.mimetype = data.mimetype || 'application/octet-stream';
this.mountType = data.mountType;
this.icon = data.icon;
if (data.type) {
this.type = data.type;
} else if (this.mimetype === 'httpd/unix-directory') {
this.type = 'dir';
} else { } else {
this.type = 'file'; this.mimetype = this.mimetype || 'application/octet-stream';
} }
if (data.tags) { if (!this.type) {
this.tags = data.tags; if (this.mimetype === 'httpd/unix-directory') {
} this.type = 'dir';
if (!this.mimetype) {
if (this.type === 'dir') {
this.mimetype = 'httpd/unix-directory';
} else { } else {
this.mimetype = 'application/octet-stream'; this.type = 'file';
} }
} }
}; };
@ -104,7 +96,7 @@
* @type String * @type String
* @deprecated rely on mimetype instead * @deprecated rely on mimetype instead
*/ */
type: 'file', type: null,
/** /**
* Permissions. * Permissions.