BUG 調整 ApiClient 改讀DB 不用config 20250604
This commit is contained in:
parent
826ae92c3b
commit
60a61e6a7b
@ -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()) {
|
||||
|
@ -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());
|
||||
|
@ -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()) {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user