Class: AnimateIt::RendersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/animate_it/renders_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::NullPolicy

Instance Method Summary collapse

Instance Method Details

#cancelObject



40
41
42
43
# File 'app/controllers/animate_it/renders_controller.rb', line 40

def cancel
  RenderStore.cancel!(params[:id])
  head :accepted
end

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/animate_it/renders_controller.rb', line 21

def create
  @composition = composition
  @render_id = SecureRandom.hex(8)
  @output_path = output_path(@render_id)
  @output_path.dirname.mkpath
  @output_relative_path = relative_output_path(@output_path)

  RenderStore.create!(
    id: @render_id,
    composition_id: @composition.id,
    total_frames: @composition.duration_in_frames,
    output_path: @output_path
  )
  start_render(@render_id, @composition.id, request.base_url, @output_path.to_s, frames_dir(@render_id).to_s,
               preview_props, render_options)

  render status: :accepted
end

#showObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/animate_it/renders_controller.rb', line 3

def show
  @render_id = params[:id]
  # `params[:id]` here is a render UUID, not a composition id — look up
  # the render record first to learn which composition produced it.
  render_record = RenderStore.find(@render_id)
  return head(:not_found) unless render_record

  AnimateIt.load_compositions!
  @composition = AnimateIt.registry.fetch(render_record.composition_id)
  @output_path = Pathname(render_record.output_path)
  if params[:download].present? && @output_path.exist?
    send_file @output_path, type: Mime::Type.lookup_by_extension(@output_path.extname.delete(".")),
                            disposition: "inline"
  end

  @output_relative_path = relative_output_path(@output_path)
end