2005-01-22 03:49:52 +01:00
|
|
|
require 'fileutils'
|
2005-01-22 02:35:00 +01:00
|
|
|
require 'application'
|
2005-01-22 03:49:52 +01:00
|
|
|
require 'instiki_errors'
|
2005-01-22 02:57:05 +01:00
|
|
|
|
2005-01-22 02:35:00 +01:00
|
|
|
class FileController < ApplicationController
|
|
|
|
|
2005-01-22 15:58:43 +01:00
|
|
|
layout 'default'
|
2005-01-22 02:35:00 +01:00
|
|
|
|
|
|
|
def file
|
2005-01-23 04:52:07 +01:00
|
|
|
check_path
|
2005-01-23 02:36:51 +01:00
|
|
|
|
2005-01-22 19:38:16 +01:00
|
|
|
if @params['file']
|
2005-01-22 20:30:49 +01:00
|
|
|
# form supplied
|
2005-01-23 14:42:56 +01:00
|
|
|
file_yard.upload_file(@file_name, @params['file'])
|
2005-01-22 20:30:49 +01:00
|
|
|
flash[:info] = "File '#{@file_name}' successfully uploaded"
|
2005-01-23 15:54:41 +01:00
|
|
|
@web.refresh_pages_with_references(@file_name)
|
2005-01-22 20:30:49 +01:00
|
|
|
return_to_last_remembered
|
2005-01-23 02:36:51 +01:00
|
|
|
elsif file_yard.has_file?(@file_name)
|
|
|
|
send_file(file_yard.file_path(@file_name))
|
2005-01-22 03:49:52 +01:00
|
|
|
else
|
2005-01-23 02:36:51 +01:00
|
|
|
logger.debug("File not found: #{file_yard.files_path}/#{@file_name}")
|
2005-01-22 19:38:16 +01:00
|
|
|
# go to the template, which is a file upload form
|
2005-01-22 02:35:00 +01:00
|
|
|
end
|
|
|
|
end
|
2005-01-22 15:58:43 +01:00
|
|
|
|
2005-01-22 19:38:16 +01:00
|
|
|
def cancel_upload
|
|
|
|
return_to_last_remembered
|
|
|
|
end
|
|
|
|
|
2005-01-23 04:52:07 +01:00
|
|
|
def pic
|
|
|
|
check_path
|
2005-01-23 14:42:56 +01:00
|
|
|
if @params['file']
|
|
|
|
# form supplied
|
|
|
|
file_yard.upload_file(@file_name, @params['file'])
|
|
|
|
flash[:info] = "Image '#{@file_name}' successfully uploaded"
|
2005-01-23 15:54:41 +01:00
|
|
|
@web.refresh_pages_with_references(@file_name)
|
2005-01-23 14:42:56 +01:00
|
|
|
return_to_last_remembered
|
|
|
|
elsif file_yard.has_file?(@file_name)
|
2005-01-23 04:52:07 +01:00
|
|
|
send_file(file_yard.file_path(@file_name))
|
|
|
|
else
|
2005-01-23 14:42:56 +01:00
|
|
|
logger.debug("Image not found: #{file_yard.files_path}/#{@file_name}")
|
|
|
|
render_action 'file'
|
2005-01-23 04:52:07 +01:00
|
|
|
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
|
|
|
|
|
2005-01-22 03:49:52 +01:00
|
|
|
end
|