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} 中...");
|
$this->info("📤 傳送檔案 {$filename} 到 {$url} 中...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client = new ApiClient($token, $baseUrl);
|
$client = new ApiClient( $baseUrl ,$token);
|
||||||
$response = $client->upload($endpoint, ['file' => $filePath], $data);
|
$response = $client->upload($endpoint, ['file' => $filePath], $data);
|
||||||
|
|
||||||
if ($response->successful()) {
|
if ($response->successful()) {
|
||||||
|
@ -289,8 +289,8 @@ class RoomControlController extends Controller
|
|||||||
];
|
];
|
||||||
$user = \App\Models\User::find(2);
|
$user = \App\Models\User::find(2);
|
||||||
$token = $user->api_plain_token;
|
$token = $user->api_plain_token;
|
||||||
$api = new \App\Services\ApiClient();
|
$api = new \App\Services\ApiClient($branch->external_ip,$token);
|
||||||
$response = $api->setToken($token)->setBaseUrl($branch->external_ip)->post('/room/sendSwitch', $payload);
|
$response = $api->post('/api/room/sendSwitch', $payload);
|
||||||
|
|
||||||
if (!$response->successful()) {
|
if (!$response->successful()) {
|
||||||
return ApiResponse::error('指令發送失敗:' . $response->body());
|
return ApiResponse::error('指令發送失敗:' . $response->body());
|
||||||
|
@ -40,8 +40,7 @@ class SendSqliteFileJob implements ShouldQueue
|
|||||||
: Branch::where('enable', true)->cursor();
|
: Branch::where('enable', true)->cursor();
|
||||||
|
|
||||||
foreach ($branches as $branch) {
|
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]);
|
$response = $client->upload('/api/upload-sqlite', ['file' => $path]);
|
||||||
|
|
||||||
if ($response->successful()) {
|
if ($response->successful()) {
|
||||||
|
@ -82,8 +82,8 @@ class RoomDetailModal extends Component
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$apiClient = new ApiClient();
|
$api = new ApiClient($branch->external_ip , $token );
|
||||||
$response = $apiClient->setToken($token)->post('/room/sendSwitch', $data);
|
$response = $api->post('/api/room/sendSwitch', $data);
|
||||||
if ($response->failed()) {
|
if ($response->failed()) {
|
||||||
$this->addError('api', 'API request failed: ' . $response->body());
|
$this->addError('api', 'API request failed: ' . $response->body());
|
||||||
return false;
|
return false;
|
||||||
|
@ -8,10 +8,17 @@ class ApiClient
|
|||||||
protected string $baseUrl;
|
protected string $baseUrl;
|
||||||
protected string $token;
|
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->baseUrl = $baseUrl;
|
||||||
$this->token = $token ?? config('services.room_api.token');
|
$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
|
public function setToken(string $token): self
|
||||||
|
@ -13,10 +13,6 @@ return [
|
|||||||
| a conventional file to locate the various service credentials.
|
| a conventional file to locate the various service credentials.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'room_api' => [
|
|
||||||
'base_url' => env('API_BASE_URL', env('APP_URL') . '/api'),
|
|
||||||
],
|
|
||||||
|
|
||||||
'postmark' => [
|
'postmark' => [
|
||||||
'token' => env('POSTMARK_TOKEN'),
|
'token' => env('POSTMARK_TOKEN'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user