Class: Marty::JobController

Inherits:
ApplicationController show all
Defined in:
app/controllers/marty/job_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#failed_authentication, #find_current_user, #get_conf, #handle_unverified_request, #logout_user, #password_authentication, #reset_signed_cookies, #session_expiration, #session_expired?, #set_signed_cookies, #set_user, #start_user_session, #successful_authentication, #toggle_dark_mode, #try_to_autologin, #user_setup

Instance Method Details

#downloadObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/marty/job_controller.rb', line 2

def download
  job_id = params['job_id']

  promise = Marty::Promise.find_by(id: job_id)

  if promise
    format = promise.cformat

    # Force result so finalized object is built
    data = promise.result(true)

    # somewhat hacky: if result has "result" key, it's used as the
    # content.
    data = data['result'] || data
    title = promise.title
  else
    format = 'json'
    data = { error: "Job not found: #{job_id}" }
    title = 'error'
  end

  res, type, disposition, filename =
    Marty::ContentHandler.export(data, format, title)

  send_data(res,
            type:        type,
            filename:    filename,
            disposition: disposition,
           )
end