Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // How does it work? Hit it with /?username=bradgessler&size=reasonably_small
- // and you get your URL (and redirect). Need more documentation? RTFSC.
- var http = require('http');
- http.createServer(function(request, response){
- var query = require('url').parse(request.url, true).query;
- if(!query || !query.username){
- response.writeHead(412, {'Content-Type': 'text/plain'});
- response.end('You need to specify /?username=twitter_name\n');
- }
- else {
- var proxy = http.createClient(80, 'api.twitter.com');
- var proxy_request = proxy.request('GET', '/1/users/show.json?screen_name=' + query.username, {'host': 'api.twitter.com'});
- var size = (query.size ? query.size : 'normal');
- proxy_request.end();
- proxy_request.on('response', function (proxy_response) {
- var body = '';
- proxy_response.setEncoding('utf8');
- proxy_response.on('data', function (chunk) {
- body = body.concat(chunk);
- });
- proxy_response.on('end', function(foo){
- var profile = JSON.parse(body);
- var imagePath = profile.profile_image_url;
- var format = /^(.+)(normal)\.\w{3}$/;
- var url = profile.profile_image_url.replace(/(normal)\.(\w+)$/, size + '.$2');
- response.writeHead(302, {'Content-Type': 'text/plain', 'Location' : url });
- response.end(url + '\n');
- });
- });
- }
- }).listen(7709);
Add Comment
Please, Sign In to add comment