# Conflicts:
#	app/controllers/settings/exports_controller.rb
#	app/models/media_attachment.rb
#	app/models/status.rb
#	app/views/about/show.html.haml
#	docker_entrypoint.sh
#	spec/views/about/show.html.haml_spec.rb
This commit is contained in:
imncls
2018-02-23 23:28:31 +09:00
100 changed files with 1395 additions and 422 deletions

View File

@@ -34,7 +34,18 @@ class MediaAttachment < ApplicationRecord
VIDEO_MIME_TYPES = ['video/webm', 'video/mp4'].freeze
AUDIO_MIME_TYPES = ['audio/mpeg', 'audio/mp4', 'audio/vnd.wav', 'audio/wav', 'audio/x-wav', 'audio/x-wave', 'audio/ogg',].freeze
IMAGE_STYLES = { original: '1280x1280>', small: '400x400>' }.freeze
IMAGE_STYLES = {
original: {
geometry: '1280x1280>',
file_geometry_parser: FastGeometryParser,
},
small: {
geometry: '400x400>',
file_geometry_parser: FastGeometryParser,
},
}.freeze
AUDIO_STYLES = {
original: {
format: 'mp4',
@@ -50,6 +61,7 @@ class MediaAttachment < ApplicationRecord
},
},
}.freeze
VIDEO_STYLES = {
small: {
convert_options: {
@@ -97,6 +109,24 @@ class MediaAttachment < ApplicationRecord
shortcode
end
def focus=(point)
return if point.blank?
x, y = (point.is_a?(Enumerable) ? point : point.split(',')).map(&:to_f)
meta = file.instance_read(:meta) || {}
meta['focus'] = { 'x' => x, 'y' => y }
file.instance_write(:meta, meta)
end
def focus
x = file.meta['focus']['x']
y = file.meta['focus']['y']
"#{x},#{y}"
end
before_create :prepare_description, unless: :local?
before_create :set_shortcode
before_post_process :set_type_and_extension
@@ -178,7 +208,7 @@ class MediaAttachment < ApplicationRecord
end
def populate_meta
meta = {}
meta = file.instance_read(:meta) || {}
file.queued_for_write.each do |style, file|
meta[style] = style == :small || image? ? image_geometry(file) : video_metadata(file)
@@ -188,16 +218,16 @@ class MediaAttachment < ApplicationRecord
end
def image_geometry(file)
geo = Paperclip::Geometry.from_file file
width, height = FastImage.size(file.path)
return {} if width.nil?
{
width: geo.width.to_i,
height: geo.height.to_i,
size: "#{geo.width.to_i}x#{geo.height.to_i}",
aspect: geo.width.to_f / geo.height.to_f,
width: width,
height: height,
size: "#{width}x#{height}",
aspect: width.to_f / height.to_f,
}
rescue Paperclip::Errors::NotIdentifiedByImageMagickError
{}
end
def video_metadata(file)