include dry monads
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "securerandom"
|
||||
require "dry/monads"
|
||||
|
||||
module Adamantium
|
||||
module Commands
|
||||
module Media
|
||||
class Upload < Command
|
||||
include Deps["settings", "logger"]
|
||||
include Deps["settings"]
|
||||
include Dry::Monads[:result]
|
||||
|
||||
def call(file:)
|
||||
pathname = Time.now.strftime("%m-%Y")
|
||||
@@ -14,8 +16,6 @@ module Adamantium
|
||||
filename = "#{SecureRandom.uuid}#{File.extname(file[:filename])}"
|
||||
|
||||
dirname = File.join("public", "media", pathname)
|
||||
logger.info(dirname)
|
||||
logger.info(File.directory?(dirname))
|
||||
|
||||
unless File.directory?(dirname)
|
||||
FileUtils.mkdir_p(dirname)
|
||||
@@ -23,14 +23,11 @@ module Adamantium
|
||||
|
||||
begin
|
||||
File.write(File.join(dirname, filename), file[:tempfile].read)
|
||||
logger.info("I WROTE")
|
||||
rescue Errno::ENOENT, NoMethodError => e
|
||||
logger.info("I FAILED to write - #{e}")
|
||||
return Failure(e.message)
|
||||
end
|
||||
|
||||
upload_path = File.join(settings.micropub_site_url, "/media/", "/#{pathname}/", filename).to_s
|
||||
logger.info(upload_path)
|
||||
Success(upload_path)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user