Optimize academy
This commit is contained in:
@@ -15,6 +15,7 @@ use App\Models\User;
|
||||
use App\Services\Artworks\ArtworkDraftService;
|
||||
use App\Services\Artworks\ArtworkPublicationService;
|
||||
use App\Services\Maturity\ArtworkMaturityService;
|
||||
use App\Services\Studio\StudioAiAssistService;
|
||||
use App\Services\TagService;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
@@ -189,7 +190,9 @@ final class UploadQueueService
|
||||
$item = $this->itemQuery()->findOrFail($itemId);
|
||||
|
||||
$item->forceFill([
|
||||
'processing_stage' => UploadBatchItem::STAGE_MATURITY_CHECK,
|
||||
'processing_stage' => $this->uploadMaturityEnabled()
|
||||
? UploadBatchItem::STAGE_MATURITY_CHECK
|
||||
: UploadBatchItem::STAGE_FINALIZED,
|
||||
'error_code' => null,
|
||||
'error_message' => null,
|
||||
'processed_at' => now(),
|
||||
@@ -290,7 +293,7 @@ final class UploadQueueService
|
||||
'apply_category' => $this->applyCategory($item, (int) ($params['category_id'] ?? 0)),
|
||||
'apply_tags' => $this->applyTags($item, (array) ($params['tags'] ?? [])),
|
||||
'set_visibility' => $this->setVisibility($item, (string) ($params['visibility'] ?? '')),
|
||||
'generate_ai' => $this->retryProcessing($item),
|
||||
'generate_ai' => $this->requestAiGeneration($item),
|
||||
default => throw ValidationException::withMessages([
|
||||
'action' => ['Unsupported upload queue action.'],
|
||||
]),
|
||||
@@ -341,16 +344,40 @@ final class UploadQueueService
|
||||
|
||||
$item->forceFill([
|
||||
'status' => UploadBatchItem::STATUS_PROCESSING,
|
||||
'processing_stage' => UploadBatchItem::STAGE_MATURITY_CHECK,
|
||||
'processing_stage' => $this->uploadMaturityEnabled()
|
||||
? UploadBatchItem::STAGE_MATURITY_CHECK
|
||||
: UploadBatchItem::STAGE_FINALIZED,
|
||||
'error_code' => null,
|
||||
'error_message' => null,
|
||||
'is_ready_to_publish' => false,
|
||||
])->save();
|
||||
|
||||
AutoTagArtworkJob::dispatch((int) $artwork->id, (string) $artwork->hash)->afterCommit();
|
||||
DetectArtworkMaturityJob::dispatch((int) $artwork->id, (string) $artwork->hash)->afterCommit();
|
||||
GenerateArtworkEmbeddingJob::dispatch((int) $artwork->id, (string) $artwork->hash)->afterCommit();
|
||||
AnalyzeArtworkAiAssistJob::dispatch((int) $artwork->id, true)->afterCommit();
|
||||
if ((bool) config('vision.auto_tagging.enabled', false)) {
|
||||
AutoTagArtworkJob::dispatch((int) $artwork->id, (string) $artwork->hash)->afterCommit();
|
||||
}
|
||||
if ($this->uploadMaturityEnabled()) {
|
||||
DetectArtworkMaturityJob::dispatch((int) $artwork->id, (string) $artwork->hash)->afterCommit();
|
||||
}
|
||||
if ((bool) config('vision.upload.embeddings.enabled', true)) {
|
||||
GenerateArtworkEmbeddingJob::dispatch((int) $artwork->id, (string) $artwork->hash)->afterCommit();
|
||||
}
|
||||
if ((bool) config('vision.upload.ai_assist.enabled', false)) {
|
||||
AnalyzeArtworkAiAssistJob::dispatch((int) $artwork->id, true)->afterCommit();
|
||||
}
|
||||
|
||||
return $this->refreshItem((int) $item->id);
|
||||
}
|
||||
|
||||
private function requestAiGeneration(UploadBatchItem $item): UploadBatchItem
|
||||
{
|
||||
$artwork = $item->artwork;
|
||||
if (! $artwork || trim((string) ($artwork->hash ?? '')) === '' || trim((string) ($artwork->file_path ?? '')) === '') {
|
||||
throw ValidationException::withMessages([
|
||||
'item' => ['This item cannot generate AI suggestions safely. Re-upload the original file instead.'],
|
||||
]);
|
||||
}
|
||||
|
||||
app(StudioAiAssistService::class)->queueAnalysis($artwork, true);
|
||||
|
||||
return $this->refreshItem((int) $item->id);
|
||||
}
|
||||
@@ -543,13 +570,13 @@ final class UploadQueueService
|
||||
$maturityStatus = Str::lower((string) ($artwork?->maturity_status ?? ArtworkMaturityService::STATUS_CLEAR));
|
||||
$maturityAiStatus = Str::lower((string) ($artwork?->maturity_ai_status ?? ArtworkMaturityService::AI_STATUS_NOT_REQUESTED));
|
||||
$aiStatus = Str::lower((string) ($artwork?->ai_status ?? ''));
|
||||
$visionEnabled = (bool) config('vision.enabled', true);
|
||||
$uploadMaturityEnabled = $this->uploadMaturityEnabled();
|
||||
|
||||
$maturityPending = $visionEnabled && in_array($maturityAiStatus, [
|
||||
$maturityPending = $uploadMaturityEnabled && in_array($maturityAiStatus, [
|
||||
ArtworkMaturityService::AI_STATUS_PENDING,
|
||||
ArtworkMaturityService::AI_STATUS_NOT_REQUESTED,
|
||||
], true);
|
||||
$maturityFailed = $visionEnabled && $maturityAiStatus === ArtworkMaturityService::AI_STATUS_FAILED;
|
||||
$maturityFailed = $uploadMaturityEnabled && $maturityAiStatus === ArtworkMaturityService::AI_STATUS_FAILED;
|
||||
$needsReview = $maturityStatus === ArtworkMaturityService::STATUS_SUSPECTED || $maturityFailed;
|
||||
$needsMetadata = ! $hasTitle || ! $hasCategory;
|
||||
$blockingUploadFailure = ! $hasProcessedMedia && ($this->nullableString($item->error_code) !== null || $this->nullableText($item->error_message) !== null);
|
||||
@@ -634,9 +661,9 @@ final class UploadQueueService
|
||||
}
|
||||
if ($maturityStatus === ArtworkMaturityService::STATUS_SUSPECTED) {
|
||||
$missing[] = 'Needs maturity review';
|
||||
} elseif ((bool) config('vision.enabled', true) && in_array($maturityAiStatus, [ArtworkMaturityService::AI_STATUS_PENDING, ArtworkMaturityService::AI_STATUS_NOT_REQUESTED], true)) {
|
||||
} elseif ($this->uploadMaturityEnabled() && in_array($maturityAiStatus, [ArtworkMaturityService::AI_STATUS_PENDING, ArtworkMaturityService::AI_STATUS_NOT_REQUESTED], true)) {
|
||||
$missing[] = 'Maturity analysis pending';
|
||||
} elseif ((bool) config('vision.enabled', true) && $maturityAiStatus === ArtworkMaturityService::AI_STATUS_FAILED) {
|
||||
} elseif ($this->uploadMaturityEnabled() && $maturityAiStatus === ArtworkMaturityService::AI_STATUS_FAILED) {
|
||||
$missing[] = 'Maturity check failed';
|
||||
}
|
||||
|
||||
@@ -690,6 +717,12 @@ final class UploadQueueService
|
||||
return (int) round((collect($checks)->filter()->count() / count($checks)) * 100);
|
||||
}
|
||||
|
||||
private function uploadMaturityEnabled(): bool
|
||||
{
|
||||
return (bool) config('vision.enabled', true)
|
||||
&& (bool) config('vision.upload.maturity.enabled', false);
|
||||
}
|
||||
|
||||
private function normalizeDefaults(array $defaults): array
|
||||
{
|
||||
$visibility = (string) ($defaults['visibility'] ?? Artwork::VISIBILITY_PUBLIC);
|
||||
|
||||
Reference in New Issue
Block a user