-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpickbox_server.rb
More file actions
68 lines (54 loc) · 1.69 KB
/
pickbox_server.rb
File metadata and controls
68 lines (54 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
PICKBOX_PATH = ''
$LOAD_PATH << PICKBOX_PATH
require 'rubygems'
require 'sinatra'
require 'server_db'
require 'filefunc'
get '/:cipher_hash' do
raise Sinatra::NotFound unless File.exists?(File.join(Dir.pwd,'files',params[:cipher_hash]))
send_file File.join(Dir.pwd,'files',params[:cipher_hash])
end
get '/exists/:cipher_hash' do
File.exists?(File.join(Dir.pwd,'files',params[:cipher_hash])) ? 'true' : nil
end
post '/register' do
user = User.new
user.username = params[:username]
user.password = params[:password]
user.save!
end
post '/get_dir' do
user = User.first(:username=>params[:username])
status 500 if user.nil?
status 401 unless params[:password]==user.password
return nil if user.dir_hash.nil?
if File.exists?(File.join(Dir.pwd,'files', user.dir_hash))
send_file File.join(Dir.pwd,'files', user.dir_hash)
else
nil
end
end
post '/upload_dir' do
Dir::mkdir('files') unless File.exists? 'files'
user = User.first(:username=>params[:username])
status 500 if user.nil?
status 401 unless params[:password]==user.password
output_path = File.join('files',params[:cipher_hash])
output = File.new(output_path,'w')
output.write(params[:file])
output.flush
output.close
user.dir_hash = params[:cipher_hash]
user.save!
end
post '/upload' do
Dir::mkdir('files') unless File.exists? 'files'
# user = User.first(:username=>params[:username])
# status 500 if user.nil?
# status 401 unless params[:password]==user.password
output_path = File.join('files',params[:cipher_hash])
output = File.new(output_path,'w')
output.write(params[:file])
output.flush
output.close
end