| | |
| | | if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { |
| | | onload(xhr.response); |
| | | } else { |
| | | onerror(); |
| | | onerror(new Error('Request failed')); |
| | | } |
| | | }; |
| | | xhr.onerror = onerror; |
| | |
| | | if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { |
| | | onload(xhr.response); |
| | | } else { |
| | | onerror(); |
| | | onerror(new Error('Request failed')); |
| | | } |
| | | }; |
| | | xhr.onerror = onerror; |
| | | xhr.send(data); |
| | | } |
| | | function xhrDELETE(url, onload, onerror) { |
| | | var xhr = new XMLHttpRequest(); |
| | | xhr.open('DELETE', url, true); |
| | | xhr.responseType = 'text'; |
| | | xhr.onload = function() { |
| | | if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { |
| | | onload(xhr.response); |
| | | } else { |
| | | onerror(new Error('Request failed')); |
| | | } |
| | | }; |
| | | xhr.onerror = onerror; |
| | | xhr.send(); |
| | | } |
| | | var settings = { |
| | | remoteAPIEndpoint: 'http://asmjs.brigadoon.outoforder.cc/cloud' |
| | |
| | | var provider = { |
| | | vendor: 'Urkle!', |
| | | allFiles: function(options, onsuccess, onerror) { |
| | | // could encapsulate onload + onerror to provide extra functionality here |
| | | xhrGET(settings.remoteAPIEndpoint + '/storage/files?appToken=' + encodeURIComponent(options.applicationtoken), function(data) { |
| | | var json = JSON.parse(data), |
| | | ret = []; |
| | |
| | | +'×tamp=' + encodeURIComponent(fileinfo.timestamp.getTime()); |
| | | xhrPUT(settings.remoteAPIEndpoint + '/storage/files?' + q, data, onsuccess, onerror); |
| | | }, |
| | | rm: function() { |
| | | |
| | | rm: function(options, fileinfo, onsuccess, onerror) { |
| | | xhrDELETE(settings.remoteAPIEndpoint + '/storage/files/' + fileinfo.path, onsuccess, onerror); |
| | | } |
| | | }; |
| | | |