emscripten Humble Cloud interface
Edward Rudd
2014-08-21 f4622ebcaa2242493bab672ce285bbfa80cf5e8d

move handling of server response parsing and "adjusting" to the provider

2 files modified
32 ■■■■■ changed files
client/library/library_cloudfs.js 17 ●●●● patch | view | raw | blame | history
humble_cloud/urkle_cloud.js 15 ●●●● patch | view | raw | blame | history
client/library/library_cloudfs.js
@@ -96,25 +96,25 @@
          mount.opts.provider.listFiles(mount.opts.cloud, 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],
                  timestamp = new Date(parseInt(f.timestamp));
            for(var k in data) {
              var f = data[k],
                  timestamp = new Date(f.timestamp);
              if (f.path.indexOf('/') !== -1) {
                  // we have folders.. stuff them in the list
                  var parts = f.path.split('/');
                  var parts = f.path.split('/'),
                      prefix = '';
                  // remove the "file" from the end
                  parts.pop();
                  // remove the empty directory from the beginning
                  if (parts[0] == '') parts.shift();
                  var prefix = '';
                  parts.forEach(function(e) {
                      var p = PATH.join2(prefix, e),
                      var p = prefix.length ? PATH.join2(prefix, e) : e,
                          abs = toAbsolute(p);
                      if (!(abs in entries)) {
                          entries[abs] = {
                              path: p,
                              type: 'dir',
                              timestamp: timestamp
                          };
                      }
@@ -123,8 +123,9 @@
              }
              var p = toAbsolute(f.path);
              entries[p] = {
                url: (f.url.substr(0, 1) == '/') ? CLOUDFS.remoteAPIEndpoint + f.url : f.url,
                url: f.url,
                path: f.path.trim('/'),
                type: 'file',
                timestamp: timestamp,
                size: f.size
              };
humble_cloud/urkle_cloud.js
@@ -22,9 +22,20 @@
    var provider = {
        vendor: 'Urkle!',
        listFiles: function(options, onload, onerror) {
        listFiles: function(options, onsuccess, onerror) {
            // could encapsulate onload + onerror to provide extra functionality here
            xhrGET(settings.remoteAPIEndpoint + '/storage/files?appToken=' + encodeURIComponent(options.applicationToken), onload, onerror);
            xhrGET(settings.remoteAPIEndpoint + '/storage/files?appToken=' + encodeURIComponent(options.applicationtoken), function(data) {
                var json = JSON.parse(data),
                    ret = [];
                ret = json.data.map(function(f) {
                    if (f.url.substr(0, 1) == '/') {
                        f.url = settings.remoteAPIEndpoint + f.url;
                    }
                    f.timestamp = parseInt(f.timestamp);
                    return f;
                });
                onsuccess(ret)
            }, onerror);
        },
        downloadFile: function() {