From 16521075492bb3540527e5c7a83c3a559bbc0aeb Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Thu, 14 Sep 2023 22:30:33 -0700 Subject: [PATCH] got app working reasonably well, and removed db file, that shouldn't be in the db --- app.rb | 11 ++++++++++- db/url_shortener.db | Bin 20480 -> 0 bytes views/create.erb | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) delete mode 100644 db/url_shortener.db diff --git a/app.rb b/app.rb index f437352..fbc0383 100644 --- a/app.rb +++ b/app.rb @@ -1,8 +1,12 @@ require 'roda' require 'securerandom' require 'json' +require 'sequel' +require 'logger' class App < Roda + DB = Sequel.sqlite('db/url_shortener.db') + links = DB[:links] plugin :render, escape: true route do |r| r.root do @@ -10,10 +14,15 @@ class App < Roda end r.get String do | url_code | - "redirect to url" + link = links.filter(:code => url_code).first[:url] + r.redirect link end r.post "create" do + url = r.params['url'] + code = SecureRandom.urlsafe_base64 4 + links.insert(url: url, code: code) + @new_link = 'http://' + request.env['HTTP_HOST'] + '/' + links.filter(:url => url).first[:code] view :create end end diff --git a/db/url_shortener.db b/db/url_shortener.db deleted file mode 100644 index 1562d33e71a0c830ac09102d24e79c73c645ad0a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI%%SyvQ6oBEGSg)WFTx5H|O#>oca3cs-jUdLVwOzPsVx4NVCYVNX+c$9OllUAy zkPDMQv2N|=FWDS&b?HZ$k#3Scg_&%tWu>*+7g0)8@;;sSVYBi{u{Laa zI2kim)cV8MqW!KaOP|XASo*Y$y*nnJEd&ri009ILKmY**5I_I{1V#h~+M0D7M-Rd* zyy=-<6hHRM+tgvht2I4o)((76f^sd8YVeZw0(lM7&V86xw{~`1sh>Bc-tv8E)lV*4 z-kJoRv`r{1;eR%V<%N2@5lHE;drUS3AG!?#)x!j^b`IGPV9DJF-)x{A$vEl*EBVac1sJDo5UN zt>rhRy78O6yO^J)?QfM|Gz1Vp009ILKmY**5I_I{1Q3`&0ZUu+Mg5=u^rsHome +

<%= @new_link %>