Skip to content
This repository
tree: 555a70f1fb
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 51 lines (37 sloc) 1.143 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))

require 'mongo'
require 'mongo_mapper'
require 'rack'
require 'rack/contrib/jsonp'
require 'rack/rewrite'

require 'meme_captain'

use Rack::ConditionalGet
use Rack::Sendfile
use Rack::JSONP

use Rack::Static, :urls => %w{/tmp}, :root => 'public'

MongoMapper.connection = Mongo::Connection.new
MongoMapper.database = 'memecaptain'

MemeCaptain::MemeData.ensure_index :meme_id

MemeCaptain::MemeData.ensure_index [
  [:source_url, 1],
  [:texts, 1],
]

MemeCaptain::Upload.ensure_index :upload_id

MemeCaptain::SourceFetchFail.ensure_index :url

use Rack::Rewrite do
  rewrite %r{/([gi])\?(.+)}, lambda { |match, rack_env|
    result = match[0]

    if match[2].index('tt=') or match[2].index('tb=')
      q = Rack::Utils.parse_query(match[2])
      if q.key?('tt') or q.key?('tb')
        q['t1'] = q.delete('tt') if q.key?('tt')
        q['t2'] = q.delete('tb') if q.key?('tb')
        new_q = q.map { |k,v|
          "#{Rack::Utils.escape(k)}=#{Rack::Utils.escape(v)}" }.join('&')
        result = "#{match[1]}?#{new_q}"
      end
    end

    result
  }
end

run MemeCaptain::Server
Something went wrong with that request. Please try again.