summary refs log tree commit diff stats
path: root/web/web.rb
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-11-29 23:01:44 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2023-11-29 23:01:44 -0500
commitede07e6e38a346b3ff0bbccefb655f3ae0a32504 (patch)
treee8f08bd250bd0611228b0688f8430bf47ed695dd /web/web.rb
parent9c324f51cf3eb46251e4114cd3cdd7a56305f826 (diff)
downloadlingo-ede07e6e38a346b3ff0bbccefb655f3ae0a32504.tar.gz
lingo-ede07e6e38a346b3ff0bbccefb655f3ae0a32504.tar.bz2
lingo-ede07e6e38a346b3ff0bbccefb655f3ae0a32504.zip
Rewrite web component with Sinatra
Diffstat (limited to 'web/web.rb')
-rw-r--r--web/web.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/web/web.rb b/web/web.rb new file mode 100644 index 0000000..15c088e --- /dev/null +++ b/web/web.rb
@@ -0,0 +1,44 @@
1require 'rack/cache'
2require 'yaml'
3
4require 'rubygems'
5require 'bundler/setup'
6Bundler.require :default
7
8use Rack::Cache
9
10config = YAML.load(open("config.yml"))
11db = Sequel.connect("sqlite://#{config["database"]}")
12
13class LingoScore < Sequel::Model
14end
15
16get '/' do
17 @scores = LingoScore.reverse_order(:score)
18
19 haml :index
20end
21
22post '/update' do
23 if params[:secret_code] != config["secret_code"] then
24 403
25 else
26 if LingoScore.where(user_id: params[:user_id]).count == 0
27 score = LingoScore.new(score: 0)
28 else
29 score = LingoScore.first(user_id: params[:user_id])
30 end
31 score.username = params[:username]
32 score.avatar_url = CGI.unescape(params[:avatar_url])
33 score.score += 1
34 score.save
35
36 201
37 end
38end
39
40get '/style.css' do
41 cache_control :public, :max_age => 36000
42
43 scss :style
44end