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

Unified Diff: lib/client.js

Issue 8402021: Crawler frontend (Closed)
Patch Set: Fixed issues found in review Created Sept. 24, 2012, 2:10 p.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') | lib/crawler.js » ('J')
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,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);
+};
« no previous file with comments | « icon64.png ('k') | lib/crawler.js » ('j') | lib/crawler.js » ('J')

Powered by Google App Engine
This is Rietveld