Skip to content

Instantly share code, notes, and snippets.

@lmorchard
Created July 19, 2012 19:43
Show Gist options
  • Save lmorchard/3146304 to your computer and use it in GitHub Desktop.
Save lmorchard/3146304 to your computer and use it in GitHub Desktop.
getFileContent: function(fileObjOrUrl) {
var url = fileObjOrUrl.url || fileObjOrUrl;
if(!url) return '';
var result = '',
p = kuma.url.parse(env.url, true),
base_url = p.protocol + '//' + p.host;
url = base_url + url;
var key = 'kuma:get_attachment_content:' + md5(url.toLowerCase());
return cacheFn(key, 3600, function(next) {
try {
request({
method: 'GET',
headers: { 'Cache-Control': env.cache_control },
url: url
}, function(err, resp, body) {
if(resp && 200 == resp.statusCode) {
next('[' + body + ']');
}
else if(err) {
next(err);
}
else {
next( 'bad response');
}
});
} catch(e) {
next('Exception' + e + ': ' + url);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment