Browse Source

Do not generate thumbnails by default. Cleanup tmp dir after extraction.

Lukasz Badura 5 months ago
parent
commit
85d8b20437
1 changed files with 6 additions and 7 deletions
  1. 6 7
      lib/fotos/zip_extractor.rb

+ 6 - 7
lib/fotos/zip_extractor.rb

@@ -7,6 +7,7 @@ module Fotos
     def initialize(options)
       @zip_file_path = options[:zip]
       @destination_path = options[:dest]
+      @tmp_dir_path = File.join(Pathname.pwd, 'tmp')
       @extracted_paths = []
       @copied_paths = []
     end
@@ -14,21 +15,19 @@ module Fotos
     attr_reader :zip_file_path, :destination_path
 
     def call
+      Dir.mkdir(@tmp_dir_path) unless Dir.exist?(@tmp_dir_path)
       extract
       copy
-      generate_thumbnails
+    ensure
+      FileUtils.rm_r(@tmp_dir_path)
     end
 
     private
     def extract
       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|
           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
           entry.extract(dest_path)
         rescue Zip::DestinationFileExistsError
@@ -48,7 +47,7 @@ module Fotos
         exif_date_str = exif.date_time.strftime(date_format)
 
         # 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))
 
         # create destination dir if not already there