Created
March 16, 2011 16:45
-
-
Save rolfb/872798 to your computer and use it in GitHub Desktop.
Cloudapp plugin for inline images with heroku as proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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