Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cloudapp plugin for inline images with heroku as proxy
require 'open-uri'
run lambda { |env|
request = Rack::Request.new(env)
clly_url = request.query_string.gsub("#.png", "")
clly_content = clly_url + "/content"
begin
clly_image = open(clly_content)
[302, {'Location'=> clly_content, 'Content-Type' => 'text/html'}, []]
rescue
[302, {'Location'=> clly_url, 'Content-Type' => 'text/html'}, []]
end
}
plugin.onMessageSend = function(talkerEvent){
var match,content;
if (match = talkerEvent.content.match(/https?:\/\/cl.ly\/[^\/]+?\b/)) {
content = talkerEvent.content.replace(match, "http://clly-attachment.heroku.com?" + match + "#.png");
Talker.sendMessage(content);
Talker.getMessageBox().val('');
return false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment