Allow video uploads
This commit is contained in:
@@ -14,7 +14,7 @@ module Adamantium
|
|||||||
include Dry::Monads[:result]
|
include Dry::Monads[:result]
|
||||||
|
|
||||||
IMAGE_TYPES = %i[jpeg jpg png].freeze
|
IMAGE_TYPES = %i[jpeg jpg png].freeze
|
||||||
VIDEO_TYPES = %i[gif].freeze
|
VIDEO_TYPES = %i[gif iso].freeze
|
||||||
VALID_UPLOAD_TYPES = IMAGE_TYPES + VIDEO_TYPES
|
VALID_UPLOAD_TYPES = IMAGE_TYPES + VIDEO_TYPES
|
||||||
|
|
||||||
def call(file:)
|
def call(file:)
|
||||||
@@ -24,7 +24,7 @@ module Adamantium
|
|||||||
return Failure(:invalid_file_type) unless VALID_UPLOAD_TYPES.include? type
|
return Failure(:invalid_file_type) unless VALID_UPLOAD_TYPES.include? type
|
||||||
|
|
||||||
result = save_image(file: file) if IMAGE_TYPES.include? type
|
result = save_image(file: file) if IMAGE_TYPES.include? type
|
||||||
result = save_video(file: file) if VIDEO_TYPES.include? type
|
result = save_video(file: file, type: type) if VIDEO_TYPES.include? type
|
||||||
|
|
||||||
if result.success?
|
if result.success?
|
||||||
Success(result.value!)
|
Success(result.value!)
|
||||||
@@ -43,7 +43,7 @@ module Adamantium
|
|||||||
SecureRandom.uuid
|
SecureRandom.uuid
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_video(file:)
|
def save_video(file:, type:)
|
||||||
fullsize_filename = "#{uuid}.mp4"
|
fullsize_filename = "#{uuid}.mp4"
|
||||||
|
|
||||||
dirname = File.join("public", "media", pathname)
|
dirname = File.join("public", "media", pathname)
|
||||||
@@ -53,7 +53,12 @@ module Adamantium
|
|||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Open3.popen3("ffmpeg -i #{file[:tempfile].path} -movflags faststart -pix_fmt yuv420p -vf 'scale=trunc(iw/2)*2:trunc(ih/2)*2' #{File.join(dirname, fullsize_filename)}")
|
case type
|
||||||
|
when :gif
|
||||||
|
Open3.popen3("ffmpeg -i #{file[:tempfile].path} -movflags faststart -pix_fmt yuv420p -vf 'scale=trunc(iw/2)*2:trunc(ih/2)*2' #{File.join(dirname, fullsize_filename)}")
|
||||||
|
when :iso
|
||||||
|
Open3.popen3("ffmpeg -i #{file[:tempfile].path} -vcodec libx264 -crf 28 #{File.join(dirname, fullsize_filename)}")
|
||||||
|
end
|
||||||
rescue Errno::ENOENT, NoMethodError => e
|
rescue Errno::ENOENT, NoMethodError => e
|
||||||
return Failure(e.message)
|
return Failure(e.message)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user