mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-19 00:22:15 +00:00
controller refactoring part 25
This commit is contained in:
44
src/Domain/Zip/Controllers/VisitorGetZipController.php
Normal file
44
src/Domain/Zip/Controllers/VisitorGetZipController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Domain\Zip\Controllers;
|
||||
|
||||
use Domain\Zip\Models\Zip;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Domain\Traffic\Actions\RecordDownloadAction;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class VisitorGetZipController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private RecordDownloadAction $recordDownload,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get generated zip for visitor
|
||||
*/
|
||||
public function __invoke(
|
||||
$id,
|
||||
$token,
|
||||
): StreamedResponse {
|
||||
$disk = Storage::disk('local');
|
||||
|
||||
$zip = Zip::where('id', $id)
|
||||
->where('shared_token', $token)
|
||||
->first();
|
||||
|
||||
// Store user download size
|
||||
($this->recordDownload)(
|
||||
file_size: $disk->size("zip/$zip->basename"),
|
||||
user_id: $zip->user_id,
|
||||
);
|
||||
|
||||
return $disk->download("zip/$zip->basename", $zip->basename, [
|
||||
'Content-Type' => 'application/zip',
|
||||
'Content-Length' => $disk->size("zip/$zip->basename"),
|
||||
'Accept-Ranges' => 'bytes',
|
||||
'Content-Range' => 'bytes 0-600/' . $disk->size("zip/$zip->basename"),
|
||||
'Content-Disposition' => 'attachment; filename=' . $zip->basename,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user