BUG 調整 ApiClient 改讀DB 不用config 20250604

This commit is contained in:
allen.yan 2025-06-04 09:43:24 +08:00
parent 826ae92c3b
commit 60a61e6a7b
6 changed files with 16 additions and 14 deletions

View File

@ -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()) {

View File

@ -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());

View File

@ -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()) {

View File

@ -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;

View File

@ -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

View File

@ -14,10 +14,6 @@ return [
|
*/
'room_api' => [
'base_url' => env('API_BASE_URL', env('APP_URL') . '/api'),
],
'postmark' => [
'token' => env('POSTMARK_TOKEN'),
],