- add symlink for gestionnaire download documents
- add download folder documents in public folder
This commit is contained in:
parent
e7570564f8
commit
b437edefd1
2 changed files with 10 additions and 4 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -22,9 +22,10 @@
|
|||
*.iws
|
||||
|
||||
public/uploads
|
||||
public/downloads
|
||||
bin/*
|
||||
config/initializers/token.rb
|
||||
doc/*.svg
|
||||
rubocop.html
|
||||
config/france_connect.yml
|
||||
vendor/**/*
|
||||
vendor/**/*
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue