Index: lib/client.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/lib/client.js |
@@ -0,0 +1,41 @@ |
+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, filePath, callback) |
+{ |
+ let formData = Cc["@mozilla.org/files/formdata;1"] |
+ .createInstance(Ci.nsIDOMFormData); |
+ formData.append("file", new File(filePath)); |
+ |
+ 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, dataFilePath, callback) |
+{ |
+ postFile(backendUrl + "/crawlerData", dataFilePath, callback); |
+}; |