upgrade to laravel 12 done
This commit is contained in:
@@ -65,9 +65,21 @@ class ComfyUi implements ApiPluginInterface
|
||||
|
||||
public function getProgress(string $imageUUID): array
|
||||
{
|
||||
$this->logDebug('Getting progress for image.', ['image_uuid' => $imageUUID]);
|
||||
// Implement ComfyUI specific progress check
|
||||
return ['progress' => 0];
|
||||
$this->logDebug('Progress updates are handled via WebSocket.', ['image_uuid' => $imageUUID]);
|
||||
return ['progress' => 0]; // Progress is now handled by WebSocket
|
||||
}
|
||||
|
||||
private function getHistory(string $promptId): array
|
||||
{
|
||||
// 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);
|
||||
if ($response->failed()) {
|
||||
throw new \Exception('Failed to get history from ComfyUI');
|
||||
}
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
public function processImageStyleChange(string $imagePath, string $prompt, string $modelId, ?string $parameters = null): array
|
||||
@@ -85,10 +97,8 @@ class ComfyUi implements ApiPluginInterface
|
||||
$queueResponse = $this->queuePrompt($promptData);
|
||||
$promptId = $queueResponse['prompt_id'];
|
||||
|
||||
// 4. Wait for and get the result
|
||||
$result = $this->waitForResult($promptId);
|
||||
|
||||
return ['base64Data' => $result];
|
||||
// Return the prompt_id for frontend WebSocket tracking
|
||||
return ['prompt_id' => $promptId];
|
||||
}
|
||||
|
||||
private function uploadImage(string $imagePath): array
|
||||
@@ -96,7 +106,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(120)->post(rtrim($this->apiProvider->api_url, '/') . '/upload/image', [
|
||||
)->timeout(60)->post(rtrim($this->apiProvider->api_url, '/') . '/upload/image', [
|
||||
'type' => 'input',
|
||||
'overwrite' => 'false',
|
||||
]);
|
||||
@@ -126,7 +136,7 @@ class ComfyUi implements ApiPluginInterface
|
||||
private function queuePrompt(array $promptData): array
|
||||
{
|
||||
$this->logInfo('Queueing prompt in ComfyUI.');
|
||||
$response = Http::timeout(120)->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()]);
|
||||
@@ -136,30 +146,64 @@ class ComfyUi implements ApiPluginInterface
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
private function waitForResult(string $promptId): string
|
||||
public function waitForResult(string $promptId): string
|
||||
{
|
||||
$this->logInfo('Waiting for ComfyUI result.', ['prompt_id' => $promptId]);
|
||||
while (true) {
|
||||
$response = Http::timeout(120)->get($this->apiProvider->api_url . '/history/' . $promptId);
|
||||
$data = $response->json();
|
||||
set_time_limit(120); // Set maximum execution time for this function
|
||||
$this->logInfo('waitForResult: Waiting for ComfyUI result.', ['prompt_id' => $promptId]);
|
||||
$startTime = microtime(true);
|
||||
$timeout = 180; // seconds
|
||||
|
||||
if (!empty($data[$promptId]['outputs'])) {
|
||||
$outputs = $data[$promptId]['outputs'];
|
||||
// Assuming the first output with an image is the one we want
|
||||
foreach ($outputs as $output) {
|
||||
if (isset($output['images'][0]['type']) && $output['images'][0]['type'] === 'output') {
|
||||
$imageUrl = sprintf('%s/view?filename=%s&subfolder=%s&type=output',
|
||||
$this->apiProvider->api_url,
|
||||
$output['images'][0]['filename'],
|
||||
$output['images'][0]['subfolder']
|
||||
);
|
||||
$image_data = file_get_contents($imageUrl);
|
||||
return base64_encode($image_data);
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
if (microtime(true) - $startTime > $timeout) {
|
||||
$this->logError('waitForResult: ComfyUI result polling timed out.', ['prompt_id' => $promptId]);
|
||||
throw new \Exception('ComfyUI result polling timed out.');
|
||||
}
|
||||
|
||||
sleep(2); // Wait for 2 seconds before polling again
|
||||
try {
|
||||
$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()) {
|
||||
$this->logError('waitForResult: Failed to get history from ComfyUI.', ['prompt_id' => $promptId, 'response' => $response->body()]);
|
||||
throw new \Exception('Failed to get history from ComfyUI');
|
||||
}
|
||||
|
||||
$data = $response->json();
|
||||
$this->logDebug('waitForResult: History API response data.', ['data' => $data, 'prompt_id' => $promptId]);
|
||||
|
||||
if (isset($data[$promptId]['outputs'])) {
|
||||
$outputs = $data[$promptId]['outputs'];
|
||||
$this->logInfo('waitForResult: Found outputs in history.', ['prompt_id' => $promptId, 'outputs_count' => count($outputs)]);
|
||||
|
||||
foreach ($outputs as $output) {
|
||||
if (isset($output['images'][0]['type']) && $output['images'][0]['type'] === 'output') {
|
||||
$imageUrl = sprintf('%s/view?filename=%s&subfolder=%s&type=output',
|
||||
rtrim($this->apiProvider->api_url, '/'),
|
||||
$output['images'][0]['filename'],
|
||||
$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]);
|
||||
|
||||
if ($imageResponse->failed()) {
|
||||
$this->logError('waitForResult: Failed to retrieve image data from ComfyUI.', ['imageUrl' => $imageUrl, 'response' => $imageResponse->body()]);
|
||||
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());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->logDebug('waitForResult: No outputs found yet for prompt.', ['prompt_id' => $promptId]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logError('waitForResult: Exception caught during polling.', ['prompt_id' => $promptId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString()]);
|
||||
throw $e; // Re-throw the exception to be caught by ImageController
|
||||
}
|
||||
|
||||
usleep(500000); // Wait for 0.5 seconds before polling again
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user