Description:
added option for Apapche X-Sendfile git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@370 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r172:400ab663b3b9 - - 2 files changed: 13 inserted, 9 deleted

@@ -1,44 +1,44
1 class TasksController < ApplicationController
1 class TasksController < ApplicationController
2
2
3 before_filter :authenticate, :check_viewability
3 before_filter :authenticate, :check_viewability
4
4
5 def index
5 def index
6 redirect_to :action => 'list'
6 redirect_to :action => 'list'
7 end
7 end
8
8
9 def list
9 def list
10 @problems = Problem.find_available_problems
10 @problems = Problem.find_available_problems
11 @user = User.find(session[:user_id])
11 @user = User.find(session[:user_id])
12 end
12 end
13
13
14 def view
14 def view
15 base_filename = File.basename("#{params[:file]}.#{params[:ext]}")
15 base_filename = File.basename("#{params[:file]}.#{params[:ext]}")
16 filename = "#{RAILS_ROOT}/data/tasks/#{base_filename}"
16 filename = "#{RAILS_ROOT}/data/tasks/#{base_filename}"
17 #filename = "/home/ioi/web_grader/data/tasks/#{base_filename}"
17 #filename = "/home/ioi/web_grader/data/tasks/#{base_filename}"
18 #filename = "/home/ioi/web_grader/public/images/rails.png"
18 #filename = "/home/ioi/web_grader/public/images/rails.png"
19 if !FileTest.exists?(filename)
19 if !FileTest.exists?(filename)
20 redirect_to :action => 'index' and return
20 redirect_to :action => 'index' and return
21 end
21 end
22
22
23 - response.headers['Content-Type'] = "application/force-download"
23 + if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE
24 - response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\""
24 + response.headers['Content-Type'] = "application/force-download"
25 - response.headers["X-Sendfile"] = filename
25 + response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\""
26 - response.headers['Content-length'] = File.size(filename)
26 + response.headers["X-Sendfile"] = filename
27 - render :nothing => true
27 + response.headers['Content-length'] = File.size(filename)
28 -
28 + render :nothing => true
29 - return
29 + else
30 -
30 + send_file filename, :stream => false, :filename => base_filename
31 - send_file filename, :stream => false, :filename => base_filename
31 + end
32 end
32 end
33
33
34 protected
34 protected
35
35
36 def check_viewability
36 def check_viewability
37 user = User.find(session[:user_id])
37 user = User.find(session[:user_id])
38 if user==nil or !Configuration.show_tasks_to?(user)
38 if user==nil or !Configuration.show_tasks_to?(user)
39 redirect_to :controller => 'main', :action => 'list'
39 redirect_to :controller => 'main', :action => 'list'
40 return false
40 return false
41 end
41 end
42 end
42 end
43
43
44 end
44 end
@@ -42,48 +42,52
42 config.time_zone = 'UTC'
42 config.time_zone = 'UTC'
43
43
44 # Setting locales
44 # Setting locales
45 config.i18n.default_locale = 'th'
45 config.i18n.default_locale = 'th'
46
46
47 # See Rails::Configuration for more options
47 # See Rails::Configuration for more options
48
48
49 # -------------
49 # -------------
50 # Required gems
50 # Required gems
51 # -------------
51 # -------------
52 config.gem "haml"
52 config.gem "haml"
53 config.gem "tmail"
53 config.gem "tmail"
54 config.gem "BlueCloth", :lib => "bluecloth"
54 config.gem "BlueCloth", :lib => "bluecloth"
55
55
56 # NOTES on rspec: if you wan to test with rspec, you have to install
56 # NOTES on rspec: if you wan to test with rspec, you have to install
57 # rspec yourself, just call: [sudo] gem install rspec-rails
57 # rspec yourself, just call: [sudo] gem install rspec-rails
58
58
59 end
59 end
60
60
61 # Add new inflection rules using the following format
61 # Add new inflection rules using the following format
62 # (all these examples are active by default):
62 # (all these examples are active by default):
63 # Inflector.inflections do |inflect|
63 # Inflector.inflections do |inflect|
64 # inflect.plural /^(ox)$/i, '\1en'
64 # inflect.plural /^(ox)$/i, '\1en'
65 # inflect.singular /^(ox)en/i, '\1'
65 # inflect.singular /^(ox)en/i, '\1'
66 # inflect.irregular 'person', 'people'
66 # inflect.irregular 'person', 'people'
67 # inflect.uncountable %w( fish sheep )
67 # inflect.uncountable %w( fish sheep )
68 # end
68 # end
69
69
70 # Add new mime types for use in respond_to blocks:
70 # Add new mime types for use in respond_to blocks:
71 # Mime::Type.register "text/richtext", :rtf
71 # Mime::Type.register "text/richtext", :rtf
72 # Mime::Type.register "application/x-mobile", :mobile
72 # Mime::Type.register "application/x-mobile", :mobile
73
73
74 # Include your application configuration below
74 # Include your application configuration below
75
75
76 # These are where inputs and outputs of test requests are stored
76 # These are where inputs and outputs of test requests are stored
77 TEST_REQUEST_INPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/input'
77 TEST_REQUEST_INPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/input'
78 TEST_REQUEST_OUTPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/output'
78 TEST_REQUEST_OUTPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/output'
79
79
80 # To use ANALYSIS MODE, provide the testcases/testruns breakdown,
80 # To use ANALYSIS MODE, provide the testcases/testruns breakdown,
81 # and the directory of the grading result (usually in judge's dir).
81 # and the directory of the grading result (usually in judge's dir).
82 TASK_GRADING_INFO_FILENAME = RAILS_ROOT + '/config/tasks.yml'
82 TASK_GRADING_INFO_FILENAME = RAILS_ROOT + '/config/tasks.yml'
83 GRADING_RESULT_DIR = '/home/thailandoi/ytopc/judge/result'
83 GRADING_RESULT_DIR = '/home/thailandoi/ytopc/judge/result'
84
84
85 # Uncomment so that configuration is read only once when the server is loaded
85 # Uncomment so that configuration is read only once when the server is loaded
86 # Configuration.enable_caching
86 # Configuration.enable_caching
87
87
88 # Uncomment so that the system validates user e-mails
88 # Uncomment so that the system validates user e-mails
89 # VALIDATE_USER_EMAILS = true
89 # VALIDATE_USER_EMAILS = true
90 +
91 + # Uncomment so that Apache X-Sendfile is used when delivering files
92 + # (e.g., in /tasks/view).
93 + # USE_APACHE_XSENDFILE = true
You need to be logged in to leave comments. Login now