Sha256: 27483703c9a87a31ee1add409e889bf341f2c5b598671b2bb57b10ffd16a6c4e

Contents?: true

Size: 982 Bytes

Versions: 6

Compression:

Stored size: 982 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:)
    end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pages_core-3.15.4 app/controllers/pages_core/attachments_controller.rb
pages_core-3.15.3 app/controllers/pages_core/attachments_controller.rb
pages_core-3.15.2 app/controllers/pages_core/attachments_controller.rb
pages_core-3.15.1 app/controllers/pages_core/attachments_controller.rb
pages_core-3.14.0 app/controllers/pages_core/attachments_controller.rb
pages_core-3.13.0 app/controllers/pages_core/attachments_controller.rb