Module: S3Html
- Defined in:
- lib/s3_html.rb,
lib/s3_html/version.rb
Defined Under Namespace
Classes: S3FolderUpload
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.delete_dir(prefix) ⇒ Object
prefix - is directory path.
- .uploadHtml(file_path) ⇒ Object
Class Method Details
.delete_dir(prefix) ⇒ Object
prefix - is directory path. since s3 aws-sdk gem can’t destroy whole folder we should iterate through and delete each item. need return Responce for assurance of if it is deleted or not
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/s3_html.rb', line 32 def delete_dir(prefix) Aws.config.update({ region: S3_REGION, credentials: Aws::Credentials.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) }) s3 = Aws::S3::Resource.new(region:S3_REGION) obj_keys = s3.bucket(S3_BUCKET_NAME).objects(:prefix => prefix).collect(&:key) s3_client = get_s3_client obj_keys.map do |obj_key| s3_client.delete_object({ bucket: S3_BUCKET_NAME, key: obj_key, }) end end |
.uploadHtml(file_path) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/s3_html.rb', line 5 def uploadHtml(file_path) extract_point = '/tmp/unzipped/' uniq_path = SecureRandom.uuid.to_s index_detected = false Zip::ZipFile.open(file_path) { |zip_file| zip_file.each { |f| f_path = File.join(extract_point + uniq_path, f.name) FileUtils.mkdir_p(File.dirname(f_path)) zip_file.extract(f, f_path) unless File.exist?(f_path) } } Dir.foreach(extract_point + uniq_path) do |item| next if item == '.' or item == '..' index_detected = true if item == "index.html" end if index_detected uploader = S3FolderUpload.new(extract_point, uniq_path, current_account.id) uploader.upload!(1) else @error_message = I18n.t('push_html.invalid_page') return false end end |