-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.rb
76 lines (68 loc) · 1.97 KB
/
web.rb
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
69
70
71
72
73
74
75
76
require 'rubygems'
require 'sinatra'
require 'sinatra/flash'
load 'test.rb'
configure do
enable :sessions
set :session_secret, ENV['SESSION_SECRET'] ||= 'super secret'
end
# Handle GET-request (Show the upload form)
get "/" do
noSolutions = false
if session[:do]
if not flash[:notice]
if session[:fname2] and File.exist?("uploads/#{session[:fname]}") and File.exist?("uploads/#{session[:fname2]}")
@package = Setup.new.parse(session[:fname],session[:fname2],session.has_key?(:gender),session.has_key?(:good_ratio),params[:min],params[:max])
File.delete("uploads/#{session[:fname2]}")
File.delete("uploads/#{session[:fname]}")
elsif File.exist?("uploads/#{session[:fname]}")
@package = Setup.new.parse(session[:fname],nil,session.has_key?(:gender),session.has_key?(:good_ratio),params[:min],params[:max])
File.delete("uploads/#{session[:fname]}")
end
end
session[:do] = nil
end
erb :upload
end
# Handle POST-request (Receive and save the uploaded file)
post "/" do
if params[:gender]
session[:gender] = "on"
end
if params[:good_ratio]
session[:good_ratio] = "on"
end
if params['myfile']
if not params['myfile'][:filename].end_with? ".txt"
flash[:notice] = "Please upload .txt files"
else
session[:fname] = params['myfile'][:filename]
File.open('uploads/' + params['myfile'][:filename], "w") do |f|
f.write(params['myfile'][:tempfile].read)
end
end
if params['myfile2']
if not params['myfile2'][:filename].end_with? ".txt"
flash[:notice] = "Please upload .txt files"
else
session[:fname2] = params['myfile2'][:filename]
File.open('uploads/' + params['myfile2'][:filename], "w") do |f|
f.write(params['myfile2'][:tempfile].read)
end
end
end
else
flash[:notice] = "Please upload a file"
end
session[:do] = true
redirect '/'
end
get '/clear' do
session.clear
end
get "/special" do
"#{session[:gender]},#{session[:good_ratio]}"
end
get "/special2" do
"hello #{session[:data]}"
end