emscripten Humble Cloud interface
Edward Rudd
2014-08-20 f49a875f8013a02ec3dc56bec56affdbd883af1e

copy local getLocalSet and always use HUMBLE_CLOUD to reference methods

1 files modified
53 ■■■■ changed files
client/library/humble_cloud.js 53 ●●●● patch | view | raw | blame | history
client/library/humble_cloud.js
@@ -22,11 +22,17 @@
            window.HB_mount = mount;
            console.log("Syncing", mount, populate);
            // re-use IDBFS.getLocalSet for now
            IDBFS.getLocalSet(mount, function(err, local) {
                console.log('local files', local);
            HUMBLE_CLOUD.getLocalSet(mount, function(err, local) {
                if (err) return callback(err);
                mount.type.getRemoteSet(mount, function(err, remote) {
                  console.log('remote files', remote);
                HUMBLE_CLOUD.getRemoteSet(mount, function(err, remote) {
                    if (err) return callback(err);
                    var src = populate ? remote : local;
                    var dst = populate ? local : remote;
                    console.log('source', src);
                    console.log('destination', dst);
                });
            });
        },
@@ -44,16 +50,49 @@
          xhr.onerror = onerror;
          xhr.send(null);
        },
        getLocalSet: function(mount, callback) {
            var entries = {};
            function isRealDir(p) {
                return p !== '.' && p !== '..';
            };
            function toAbsolute(root) {
                return function(p) {
                    return PATH.join2(root, p);
                }
            };
            var check = FS.readdir(mount.mountpoint).filter(isRealDir).map(toAbsolute(mount.mountpoint));
            while (check.length) {
                var path = check.pop();
                var stat;
                try {
                    stat = FS.stat(path);
                } catch (e) {
                    return callback(e);
                }
                if (FS.isDir(stat.mode)) {
                    check.push.apply(check, FS.readdir(path).filter(isRealDir).map(toAbsolute(path)));
                }
                entries[path] = { timestamp: stat.mtime };
            }
            return callback(null, { type: 'local', entries: entries });
        },
        getRemoteSet: function(mount, callback) {
          var url = mount.type.remoteAPIEndpoint + '/storage/files';
          mount.type.xhrLoad(url, function(data) {
          var url = HUMBLE_CLOUD.remoteAPIEndpoint + '/storage/files';
            HUMBLE_CLOUD.xhrLoad(url, function(data) {
            var entries = {},
                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] = {
                url: (f.url.substr(0, 1) == '/') ? mount.type.remoteAPIEndpoint + f.url : f.url,
                url: (f.url.substr(0, 1) == '/') ? HUMBLE_CLOUD.remoteAPIEndpoint + f.url : f.url,
                timestamp: new Date(parseInt(f.timestamp)),
                size: f.size
              }