| | |
| | | |
| | | (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); |
| | |
| | | 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) { |
| | |
| | | }, 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) |
| | |
| | | xhrDELETE(settings.remoteAPIEndpoint + '/storage/files/' + fileinfo.path, onsuccess, onerror); |
| | | }, |
| | | isAvailable: function(options) { |
| | | return false; |
| | | return true; |
| | | } |
| | | }; |
| | | |