-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapp.rb
56 lines (45 loc) · 1.1 KB
/
webapp.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'sinatra'
require './se.rb'
require './bounty.rb'
require './cache.rb'
se = SE.new('y6kJ2wLn7yuN7ilUOvBRPw((')
bounty_image_cache = Cache.new(60*60*24) do |domain, bounties, reputation|
bounty_image(domain, bounties, reputation)
end
bounty_info_cache = Cache.new(60*5) do |site|
bounty_image_cache[site.bounties]
end
get '/:site/bounty.png' do
expires 0, :no_cache, :no_store, :must_revalidate
content_type 'image/png'
site = params[:site]
bounty_info_cache[se.site(site)].blob
end
get '/bounty.png' do
expires 0, :no_cache, :no_store, :must_revalidate
begin
content_type 'image/png'
site = params[:site] || request.referrer
bounty_info_cache[se.site(site)].blob
rescue SiteDoesNotExistError
status 404
send_file "./resources/invalid-referrer.png"
end
end
get '/cache/:action/:which' do
c = {'info' => bounty_info_cache, 'image' => bounty_image_cache}[params[:which]]
case params[:action]
when 'display'
c.to_s
when 'flush'
c.flush
"#{:name} cache flushed"
end
end
get '/info' do
se.info.to_s
end
get // do
status 404
"404: Not Found"
end