Runware/ComfyUI fixes, dashboard links, import action, Leonardo plugin, widget, added status field and test connection button
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Api\Plugins;
|
||||
|
||||
use App\Models\ApiProvider;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ComfyUi implements ApiPluginInterface
|
||||
{
|
||||
@@ -41,6 +42,7 @@ class ComfyUi implements ApiPluginInterface
|
||||
} else {
|
||||
$this->logError('Failed to enable ComfyUi plugin.', ['provider_name' => $this->apiProvider->name]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -53,12 +55,14 @@ class ComfyUi implements ApiPluginInterface
|
||||
} else {
|
||||
$this->logError('Failed to disable ComfyUi plugin.', ['provider_name' => $this->apiProvider->name]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getStatus(string $imageUUID): array
|
||||
{
|
||||
$this->logDebug('Getting status for image.', ['image_uuid' => $imageUUID]);
|
||||
|
||||
// Implement ComfyUI specific status check
|
||||
return ['status' => 'unknown'];
|
||||
}
|
||||
@@ -66,6 +70,7 @@ class ComfyUi implements ApiPluginInterface
|
||||
public function getProgress(string $imageUUID): array
|
||||
{
|
||||
$this->logDebug('Progress updates are handled via WebSocket.', ['image_uuid' => $imageUUID]);
|
||||
|
||||
return ['progress' => 0]; // Progress is now handled by WebSocket
|
||||
}
|
||||
|
||||
@@ -74,11 +79,12 @@ class ComfyUi implements ApiPluginInterface
|
||||
// This method is no longer used for progress polling, but might be used for final result retrieval
|
||||
$apiUrl = rtrim($this->apiProvider->api_url, '/');
|
||||
$timeout = 60; // seconds
|
||||
$this->logDebug('ComfyUI History API URL:', ['url' => $apiUrl . '/history/' . $promptId, 'timeout' => $timeout]);
|
||||
$response = Http::timeout($timeout)->get($apiUrl . '/history/' . $promptId);
|
||||
$this->logDebug('ComfyUI History API URL:', ['url' => $apiUrl.'/history/'.$promptId, 'timeout' => $timeout]);
|
||||
$response = Http::timeout($timeout)->get($apiUrl.'/history/'.$promptId);
|
||||
if ($response->failed()) {
|
||||
throw new \Exception('Failed to get history from ComfyUI');
|
||||
}
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
@@ -87,7 +93,7 @@ class ComfyUi implements ApiPluginInterface
|
||||
$this->logInfo('Starting ComfyUI style change process.', ['image_id' => $image->id, 'style_id' => $style->id]);
|
||||
|
||||
// 1. Upload image to ComfyUI
|
||||
$uploadResponse = $this->uploadImage(public_path('storage/' . $image->path));
|
||||
$uploadResponse = $this->uploadImage(public_path('storage/'.$image->path));
|
||||
$filename = $uploadResponse['name'];
|
||||
|
||||
// 2. Construct the prompt
|
||||
@@ -106,7 +112,7 @@ class ComfyUi implements ApiPluginInterface
|
||||
$this->logInfo('Uploading image to ComfyUI.', ['image_path' => $imagePath]);
|
||||
$response = Http::attach(
|
||||
'image', file_get_contents($imagePath), basename($imagePath)
|
||||
)->timeout(60)->post(rtrim($this->apiProvider->api_url, '/') . '/upload/image', [
|
||||
)->timeout(60)->post(rtrim($this->apiProvider->api_url, '/').'/upload/image', [
|
||||
'type' => 'input',
|
||||
'overwrite' => 'false',
|
||||
]);
|
||||
@@ -131,7 +137,7 @@ class ComfyUi implements ApiPluginInterface
|
||||
$modelParams = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (is_string($styleParams)) {
|
||||
$styleParams = json_decode($styleParams, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
@@ -161,9 +167,9 @@ class ComfyUi implements ApiPluginInterface
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$this->logError('Failed to decode workflow JSON after placeholder replacement.', [
|
||||
'json_error' => json_last_error_msg(),
|
||||
'workflow_string' => $workflow
|
||||
'workflow_string' => $workflow,
|
||||
]);
|
||||
throw new \Exception('Failed to construct valid ComfyUI workflow JSON: ' . json_last_error_msg());
|
||||
throw new \Exception('Failed to construct valid ComfyUI workflow JSON: '.json_last_error_msg());
|
||||
}
|
||||
|
||||
return $decodedWorkflow;
|
||||
@@ -172,7 +178,7 @@ class ComfyUi implements ApiPluginInterface
|
||||
private function queuePrompt(array $promptData): array
|
||||
{
|
||||
$this->logInfo('Queueing prompt in ComfyUI.');
|
||||
$response = Http::timeout(60)->post(rtrim($this->apiProvider->api_url, '/') . '/prompt', ['prompt' => $promptData]);
|
||||
$response = Http::timeout(60)->post(rtrim($this->apiProvider->api_url, '/').'/prompt', ['prompt' => $promptData]);
|
||||
|
||||
if ($response->failed()) {
|
||||
$this->logError('Failed to queue prompt in ComfyUI.', ['response' => $response->body()]);
|
||||
@@ -196,7 +202,7 @@ class ComfyUi implements ApiPluginInterface
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::timeout(60)->get(rtrim($this->apiProvider->api_url, '/') . '/history/' . $promptId);
|
||||
$response = Http::timeout(60)->get(rtrim($this->apiProvider->api_url, '/').'/history/'.$promptId);
|
||||
$this->logDebug('waitForResult: History API response status.', ['status' => $response->status(), 'prompt_id' => $promptId]);
|
||||
|
||||
if ($response->failed()) {
|
||||
@@ -219,7 +225,7 @@ class ComfyUi implements ApiPluginInterface
|
||||
$output['images'][0]['subfolder']
|
||||
);
|
||||
$this->logInfo('waitForResult: Constructed image URL.', ['imageUrl' => $imageUrl, 'prompt_id' => $promptId]);
|
||||
|
||||
|
||||
$imageResponse = Http::timeout(60)->get($imageUrl);
|
||||
$this->logDebug('waitForResult: Image fetch response status.', ['status' => $imageResponse->status(), 'imageUrl' => $imageUrl]);
|
||||
|
||||
@@ -228,6 +234,7 @@ class ComfyUi implements ApiPluginInterface
|
||||
throw new \Exception('Failed to retrieve image data from ComfyUI');
|
||||
}
|
||||
$this->logInfo('waitForResult: Successfully retrieved image data.', ['prompt_id' => $promptId]);
|
||||
|
||||
return base64_encode($imageResponse->body());
|
||||
}
|
||||
}
|
||||
@@ -245,13 +252,31 @@ class ComfyUi implements ApiPluginInterface
|
||||
|
||||
public function testConnection(array $data): bool
|
||||
{
|
||||
$apiUrl = rtrim($data['api_url'], '/');
|
||||
$apiUrl = rtrim($data['api_url'] ?? '', '/');
|
||||
|
||||
if (! $apiUrl) {
|
||||
throw new \RuntimeException('ComfyUI API-URL fehlt.');
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::timeout(5)->get($apiUrl . '/queue');
|
||||
return $response->successful();
|
||||
$response = Http::timeout(5)->get($apiUrl.'/queue');
|
||||
|
||||
if ($response->successful()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$body = $response->body();
|
||||
$snippet = $body ? Str::limit($body, 200) : null;
|
||||
|
||||
$this->logError('ComfyUI connection test failed: HTTP error.', [
|
||||
'status' => $response->status(),
|
||||
'body' => $snippet,
|
||||
]);
|
||||
|
||||
throw new \RuntimeException('ComfyUI HTTP '.$response->status().($snippet ? ': '.$snippet : ''));
|
||||
} catch (\Exception $e) {
|
||||
$this->logError('ComfyUI connection test failed.', ['error' => $e->getMessage()]);
|
||||
return false;
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,52 +284,57 @@ class ComfyUi implements ApiPluginInterface
|
||||
{
|
||||
$this->logInfo('Checking ComfyUI availability.');
|
||||
|
||||
if (!$this->apiProvider->enabled) {
|
||||
if (! $this->apiProvider->enabled) {
|
||||
$this->logDebug('ComfyUI provider is disabled.');
|
||||
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Provider is disabled',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
'provider_name' => $this->apiProvider->name,
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($this->apiProvider->api_url)) {
|
||||
$this->logDebug('ComfyUI API URL is not configured.');
|
||||
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'API URL not configured',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
'provider_name' => $this->apiProvider->name,
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::timeout(5)->get(rtrim($this->apiProvider->api_url, '/') . '/queue');
|
||||
$response = Http::timeout(5)->get(rtrim($this->apiProvider->api_url, '/').'/queue');
|
||||
if ($response->successful()) {
|
||||
$this->logInfo('ComfyUI is available.');
|
||||
|
||||
return [
|
||||
'available' => true,
|
||||
'reason' => 'Connection successful',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
'provider_name' => $this->apiProvider->name,
|
||||
];
|
||||
} else {
|
||||
$this->logError('ComfyUI connection failed.', ['status' => $response->status()]);
|
||||
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Connection failed: ' . $response->status(),
|
||||
'reason' => 'Connection failed: '.$response->status(),
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
'provider_name' => $this->apiProvider->name,
|
||||
];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logError('ComfyUI availability check failed.', ['error' => $e->getMessage()]);
|
||||
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Connection error: ' . $e->getMessage(),
|
||||
'reason' => 'Connection error: '.$e->getMessage(),
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
'provider_name' => $this->apiProvider->name,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -312,11 +342,12 @@ class ComfyUi implements ApiPluginInterface
|
||||
public function searchModels(string $searchTerm): array
|
||||
{
|
||||
$this->logInfo('ComfyUI does not support model search. Returning empty list.', ['searchTerm' => $searchTerm]);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
public function getStyledImage(string $promptId): string
|
||||
{
|
||||
return $this->waitForResult($promptId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user