Beginnings of a FileController (serving the file upload feature)
This commit is contained in:
parent
71407f9b9f
commit
12a34823a8
5 changed files with 83 additions and 26 deletions
30
app/controllers/file_controller.rb
Normal file
30
app/controllers/file_controller.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'application'
|
||||
class FileController < ApplicationController
|
||||
|
||||
layout 'default', :except => [:rss_feed, :rss_with_headlines, :tex, :export_tex, :export_html]
|
||||
|
||||
def file
|
||||
if have_file?(@params['id'])
|
||||
render_text 'Download file'
|
||||
else
|
||||
render_text 'form'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def have_file?(file_name)
|
||||
sanitize_file_name(file_name)
|
||||
@wiki.storage_path
|
||||
end
|
||||
|
||||
SANE_FILE_NAME = /[-_A-Za-z0-9]{1,255}/
|
||||
def sanitize_file_name(file_name)
|
||||
unless file_name =~ SANE_FILE_NAME
|
||||
raise "Invalid file name: '#{file_name}'.\n" +
|
||||
"Only latin characters, digits, underscores and dashes are accepted."
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue