Skip to content

Commit 2aeed74

Browse files
committed
Nice random string calculation and cleanup
1 parent cc48432 commit 2aeed74

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

app.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,20 @@
33
require 'fileutils'
44
require 'json'
55

6+
# upload with:
7+
# curl -v -F "data=@/path/to/filename" http://localhost:9292/upload
8+
69
get '/' do
710
content_type :json
811
{ :files => Dir.glob('files/**/*.*') }.to_json
912
end
1013

11-
# upload with:
12-
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename
13-
1414
post '/upload' do
1515
userdir = File.join("files")
1616
FileUtils.mkdir_p(userdir)
17-
filename = File.join(userdir, "#{(0...50).map{ ('a'..'z').to_a[rand(8)] }.join}-#{params[:data][:filename]}")
17+
filename = File.join(userdir, "#{rand(32**8).to_s(32)}-#{params[:data][:filename]}")
1818

19-
datafile = params[:data]
20-
2119
File.open(filename, 'wb') do |file|
22-
file.write(datafile[:tempfile].read)
20+
file.write(params[:data][:tempfile].read)
2321
end
2422
end
25-
26-
# max 20
27-
# äldst föst
28-
# tidsstämpel

0 commit comments

Comments
 (0)