Save workspace changes
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Artwork;
|
||||
use App\Services\TagNormalizer;
|
||||
use App\Services\Vision\VisionService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Synchronous Vision tag suggestions for the upload wizard.
|
||||
*
|
||||
* POST /api/uploads/{id}/vision-suggest
|
||||
*
|
||||
* Calls the Vision gateway (/analyze/all) synchronously and returns
|
||||
* normalised tag suggestions immediately — without going through the queue.
|
||||
* The queue-based AutoTagArtworkJob still runs in the background and writes
|
||||
* to the DB; this endpoint gives the user instant pre-fill on Step 2.
|
||||
*/
|
||||
final class UploadVisionSuggestController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly VisionService $vision,
|
||||
private readonly TagNormalizer $normalizer,
|
||||
) {}
|
||||
|
||||
public function __invoke(int $id, Request $request): JsonResponse
|
||||
{
|
||||
if (! $this->vision->isEnabled()) {
|
||||
return response()->json(['tags' => [], 'vision_enabled' => false]);
|
||||
}
|
||||
|
||||
$artwork = Artwork::query()->findOrFail($id);
|
||||
$this->authorizeOrNotFound($request->user(), $artwork);
|
||||
$limit = (int) $request->query('limit', 10);
|
||||
|
||||
return response()->json($this->vision->suggestTags($artwork, $this->normalizer, $limit));
|
||||
}
|
||||
|
||||
private function authorizeOrNotFound(mixed $user, Artwork $artwork): void
|
||||
{
|
||||
if (! $user) {
|
||||
abort(404);
|
||||
}
|
||||
if ((int) $artwork->user_id !== (int) $user->id) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user