emscripten Humble Cloud interface
Edward Rudd
2014-08-20 7aede50a03c43c05a0a6a796466c7baaed9e5ab7

populate "folders" in remote list based on the files on the cloud

1 files modified
29 ■■■■ changed files
client/library/humble_cloud.js 29 ●●●● patch | view | raw | blame | history
client/library/humble_cloud.js
@@ -36,7 +36,7 @@
                });
            });
        },
        // XHR Utility function
        xhrLoad: function(url, onload, onerror) {
          var xhr = new XMLHttpRequest();
          xhr.open('GET', url, true);
@@ -50,6 +50,7 @@
          xhr.onerror = onerror;
          xhr.send(null);
        },
        // Getting list of entities
        getLocalSet: function(mount, callback) {
            var entries = {};
@@ -87,13 +88,31 @@
          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
              }
            }