Sha256: fa2a8804a26528059cc2a151c3b92b665937d56481689cf0943f126fdacbcaa3

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

# encoding: utf-8

module PagesCore
  module Frontend
    class PageFilesController < ::FrontendController
      before_action :find_page_file, only: [:show, :edit, :update, :destroy]

      def show
        if !modified?(@page_file)
          render(text: "304 Not Modified", status: 304) && return
        end

        if @page_file.updated_at?
          response.headers["Last-Modified"] = @page_file.updated_at.httpdate
        end

        send_data(
          @page_file.data,
          filename:    @page_file.filename,
          type:        @page_file.content_type,
          disposition: "attachment"
        )
      end

      private

      def modified?(page_file)
        return true unless if_modified_since && page_file.updated_at?
        page_file.updated_at > if_modified_since
      end

      def if_modified_since
        return nil if request.env["HTTP_IF_MODIFIED_SINCE"].blank?
        Time.rfc2822(request.env["HTTP_IF_MODIFIED_SINCE"])
      end

      def find_page_file
        @page_file = PageFile.find(params[:id])
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pages_core-3.4.3 app/controllers/pages_core/frontend/page_files_controller.rb
pages_core-3.4.2 app/controllers/pages_core/frontend/page_files_controller.rb