Skip to content

Commit

Permalink
default failene
Browse files Browse the repository at this point in the history
  • Loading branch information
qinmingyuan committed Oct 10, 2024
1 parent 00322d7 commit cedd0fa
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/rails_com/utils/url_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def filepath_from_url(url, filename: SecureRandom.alphanumeric)
file_path
end

def init_file(filename = SecureRandom.alphanumeric)
file_path = Rails.root.join('tmp/files', filename)
file_path.dirname.exist? || file_path.dirname.mkpath
file = File.new(file_path, 'w+')
file.binmode
[file_path, file]
end

private
def fetch_file(url, file)
res = HTTPX.plugin(:follow_redirects).get(url)
Expand All @@ -33,11 +41,4 @@ def fetch_file(url, file)
rescue => e
end

def init_file(filename)
file_path = Rails.root.join('tmp/files', filename)
file_path.dirname.exist? || file_path.dirname.mkpath
file = File.new(file_path, 'w+')
file.binmode
[file_path, file]
end
end

0 comments on commit cedd0fa

Please sign in to comment.