修正多筆資料迴圈跳出機制

This commit is contained in:
Raymond Yang 2026-03-12 14:51:25 +08:00
parent 2f4532cc0b
commit a4afd684ab

View File

@ -48,8 +48,8 @@ fun main() {
if (ipAddress != null) {
println("您目前的 WAN IP 位址為: $ipAddress")
try {
configs.forEach { (token, domain) ->
try {
println("[$domain]驗證 CF 權杖是否有效...")
val verifyTokenResult = apiService.getVerifyToken("Bearer $token")
if (verifyTokenResult.success) {
@ -59,7 +59,7 @@ fun main() {
println("[$domain]Zone 資料載入成功,取得域名資料中...")
val zoneData = zonesResult.result.firstOrNull { it.name == domain } ?: run {
println("無法找到指定的域名 [ $domain ]...")
return@runBlocking
return@forEach
}
val zoneId = zoneData.id
val zoneDnsRecords = apiService.getZoneDnsRecords("Bearer $token", zoneId)
@ -67,7 +67,7 @@ fun main() {
println("[$domain]域名資料載入成功,處理中...")
val record = zoneDnsRecords.result.firstOrNull { it.name == domain } ?: run {
println("無法找到指定的域名 [ $domain ]...")
return@runBlocking
return@forEach
}
val recordId = record.id
val updateDnsBody = UpdateDnsBody(
@ -77,32 +77,29 @@ fun main() {
ttl = 120,
proxied = false
)
val updateDnsResult = apiService.updateZoneDnsRecords("Bearer $token", zoneId, recordId, updateDnsBody)
val updateDnsResult =
apiService.updateZoneDnsRecords("Bearer $token", zoneId, recordId, updateDnsBody)
if (updateDnsResult.success) {
println("[$domain]更新 DDNS 成功")
exitProcess(0)
} else {
println("[$domain]更新 DDNS 失敗")
exitProcess(0)
}
} else {
println("[$domain]無法取得域名資料")
exitProcess(0)
}
} else {
println("[$domain]無法取得 Zone 資料")
exitProcess(0)
}
} else {
println("[$domain]CF 權杖無效")
exitProcess(0)
}
}
} catch (e: Exception) {
e.printStackTrace()
println("Error: ${e.message}")
exitProcess(0)
}
}
exitProcess(0)
} else {
println("無法取得 WAN IP 位址...")
exitProcess(0)