file routes refactoring

This commit is contained in:
Peter Papp
2021-03-07 11:18:44 +01:00
parent 1f615c54af
commit 9f1174b547
5 changed files with 106 additions and 47 deletions
+8 -10
View File
@@ -102,21 +102,19 @@ class FileAccessController extends Controller
*/
public function get_zip($id)
{
$zip = Zip::where('id', $id)
$zip = Zip::whereId($id)
->where('user_id', Auth::id())
->first();
->firstOrFail();
$zip_path = 'zip/' . $zip->basename;
$disk = Storage::disk('local');
$header = [
return $disk->download("zip/$zip->basename", $zip->basename, [
"Content-Type" => 'application/zip',
"Content-Length" => Storage::disk('local')->size($zip_path),
"Content-Length" => $disk->size("zip/$zip->basename"),
"Accept-Ranges" => "bytes",
"Content-Range" => "bytes 0-600/" . Storage::disk('local')->size($zip_path),
"Content-Disposition" => "attachment; filename=" . $zip->basename,
];
return Storage::disk('local')->download($zip_path, $zip->basename, $header);
"Content-Range" => "bytes 0-600/" . $disk->size("zip/$zip->basename"),
"Content-Disposition" => "attachment; filename=$zip->basename",
]);
}
/**
+9
View File
@@ -50,6 +50,8 @@ class RouteServiceProvider extends ServiceProvider
$this->mapMaintenanceRoutes();
$this->mapFileRoutes();
$this->mapWebRoutes();
}
@@ -74,6 +76,13 @@ class RouteServiceProvider extends ServiceProvider
->group(base_path('routes/maintenance.php'));
}
protected function mapFileRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/file.php'));
}
/**
* Define the "api" routes for the application.
*