commit 78a6c49198c681a3c16d787f1d052bf5c9be9976 Author: Josh Sherman Date: Thu Sep 1 21:58:34 2011 -0400 Base server, no parsing of dbus-send output. diff --git a/README.md b/README.md new file mode 100644 index 0000000..85b24f3 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Launch the server and punch this in your browser: + +http://localhost:3000/status/current_downloads diff --git a/ubuntuone.js b/ubuntuone.js new file mode 100644 index 0000000..32c235d --- /dev/null +++ b/ubuntuone.js @@ -0,0 +1,33 @@ +var http = require('http'), + exec = require('child_process').exec, + pieces, interface, method, dbus_send, child; + +http.createServer(function(request, response) +{ + pieces = request.url.split('/'); + + response.writeHead(200, {'Content-Type': 'text/plain'}); + + if (pieces.length == 3) + { + interface = pieces[1].toLowerCase(); + method = pieces[2].toLowerCase(); + + dbus_send = 'dbus-send --session --print-reply --type=method_call' + + ' --dest=com.ubuntuone.SyncDaemon /' + interface + + ' com.ubuntuone.SyncDaemon.' + interface.charAt(0).toUpperCase() + interface.slice(1) + '.' + method.toLowerCase(); + + child = exec(dbus_send, function(error, stdout, stderr) + { + if (error !== null) + { + response.end(stderr); + } + else + { + response.end(stdout); + } + + }); + } +}).listen(3000, "127.0.0.1");