Route downloads through controller; file IDs as hash to prevent guessing; download count; download list on airport page

This commit is contained in:
Nabeel Shahzad
2018-04-02 12:55:37 -05:00
parent 3ddee56359
commit 9e1e0142e9
8 changed files with 131 additions and 11 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Http\Controllers\Frontend;
use App\Interfaces\Controller;
use App\Models\File;
use Auth;
use Flash;
use Illuminate\Support\Facades\Storage;
/**
* Class FileController
* @package App\Http\Controllers\Frontend
*/
class FileController extends Controller
{
/**
* Show the application dashboard.
*/
public function show($id)
{
/**
* @var File $file
*/
$file = File::find($id);
if (!$file) {
Flash::error('File doesn\'t exist');
return redirect()->back();
}
// Allowed to download? If not, direct to login
if (!$file->public && !Auth::check()) {
return redirect(config('app.login_redirect'));
}
++$file->download_count;
$file->save();
if($file->disk === 'public') {
$storage = Storage::disk('public');
return $storage->download($file->path, $file->filename);
}
// TODO: Config for streamed response?
return redirect()->to($file->url);
}
}