diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-11-29 23:01:44 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-11-29 23:01:44 -0500 |
commit | ede07e6e38a346b3ff0bbccefb655f3ae0a32504 (patch) | |
tree | e8f08bd250bd0611228b0688f8430bf47ed695dd /web/web.rb | |
parent | 9c324f51cf3eb46251e4114cd3cdd7a56305f826 (diff) | |
download | lingo-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.rb | 44 |
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 @@ | |||
1 | require 'rack/cache' | ||
2 | require 'yaml' | ||
3 | |||
4 | require 'rubygems' | ||
5 | require 'bundler/setup' | ||
6 | Bundler.require :default | ||
7 | |||
8 | use Rack::Cache | ||
9 | |||
10 | config = YAML.load(open("config.yml")) | ||
11 | db = Sequel.connect("sqlite://#{config["database"]}") | ||
12 | |||
13 | class LingoScore < Sequel::Model | ||
14 | end | ||
15 | |||
16 | get '/' do | ||
17 | @scores = LingoScore.reverse_order(:score) | ||
18 | |||
19 | haml :index | ||
20 | end | ||
21 | |||
22 | post '/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 | ||
38 | end | ||
39 | |||
40 | get '/style.css' do | ||
41 | cache_control :public, :max_age => 36000 | ||
42 | |||
43 | scss :style | ||
44 | end | ||