55 lines
1.3 KiB
Ruby
55 lines
1.3 KiB
Ruby
# typed: true
|
|
module LogEntriesHelper
|
|
def is_send_data_content_type?(content_type)
|
|
is_renderable_image_type?(content_type) ||
|
|
is_renderable_video_type?(content_type) ||
|
|
is_flash_content_type?(content_type)
|
|
end
|
|
|
|
def path_iterative_parts(uri_path)
|
|
path_parts = uri_path.split("/")
|
|
(1...path_parts.length).map do |i|
|
|
[
|
|
path_parts[i],
|
|
path_parts[0..i].join("/") + (i == path_parts.length - 1 ? "" : "/"),
|
|
]
|
|
end
|
|
end
|
|
|
|
def ext_for_content_type(content_type)
|
|
case content_type
|
|
when "image/jpeg"
|
|
"jpeg"
|
|
when "image/jpg"
|
|
"jpg"
|
|
when "image/png"
|
|
"png"
|
|
when "image/gif"
|
|
"gif"
|
|
when "video/webm"
|
|
"webm"
|
|
else
|
|
nil
|
|
end
|
|
end
|
|
|
|
def is_renderable_image_type?(content_type)
|
|
%w[image/jpeg image/jpg image/png image/gif].any? do |ct|
|
|
content_type.starts_with?(ct)
|
|
end
|
|
end
|
|
|
|
def is_thumbable_content_type?(content_type)
|
|
%w[video/webm].any? { |ct| content_type.starts_with?(ct) } ||
|
|
is_renderable_image_type?(content_type)
|
|
end
|
|
|
|
def is_renderable_video_type?(content_type)
|
|
%w[video/mp4 video/webm].any? { |ct| content_type.starts_with?(ct) }
|
|
end
|
|
|
|
def is_flash_content_type?(content_type)
|
|
content_type =~ %r{application/x-shockwave-flash}
|
|
end
|
|
end
|