(function() {

    app.service('MediaPreview', function() {
        var types = {
            file: {
                icon: 'material/insert-drive-file',
            },
            video: {
                icon: 'material/videocam',
            },
            image: {
                icon: 'material/photo',
            },
            folder: {
                icon: 'material/folder',
            }
        };

        this.init = function(options) {

            options = options || {};

            var preview = {};
            var get_media = options.get_media || agneta.get_media;

            preview.set = function(object) {

                object.background = backgroundImage(object);

                if (!object.background) {
                    object.icon = objectIcon(object);
                    if (!object.icon) {
                        object.extension = object.ext;
                    }
                }

                return object;
            };

            preview.hasBackground = function(file) {
                switch (file.type) {
                    case 'image':
                    case 'icon':
                        return true;
                }
            };

            //------------------------------------------------------------

            function backgroundImage(file, size) {
                var url = image(file, size);
                if (url) {
                    return "url(" + url + ')';
                }
            }

            function image(file, size) {
                size = size || 'square';
                switch (file.type) {
                    case 'image':
                        return getUrl(file, size);
                    case 'icon':
                        return getUrl(file);
                }
            }

            preview.backgroundImage = backgroundImage;
            preview.image = image;

            //------------------------------------------------------------

            function getUrl(file, size) {
                var version = new Date(file.updatedAt).valueOf();
                return get_media(file.location, size) + '?version=' + version;
            }


            preview.getUrl = getUrl;

            //------------------------------------------------------------


            function objectIcon(object) {
                if(!object){
                  return;
                }
                var location = getIcon(object);

                if (location) {
                    return getUrl({
                        location: location,
                        updatedAt: object.updatedAt
                    });
                }

            }

            preview.objectIcon = objectIcon;

            //------------------------------------------------------------

            function getIcon(object) {

                var type = types[object.type];
                if (type && type.icon) {
                    return 'icons/' + type.icon;
                }
            }

            preview.getIcon = getIcon;

            preview.toScope = function(scope) {
                scope.preview = scope.preview || {};
                scope.preview.hasBackground = preview.hasBackground;
                scope.preview.backgroundImage = preview.backgroundImage;
                scope.preview.objectIcon = preview.objectIcon;
                scope.preview.get = preview.get;
            };

            return preview;

        };

        this.public = this.init();
        this.private = this.init({
            get_media: agneta.prv_media
        });

    });
})();

@@ -1989,35 +1989,86 @@
 etUrl(file, size
-) %7B
+, media) %7B%0A                media = media %7C%7C get_media;
 %0A               
@@ -2141,20 +2141,16 @@
  return 
-get_
 media(fi
@@ -2384,16 +2384,17 @@
       if
+ 
 (!object
@@ -2394,18 +2394,21 @@
 !object)
+ 
 %7B%0A
+  
         
@@ -2656,16 +2656,16 @@
 datedAt%0A
-
         
@@ -2677,16 +2677,40 @@
        %7D
+, null, agneta.get_media
 );%0A     

Fix icon previews on private media library