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, window, filePath, callback) |
| 13 { |
| 14 let formData = new window.FormData; |
| 15 formData.append("file", new window.File(filePath)); |
| 16 |
| 17 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] |
| 18 .createInstance(Ci.nsIXMLHttpRequest); |
| 19 request.mozBackgroundRequest = true; |
| 20 request.open("POST", url); |
| 21 if (callback) |
| 22 request.addEventListener("load", callback.bind(undefined, request)); |
| 23 request.send(formData); |
| 24 } |
| 25 |
| 26 let Client = exports.Client = {}; |
| 27 |
| 28 Client.fetchCrawlableSites = function(backendUrl, callback) |
| 29 { |
| 30 get(backendUrl + "/crawlableSites", function(request) |
| 31 { |
| 32 let sites = request.responseText.trim().split("\n"); |
| 33 callback(sites); |
| 34 }); |
| 35 }; |
| 36 |
| 37 Client.sendCrawlerDataFile = function(backendUrl, window, dataFilePath, callback
) |
| 38 { |
| 39 postFile(backendUrl + "/crawlerData", window, dataFilePath, callback); |
| 40 }; |
OLD | NEW |