Sha256: 8ad20fa6ab00b5f7f56df72a2186dcd264bb97f50d9f3ef870dd4672cb82b901
Contents?: true
Size: 1.52 KB
Versions: 2
Compression:
Stored size: 1.52 KB
Contents
# Copyright © 2012 The Pennsylvania State University # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. class UnzipJob @queue = :unzip def self.perform(pid) zip_file = GenericFile.find(pid, :cast => true) Zip::Archive.open_buffer(zip_file.content.content) do |archive| archive.each do |f| @generic_file = GenericFile.new @generic_file.batch_id = zip_file.batch.pid file_name = f.name mime_types = MIME::Types.of(file_name) mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type options = {:label=>file_name, :dsid=>'content', :mimeType=>mime_type} @generic_file.add_file_datastream(f.read, options) @generic_file.set_title_and_label( file_name, :only_if_blank=>true ) @generic_file.apply_depositor_metadata(zip_file.edit_users.first) @generic_file.date_uploaded = Time.now.ctime @generic_file.date_modified = Time.now.ctime @generic_file.terms_of_service = '1' @generic_file.save end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sufia-0.0.1.pre2 | app/models/unzip_job.rb |
sufia-0.0.1.pre1 | app/models/unzip_job.rb |