- Added support for uploading and compressing GLB models using Draco in the backoffice. - Implemented commands for importing and re-compressing 3D models. - Updated model resource to handle 3D model uploads and validations. - Introduced a new script for compressing GLB files with Draco. - Modified Vite configuration to remove GLB files from the build output. - Updated package dependencies to include GLTF-transform libraries for handling 3D models. - Added tests to ensure proper functionality of 3D model handling and compression.
38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Support\Configuratore\Media;
|
|
use App\Support\Configuratore\Modelli3d;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
class MediaController extends Controller
|
|
{
|
|
/**
|
|
* GET /api/media/{percorso}
|
|
* Immagini e modelli 3D (compressi) del configuratore dal disco public, con gli header CORS dell'API (necessari
|
|
* alle texture WebGL caricate da un'altra origine).
|
|
*/
|
|
public function __invoke(string $percorso): BinaryFileResponse
|
|
{
|
|
$disco = Storage::disk('public');
|
|
|
|
abort_if(
|
|
str_contains($percorso, '..')
|
|
|| ! Str::startsWith($percorso, Media::CARTELLE)
|
|
|| ! $disco->exists($percorso),
|
|
404
|
|
);
|
|
|
|
// I modelli 3D hanno l'hash del contenuto nel nome: un nuovo caricamento cambia URL.
|
|
$modello3d = Str::startsWith($percorso, Modelli3d::CARTELLA_DRACO.'/');
|
|
|
|
return response()->file($disco->path($percorso), [
|
|
'Cache-Control' => $modello3d ? 'public, max-age=31536000, immutable' : 'public, max-age=86400',
|
|
] + ($modello3d ? ['Content-Type' => 'model/gltf-binary'] : []));
|
|
}
|
|
}
|