From 47f874159242cbd6e7a1c8fde478f7398d2aace4 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Fri, 22 Sep 2023 15:11:06 -0700 Subject: [PATCH] added logic to prevent duplicate url's from being entered, it just fetches the url and load it instead --- app.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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