optimizations

This commit is contained in:
2026-03-28 19:15:39 +01:00
parent 0b25d9570a
commit cab4fbd83e
509 changed files with 1016804 additions and 1605 deletions

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Artwork;
use App\Services\Vision\VectorService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use RuntimeException;
final class SimilarAiArtworksController extends Controller
{
public function __construct(private readonly VectorService $vectors)
{
}
public function __invoke(Request $request, int $id): JsonResponse
{
$artwork = Artwork::query()->public()->published()->find($id);
if ($artwork === null) {
return response()->json(['error' => 'Artwork not found'], 404);
}
if (! $this->vectors->isConfigured()) {
return response()->json([
'data' => [],
'reason' => 'vector_gateway_not_configured',
], 503);
}
$limit = max(1, min(24, (int) $request->query('limit', 12)));
try {
$items = $this->vectors->similarToArtwork($artwork, $limit);
} catch (RuntimeException $e) {
return response()->json([
'data' => [],
'reason' => 'vector_gateway_error',
'message' => $e->getMessage(),
], 502);
}
return response()->json([
'data' => $items,
'meta' => [
'source' => 'vector_gateway',
'artwork_id' => $artwork->id,
'limit' => $limit,
],
]);
}
}