include dry monads
This commit is contained in:
@@ -2,11 +2,10 @@ module Adamantium
|
|||||||
module Actions
|
module Actions
|
||||||
module Media
|
module Media
|
||||||
class Create < Action
|
class Create < Action
|
||||||
include Deps["commands.media.upload", "logger"]
|
include Deps["commands.media.upload"]
|
||||||
before :authenticate!
|
before :authenticate!
|
||||||
|
|
||||||
def handle(req, res)
|
def handle(req, res)
|
||||||
logger.info("I am CREATE")
|
|
||||||
data = req.params[:file]
|
data = req.params[:file]
|
||||||
|
|
||||||
halt 401 unless verify_scope(req: req, scope: :media)
|
halt 401 unless verify_scope(req: req, scope: :media)
|
||||||
@@ -17,7 +16,6 @@ module Adamantium
|
|||||||
end
|
end
|
||||||
|
|
||||||
m.success do |v|
|
m.success do |v|
|
||||||
logger.info("I have CREATED")
|
|
||||||
res.status = 201
|
res.status = 201
|
||||||
res.headers["Location"] = v
|
res.headers["Location"] = v
|
||||||
res.body = {
|
res.body = {
|
||||||
|
@@ -2,11 +2,9 @@ module Adamantium
|
|||||||
module Actions
|
module Actions
|
||||||
module Media
|
module Media
|
||||||
class Show < Action
|
class Show < Action
|
||||||
include Deps["settings", "logger"]
|
include Deps["settings"]
|
||||||
|
|
||||||
def handle(req, res)
|
def handle(req, res)
|
||||||
logger.info("I am SHOW")
|
|
||||||
|
|
||||||
res.body = if req.params[:q] == "source"
|
res.body = if req.params[:q] == "source"
|
||||||
{
|
{
|
||||||
items: media_url(req.params[:file])
|
items: media_url(req.params[:file])
|
||||||
|
@@ -1,12 +1,14 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "securerandom"
|
require "securerandom"
|
||||||
|
require "dry/monads"
|
||||||
|
|
||||||
module Adamantium
|
module Adamantium
|
||||||
module Commands
|
module Commands
|
||||||
module Media
|
module Media
|
||||||
class Upload < Command
|
class Upload < Command
|
||||||
include Deps["settings", "logger"]
|
include Deps["settings"]
|
||||||
|
include Dry::Monads[:result]
|
||||||
|
|
||||||
def call(file:)
|
def call(file:)
|
||||||
pathname = Time.now.strftime("%m-%Y")
|
pathname = Time.now.strftime("%m-%Y")
|
||||||
@@ -14,8 +16,6 @@ module Adamantium
|
|||||||
filename = "#{SecureRandom.uuid}#{File.extname(file[:filename])}"
|
filename = "#{SecureRandom.uuid}#{File.extname(file[:filename])}"
|
||||||
|
|
||||||
dirname = File.join("public", "media", pathname)
|
dirname = File.join("public", "media", pathname)
|
||||||
logger.info(dirname)
|
|
||||||
logger.info(File.directory?(dirname))
|
|
||||||
|
|
||||||
unless File.directory?(dirname)
|
unless File.directory?(dirname)
|
||||||
FileUtils.mkdir_p(dirname)
|
FileUtils.mkdir_p(dirname)
|
||||||
@@ -23,14 +23,11 @@ module Adamantium
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
File.write(File.join(dirname, filename), file[:tempfile].read)
|
File.write(File.join(dirname, filename), file[:tempfile].read)
|
||||||
logger.info("I WROTE")
|
|
||||||
rescue Errno::ENOENT, NoMethodError => e
|
rescue Errno::ENOENT, NoMethodError => e
|
||||||
logger.info("I FAILED to write - #{e}")
|
|
||||||
return Failure(e.message)
|
return Failure(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
upload_path = File.join(settings.micropub_site_url, "/media/", "/#{pathname}/", filename).to_s
|
upload_path = File.join(settings.micropub_site_url, "/media/", "/#{pathname}/", filename).to_s
|
||||||
logger.info(upload_path)
|
|
||||||
Success(upload_path)
|
Success(upload_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user