Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/client.js

Issue 8402021: Crawler frontend (Closed)
Patch Set: Created Sept. 26, 2012, 8:25 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « icon64.png ('k') | lib/crawler.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+};
« no previous file with comments | « icon64.png ('k') | lib/crawler.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld