This commit is contained in:
25
app/controllers/action_text/markdown/uploads_controller.rb
Normal file
25
app/controllers/action_text/markdown/uploads_controller.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class ActionText::Markdown::UploadsController < ApplicationController
|
||||
allow_unauthenticated_access only: :show
|
||||
|
||||
before_action do
|
||||
ActiveStorage::Current.url_options = { protocol: request.protocol, host: request.host, port: request.port }
|
||||
end
|
||||
|
||||
def create
|
||||
@record = GlobalID::Locator.locate_signed params[:record_gid]
|
||||
|
||||
@markdown = @record.safe_markdown_attribute params[:attribute_name]
|
||||
@markdown.uploads.attach [ params[:file] ]
|
||||
@markdown.save!
|
||||
|
||||
@upload = @markdown.uploads.attachments.last
|
||||
|
||||
render :create, status: :created, formats: :json
|
||||
end
|
||||
|
||||
def show
|
||||
@attachment = ActiveStorage::Attachment.find_by! slug: "#{params[:slug]}.#{params[:format]}"
|
||||
expires_in 1.year, public: true
|
||||
redirect_to @attachment.url
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user