emscripten Humble Cloud interface
Edward Rudd
2014-10-14 28dbc410b10c9d67cdd00f25a73083e58204ea01
humble_cloud/urkle_cloud.js
@@ -4,10 +4,10 @@
(function() {
    // @todo: This may need adjusting to support fetching binary.
    function xhrGET(url, onload, onerror) {
    function xhrGET(url, isBin, onload, onerror) {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url, true);
        xhr.responseType = 'text';
        xhr.responseType = isBin ? 'arraybuffer' : 'text';
        xhr.onload = function () {
            if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) {
                onload(xhr.response);
@@ -54,7 +54,7 @@
    var provider = {
        vendor: 'Urkle!',
        allFiles: function(options, onsuccess, onerror) {
            xhrGET(settings.remoteAPIEndpoint + '/storage/files?appToken=' + encodeURIComponent(options.applicationtoken), function(data) {
            xhrGET(settings.remoteAPIEndpoint + '/storage/files?appToken=' + encodeURIComponent(options.applicationtoken), false, function(data) {
                var json = JSON.parse(data),
                    ret = [];
                ret = json.data.map(function(f) {
@@ -68,7 +68,7 @@
            }, onerror);
        },
        read: function(options, url, onsuccess, onerror) {
            xhrGET(url, onsuccess, onerror);
            xhrGET(url, true, onsuccess, onerror);
        },
        write: function(options, fileinfo, data, onsuccess, onerror) {
            var q = 'appToken=' + encodeURIComponent(options.applicationtoken)
@@ -80,7 +80,7 @@
          xhrDELETE(settings.remoteAPIEndpoint + '/storage/files/' + fileinfo.path, onsuccess, onerror);
        },
        isAvailable: function(options) {
          return false;
          return true;
        }
    };