- add symlink for gestionnaire download documents

- add download folder documents in public folder
This commit is contained in:
Xavier J 2016-01-05 16:26:59 +01:00
parent e7570564f8
commit b437edefd1
2 changed files with 10 additions and 4 deletions

1
.gitignore vendored
View file

@ -22,6 +22,7 @@
*.iws
public/uploads
public/downloads
bin/*
config/initializers/token.rb
doc/*.svg

View file

@ -1,7 +1,7 @@
require 'securerandom'
class Downloader
BASE_PATH_DISK = File.join(Rails.root, "public/")
BASE_PATH_DISK = File.join(Rails.root, "public/downloads/")
def initialize(filename, filename_suffix = '')
@filename = filename.to_s
@ -10,11 +10,11 @@ class Downloader
generate_random_base_path!
FileUtils.cp @filename, "#{@base_path}/#{@filename_suffix}.#{@extension}"
FileUtils.ln_s @filename, "#{@base_path}/#{@filename_suffix}.#{@extension}"
end
def url
@url ||= File.join(TPS::Application::URL, random_folder_name, "#{@filename_suffix}.#{@extension}")
@url ||= File.join(TPS::Application::URL, 'downloads', random_folder_name, "#{@filename_suffix}.#{@extension}")
end
protected
@ -26,6 +26,11 @@ class Downloader
loop do
self.random_folder_name = SecureRandom.hex
base_path = File.join(BASE_PATH_DISK, self.random_folder_name)
unless File.directory?(BASE_PATH_DISK)
Dir.mkdir(BASE_PATH_DISK)
end
unless File.directory?(base_path)
Dir.mkdir(base_path)
break base_path