X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fimage_resource_controller.rb;h=b143753c5aff31ec2c73458d652d58f09c4f7ead;hb=b3b1e49e70868759807216c9df7233b0bd8f769b;hp=b8f80680216481a55fa922f8e0bf1eaadabafaec;hpb=48cd27bb8717d99bf4d356329c7fd9bdb228ceb8;p=elecoma%2Felecoma.git diff --git a/app/controllers/image_resource_controller.rb b/app/controllers/image_resource_controller.rb index b8f8068..b143753 100644 --- a/app/controllers/image_resource_controller.rb +++ b/app/controllers/image_resource_controller.rb @@ -1,21 +1,34 @@ class ImageResourceController < BaseController + ssl_allowed :show, :thumbnail #caches_page :show def show if params[:filename] @res = ImageResource.find_by_name(params[:filename]) end if params[:id] - @res ||= ImageResource.find_by_id(params[:id]) + @res ||= ImageResource.find_by_id(params[:id].to_i) end raise ActiveRecord::RecordNotFound unless @res - if request.mobile? + if request.mobile? && !request.mobile.respond_to?('smartphone?') + format = nil + if request.mobile.instance_of?(Jpmobile::Mobile::Docomo) + format = :gif + elsif request.mobile.instance_of?(Jpmobile::Mobile::Au) + format = :gif + elsif request.mobile.instance_of?(Jpmobile::Mobile::Softbank) + format = :png + else + format = :jpeg + end if params[:width].present? || params[:height].present? width, height = [params[:width].to_i, params[:height].to_i] else width, height = request.mobile.display.width, request.mobile.display.height end - send_file @res, @res.scaled_image(width, height) + send_file @res, @res.scaled_image(width, height, format), format + elsif params[:format] + send_file @res, @res.view_with_format(params[:format]) else send_file @res, @res.view end @@ -26,13 +39,23 @@ class ImageResourceController < BaseController private - def send_file(res, data) + def send_file(res, data, format = nil) raise ActiveRecord::RecordNotFound unless res raise ActiveRecord::RecordNotFound unless data content_type = res.content_type if request.mobile? content_type.gsub!(/pjpeg/, "jpeg") end + if format + case format + when :gif + content_type = "image/gif" + when :png + content_type = "image/png" + when :jpeg + content_type = "image/jpeg" + end + end send_data(data, :type => content_type, :disposition => 'inline') end end