6 enable :inline_templates
8 set :upload_password, '0e5f7d398e6f9cd1f6bac5cc823e363aec636495'
10 def password_match?(password)
11 return TRUE if settings.upload_password.nil?
12 (not password.nil?) && Digest::SHA1.hexdigest(password) == settings.upload_password
15 def uploaded_file(file)
16 "#{options.root}/files/#{file}"
20 content_type 'text/css', :charset => 'utf-8'
28 get '/ready/:name' do |name|
29 path = uploaded_file(name)
30 unless File.exists? path then
33 base = request.url.gsub(/\/ready\/[^\/]*$/, '')
34 @url = "#{base}/#{name}"
38 get '/:name' do |name|
39 path = uploaded_file(name)
40 unless File.exists? path then
47 unless password_match? params[:upload_password] then
51 tmpfile = params[:file][:tempfile]
52 name = params[:file][:filename]
54 if tmpfile.nil? || name.nil? then
55 @error = "No file selected"
58 FileUtils::cp(tmpfile.path, uploaded_file(name))
59 redirect "ready/#{name}"
64 url = request.scheme + "://"
66 if request.scheme == "https" && request.port != 443 ||
67 request.scheme == "http" && request.port != 80
68 url << ":#{request.port}"
70 url << request.script_name
81 %base{ :href => base_href }
82 %link{ :rel => 'stylesheet', :href => "style.css", :type => 'text/css',
83 :media => "screen, projection" }
84 %script{ :type => 'text/javascript', :src => 'javascripts/jquery.min.js' }
85 %script{ :type => 'text/javascript', :src => 'javascripts/jquery.lightBoxFu.js' }
86 %script{ :type => 'text/javascript', :src => 'javascripts/jquery.uploadProgress.js' }
87 %script{ :type => 'text/javascript', :src => 'javascripts/coquelicot.js' }
96 %form#upload{ :enctype => 'multipart/form-data',
97 :action => 'upload', :method => 'post' }
99 %input{ :type => 'file', :name => 'file' }
101 %input{ :type => 'submit', :value => 'Send file' }
106 %a{ :href => @url }= @url
112 background-color: $green
117 text-decoration: underline
121 background-color: red
123 border: black solid 1px
131 background: url('images/ajax-loader.gif') no-repeat