diff --git a/app.rb b/app.rb index a7a9ba5..736d0dc 100644 --- a/app.rb +++ b/app.rb @@ -19,8 +19,10 @@ class App < Roda r.post "create" do url = r.params['url'] - code = SecureRandom.urlsafe_base64 4 - links.insert(url: url, code: code) + if nil == links.filter(:url => url).first + code = SecureRandom.urlsafe_base64 5 + links.insert(url: url, code: code) + end @new_link = 'http://' + request.env['HTTP_HOST'] + '/' + links.filter(:url => url).first[:code] view :create end