display images from the file yard
This commit is contained in:
parent
d6fe54f4ad
commit
39f854a11e
|
@ -7,11 +7,8 @@ class FileController < ApplicationController
|
|||
layout 'default'
|
||||
|
||||
def file
|
||||
raise Instiki::ValidationError.new("Invalid path: no file name") unless @file_name
|
||||
raise Instiki::ValidationError.new("Invalid path: no web name") unless @web_name
|
||||
raise Instiki::ValidationError.new("Invalid path: unknown web name") unless @web
|
||||
check_path
|
||||
|
||||
file_yard = @wiki.file_yard(@web)
|
||||
if @params['file']
|
||||
# form supplied
|
||||
file_yard.upload(@file_name, @params['file'])
|
||||
|
@ -29,4 +26,25 @@ class FileController < ApplicationController
|
|||
return_to_last_remembered
|
||||
end
|
||||
|
||||
def pic
|
||||
check_path
|
||||
if file_yard.has_file?(@file_name)
|
||||
send_file(file_yard.file_path(@file_name))
|
||||
else
|
||||
render_text "Image not found: #{@file_name}", '404 Not Found'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_path
|
||||
raise Instiki::ValidationError.new("Invalid path: no file name") unless @file_name
|
||||
raise Instiki::ValidationError.new("Invalid path: no web name") unless @web_name
|
||||
raise Instiki::ValidationError.new("Invalid path: unknown web name") unless @web
|
||||
end
|
||||
|
||||
def file_yard
|
||||
@wiki.file_yard(@web)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_file_download_text_file
|
||||
File.open(FILE_AREA + '/foo.txt', 'wb') { |f| f.write "aaa\nbbb\n" }
|
||||
File.open("#{FILE_AREA}/foo.txt", 'wb') { |f| f.write "aaa\nbbb\n" }
|
||||
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.txt'
|
||||
|
||||
|
@ -39,7 +39,7 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_file_download_pdf_file
|
||||
File.open(FILE_AREA + '/foo.pdf', 'wb') { |f| f.write "aaa\nbbb\n" }
|
||||
File.open("#{FILE_AREA}/foo.pdf", 'wb') { |f| f.write "aaa\nbbb\n" }
|
||||
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.pdf'
|
||||
|
||||
|
@ -48,4 +48,13 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
assert_equal 'application/pdf', r.headers['Content-Type']
|
||||
end
|
||||
|
||||
def test_pic_download_gif
|
||||
FileUtils.cp("#{RAILS_ROOT}/test/fixtures/rails.gif", FILE_AREA)
|
||||
|
||||
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails.gif'
|
||||
|
||||
assert_success
|
||||
assert_equal File.size("#{FILE_AREA}/rails.gif"), r.binary_content.size
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue