runware.ai connection test funktioniert, drucken dialog implementiert

This commit is contained in:
2025-08-08 10:11:56 +02:00
parent ad893b48a7
commit cfceaed08f
12 changed files with 305 additions and 82 deletions

View File

@@ -26,6 +26,7 @@ use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Log;
use App\Api\Plugins\PluginLoader;
class ApiProviderResource extends Resource
{
@@ -90,67 +91,59 @@ class ApiProviderResource extends Resource
->action(function (array $data, Forms\Components\Component $component, \Livewire\Component $livewire) {
$formData = $component->getLivewire()->form->getState();
$apiUrl = str_replace('127.0.0.1', 'localhost', $formData['api_url'] ?? null);
$plugin = $formData['plugin'] ?? null;
$username = $formData['username'] ?? null;
$password = $formData['password'] ?? null;
$pluginName = $formData['plugin'] ?? null;
$token = $formData['token'] ?? null;
if (!$pluginName) {
Notification::make()
->title(__('filament.resource.api_provider.notification.connection_failed'))
->body('Please select a plugin first.')
->danger()
->send();
$component->getLivewire()->dispatch('testConnectionFinished', result: 'failed');
return;
}
try {
$http = Http::timeout(25);
// Create a dummy ApiProvider model for the test
$dummyApiProvider = new \App\Models\ApiProvider();
$dummyApiProvider->api_url = $apiUrl;
$dummyApiProvider->token = $token;
if ($username && $password) {
$http->withBasicAuth($username, $password);
} elseif ($token) {
$http->withToken($token);
}
// Load the specific plugin using the PluginLoader
$pluginInstance = PluginLoader::getPlugin($pluginName, $dummyApiProvider);
$response = $http->get($apiUrl);
// Call the testConnection method of the plugin
$testResult = $pluginInstance->testConnection([
'api_url' => $apiUrl,
'token' => $token,
'username' => $formData['username'] ?? null,
'password' => $formData['password'] ?? null,
]);
if ($response->successful()) {
Log::info('External API connection successful.', [
'api_url' => $apiUrl,
'plugin' => $plugin,
]);
if ($testResult) {
Notification::make()
->title(__('filament.resource.api_provider.notification.connection_successful'))
->success()
->send();
$component->getLivewire()->dispatch('testConnectionFinished', result: 'success');
} else {
Log::warning('External API connection failed: Non-successful response.', [
'api_url' => $apiUrl,
'plugin' => $plugin,
'status' => $response->status(),
'response_body' => $response->body(),
]);
Notification::make()
->title(__('filament.resource.api_provider.notification.connection_failed'))
->body($response->json('message', 'An unknown error occurred.'))
->body('Plugin reported connection failed. Check logs for details.')
->danger()
->send();
$component->getLivewire()->dispatch('testConnectionFinished', result: 'failed');
}
} catch (\Illuminate\Http\Client\RequestException $e) {
Log::error('External API connection failed: Timeout or network error.', [
'api_url' => $apiUrl,
'plugin' => $plugin,
'error_message' => $e->getMessage(),
]);
Notification::make()
->title(__('filament.resource.api_provider.notification.connection_failed'))
->body('Timeout or network error: ' . $e->getMessage())
->danger()
->send();
$component->getLivewire()->dispatch('testConnectionFinished', result: 'failed');
} catch (\Exception $e) {
Log::error('External API connection failed: An unexpected error occurred.', [
Log::error('Plugin test connection failed: An unexpected error occurred.', [
'api_url' => $apiUrl,
'plugin' => $plugin,
'plugin' => $pluginName,
'error_message' => $e->getMessage(),
]);
Notification::make()
->title(__('filament.resource.api_provider.notification.connection_failed'))
->body('An unexpected error occurred: ' . $e->getMessage())
->body('An unexpected error occurred during plugin test: ' . $e->getMessage())
->danger()
->send();
$component->getLivewire()->dispatch('testConnectionFinished', result: 'failed');