emscripten Humble Cloud interface
Edward Rudd
2014-08-21 768ceb4b7ccda28c3fe05eda1fa200a3f4b6d2d2

filled out uploadFile support in sample cloud provider

1 files modified
23 ■■■■■ changed files
humble_cloud/urkle_cloud.js 23 ●●●●● patch | view | raw | blame | history
humble_cloud/urkle_cloud.js
@@ -3,9 +3,11 @@
if (!CLOUD_PROVIDERS) CLOUD_PROVIDERS = (typeof CLOUD_PROVIDERS !== 'undefined' ? CLOUD_PROVIDERS : null) || {};
(function() {
    // @todo: This may need adjusting to support fetching binary.
    function xhrGET(url, onload, onerror) {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url, true);
        xhr.responseType = 'text';
        xhr.onload = function () {
            if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) {
                onload(xhr.response);
@@ -15,6 +17,21 @@
        };
        xhr.onerror = onerror;
        xhr.send(null);
    }
    // @todo: this may need adjusting to support putting binary.
    function xhrPUT(url, data, onload, onerror) {
        var xhr = new XMLHttpRequest();
        xhr.open('PUT', url, true);
        xhr.responseType = 'text';
        xhr.onload = function () {
            if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) {
                onload(xhr.response);
            } else {
                onerror();
            }
        };
        xhr.onerror = onerror;
        xhr.send(data);
    }
    var settings = {
        remoteAPIEndpoint: 'http://asmjs.brigadoon.outoforder.cc/cloud'
@@ -40,7 +57,11 @@
        downloadFile: function(options, url, onsuccess, onerror) {
            xhrGET(url, onsuccess, onerror);
        },
        uploadFile: function(options, path, data, onsuccess, onerror) {
        uploadFile: function(options, fileinfo, data, onsuccess, onerror) {
            var q = 'appToken=' + encodeURIComponent(options.applicationtoken)
                   +'&path=' + encodeURIComponent(fileinfo.path)
                   +'&timestamp=' + encodeURIComponent(fileinfo.timestamp.getTime());
            xhrPUT(settings.remoteAPIEndpoint + '/storage/files?' + q, data, onsuccess, onerror);
        },
        removeFile: function() {