Sha256: d4bf953123f6868aae4b123d931d40c9712837b1a91c3c839c5f9ed11c618e57

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 KB

Contents

module Sufia::FilesController
  module BrowseEverything
    include ActiveSupport::Concern

    def create 
      if params[:selected_files].present?
        create_from_browse_everything(params)
      else
        super
      end
    end

    protected

      def create_from_browse_everything(params)
        params[:selected_files].each_pair do |index, file_info| 
          next if file_info.blank? || file_info["url"].blank?
          create_file_from_url(file_info["url"], file_info["file_name"])
        end
        redirect_to self.class.upload_complete_path( params[:batch_id])
      end
      
      # Generic utility for creating GenericFile from a URL
      # Used in to import files using URLs from a file picker like browse_everything 
      def create_file_from_url(url, file_name, batch_id=nil)
        generic_file = ::GenericFile.new(import_url: url, label: file_name).tap do |gf|
          actor = Sufia::GenericFile::Actor.new(gf, current_user)
          actor.create_metadata(params[:batch_id])
          gf.save!
          Sufia.queue.push(ImportUrlJob.new(gf.pid))
        end
      end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sufia-5.0.0 app/controllers/concerns/sufia/files_controller/browse_everything.rb
sufia-5.0.0.rc1 app/controllers/concerns/sufia/files_controller/browse_everything.rb
sufia-4.3.1 app/controllers/concerns/sufia/files_controller/browse_everything.rb
sufia-4.2.0 app/controllers/concerns/sufia/files_controller/browse_everything.rb
sufia-4.1.0 app/controllers/concerns/sufia/files_controller/browse_everything.rb
sufia-4.0.1 app/controllers/concerns/sufia/files_controller/browse_everything.rb
sufia-4.0.0 app/controllers/concerns/sufia/files_controller/browse_everything.rb
sufia-4.0.0.rc2 app/controllers/concerns/sufia/files_controller/browse_everything.rb