Permalink
Browse files

Cleaned up the code a bit.

Created view files for each response.
Added ejs for rendering.
  • Loading branch information...
1 parent 116da86 commit 5764d344ee0363f413cbad6eec2bd7e0c51233af @thomaschaaf thomaschaaf committed Jan 28, 2012
Showing with 89 additions and 97 deletions.
  1. +2 −1 app.js
  2. +1 −0 package.json
  3. +51 −88 routes/index.js
  4. +9 −0 views/getPhotoStatus.html
  5. +0 −2 views/index.jade
  6. +0 −6 views/layout.jade
  7. +6 −0 views/markLastPhotoInRoll.html
  8. +12 −0 views/startSession.html
  9. +8 −0 views/uploadSuccess.html
View
@@ -13,7 +13,8 @@ var app = module.exports = express.createServer();
app.configure(function(){
app.set('views', __dirname + '/views');
- app.set('view engine', 'jade');
+ app.register("html", require('ejs'));
+ app.set('view engine', 'html');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
View
@@ -8,5 +8,6 @@
, "MD5": ">= 0.0.0"
, "xml2js": ">= 0.0.1"
, "tar": ">= 0.0.1"
+ , "ejs": ">= 0.0.1"
}
}
View
@@ -1,30 +1,14 @@
var qs = require("querystring"),
xml2js = require("xml2js"),
parser = new xml2js.Parser(),
- md5 = require("MD5");
-var config = require("../config");
-var crypto = require("crypto");
-var tar = require("tar");
-var fs = require("fs");
+ config = require("../config"),
+ crypto = require("crypto"),
+ tar = require("tar"),
+ fs = require("fs");
/*
* GET home page.
*/
-var long = "00185642b77d"+"e83bee6ad0fa752888892f49b95b7a4e"+"50333eaad68ce9f73db40bad23a2952c";
-
-
-//console.log(md5(new Buffer("\\x00\\x18VB\\xb7}\\xe8;\\xeej\\xd0\\xfau(\\x88\\x89/I\\xb9[zNP3>\\xaa\\xd6\\x8c\\xe9\\xf7=\\xb4\\x0b\\xad#\\xa2\\x95,", "utf8").toString("hex")));
-//console.log(long);
-// hex '\x00\x18VB\xb7}\xe8;\xeej\xd0\xfau(\x88\x89/I\xb9[zNP3>\xaa\xd6\x8c\xe9\xf7=\xb4\x0b\xad#\xa2\x95,'
-//var hex = new Buffer(long, "hex").toString();
-
-var string = new Buffer(long, "hex");
-
-console.log(string);
-
-var hash = crypto.createHash("md5");
-hash.update(string);
-console.log(hash.digest("hex"));
function md5HexDigest(data)
{
@@ -34,35 +18,21 @@ function md5HexDigest(data)
return hash.digest("hex");
}
-//console.log(hex);
-
-
-//console.log(md5(hex));
-
-//var string = hex;
-
-var string = "ä";
-var foo = new Buffer("ä").toString("hex");
-
-console.log(foo);
-console.log(md5("\\x84"));
-
-
exports.index = function(req, res){
res.render('index', { title: 'Express' })
};
exports.upload = function(req, res) {
- console.log(req.files.FILENAME.path);
-fs.createReadStream(req.files.FILENAME.path)
+ console.log(req.files.FILENAME);
+ fs.createReadStream(req.files.FILENAME.path)
.pipe(tar.Extract({ path: __dirname + "/extract" }))
- .on("error", function (er) {
+ .on("error", function (err) {
console.error("error here")
})
.on("end", function () {
console.error("done")
- res.send('<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><UploadPhotoResponse xmlns="http://localhost/api/soap/eyefilm"><success>true</success></UploadPhotoResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>');
+ res.render('uploadSucces', {layout: false});
})
console.log("LET ME UPLOAD!");
@@ -76,65 +46,42 @@ exports.soap = function(req, res) {
//StartSession
//GetPhotoStatus
//MarkLastPhotoInRoll
-
+ var renderStartSession = function(err, data) {
+ var obj = data["SOAP-ENV:Body"]["ns1:StartSession"];
+ var credential = md5HexDigest(obj.macaddress + obj.cnonce + config.cards[obj.macaddress].uploadkey);
+ res.render('startSession', {layout:false, "credential": credential, "snonce":"d7eda40e374e8a34ee97554ebbfea0b5", "transfermodetimestamp": obj.transfermodetimestamp});
+ };
+
+ var renderGetPhotoStatus = function(err, data) {
+ var obj = data["SOAP-ENV:Body"]["ns1:GetPhotoStatus"];
+ var credential = md5HexDigest(obj.macaddress + config.cards[obj.macaddress].uploadkey + "d7eda40e374e8a34ee97554ebbfea0b5");
+ res.render('GetPhotoStatus', {layout:false});
+ };
+
+ var getData = function(callback) {
+ var body = '';
+ var parsedbody = '';
+ req.on('data', function (data) {
+ body += data;
+ });
+ req.on('end', function () {
+ var decodedBody = decodeURIComponent(qs.stringify(qs.parse(body)));
+ parser.parseString(decodedBody, callback);
+ });
+ };
switch(req.headers.soapaction.substr(5, req.headers.soapaction.length-6)) {
case "StartSession":
console.log("startsession");
//console.log(req.params);
- var body = '';
- var parsedbody = '';
- req.on('data', function (data) {
- body += data;
- //console.log(data);
- });
- req.on('end', function () {
-
- var POST = qs.stringify(qs.parse(body));
- POST = decodeURIComponent(POST);
- // use POST
- console.log(decodeURIComponent(POST));
- parser.parseString(POST, function(err, data) {
- var obj = data["SOAP-ENV:Body"]["ns1:StartSession"];
- var credential = md5HexDigest(obj.macaddress + obj.cnonce + config.cards[obj.macaddress].uploadkey);
- console.log(credential);
- console.log(obj);
- console.log(obj.transfermodetimestamp);
- res.send('<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><StartSessionResponse xmlns="http://localhost/api/soap/eyefilm"><credential>'+credential+'</credential><snonce>d7eda40e374e8a34ee97554ebbfea0b5</snonce><transfermode>2</transfermode><transfermodetimestamp>' + obj.transfermodetimestamp + '</transfermodetimestamp><upsyncallowed>false</upsyncallowed></StartSessionResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>');
-
- });
-
- });
-
-
+ getData(renderStartSession);
break;
case "GetPhotoStatus":
console.log("GetPhotoStatus");
- var body = '';
- var parsedbody = '';
- req.on('data', function (data) {
- body += data;
- //console.log(data);
- });
- req.on('end', function () {
-
- var POST = qs.stringify(qs.parse(body));
- POST = decodeURIComponent(POST);
- // use POST
- console.log(decodeURIComponent(POST));
- parser.parseString(POST, function(err, data) {
- var obj = data["SOAP-ENV:Body"]["ns1:GetPhotoStatus"];
- var credential = md5HexDigest(obj.macaddress + config.cards[obj.macaddress].uploadkey + "d7eda40e374e8a34ee97554ebbfea0b5");
- console.log(credential);
- console.log(obj.credential);
- res.send('<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><GetPhotoStatusResponse xmlns="http://localhost/api/soap/eyefilm"><fileid>1</fileid><offset>0</offset></GetPhotoStatusResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>');
-
- });
-
- });
+ getData(renderGetPhotoStatus);
break;
case "MarkLastPhotoInRoll":
- res.send('<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><MarkLastPhotoInRollResponse xmlns="http://localhost/api/soap/eyefilm" /></SOAP-ENV:Body></SOAP-ENV:Envelope>');
+ res.render('markLastPhotoInRoll', {layout: false});
break;
default:
console.log("Different request", req.headers);
@@ -143,4 +90,20 @@ exports.soap = function(req, res) {
console.log(req.headers.soapaction.substr(5, req.headers.soapaction.length-6));
break;
}
-};
+};
+
+// Mitschnitt
+// POST /loc/json HTTP/1.1
+// Host: www.google.com
+// User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.25) Gecko/20111212 Firefox/3.6.25
+// Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
+// Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
+// Accept-Encoding: gzip,deflate
+// Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+// Keep-Alive: 115
+// Connection: keep-alive
+// Content-Length: 1067
+// Content-Type: text/plain; charset=UTF-8
+// Pragma: no-cache
+// Cache-Control: no-cache
+// {"version":"1.1.0","request_address":true,"access_token":"2:L7MQY8kub3DN_do_:3pusanbwJID_Zu6q","wifi_towers":[{"mac_address":"7c-4f-b5-21-ed-94","ssid":"INTERNET","signal_strength":-33},{"mac_address":"88-25-2c-54-30-07","ssid":"WLAN-543029","signal_strength":-51},{"mac_address":"00-25-5e-74-e4-db","ssid":"ALICE-WLANDA","signal_strength":-79},{"mac_address":"28-cf-da-b8-d5-cd","ssid":"redbirn","signal_strength":-85},{"mac_address":"00-26-4d-3c-94-1f","ssid":"EasyBox-3C9439","signal_strength":-73},{"mac_address":"00-1d-19-eb-91-47","ssid":"WLAN-EB9166","signal_strength":-86},{"mac_address":"00-12-bf-b2-b7-c5","ssid":"WLAN-B2B705","signal_strength":-80},{"mac_address":"88-25-2c-21-a6-ef","ssid":"EasyBox-21A645","signal_strength":-79},{"mac_address":"04-c0-6f-d4-7d-14","ssid":"WLAN-7D1407","signal_strength":-91},{"mac_address":"7c-4f-b5-83-f8-f7","ssid":"Toner_Schoerke","signal_strength":-67},{"mac_address":"f0-7d-68-8e-59-2e","ssid":"Lian","signal_strength":-89},{"mac_address":"bc-05-43-e2-a8-e2","ssid":"FRITZ!Box Fon WLAN 7112","signal_strength":-76}]}
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
+ <SOAP-ENV:Body>
+ <GetPhotoStatusResponse xmlns="http://localhost/api/soap/eyefilm">
+ <fileid>1</fileid>
+ <offset>0</offset>
+ </GetPhotoStatusResponse>
+ </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
View
@@ -1,2 +0,0 @@
-h1= title
-p Welcome to #{title}
View
@@ -1,6 +0,0 @@
-!!!
-html
- head
- title= title
- link(rel='stylesheet', href='/stylesheets/style.css')
- body!= body
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
+ <SOAP-ENV:Body>
+ <MarkLastPhotoInRollResponse xmlns="http://localhost/api/soap/eyefilm" />
+ </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
+ <SOAP-ENV:Body>
+ <StartSessionResponse xmlns="http://localhost/api/soap/eyefilm">
+ <credential><%= credential %></credential>
+ <snonce><%= snonce %></snonce>
+ <transfermode>2</transfermode>
+ <transfermodetimestamp><%= transfermodetimestamp %></transfermodetimestamp>
+ <upsyncallowed>false</upsyncallowed>
+ </StartSessionResponse>
+ </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
+ <SOAP-ENV:Body>
+ <UploadPhotoResponse xmlns="http://localhost/api/soap/eyefilm">
+ <success>true</success>
+ </UploadPhotoResponse>
+ </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>

0 comments on commit 5764d34

Please sign in to comment.