Class: DraftForge::ExportsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/draft_forge/exports_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/draft_forge/exports_controller.rb', line 7

def create
  html = if params[:content_json].present?
           EditorJsRenderer.call(params[:content_json])
         else
           params[:content_html].to_s
         end
  filename = params[:filename].presence || "document.pdf"

  export = Export.create!(status: :queued, requested_filename: filename)
  ExportPdfJob.perform_later(export.id, html)

  render json: { id: export.id, status: export.status }
rescue => e
  render json: { error: e.message }, status: 422
end

#showObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/draft_forge/exports_controller.rb', line 23

def show
  export = Export.find(params[:id])
  if export.complete? && export.pdf.attached?
    url = Rails.application.routes.url_helpers.rails_blob_url(export.pdf, only_path: false)
    render json: { id: export.id, status: export.status, download_url: url }
  else
    render json: { id: export.id, status: export.status }
  end
rescue ActiveRecord::RecordNotFound
  render json: { error: "Not found" }, status: 404
end