From a4afd684abd895897890a9c3512ef7d728516b06 Mon Sep 17 00:00:00 2001 From: Raymond Yang Date: Thu, 12 Mar 2026 14:51:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=A4=9A=E7=AD=86=E8=B3=87?= =?UTF-8?q?=E6=96=99=E8=BF=B4=E5=9C=88=E8=B7=B3=E5=87=BA=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/Main.kt | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 9ac04af..1c7cb39 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -48,8 +48,8 @@ fun main() { if (ipAddress != null) { println("您目前的 WAN IP 位址為: $ipAddress") - try { - configs.forEach { (token, domain) -> + 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) } - } catch (e: Exception) { - e.printStackTrace() - println("Error: ${e.message}") - exitProcess(0) } + exitProcess(0) } else { println("無法取得 WAN IP 位址...") exitProcess(0)