tasks/lib/filestoreutil.js
function structureResolve(resolve, sPathStartWith) {
    var aToResolve = [];
    var aResolved = [];

    if (typeof resolve === 'object' && resolve instanceof Array) {
        aToResolve = resolve;
    } else if (typeof resolve === 'string') {
        aToResolve.push(resolve);
    } else {
        return null;
    }

    // resolve
    aToResolve.forEach(function (item) {
        var aSplit = item.split('/');

        for (var i = 0; i < aSplit.length; i++) {
            var aConc = aSplit.slice(0, i + 1);
            var sConc = (aConc.length > 1) ? aConc.join('/') : aConc[0];

            if (sConc.length > 0) {
                aResolved.push({
                    type: (i < (aSplit.length - 1)) ? OBJECT_TYPE.folder : OBJECT_TYPE.file,
                    id: (sConc.charAt(0) !== sPathStartWith) ? sPathStartWith + sConc : sConc
                });
            }
        }
    });

    // remove dups
    aResolved = aResolved.sort(function (sVal1, sVal2) {
        var sA = JSON.stringify(sVal1);
        var sB = JSON.stringify(sVal2);

        if (sA === sB) {
            return 0;
        } else if (sA <= sB) {
            return -1;
        } else {
            return 1;
        }
    })
        .filter(function (oItem, iPos) {
            if (iPos > 0) {
                return JSON.stringify(aResolved[iPos - 1]) !== JSON.stringify(oItem);
            } else {
                return true;
            }
        });

    return aResolved;
}
function structureResolve(resolve, sPathStartWith) {
    var aToResolve = [];
    var aResolved = [];

    if (typeof resolve === 'object' && resolve instanceof Array) {
        aToResolve = resolve;
    } else if (typeof resolve === 'string') {
        aToResolve.push(resolve);
    } else {
        return null;
    }

    // resolve
    aToResolve.forEach(function (item) {
        var aSplit = item.split('/');

        for (var i = 0; i < aSplit.length; i++) {
            var aConc = aSplit.slice(0, i + 1);
            var sConc = (aConc.length > 1) ? aConc.join('/') : aConc[0];

            if (sConc.length > 0) {
                aResolved.push({
                    type: (i < (aSplit.length - 1)) ? OBJECT_TYPE.folder : OBJECT_TYPE.file,
                    id: (sConc.charAt(0) !== sPathStartWith) ? sPathStartWith + sConc : sConc
                });
            }
        }
    });

    // remove dups
    aResolved = aResolved.sort(function (sVal1, sVal2) {
        var sA = JSON.stringify(sVal1);
        var sB = JSON.stringify(sVal2);

        if (sA === sB) {
            return 0;
        } else if (sA <= sB) {
            return -1;
        } else {
            return 1;
        }
    })
        .filter(function (oItem, iPos) {
            if (iPos > 0) {
                return JSON.stringify(aResolved[iPos - 1]) !== JSON.stringify(oItem);
            } else {
                return true;
            }
        });

    return aResolved;
}
function structureResolve ( resolve , sPathStartWith ) { var aToResolve = [ ] ; var aResolved = [ ] ; if ( typeof resolve === 'object' && resolve instanceof Array ) { aToResolve = resolve ; } else if ( typeof resolve === 'string' ) { aToResolve . push ( resolve ) ; } else { return null ; } // resolve aToResolve . forEach ( function ( item ) { var aSplit = item . split ( '/' ) ; for ( var i = 0 ; i < aSplit . length ; i ++ ) { var aConc = aSplit . slice ( 0 , i + 1 ) ; var sConc = ( aConc . length > 1 ) ? aConc . join ( '/' ) : aConc [ 0 ] ; if ( sConc . length > 0 ) { aResolved . push ( { type : ( i < ( aSplit . length - 1 ) ) ? OBJECT_TYPE . folder : OBJECT_TYPE . file , id : ( sConc . charAt ( 0 ) !== sPathStartWith ) ? sPathStartWith + sConc : sConc } ) ; } } } ) ; // remove dups aResolved = aResolved . sort ( function ( sVal1 , sVal2 ) { var sA = JSON . stringify ( sVal1 ) ; var sB = JSON . stringify ( sVal2 ) ; if ( sA === sB ) { return 0 ; } else if ( sA <= sB ) { return - 1 ; } else { return 1 ; } } ) . filter ( function ( oItem , iPos ) { if ( iPos > 0 ) { return JSON . stringify ( aResolved [ iPos - 1 ] ) !== JSON . stringify ( oItem ) ; } else { return true ; } } ) ; return aResolved ; }
Resolves file structure into single folders and files
@param {(string|string)} resolve file or file array
@param {string} sPathStartWith path has to start with that value
@return {Array} array with resolved folders and files
Resolves file structure into single folders and files