Wire admin studio SSR and search infrastructure

This commit is contained in:
2026-05-01 11:46:06 +02:00
parent 257b0dbef6
commit 18cea8b0f0
329 changed files with 197465 additions and 2741 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Services\Vision;
use App\Models\Artwork;
use Illuminate\Support\Facades\Http;
use RuntimeException;
final class ArtworkVectorIndexService
@@ -44,7 +45,12 @@ final class ArtworkVectorIndexService
{
$payload = $this->payloadForArtwork($artwork);
$this->client->upsertByUrl($payload['url'], (int) $artwork->id, $payload['metadata']);
$filePayload = $this->downloadArtworkImage($artwork, $payload['url']);
if ($filePayload === null) {
throw new RuntimeException('Unable to download artwork image bytes for vector upsert for artwork ' . (int) $artwork->id . '.');
}
$this->client->upsertByFileContents($filePayload['contents'], $filePayload['filename'], (int) $artwork->id, $payload['metadata']);
$artwork->forceFill([
'last_vector_indexed_at' => now(),
@@ -52,4 +58,32 @@ final class ArtworkVectorIndexService
return $payload;
}
/**
* @return array{contents: string, filename: string}|null
*/
private function downloadArtworkImage(Artwork $artwork, string $url): ?array
{
$response = Http::accept('*/*')
->connectTimeout(5)
->timeout(20)
->retry(1, 200, throw: false)
->get($url);
if (! $response->ok()) {
return null;
}
$contents = $response->body();
if ($contents === '') {
return null;
}
$ext = strtolower(ltrim((string) ($artwork->thumb_ext ?: 'webp'), '.'));
return [
'contents' => $contents,
'filename' => sprintf('artwork-%d.%s', (int) $artwork->id, $ext !== '' ? $ext : 'webp'),
];
}
}