Initial commit
This commit is contained in:
32
app/commands/media/upload.rb
Normal file
32
app/commands/media/upload.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Adamantium
|
||||
module Commands
|
||||
module Media
|
||||
class Upload < Command
|
||||
include Deps["settings"]
|
||||
|
||||
def call(file:)
|
||||
pathname = Time.now.strftime("%m-%Y")
|
||||
|
||||
filename = file[:filename].split("/").last
|
||||
|
||||
dirname = File.join("public", "media", pathname)
|
||||
|
||||
unless File.directory?(dirname)
|
||||
FileUtils.mkdir_p(dirname)
|
||||
end
|
||||
|
||||
begin
|
||||
File.write(File.join(dirname, filename), file[:tempfile].read)
|
||||
rescue Errno::ENOENT, NoMethodError => e
|
||||
return Failure(e.message)
|
||||
end
|
||||
|
||||
upload_path = File.join(settings.micropub_site_url, "/media/", "/#{pathname}/", filename).to_s
|
||||
Success(upload_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user