You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
556 B
34 lines
556 B
require 'sinatra'
|
|
require 'redis'
|
|
require 'haml'
|
|
require 'sass'
|
|
|
|
redis = Redis.new
|
|
|
|
helpers do
|
|
include Rack::Utils
|
|
alias_method :h, :escape_html
|
|
|
|
def random_string(length)
|
|
rand(36**length).to_s(36)
|
|
end
|
|
end
|
|
|
|
get ('/styles/main.css'){ scss :styles }
|
|
|
|
get '/' do
|
|
haml :index
|
|
end
|
|
|
|
post '/' do
|
|
if params[:url] and not params[:url].empty?
|
|
@shortcode = random_string 5
|
|
redis.setnx "links:#{@shortcode}", params[:url]
|
|
end
|
|
haml :index
|
|
end
|
|
|
|
get '/:shortcode' do
|
|
@url = redis.get "links:#{params[:shortcode]}"
|
|
redirect @url || '/'
|
|
end
|