first
This commit is contained in:
40
app/Http/Controllers/User/AudioController.php
Normal file
40
app/Http/Controllers/User/AudioController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\TranscriptionProject;
|
||||
use App\Services\StorageService;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class AudioController extends Controller
|
||||
{
|
||||
public function __construct(private readonly StorageService $storage) {}
|
||||
|
||||
public function stream(TranscriptionProject $project): StreamedResponse
|
||||
{
|
||||
$this->authorize('viewAudio', $project);
|
||||
|
||||
$path = $project->stored_audio_path;
|
||||
|
||||
abort_unless($this->storage->exists($path), 404);
|
||||
|
||||
$size = $this->storage->size($path);
|
||||
$mimeType = $project->mime_type;
|
||||
|
||||
return response()->stream(function () use ($path) {
|
||||
$stream = $this->storage->readStream($path);
|
||||
if ($stream) {
|
||||
fpassthru($stream);
|
||||
fclose($stream);
|
||||
}
|
||||
}, 200, [
|
||||
'Content-Type' => $mimeType,
|
||||
'Content-Length' => $size,
|
||||
'Content-Disposition' => 'inline',
|
||||
'Cache-Control' => 'no-store, no-cache, private, must-revalidate',
|
||||
'X-Content-Type-Options' => 'nosniff',
|
||||
'Accept-Ranges' => 'bytes',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user