OLD | NEW |
(Empty) | |
| 1 function get(url, callback) |
| 2 { |
| 3 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] |
| 4 .createInstance(Ci.nsIXMLHttpRequest); |
| 5 request.mozBackgroundRequest = true; |
| 6 request.open("GET", url); |
| 7 if (callback) |
| 8 request.addEventListener("load", callback.bind(undefined, request)); |
| 9 request.send(); |
| 10 } |
| 11 |
| 12 function postFile(url, filePath, callback) |
| 13 { |
| 14 let formData = Cc["@mozilla.org/files/formdata;1"] |
| 15 .createInstance(Ci.nsIDOMFormData); |
| 16 formData.append("file", new File(filePath)); |
| 17 |
| 18 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] |
| 19 .createInstance(Ci.nsIXMLHttpRequest); |
| 20 request.mozBackgroundRequest = true; |
| 21 request.open("POST", url); |
| 22 if (callback) |
| 23 request.addEventListener("load", callback.bind(undefined, request)); |
| 24 request.send(formData); |
| 25 } |
| 26 |
| 27 let Client = exports.Client = {}; |
| 28 |
| 29 Client.fetchCrawlableSites = function(backendUrl, callback) |
| 30 { |
| 31 get(backendUrl + "/crawlableSites", function(request) |
| 32 { |
| 33 let sites = request.responseText.trim().split("\n"); |
| 34 callback(sites); |
| 35 }); |
| 36 }; |
| 37 |
| 38 Client.sendCrawlerDataFile = function(backendUrl, dataFilePath, callback) |
| 39 { |
| 40 postFile(backendUrl + "/crawlerData", dataFilePath, callback); |
| 41 }; |
OLD | NEW |