2019-07-01 15:55:37 +02:00
|
|
|
class ActiveStorage::DownloadableFile
|
|
|
|
def initialize(attached)
|
|
|
|
if using_local_backend?
|
|
|
|
@url = 'file://' + ActiveStorage::Blob.service.path_for(attached.key)
|
|
|
|
else
|
|
|
|
@url = attached.service_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
|
|
|
@url
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.create_list_from_dossier(dossier)
|
|
|
|
pjs = PiecesJustificativesService.liste_pieces_justificatives(dossier)
|
2019-11-20 11:44:04 +01:00
|
|
|
pjs.map do |piece_justificative|
|
2019-07-01 15:55:37 +02:00
|
|
|
[
|
2020-07-20 11:14:34 +02:00
|
|
|
piece_justificative,
|
2020-07-20 11:22:56 +02:00
|
|
|
self.timestamped_filename(piece_justificative)
|
2019-07-01 15:55:37 +02:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-07-20 11:22:56 +02:00
|
|
|
def self.timestamped_filename(piece_justificative)
|
|
|
|
extension = File.extname(piece_justificative.filename.to_s)
|
|
|
|
basename = File.basename(piece_justificative.filename.to_s, extension)
|
|
|
|
timestamp = piece_justificative.created_at.strftime("%d-%m-%Y-%H-%S")
|
|
|
|
|
|
|
|
"#{basename}-#{timestamp}#{extension}"
|
|
|
|
end
|
|
|
|
|
2019-07-01 15:55:37 +02:00
|
|
|
def using_local_backend?
|
|
|
|
[:local, :local_test, :test].include?(Rails.application.config.active_storage.service)
|
|
|
|
end
|
|
|
|
end
|