Sha256: 735c1247ed1f827d9745c5cd5d135f3c0be7126bc8b598d9b1d5be7d975f92ba

Contents?: true

Size: 927 Bytes

Versions: 8

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

module PagesCore
  class AttachmentsController < ::ApplicationController
    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_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

8 entries across 8 versions & 1 rubygems

Version Path
pages_core-3.9.2 app/controllers/pages_core/attachments_controller.rb
pages_core-3.9.1 app/controllers/pages_core/attachments_controller.rb
pages_core-3.9.0 app/controllers/pages_core/attachments_controller.rb
pages_core-3.8.3 app/controllers/pages_core/attachments_controller.rb
pages_core-3.8.2 app/controllers/pages_core/attachments_controller.rb
pages_core-3.8.1 app/controllers/pages_core/attachments_controller.rb
pages_core-3.8.0 app/controllers/pages_core/attachments_controller.rb
pages_core-3.7.0 app/controllers/pages_core/attachments_controller.rb