diff --git a/scripts/config.json b/scripts/config.json index 4c30869..1308956 100644 --- a/scripts/config.json +++ b/scripts/config.json @@ -1,7 +1,6 @@ { "apiUrl": "https://superstar.dnsnet.cc", "branchName": "測試", - "roomName": "102", "email": "MachineKTV@gmail.com", "password": "aa147258-" } \ No newline at end of file diff --git a/scripts/heartbeat.ps1 b/scripts/heartbeat.ps1 index 98e3281..02a8433 100644 --- a/scripts/heartbeat.ps1 +++ b/scripts/heartbeat.ps1 @@ -12,7 +12,12 @@ if (!(Test-Path $configPath)) { exit 1 } -$config = Get-Content $configPath | ConvertFrom-Json +try { + $config = Get-Content $configPath -Encoding UTF8 | Out-String | ConvertFrom-Json +} catch { + Log "error Failed to read config.json: $($_.Exception.Message)" + exit 1 +} # Config values $apiUrl = $config.apiUrl.TrimEnd('/') # 移除結尾的 / @@ -29,7 +34,7 @@ $ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object { function Get-Token { $body = @{ - branch_name = $branchName + branch_name = $branchName room_name = $env:COMPUTERNAME room_ip = $ip email = $email @@ -38,10 +43,13 @@ function Get-Token { $url = "$apiUrl/api/room/receiveRegister" Log "curl Requesting token from: $url" - + # 將送出的 JSON log 起來 + Log "curl Payload: $body" + try { $response = Invoke-RestMethod -Uri $url -Method Post ` - -Body $body -ContentType "application/json" + -Body $body ` + -ContentType "application/json; charset=utf-8" if ($response.data.token) { Log "ok Token acquired: $($response.data.token)" @@ -57,6 +65,7 @@ function Get-Token { } function Send-Heartbeat($token, $ip) { + Log "start Send - Heartbeat $token ,$ip" while ($true) { $heartbeat = @{ branch_name = $branchName @@ -70,7 +79,7 @@ function Send-Heartbeat($token, $ip) { try { Invoke-RestMethod -Uri "$apiUrl/api/room/heartbeat" -Method Post ` -Headers @{ Authorization = "Bearer $token" } ` - -Body $heartbeat -ContentType "application/json" + -Body $heartbeat -ContentType "application/json; charset=utf-8" } catch { Log "error Heartbeat failed: $($_.Exception.Message)"