mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-06 02:33:48 +00:00
45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?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,
|
|
]);
|
|
}
|
|
}
|