From ede07e6e38a346b3ff0bbccefb655f3ae0a32504 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 29 Nov 2023 23:01:44 -0500 Subject: Rewrite web component with Sinatra --- web/web.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 web/web.rb (limited to 'web/web.rb') 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 @@ +require 'rack/cache' +require 'yaml' + +require 'rubygems' +require 'bundler/setup' +Bundler.require :default + +use Rack::Cache + +config = YAML.load(open("config.yml")) +db = Sequel.connect("sqlite://#{config["database"]}") + +class LingoScore < Sequel::Model +end + +get '/' do + @scores = LingoScore.reverse_order(:score) + + haml :index +end + +post '/update' do + if params[:secret_code] != config["secret_code"] then + 403 + else + if LingoScore.where(user_id: params[:user_id]).count == 0 + score = LingoScore.new(score: 0) + else + score = LingoScore.first(user_id: params[:user_id]) + end + score.username = params[:username] + score.avatar_url = CGI.unescape(params[:avatar_url]) + score.score += 1 + score.save + + 201 + end +end + +get '/style.css' do + cache_control :public, :max_age => 36000 + + scss :style +end -- cgit 1.4.1