Add status page on route GET /
This commit is contained in:
parent
f877e8ad78
commit
4718f2f2f9
14
server.rb
14
server.rb
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user