From 978c7c14920574e8eeac0a46c772f58b1d3ad144 Mon Sep 17 00:00:00 2001 From: Lizandro Date: Tue, 11 Aug 2026 00:34:27 +0000 Subject: [PATCH] fix: tolerar URL de OCR con /extract incluido por error Si en el panel se pega la URL completa (https://host/extract) en vez del dominio base, el servicio duplicaba la ruta (.../extract/extract) y daba 404. normalizarUrl() ahora le quita el /extract final si ya viene, tanto en el flujo real como en el boton "Probar conexion". Co-Authored-By: Claude Sonnet 5 --- app/Http/Livewire/Chat/ShowConfiguracionChat.php | 2 +- app/Services/OcrExtractionService.php | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Http/Livewire/Chat/ShowConfiguracionChat.php b/app/Http/Livewire/Chat/ShowConfiguracionChat.php index cd44041..077534c 100755 --- a/app/Http/Livewire/Chat/ShowConfiguracionChat.php +++ b/app/Http/Livewire/Chat/ShowConfiguracionChat.php @@ -182,7 +182,7 @@ class ShowConfiguracionChat extends Component public function probarOcr(): void { - $url = rtrim(trim($this->ocr_url ?: ChatConfig::get('ocr_url')), '/'); + $url = \App\Services\OcrExtractionService::normalizarUrl($this->ocr_url ?: ChatConfig::get('ocr_url')); $token = trim($this->ocr_token ?: ChatConfig::get('ocr_token')); if (! $url) { diff --git a/app/Services/OcrExtractionService.php b/app/Services/OcrExtractionService.php index ff515f6..22ff500 100644 --- a/app/Services/OcrExtractionService.php +++ b/app/Services/OcrExtractionService.php @@ -13,10 +13,17 @@ class OcrExtractionService public function __construct() { - $this->url = rtrim(ChatConfig::get('ocr_url', ''), '/'); + $this->url = self::normalizarUrl(ChatConfig::get('ocr_url', '')); $this->token = ChatConfig::get('ocr_token', ''); } + /** Acepta tanto "https://host" como "https://host/extract" (error comun de configuracion). */ + public static function normalizarUrl(string $url): string + { + $url = rtrim(trim($url), '/'); + return preg_replace('#/extract$#', '', $url); + } + public function habilitado(): bool { return ChatConfig::get('ocr_habilitado', '0') === '1' && $this->url !== '';