Skip to content

Commit

Permalink
Merge branch 'other' of github.com:eivu/client-ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
dabobert committed Apr 3, 2023
2 parents 5c0765b + 4c4e093 commit c2413e2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ ruby client for interacting with eivu server

```
require './lib/eivu'
Eivu::Client.configuration
Eivu::Client.new.upload_file path_to_file: "/Users/jinx/Downloads/PXL_20230124_162634633.jpg"
Eivu::Client.new.upload_folder path_to_folder: "/Users/jinx/Downloads/xfer", peepy: true, nsfw: true
Eivu::Client.new.upload_folder path_to_folder: "/Users/jinx/Downloads/demo"
Eivu::Client.new.upload_folder peepy: true, nsfw: true, path_to_folder: "/Users/jinx/Downloads/xfer"
```
```
57 changes: 41 additions & 16 deletions lib/eivu/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ def upload_file(path_to_file:, peepy: false, nsfw: false)
if cloud_file.transfered?
puts " Completing"
cloud_file.complete!(year:, rating:, release_pos: nil, metadata_list:, matched_recording: nil)
# end
else
# binding.pry
# if cloud_file.state_history.empty?
puts " Updating/Skipping"
cloud_file.update_metadata!(year:, rating:, release_pos: nil, metadata_list:, matched_recording: nil)
end
Expand All @@ -95,23 +92,27 @@ def upload_file(path_to_file:, peepy: false, nsfw: false)

def upload_folder(path_to_folder:, peepy: false, nsfw: false)
Folder.traverse(path_to_folder) do |path_to_file|
upload_file(path_to_file:, peepy:, nsfw:)
@status[:failure].delete(path_to_file)
@status[:success][path_to_file] = 'Upload successful'
rescue StandardError => e
@status[:failure][path_to_file] = e
@status[:success].delete(path_to_file)
end
FileUtils.mkdir_p('logs')
CSV.open('logs/success.csv', 'a+') do |success_log|
@status[:success].each {|v| success_log << [Time.now, v]}
end
CSV.open('logs/failure.csv', 'a+') do |failure_log|
@status[:failure].each {|v| failure_log << [Time.now, v]}
begin
upload_file(path_to_file:, peepy:, nsfw:)
if verify_upload!(path_to_file)
track_success(path_to_file)
else
track_failure(path_to_file, "upload did not complete")
end
rescue StandardError => error
track_failure(path_to_file, error)
end
end
write_logs
@status
end

def verify_upload!(path_to_file)
md5 = Eivu::Client::CloudFile.generate_md5(path_to_file)&.downcase
instance = Eivu::Client::CloudFile.fetch(md5.upcase)
instance&.state&.to_sym == Eivu::Client::CloudFile::STATE_COMPLETED
end

def configuration
@configuration ||= self.class.configuration
end
Expand Down Expand Up @@ -174,6 +175,30 @@ def validated_remote_md5!(remote_path_to_file:, path_to_file:, md5:)

private

def write_logs
FileUtils.mkdir_p('logs')
CSV.open('logs/success.csv', 'a+') do |success_log|
@status[:success].each {|v| success_log << [Time.now, v]}
end
CSV.open('logs/failure.csv', 'a+') do |failure_log|
@status[:failure].each {|v| failure_log << [Time.now, v]}
end
end

def track_success(path_to_file)
md5 = Eivu::Client::CloudFile.generate_md5(path_to_file)
key = "#{path_to_file}|#{md5}"
@status[:failure].delete(key)
@status[:success][key] = 'Upload successful'
end

def track_failure(path_to_file, error)
md5 = Eivu::Client::CloudFile.generate_md5(path_to_file)
key = "#{path_to_file}|#{md5}"
@status[:failure][key] = error
@status[:success].delete(key)
end

def s3_client
settings = {
region: configuration.region,
Expand Down
1 change: 1 addition & 0 deletions lib/eivu/client/cloud_file.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'aws-sdk-s3'
require 'active_support/core_ext/hash/keys'
require 'dry/struct'
require 'dry/struct/setters'
require 'pry'
Expand Down

0 comments on commit c2413e2

Please sign in to comment.