diff --git a/app/Console/Commands/SendSqliteFile.php b/app/Console/Commands/SendSqliteFile.php index b687ea3..2cb5213 100644 --- a/app/Console/Commands/SendSqliteFile.php +++ b/app/Console/Commands/SendSqliteFile.php @@ -44,7 +44,7 @@ class SendSqliteFile extends Command $this->info("📤 傳送檔案 {$filename} 到 {$url} 中..."); try { - $client = new ApiClient($token, $baseUrl); + $client = new ApiClient( $baseUrl ,$token); $response = $client->upload($endpoint, ['file' => $filePath], $data); if ($response->successful()) { diff --git a/app/Http/Controllers/RoomControlController.php b/app/Http/Controllers/RoomControlController.php index 9b7f27e..8f1c489 100644 --- a/app/Http/Controllers/RoomControlController.php +++ b/app/Http/Controllers/RoomControlController.php @@ -289,8 +289,8 @@ class RoomControlController extends Controller ]; $user = \App\Models\User::find(2); $token = $user->api_plain_token; - $api = new \App\Services\ApiClient(); - $response = $api->setToken($token)->setBaseUrl($branch->external_ip)->post('/room/sendSwitch', $payload); + $api = new \App\Services\ApiClient($branch->external_ip,$token); + $response = $api->post('/api/room/sendSwitch', $payload); if (!$response->successful()) { return ApiResponse::error('指令發送失敗:' . $response->body()); diff --git a/app/Jobs/SendSqliteFileJob.php b/app/Jobs/SendSqliteFileJob.php index 0fadb24..9f07e38 100644 --- a/app/Jobs/SendSqliteFileJob.php +++ b/app/Jobs/SendSqliteFileJob.php @@ -40,8 +40,7 @@ class SendSqliteFileJob implements ShouldQueue : Branch::where('enable', true)->cursor(); foreach ($branches as $branch) { - $client = new ApiClient($token, $branch->external_ip); - + $client = new ApiClient($branch->external_ip , $token ); $response = $client->upload('/api/upload-sqlite', ['file' => $path]); if ($response->successful()) { diff --git a/app/Livewire/Admin/RoomDetailModal.php b/app/Livewire/Admin/RoomDetailModal.php index bb494f4..32d0acf 100644 --- a/app/Livewire/Admin/RoomDetailModal.php +++ b/app/Livewire/Admin/RoomDetailModal.php @@ -82,8 +82,8 @@ class RoomDetailModal extends Component return false; } - $apiClient = new ApiClient(); - $response = $apiClient->setToken($token)->post('/room/sendSwitch', $data); + $api = new ApiClient($branch->external_ip , $token ); + $response = $api->post('/api/room/sendSwitch', $data); if ($response->failed()) { $this->addError('api', 'API request failed: ' . $response->body()); return false; diff --git a/app/Services/ApiClient.php b/app/Services/ApiClient.php index 43728ea..84242f3 100644 --- a/app/Services/ApiClient.php +++ b/app/Services/ApiClient.php @@ -8,10 +8,17 @@ class ApiClient protected string $baseUrl; protected string $token; - public function __construct(string $token = null, ?string $baseUrl = null) + public function __construct(string $baseUrl = null,string $token = null) { - $this->baseUrl = rtrim($baseUrl ?? config('services.room_api.base_url', 'https://ktv.test/api'), '/'); - $this->token = $token ?? config('services.room_api.token'); + $this->baseUrl = $baseUrl; + $this->token = $token; + } + + public function set(string $baseUrl = null,string $token = null):self + { + $this->baseUrl = $baseUrl; + $this->token = $token; + return $this; } public function setToken(string $token): self diff --git a/config/services.php b/config/services.php index 46f3d85..27a3617 100644 --- a/config/services.php +++ b/config/services.php @@ -13,10 +13,6 @@ return [ | a conventional file to locate the various service credentials. | */ - - 'room_api' => [ - 'base_url' => env('API_BASE_URL', env('APP_URL') . '/api'), - ], 'postmark' => [ 'token' => env('POSTMARK_TOKEN'),