Permalink
Browse files

first working version

  • Loading branch information...
Gunnar Magholder
Gunnar Magholder committed Jul 11, 2013
1 parent 6aba984 commit 888e9323d74ece4ae48434e3e6506031a300e906
Showing with 15 additions and 4 deletions.
  1. +15 −4 silkveil.js
View
@@ -1,4 +1,6 @@
var http = require('http');
+var url = require('url');
+
var mappings = {
'magholder': {
action: 'redirect',
@@ -7,13 +9,22 @@ var mappings = {
},
'ursel': {
action: 'download',
- url: 'https://www.facebook.com/photo.php?fbid=10201281285979248&l=76a440aac7',
+ url: 'http://www.facebook.com/photo.php?fbid=10201281285979248&l=76a440aac7',
fileName: 'ursel.jpg',
forceDownload: false
}
};
var actions = {
- 'download': function (res, mapping) {
+ 'download': function (res,mapping) {
+ console.log('fetching ' + mapping.url);
+ http.get(url.parse(mapping.url), function(data) {
+ var contentDisposition = mapping.forceDownload ? 'attachment' : 'inline';
+ res.writeHead(data.statusCode, {
+ 'Content-Type': mapping.contentType,
+ 'Content-Disposition': contentDisposition + '; filename=' + mapping.fileName + ';'
+ });
+ data.pipe(res);
+ });
},
'error': function (res,mapping) {
res.writeHead(mapping.statusCode, {
@@ -24,7 +35,7 @@ var actions = {
'redirect': function (res, mapping) {
var statusCode = (mapping.type === 'permanent') ? 301 : 307;
res.writeHead(statusCode, {
- 'Location', mapping.url
+ 'Location': mapping.url
});
res.end();
}
@@ -36,6 +47,6 @@ http.createServer(function(req,res) {
statusCode: 404,
data: 'file not found'
};
- actions[mapping.action](res.mapping);
+ actions[mapping.action](res,mapping);
console.log(mapping);
}).listen(3000);

0 comments on commit 888e932

Please sign in to comment.