app/controllers/jobs_controller.rb
# unzip a job to /storage/left if not already there, and stream it to the
# user if it does already exist...
unzip a job to /storage/left if not already there, and stream it to the
user if it does already exist
unzip a job to / storage / left if not already there and stream it to the user if it does already exist
def leftstream
    jobid = params[:id]
    @job = Job.find(jobid)
    if !check_user(@job) or @job.status != 'finished' 
      render :status=>401, :json=>{:message=>"Forbidden"}
      return
    end
    leftdir = "/storage/left"
    if !File.exists?("#{leftdir}/#{jobid}.pdf")
      Rails.logger.info("Creating directory for #{jobid}")
      begin
        File.open("#{leftdir}/#{jobid}.zip","w") {|f| f.write(@job.outfile.read.force_encoding('UTF-8')) }
        system("cd #{leftdir} && unzip #{jobid}.zip && rm #{jobid}.zip")
        if File.exists?("#{leftdir}/#{jobid}/output/output_mobile.pdf")
          system("mv #{leftdir}/#{jobid}/output/output_mobile.pdf #{leftdir}/#{jobid}.pdf")
        else
          system("mv #{leftdir}/#{jobid}/output/output.pdf #{leftdir}/#{jobid}.pdf")
        end
        system("rm -rf #{leftdir}/#{jobid}")
      rescue
        render :status=>500, :json=>{:message=>"File retrieval failed"}
        return
      end
    else
      Rails.logger.info("Output for #{jobid} already exists")
    end
    send_file "#{leftdir}/#{jobid}.pdf", :content_type => "application/pdf", :filename => "#{jobid}.pdf"
  end
def leftstream jobid = params [ :id ] @job = Job . find ( jobid ) if ! check_user ( @job ) or @job . status != 'finished' render :status => 401 , :json => { :message => "Forbidden" } return end leftdir = "/storage/left" if ! File . exists? ( "#{leftdir}/#{jobid}.pdf" ) Rails . logger . info ( "Creating directory for #{jobid}" ) begin File . open ( "#{leftdir}/#{jobid}.zip" , "w" ) { | f | f . write ( @job . outfile . read . force_encoding ( 'UTF-8' ) ) } system ( "cd #{leftdir} && unzip #{jobid}.zip && rm #{jobid}.zip" ) if File . exists? ( "#{leftdir}/#{jobid}/output/output_mobile.pdf" ) system ( "mv #{leftdir}/#{jobid}/output/output_mobile.pdf #{leftdir}/#{jobid}.pdf" ) else system ( "mv #{leftdir}/#{jobid}/output/output.pdf #{leftdir}/#{jobid}.pdf" ) end system ( "rm -rf #{leftdir}/#{jobid}" ) rescue render :status => 500 , :json => { :message => "File retrieval failed" } return end else Rails . logger . info ( "Output for #{jobid} already exists" ) end send_file "#{leftdir}/#{jobid}.pdf" , :content_type => "application/pdf" , :filename => "#{jobid}.pdf" end
unzip a job to /storage/left if not already there, and stream it to the
user if it does already exist...
unzip a job to / storage / left if not already there and stream it to the user if it does already exist ...
# stream the pdf