diff options
author | Patrick Simianer <p@simianer.de> | 2016-06-22 07:04:12 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2016-06-22 07:04:12 +0200 |
commit | 669ce7abd7d6b632bf1844afdb2cf0b28e1efed6 (patch) | |
tree | 3d6add77d3629a039f785d951844f378eca1a44b /file_upload.rb | |
parent | 9097ff1e4ecdf42c99585bc9d399590442720052 (diff) |
faster, better, stronger
Diffstat (limited to 'file_upload.rb')
-rw-r--r-- | file_upload.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/file_upload.rb b/file_upload.rb index 5bb1d44..0599ef3 100644 --- a/file_upload.rb +++ b/file_upload.rb @@ -1,4 +1,4 @@ -require 'sinatra/base' +require 'sinatra' require 'haml' class FileUpload < Sinatra::Base @@ -6,6 +6,9 @@ class FileUpload < Sinatra::Base enable :static enable :sessions + #set :bind, 'upload.simianer.de' + set :port, 8000 + set :environment, :production set :views, File.join(File.dirname(__FILE__), 'views') set :public_folder, File.join(File.dirname(__FILE__), 'public') end @@ -30,12 +33,12 @@ class FileUpload < Sinatra::Base saved_token = `cat #{dir}/.token`.strip if token == saved_token return true - end + end return false end def check_dirname dirname - return dirname.match /^[a-zA-Z0-9_-]+$/ + return dirname.match /^[a-zA-Z0-9_]+$/ end def get_dir dirname @@ -101,7 +104,7 @@ class FileUpload < Sinatra::Base get "/list_dir/:dirname/:token" do log '/list_dir', params - + dirname = params[:dirname] dir = get_dir dirname token = params[:token] @@ -110,7 +113,7 @@ class FileUpload < Sinatra::Base if allowed s = "<ul>" - s += Dir[dir+"/*"].map { |i| i.gsub(get_dir(""),"") }.map { |i| "<li>#{i}</li>" }.join "\n" + s += Dir[dir+"/*"].map { |i| i.gsub(get_dir(""),"") }.map { |i| "<li>#{i}</li>" }.sort.join "\n" s += "</ul>" return s end |