Index: lib/client.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/lib/client.js |
@@ -0,0 +1,40 @@ |
+function get(url, callback) |
+{ |
+ let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] |
+ .createInstance(Ci.nsIXMLHttpRequest); |
+ request.mozBackgroundRequest = true; |
+ request.open("GET", url); |
+ if (callback) |
+ request.addEventListener("load", callback.bind(undefined, request)); |
+ request.send(); |
+} |
+ |
+function postFile(url, window, filePath, callback) |
+{ |
+ let formData = new window.FormData; |
+ formData.append("file", new window.File(filePath)); |
Wladimir Palant
2012/09/25 09:40:39
As discussed on IRC: we can avoid using the window
|
+ |
+ let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] |
+ .createInstance(Ci.nsIXMLHttpRequest); |
+ request.mozBackgroundRequest = true; |
+ request.open("POST", url); |
+ if (callback) |
+ request.addEventListener("load", callback.bind(undefined, request)); |
+ request.send(formData); |
+} |
+ |
+let Client = exports.Client = {}; |
+ |
+Client.fetchCrawlableSites = function(backendUrl, callback) |
+{ |
+ get(backendUrl + "/crawlableSites", function(request) |
+ { |
+ let sites = request.responseText.trim().split("\n"); |
+ callback(sites); |
+ }); |
+}; |
+ |
+Client.sendCrawlerDataFile = function(backendUrl, window, dataFilePath, callback) |
+{ |
+ postFile(backendUrl + "/crawlerData", window, dataFilePath, callback); |
+}; |