Add status page on route GET /

This commit is contained in:
Christoffer Müller Madsen 2017-08-01 01:23:17 +02:00
parent f877e8ad78
commit 4718f2f2f9

View File

@ -6,6 +6,18 @@ set :port, '35257'
USERS = { 'christoffermadsen' => 'lolol' } USERS = { 'christoffermadsen' => 'lolol' }
FILENAME_GENERATOR = lambda {rand(36**6).to_s(36)} FILENAME_GENERATOR = lambda {rand(36**6).to_s(36)}
get '/' do
split_log = Array.new
File.open 'uploads.log', 'r' do |log|
log.each_line { |l| split_log << l }
end
count = split_log.count
latest = split_log[-1]
body "<b>#{count}</b> image#{unless count == 1 then "s" end} uploaded<br>" +
"Latest uploaded: <b>#{latest}</b>"
end
post '/upload' do post '/upload' do
user = params['user'] user = params['user']
@ -31,7 +43,7 @@ post '/upload' do
end end
File.open "uploads.log", 'a+' do |log| File.open "uploads.log", 'a+' do |log|
log << filename log << filename + "\n"
end end
return [200, filename] return [200, filename]