mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-25 08:14:29 +02:00
36 lines
993 B
PHP
36 lines
993 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Http;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
abstract class ResponseStreamAction extends StreamAction
|
|
{
|
|
public function stream(string $disposition = 'inline'): StreamedResponse
|
|
{
|
|
$response = new StreamedResponse();
|
|
|
|
$disposition = $response->headers->makeDisposition($disposition, $this->streamable->basename());
|
|
|
|
$response->headers->replace([
|
|
'Accept-Ranges' => 'bytes',
|
|
'Content-Type' => $this->streamable->mimetype(),
|
|
'Content-Length' => $this->streamable->size(),
|
|
'Content-Disposition' => $disposition,
|
|
]);
|
|
|
|
$fs = Storage::disk($this->disk());
|
|
|
|
$response->setCallback(function () use ($fs): void {
|
|
$stream = $fs->readStream($this->streamable->path());
|
|
fpassthru($stream);
|
|
fclose($stream);
|
|
});
|
|
|
|
return $response;
|
|
}
|
|
}
|