Sha256: d1c6d8bd68a4937e8d307d5bb96f2892ff5d0a4cd1c611caa3d7041cbe80e4c6

Contents?: true

Size: 994 Bytes

Versions: 14

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

module PagesCore
  class AttachmentsController < ::ApplicationController
    include PagesCore::RangedResponse

    before_action :verify_signed_params
    before_action :find_attachment, only: %i[show download]

    static_cache :show, permanent: true

    def show
      send_attachment
    end

    def download
      send_attachment disposition: "attachment"
    end

    private

    def find_attachment
      @attachment = Attachment.find(params[:id])
    end

    def send_attachment(disposition: "inline")
      unless stale?(etag: @attachment, last_modified: @attachment.updated_at)
        return
      end

      send_ranged_data(@attachment.data,
                       filename: @attachment.filename,
                       type: @attachment.content_type,
                       disposition: disposition)
    end

    def verify_signed_params
      key = params[:id].to_i.to_s
      Attachment.verifier.verify(key, params[:digest])
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
pages_core-3.12.7 app/controllers/pages_core/attachments_controller.rb
pages_core-3.12.6 app/controllers/pages_core/attachments_controller.rb
pages_core-3.12.5 app/controllers/pages_core/attachments_controller.rb
pages_core-3.12.4 app/controllers/pages_core/attachments_controller.rb
pages_core-3.12.3 app/controllers/pages_core/attachments_controller.rb
pages_core-3.12.2 app/controllers/pages_core/attachments_controller.rb
pages_core-3.12.1 app/controllers/pages_core/attachments_controller.rb
pages_core-3.12.0 app/controllers/pages_core/attachments_controller.rb
pages_core-3.11.3 app/controllers/pages_core/attachments_controller.rb
pages_core-3.11.2 app/controllers/pages_core/attachments_controller.rb
pages_core-3.11.1 app/controllers/pages_core/attachments_controller.rb
pages_core-3.11.0 app/controllers/pages_core/attachments_controller.rb
pages_core-3.10.2 app/controllers/pages_core/attachments_controller.rb
pages_core-3.10.1 app/controllers/pages_core/attachments_controller.rb