var LibraryHUMBLE_CLOUD = {
|
$HUMBLE_CLOUD__deps: ['$FS', '$MEMFS', '$PATH'],
|
$HUMBLE_CLOUD__postset: 'HUMBLE_CLOUD.staticInit()',
|
$HUMBLE_CLOUD: {
|
applicationToken: '__NOTOKEN__',
|
remoteAPIEndpoint: 'http://asmjs.brigadoon.outoforder.cc/cloud/',
|
|
staticInit: function() {
|
console.log('Humble Cloud Init');
|
addRunDependency('HUMBLE_CLOUD');
|
FS.createFolder('/', 'user_cloud', true, true);
|
FS.mount(HUMBLE_CLOUD, {}, '/user_cloud');
|
console.log('Doing stuff to synchronize files');
|
removeRunDependency('HUMBLE_CLOUD');
|
},
|
|
mount: function(mount) {
|
console.log("Mounting", mount);
|
return MEMFS.mount.apply(null, arguments);
|
},
|
syncfs: function(mount, populate, callback) {
|
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);
|
|
mount.type.getRemoteSet(mount, function(err, remote) {
|
console.log('remote files', remote);
|
});
|
});
|
},
|
|
xhrLoad: function(url, onload, onerror) {
|
var xhr = new XMLHttpRequest();
|
xhr.open('GET', url, true);
|
xhr.onload = function () {
|
if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) {
|
onload(xhr.response);
|
} else {
|
onerror();
|
}
|
};
|
xhr.onerror = onerror;
|
xhr.send(null);
|
},
|
getRemoteSet: function(mount, callback) {
|
var url = mount.type.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] = {
|
timestamp: new Date(parseInt(f.timestamp)),
|
size: f.size
|
}
|
}
|
return callback(null, { type: 'remote', entries: entries } );
|
}, function(e) {
|
callback(e || new Error('failed request'));
|
});
|
}
|
},
|
humble_cloud_init: function() {
|
// Dummy function to pull in the rest of the functions
|
}
|
};
|
|
autoAddDeps(LibraryHUMBLE_CLOUD, '$HUMBLE_CLOUD');
|
mergeInto(LibraryManager.library, LibraryHUMBLE_CLOUD);
|