Skip to content

Instantly share code, notes, and snippets.

@rolfb
Created March 16, 2011 16:45
Show Gist options
  • Save rolfb/872798 to your computer and use it in GitHub Desktop.
Save rolfb/872798 to your computer and use it in GitHub Desktop.
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