| | |
| | | }); |
| | | }); |
| | | }, |
| | | |
| | | // XHR Utility function |
| | | xhrLoad: function(url, onload, onerror) { |
| | | var xhr = new XMLHttpRequest(); |
| | | xhr.open('GET', url, true); |
| | |
| | | xhr.onerror = onerror; |
| | | xhr.send(null); |
| | | }, |
| | | // Getting list of entities |
| | | getLocalSet: function(mount, callback) { |
| | | var entries = {}; |
| | | |
| | |
| | | var url = HUMBLE_CLOUD.remoteAPIEndpoint + '/storage/files'; |
| | | HUMBLE_CLOUD.xhrLoad(url, function(data) { |
| | | var entries = {}, |
| | | toAbsolute = function(p) { return PATH.join2(mount.mountpoint, p); }; |
| | | json = JSON.parse(data); |
| | | for(var k in json.data) { |
| | | var f = json.data[k]; |
| | | var absolute = PATH.join2(mount.mountpoint, f.path); |
| | | entries[absolute] = { |
| | | var f = json.data[k], |
| | | timestamp = new Date(parseInt(f.timestamp)); |
| | | if (f.path.indexOf('/') !== -1) { |
| | | // we have folders.. stuff them in the list |
| | | var parts = f.path.split('/'); |
| | | // remove the "file" from the end |
| | | parts.pop(); |
| | | // remove the empty directory from the beginning |
| | | if (parts[0] == '') parts.shift(); |
| | | |
| | | parts.forEach(function(e) { |
| | | var p = toAbsolute(e); |
| | | if (!(p in entries)) { |
| | | entries[p] = { |
| | | timestamp: timestamp |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | entries[toAbsolute(f.path)] = { |
| | | url: (f.url.substr(0, 1) == '/') ? HUMBLE_CLOUD.remoteAPIEndpoint + f.url : f.url, |
| | | timestamp: new Date(parseInt(f.timestamp)), |
| | | timestamp: timestamp, |
| | | size: f.size |
| | | } |
| | | } |