feat: FileController para servir archivos privados con autenticación
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -55,7 +55,7 @@ class ChatController extends Controller
|
||||
|
||||
if ($request->hasFile('attachment')) {
|
||||
$file = $request->file('attachment');
|
||||
$attachment = $file->store('chat', 'uploads');
|
||||
$attachment = $file->store('chat', 'local');
|
||||
$mime = $file->getMimeType();
|
||||
|
||||
if (str_starts_with($mime, 'image')) $attachmentType = 'image';
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class FileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Sirve archivos privados con autenticación.
|
||||
* El parámetro $path incluye el módulo como primer segmento:
|
||||
* chat/filename.jpg
|
||||
* profiles/avatar.jpg
|
||||
* tasks/homework.pdf
|
||||
*/
|
||||
public function serve(string $path)
|
||||
{
|
||||
if (!Storage::disk('local')->exists($path)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return Storage::disk('local')->response($path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user