/** * Unlocks the batch and stores the batch ID * in the current session to allow a user * access. * * @param BatchUnlockRequest $request * @param string $uuid * * @return \Illuminate\Http\RedirectResponse */ public function unlock(BatchUnlockRequest $request, $uuid) { $batch = $this->batch->locate($uuid); if ($batch->unlock($request)) { flash()->success('Success!', 'Successfully unlocked folder.'); return redirect()->route('batch.show', [$batch->uuid]); } else { return redirect()->back()->withErrors(['password' => 'Incorrect password. Try again!']); } }
/** * Locks a batch from modifications. * * @param BatchLockRequest $request * @param string $uuid * * @return \Illuminate\Http\RedirectResponse */ public function perform(BatchLockRequest $request, $uuid) { $batch = $this->batch->locate($uuid); if ($this->dispatch(new LockBatch($batch, $request))) { flash()->success('Success!', 'Your files have been locked.'); return redirect()->back(); } else { flash()->error('Error', 'This batch is already locked.'); return redirect()->back(); } }
/** * Handle an incoming request. * * @param Request $request * @param Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { $uuid = $request->route('batch_uuid'); if ($uuid) { $batch = $this->batch->locate($uuid); if ($batch->locked && !$request->session()->has($uuid)) { return redirect()->route('batch.gate', [$batch->uuid]); } } return $next($request); }
/** * Uploads files to the specified batch. * * @param UploadRequest $request * @param string $uuid */ public function perform(UploadRequest $request, $uuid) { // Locate the batch $batch = $this->batch->locate($uuid); // Retrieve the file from the request $file = $request->file('file'); // Double check the file instance if ($file instanceof UploadedFile) { // Validate file name length if (strlen($file->getClientOriginalName()) > 70) { abort(422, 'File name is too large'); } // Generate a file name with UUID and its extension $name = uuid() . "." . $file->getClientOriginalExtension(); // Get the storage path $path = $batch->uuid . DIRECTORY_SEPARATOR . $name; // Move the file into storage Storage::put($path, file_get_contents($file->getRealPath())); // Add the file to the batch $batch->addFile($file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $path); } else { abort(404); } }
/** * Zips all batch files and prompts the user to download it. * * @param string $uuid * * @return \Symfony\Component\HttpFoundation\BinaryFileResponse */ public function download($uuid) { $batch = $this->batch->locate($uuid); if ($batch->files->count() > 0) { $zip = $this->dispatch(new CreateZip($batch)); if ($zip && is_string($zip)) { return response()->download($zip); } else { flash()->error('Whoops!', 'Looks like we had an issue generating a ZIP.'); return redirect()->back(); } } else { flash()->error('Whoops!', 'There are no files to download.'); return redirect()->back(); } }
/** * Prompts the user to download the specified batch file. * * @param string $batchUuid * @param string $fileUuid * * @return \Symfony\Component\HttpFoundation\BinaryFileResponse */ public function download($batchUuid, $fileUuid) { $batch = $this->batch->locate($batchUuid); $file = $batch->findFile($fileUuid); return response()->download($file->getCompletePath(), $file->name); }