- Added PublicS3Disk and PrivateS3Disk classes for S3 disk management. - Updated ProductController and RecipeController to utilize PublicS3Disk for file uploads. - Modified MediaController to redirect to S3 URLs. - Enhanced migration script to support file migration to new S3 structure. - Updated filesystem and storage service configurations for public/private S3 disks.
26 lines
740 B
PHP
26 lines
740 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Lib\PublicS3Disk;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class MediaController extends Controller
|
|
{
|
|
public function __invoke(string $path, PublicS3Disk $s3): RedirectResponse
|
|
{
|
|
$prefix = Config::string('storage-service.prefix', 'media');
|
|
$fullPath = $prefix !== ''
|
|
? trim($prefix, '/') . '/' . ltrim($path, '/')
|
|
: ltrim($path, '/');
|
|
$s3Url = Storage::disk($s3->disk->value)->url($fullPath);
|
|
|
|
return redirect()->away($s3Url, 301, [
|
|
'Cache-Control' => 'public, max-age=31536000, immutable',
|
|
]);
|
|
}
|
|
}
|