write filenames of uploaded files to log file

This commit is contained in:
Christoffer Müller Madsen 2017-07-31 23:45:31 +02:00
parent a94e97253d
commit f877e8ad78

View File

@ -1,9 +1,9 @@
require 'sinatra'
set :bind, '0.0.0.0'
set :bind, '127.0.0.1'
set :port, '35257'
USERS = { 'christoffermadsen' => 'lolol', 'gre' => 'lol'}
USERS = { 'christoffermadsen' => 'lolol' }
FILENAME_GENERATOR = lambda {rand(36**6).to_s(36)}
@ -25,9 +25,14 @@ post '/upload' do
impure_filename = (request['filename'] || FILENAME_GENERATOR.call) << ".png"
filename = sanitize_filename(impure_filename)
File.open filename, 'w+' do |f|
puts ENV['HOME']
File.open "#{ENV['HOME']}/public_html/screenshots/#{filename}", 'w+' do |f|
f << request['imagedata'][:tempfile].read
end
File.open "uploads.log", 'a+' do |log|
log << filename
end
return [200, filename]
end