/**
  * @param ExportJob $job
  *
  * @return mixed
  * @throws FireflyException
  */
 public function download(ExportJob $job)
 {
     $disk = Storage::disk('export');
     $file = $job->key . '.zip';
     $date = date('Y-m-d \\a\\t H-i-s');
     $name = 'Export job on ' . $date . '.zip';
     $quoted = sprintf('"%s"', addcslashes($name, '"\\'));
     if (!$disk->exists($file)) {
         throw new FireflyException('Against all expectations, zip file "' . $file . '" does not exist.');
     }
     $job->change('export_downloaded');
     return response($disk->get($file), 200)->header('Content-Description', 'File Transfer')->header('Content-Type', 'application/octet-stream')->header('Content-Disposition', 'attachment; filename=' . $quoted)->header('Content-Transfer-Encoding', 'binary')->header('Connection', 'Keep-Alive')->header('Expires', '0')->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')->header('Pragma', 'public')->header('Content-Length', $disk->size($file));
 }
 /**
  * @return ExportJob
  */
 public function create() : ExportJob
 {
     $count = 0;
     while ($count < 30) {
         $key = Str::random(12);
         $existing = $this->findByKey($key);
         if (is_null($existing->id)) {
             $exportJob = new ExportJob();
             $exportJob->user()->associate($this->user);
             $exportJob->key = Str::random(12);
             $exportJob->status = 'export_status_never_started';
             $exportJob->save();
             // breaks the loop:
             return $exportJob;
         }
         $count++;
     }
     return new ExportJob();
 }