invalid-urls #18

Merged
bucky merged 5 commits from invalid-urls into master 2023-10-07 21:13:54 -07:00
Showing only changes of commit 5bce31baf2 - Show all commits
+5 -6
View File
@@ -19,11 +19,10 @@ class App < Roda
r.get String do | url_code | r.get String do | url_code |
link = links.filter(:code => url_code) link = links.filter(:code => url_code)
if link.first.nil? r.redirect link.first[:url] unless link.first.nil?
flash['message'] = "Link #{url_code} doesn't exist" @message = "Link #{url_code} doesn't exist"
r.redirect '/' response.status = 404
end view :home
r.redirect link.first[:url]
end end
r.post "create" do r.post "create" do
@@ -32,7 +31,7 @@ class App < Roda
flash['message'] = "Please enter a valid URL"; flash['message'] = "Please enter a valid URL";
r.redirect '/' r.redirect '/'
end end
if nil == links.filter(:url => url).first if links.filter(:url => url).first.nil?
code = SecureRandom.urlsafe_base64 4 code = SecureRandom.urlsafe_base64 4
links.insert(url: url, code: code) links.insert(url: url, code: code)
@message = "Link created" @message = "Link created"