Verfügbarkeitstest für API Provider ergänzt.
This commit is contained in:
@@ -15,4 +15,5 @@ interface ApiPluginInterface
|
||||
public function getStyledImage(string $promptId): string;
|
||||
public function testConnection(array $data): bool;
|
||||
public function searchModels(string $searchTerm): array;
|
||||
public function checkAvailability(): array;
|
||||
}
|
||||
@@ -255,6 +255,60 @@ class ComfyUi implements ApiPluginInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function checkAvailability(): array
|
||||
{
|
||||
$this->logInfo('Checking ComfyUI availability.');
|
||||
|
||||
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
|
||||
];
|
||||
}
|
||||
|
||||
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
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$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
|
||||
];
|
||||
} else {
|
||||
$this->logError('ComfyUI connection failed.', ['status' => $response->status()]);
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Connection failed: ' . $response->status(),
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'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(),
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function searchModels(string $searchTerm): array
|
||||
{
|
||||
$this->logInfo('ComfyUI does not support model search. Returning empty list.', ['searchTerm' => $searchTerm]);
|
||||
|
||||
@@ -139,6 +139,84 @@ class RunwareAi implements ApiPluginInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function checkAvailability(): array
|
||||
{
|
||||
$this->logInfo('Checking RunwareAI availability.');
|
||||
|
||||
if (!$this->apiProvider->enabled) {
|
||||
$this->logDebug('RunwareAI provider is disabled.');
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Provider is disabled',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($this->apiProvider->api_url)) {
|
||||
$this->logDebug('RunwareAI API URL is not configured.');
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'API URL not configured',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($this->apiProvider->token)) {
|
||||
$this->logDebug('RunwareAI API token is not configured.');
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'API token not configured',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
])->timeout(5)->post(rtrim($this->apiProvider->api_url, '/'), [
|
||||
'taskType' => 'authentication',
|
||||
'apiKey' => $this->apiProvider->token,
|
||||
'taskUUID' => (string) Str::uuid(),
|
||||
]);
|
||||
|
||||
$responseData = $response->json();
|
||||
|
||||
if ($response->successful() && isset($responseData['data']) && !isset($responseData['error'])) {
|
||||
$this->logInfo('RunwareAI is available.');
|
||||
return [
|
||||
'available' => true,
|
||||
'reason' => 'Connection successful',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
} else {
|
||||
$errorMessage = $responseData['error'] ?? 'Unknown error';
|
||||
$this->logError('RunwareAI connection failed.', [
|
||||
'status' => $response->status(),
|
||||
'error_message' => $errorMessage
|
||||
]);
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Connection failed: ' . $errorMessage,
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logError('RunwareAI availability check failed.', ['error' => $e->getMessage()]);
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Connection error: ' . $e->getMessage(),
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function searchModels(string $searchTerm): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user