單機版 v0.0.5 20250617
移除外送訊息
This commit is contained in:
parent
9e054f63ee
commit
b94a109e98
@ -7,7 +7,7 @@ use App\Models\Room;
|
|||||||
use App\Models\MachineStatus;
|
use App\Models\MachineStatus;
|
||||||
use App\Enums\RoomStatus;
|
use App\Enums\RoomStatus;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use App\Services\MachineStatusForwarder;
|
|
||||||
|
|
||||||
class CheckRoomOnlineStatus extends Command
|
class CheckRoomOnlineStatus extends Command
|
||||||
{
|
{
|
||||||
@ -33,11 +33,6 @@ class CheckRoomOnlineStatus extends Command
|
|||||||
$room->save();
|
$room->save();
|
||||||
$this->info("Room [{$room->name}] marked as offline (no recent MachineStatus)");
|
$this->info("Room [{$room->name}] marked as offline (no recent MachineStatus)");
|
||||||
}
|
}
|
||||||
$response = (new MachineStatusForwarder(
|
|
||||||
$branch->external_ip ?? '',
|
|
||||||
'/api/room/receiveSwitch',
|
|
||||||
$room->toArray()
|
|
||||||
))->forward();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -196,13 +196,6 @@ class RoomControlController extends Controller
|
|||||||
$room->is_online=1;
|
$room->is_online=1;
|
||||||
$room->touch(); // 更新 updated_at
|
$room->touch(); // 更新 updated_at
|
||||||
$room->save();
|
$room->save();
|
||||||
$response = (
|
|
||||||
new MachineStatusForwarder(
|
|
||||||
$branch->external_ip ?? '',
|
|
||||||
'/api/room/receiveSwitch',
|
|
||||||
$room->toArray()
|
|
||||||
)
|
|
||||||
)->forward();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ApiResponse::success([
|
return ApiResponse::success([
|
||||||
@ -308,11 +301,6 @@ class RoomControlController extends Controller
|
|||||||
$room->started_at=$validated['started_at'];
|
$room->started_at=$validated['started_at'];
|
||||||
$room->ended_at=$validated['ended_at'];
|
$room->ended_at=$validated['ended_at'];
|
||||||
$room->save();
|
$room->save();
|
||||||
$response = (new MachineStatusForwarder(
|
|
||||||
$branch->external_ip,
|
|
||||||
"/api/room/receiveSwitch",
|
|
||||||
$room->toArray()
|
|
||||||
))->forward();
|
|
||||||
return $validated['command']==='error' ? ApiResponse::error('機房控制失敗') : ApiResponse::success($room);
|
return $validated['command']==='error' ? ApiResponse::error('機房控制失敗') : ApiResponse::success($room);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Http\Client\Response;
|
|
||||||
use App\Services\ApiClient;
|
|
||||||
|
|
||||||
class MachineStatusForwarder
|
|
||||||
{
|
|
||||||
protected string $externalUrl;
|
|
||||||
protected string $endpoint;
|
|
||||||
protected array $validated;
|
|
||||||
protected ?User $user = null;
|
|
||||||
|
|
||||||
public function __construct(string $externalUrl, string $endpoint, array $validated)
|
|
||||||
{
|
|
||||||
$this->externalUrl = $externalUrl;
|
|
||||||
$this->endpoint = $endpoint;
|
|
||||||
$this->validated = $validated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function forward(): ?Response
|
|
||||||
{
|
|
||||||
$response = null;
|
|
||||||
$parsed = parse_url($this->externalUrl);
|
|
||||||
$hostParts = explode('.', $parsed['host']);
|
|
||||||
|
|
||||||
$mainDomain = implode('.', array_slice($hostParts, 1));
|
|
||||||
|
|
||||||
$mainDomainUrl = "{$parsed['scheme']}://{$mainDomain}";
|
|
||||||
|
|
||||||
$this->user = User::find(2); // 或用 dependency injection 把 User 帶進來
|
|
||||||
|
|
||||||
if ($this->user && $this->user->api_plain_token) {
|
|
||||||
$client = new ApiClient($mainDomainUrl, $this->user->api_plain_token);
|
|
||||||
$response = $client->post($this->endpoint, $this->validated);
|
|
||||||
|
|
||||||
/* Log::info('✅ Machine status forwarded', [
|
|
||||||
'endpoint' => $this->endpoint,
|
|
||||||
'request' => $this->validated,
|
|
||||||
'status' => $response->status(),
|
|
||||||
'body' => $response->json(),
|
|
||||||
]); */
|
|
||||||
} else {
|
|
||||||
Log::warning("🔒 User with ID 2 not found or missing token");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user