From 4718f2f2f93350be9623704d472138ecc9d68e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Tue, 1 Aug 2017 01:23:17 +0200 Subject: [PATCH] Add status page on route GET / --- server.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server.rb b/server.rb index 8c90e19..ea564c1 100644 --- a/server.rb +++ b/server.rb @@ -6,6 +6,18 @@ set :port, '35257' USERS = { 'christoffermadsen' => 'lolol' } 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 "#{count} image#{unless count == 1 then "s" end} uploaded
" + + "Latest uploaded: #{latest}" +end post '/upload' do user = params['user'] @@ -31,7 +43,7 @@ post '/upload' do end File.open "uploads.log", 'a+' do |log| - log << filename + log << filename + "\n" end return [200, filename]