Sha256: 16063cc8d1f69e2e4884f18d129ad9d82a157762dd43566b72359c01357b8e9a
Contents?: true
Size: 1.07 KB
Versions: 8
Compression:
Stored size: 1.07 KB
Contents
#!/usr/bin/env ruby $: << File.dirname(__FILE__)+'/../../lib' require 'goliath' require 'postrank-uri' # Install phantomjs: http://code.google.com/p/phantomjs/wiki/QuickStart # $> ruby rasterize.rb -sv # $> curl http://localhost:9000/?url=http://www.google.com (or rather, visit in the browser!) class Rasterize < Goliath::API use Goliath::Rack::Params use Goliath::Rack::Favicon, File.expand_path(File.dirname(__FILE__)+"/../public/favicon.ico") use Goliath::Rack::Validation::RequestMethod, %w(GET) use Goliath::Rack::Validation::RequiredParam, {:key => 'url'} def response(env) url = PostRank::URI.clean(params['url']) hash = PostRank::URI.hash(url, :clean => false) if !File.exists? filename(hash) fiber = Fiber.current EM.system('phantomjs rasterize.js ' + url.to_s + ' ' + filename(hash)) do |output, status| env.logger.info "Phantom exit status: #{status}" fiber.resume end Fiber.yield end [202, {'X-Phantom' => 'Goliath'}, IO.read(filename(hash))] end def filename(hash) "thumb/#{hash}.png" end end
Version data entries
8 entries across 8 versions & 1 rubygems