Implement creator studio and upload updates
This commit is contained in:
@@ -22,7 +22,7 @@ final class ArtworkVectorIndexService
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{url: string, metadata: array{content_type: string, category: string, user_id: string}}
|
||||
* @return array{url: string, metadata: array<string, mixed>}
|
||||
*/
|
||||
public function payloadForArtwork(Artwork $artwork): array
|
||||
{
|
||||
@@ -38,7 +38,7 @@ final class ArtworkVectorIndexService
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{url: string, metadata: array{content_type: string, category: string, user_id: string}}
|
||||
* @return array{url: string, metadata: array<string, mixed>}
|
||||
*/
|
||||
public function upsertArtwork(Artwork $artwork): array
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ use App\Models\Category;
|
||||
final class ArtworkVectorMetadataService
|
||||
{
|
||||
/**
|
||||
* @return array{content_type: string, category: string, user_id: string, tags: list<string>}
|
||||
* @return array{content_type: string, category: string, user_id: string, tags: list<string>, is_public: bool, is_deleted: bool, is_nsfw: bool, category_id: int, content_type_id: int, status: mixed}
|
||||
*/
|
||||
public function forArtwork(Artwork $artwork): array
|
||||
{
|
||||
@@ -22,9 +22,15 @@ final class ArtworkVectorMetadataService
|
||||
$category = $this->primaryCategory($artwork);
|
||||
|
||||
return [
|
||||
'content_type' => (string) ($category?->contentType?->name ?? ''),
|
||||
'category' => (string) ($category?->name ?? ''),
|
||||
'user_id' => (string) ($artwork->user_id ?? ''),
|
||||
'content_type' => (string) ($category?->contentType?->name ?? ''),
|
||||
'category' => (string) ($category?->name ?? ''),
|
||||
'user_id' => (string) ($artwork->user_id ?? ''),
|
||||
'is_public' => (bool) $artwork->is_public,
|
||||
'is_deleted' => $artwork->trashed(),
|
||||
'is_nsfw' => (bool) $artwork->is_mature,
|
||||
'category_id' => (int) ($category?->id ?? 0),
|
||||
'content_type_id' => (int) ($category?->contentType?->id ?? 0),
|
||||
'status' => $artwork->artwork_status,
|
||||
'tags' => $artwork->tags
|
||||
->pluck('slug')
|
||||
->map(static fn (mixed $slug): string => trim((string) $slug))
|
||||
|
||||
@@ -37,7 +37,7 @@ final class VectorService
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{url: string, metadata: array{content_type: string, category: string, user_id: string}}
|
||||
* @return array{url: string, metadata: array<string, mixed>}
|
||||
*/
|
||||
public function payloadForArtwork(Artwork $artwork): array
|
||||
{
|
||||
@@ -45,7 +45,7 @@ final class VectorService
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{url: string, metadata: array{content_type: string, category: string, user_id: string}}
|
||||
* @return array{url: string, metadata: array<string, mixed>}
|
||||
*/
|
||||
public function upsertArtwork(Artwork $artwork): array
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
final class VisionService
|
||||
@@ -522,33 +523,29 @@ final class VisionService
|
||||
->first();
|
||||
|
||||
if ($row && ! empty($row->path)) {
|
||||
$storageRoot = rtrim((string) config('uploads.storage_root', ''), DIRECTORY_SEPARATOR);
|
||||
$absolute = $storageRoot . DIRECTORY_SEPARATOR . str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $row->path);
|
||||
if (is_file($absolute) && is_readable($absolute)) {
|
||||
$attach = Storage::disk((string) config('uploads.object_storage.disk', 's3'))->get((string) $row->path);
|
||||
if (is_string($attach) && $attach !== '') {
|
||||
$uploadUrl = rtrim($base, '/') . '/analyze/all/file';
|
||||
try {
|
||||
$attach = file_get_contents($absolute);
|
||||
if ($attach !== false) {
|
||||
/** @var \Illuminate\Http\Client\Response $uploadResp */
|
||||
$uploadResp = $this->requestWithVisionAuth('clip', $ref)
|
||||
->attach('file', $attach, basename($absolute))
|
||||
->post($uploadUrl, ['limit' => 5]);
|
||||
/** @var \Illuminate\Http\Client\Response $uploadResp */
|
||||
$uploadResp = $this->requestWithVisionAuth('clip', $ref)
|
||||
->attach('file', $attach, basename((string) $row->path))
|
||||
->post($uploadUrl, ['limit' => 5]);
|
||||
|
||||
if ($uploadResp->ok()) {
|
||||
$debug['fallback_upload'] = [
|
||||
'endpoint' => $uploadUrl,
|
||||
'status' => $uploadResp->status(),
|
||||
'response' => $uploadResp->json() ?? $this->safeBody($uploadResp->body()),
|
||||
];
|
||||
return ['tags' => $this->extractTagList($uploadResp->json()), 'debug' => $debug];
|
||||
}
|
||||
|
||||
Log::warning('CLIP upload fallback non-ok', [
|
||||
'ref' => $ref,
|
||||
if ($uploadResp->ok()) {
|
||||
$debug['fallback_upload'] = [
|
||||
'endpoint' => $uploadUrl,
|
||||
'status' => $uploadResp->status(),
|
||||
'body' => $this->safeBody($uploadResp->body()),
|
||||
]);
|
||||
'response' => $uploadResp->json() ?? $this->safeBody($uploadResp->body()),
|
||||
];
|
||||
return ['tags' => $this->extractTagList($uploadResp->json()), 'debug' => $debug];
|
||||
}
|
||||
|
||||
Log::warning('CLIP upload fallback non-ok', [
|
||||
'ref' => $ref,
|
||||
'status' => $uploadResp->status(),
|
||||
'body' => $this->safeBody($uploadResp->body()),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('CLIP upload fallback failed', ['ref' => $ref, 'error' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user