- 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

3
.gitignore vendored
View file

@ -22,9 +22,10 @@
*.iws *.iws
public/uploads public/uploads
public/downloads
bin/* bin/*
config/initializers/token.rb config/initializers/token.rb
doc/*.svg doc/*.svg
rubocop.html rubocop.html
config/france_connect.yml config/france_connect.yml
vendor/**/* vendor/**/*

View file

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