|
@@ -7,6 +7,7 @@ module Fotos
|
|
|
def initialize(options)
|
|
def initialize(options)
|
|
|
@zip_file_path = options[:zip]
|
|
@zip_file_path = options[:zip]
|
|
|
@destination_path = options[:dest]
|
|
@destination_path = options[:dest]
|
|
|
|
|
+ @tmp_dir_path = File.join(Pathname.pwd, 'tmp')
|
|
|
@extracted_paths = []
|
|
@extracted_paths = []
|
|
|
@copied_paths = []
|
|
@copied_paths = []
|
|
|
end
|
|
end
|
|
@@ -14,21 +15,19 @@ module Fotos
|
|
|
attr_reader :zip_file_path, :destination_path
|
|
attr_reader :zip_file_path, :destination_path
|
|
|
|
|
|
|
|
def call
|
|
def call
|
|
|
|
|
+ Dir.mkdir(@tmp_dir_path) unless Dir.exist?(@tmp_dir_path)
|
|
|
extract
|
|
extract
|
|
|
copy
|
|
copy
|
|
|
- generate_thumbnails
|
|
|
|
|
|
|
+ ensure
|
|
|
|
|
+ FileUtils.rm_r(@tmp_dir_path)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
private
|
|
private
|
|
|
def extract
|
|
def extract
|
|
|
Zip::File.open(zip_file_path) do |zip_file|
|
|
Zip::File.open(zip_file_path) do |zip_file|
|
|
|
- tmp_dir_path = File.join(Pathname.pwd, 'tmp')
|
|
|
|
|
- Dir.mkdir(tmp_dir_path) unless Dir.exist?(tmp_dir_path)
|
|
|
|
|
-
|
|
|
|
|
zip_file.each do |entry|
|
|
zip_file.each do |entry|
|
|
|
file_name = entry.name.split('/').last
|
|
file_name = entry.name.split('/').last
|
|
|
- dest_path = File.join(tmp_dir_path, file_name)
|
|
|
|
|
- #puts "extracting #{entry.name}"
|
|
|
|
|
|
|
+ dest_path = File.join(@tmp_dir_path, file_name)
|
|
|
@extracted_paths << dest_path
|
|
@extracted_paths << dest_path
|
|
|
entry.extract(dest_path)
|
|
entry.extract(dest_path)
|
|
|
rescue Zip::DestinationFileExistsError
|
|
rescue Zip::DestinationFileExistsError
|
|
@@ -48,7 +47,7 @@ module Fotos
|
|
|
exif_date_str = exif.date_time.strftime(date_format)
|
|
exif_date_str = exif.date_time.strftime(date_format)
|
|
|
|
|
|
|
|
# destination dir for given file in public/images/dd-mm-yyyy
|
|
# destination dir for given file in public/images/dd-mm-yyyy
|
|
|
- dest_dir = File.join(Pathname.pwd, destination_path, 'images', exif_date_str)
|
|
|
|
|
|
|
+ dest_dir = File.join(Pathname.pwd, destination_path, exif_date_str)
|
|
|
dest_path = File.join(dest_dir, File.basename(fp))
|
|
dest_path = File.join(dest_dir, File.basename(fp))
|
|
|
|
|
|
|
|
# create destination dir if not already there
|
|
# create destination dir if not already there
|