From 89f3d5387a04bc63c5e7bc3aaee9b679e0aff3ce Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Tue, 31 Jan 2023 19:32:40 +1100 Subject: [PATCH] include dry monads --- app/actions/media/create.rb | 4 +--- app/actions/media/show.rb | 4 +--- app/commands/media/upload.rb | 9 +++------ 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/app/actions/media/create.rb b/app/actions/media/create.rb index 66c8806..ab9d725 100644 --- a/app/actions/media/create.rb +++ b/app/actions/media/create.rb @@ -2,11 +2,10 @@ module Adamantium module Actions module Media class Create < Action - include Deps["commands.media.upload", "logger"] + include Deps["commands.media.upload"] before :authenticate! def handle(req, res) - logger.info("I am CREATE") data = req.params[:file] halt 401 unless verify_scope(req: req, scope: :media) @@ -17,7 +16,6 @@ module Adamantium end m.success do |v| - logger.info("I have CREATED") res.status = 201 res.headers["Location"] = v res.body = { diff --git a/app/actions/media/show.rb b/app/actions/media/show.rb index cf9ead8..2a0227a 100644 --- a/app/actions/media/show.rb +++ b/app/actions/media/show.rb @@ -2,11 +2,9 @@ module Adamantium module Actions module Media class Show < Action - include Deps["settings", "logger"] + include Deps["settings"] def handle(req, res) - logger.info("I am SHOW") - res.body = if req.params[:q] == "source" { items: media_url(req.params[:file]) diff --git a/app/commands/media/upload.rb b/app/commands/media/upload.rb index f68471d..8e142a3 100644 --- a/app/commands/media/upload.rb +++ b/app/commands/media/upload.rb @@ -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