From 2bc0eb33b8a9cb5209d9060bc1e0ca839d2ba345 Mon Sep 17 00:00:00 2001 From: Fin Date: Mon, 24 Feb 2025 09:51:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=91=E9=80=81=E5=88=B0?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E8=AE=BE=E5=A4=87=E5=BF=AB=E6=8D=B7=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bark/Intents/PushToCurrentIntent.swift | 15 ++++++++------- Bark/Intents/PushToOtherIntent.swift | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Bark/Intents/PushToCurrentIntent.swift b/Bark/Intents/PushToCurrentIntent.swift index 9139c0a..59374e8 100644 --- a/Bark/Intents/PushToCurrentIntent.swift +++ b/Bark/Intents/PushToCurrentIntent.swift @@ -41,15 +41,16 @@ struct PushToCurrentIntent: AppIntent { var group: String? func perform() async throws -> some IntentResult & ReturnsValue { - let url = ServerManager.shared.currentServer.address + "/\(ServerManager.shared.currentServer.key)" + guard let address = URL(string: address) else { + throw "Invalid URL" + } var params: [String: Any] = [:] - if let title { + if let title, !title.isEmpty { params["title"] = title.urlDecoded() } - if let body { - // url解码 body + if let body, !body.isEmpty { params["body"] = body.urlDecoded() } if title == nil, body == nil { @@ -64,17 +65,17 @@ struct PushToCurrentIntent: AppIntent { if isCall { params["call"] = 1 } - if let sound { + if let sound, !sound.isEmpty { params["sound"] = sound } if let icon { params["icon"] = icon.absoluteString } - if let group { + if let group, !group.isEmpty { params["group"] = group } - let response = await AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default) + let response = await AF.request(address, method: .post, parameters: params, encoding: JSONEncoding.default) .serializingDecodable(PushResponse.self) .response diff --git a/Bark/Intents/PushToOtherIntent.swift b/Bark/Intents/PushToOtherIntent.swift index ae27306..5ddf5cb 100644 --- a/Bark/Intents/PushToOtherIntent.swift +++ b/Bark/Intents/PushToOtherIntent.swift @@ -40,15 +40,17 @@ struct PushToOtherIntent: AppIntent { var group: String? func perform() async throws -> some IntentResult & ReturnsValue { - let url = ServerManager.shared.currentServer.address + "/\(ServerManager.shared.currentServer.key)" + guard let address = URL(string: address) else { + throw "Invalid URL" + } var params: [String: Any] = [:] - if let title { - params["title"] = title + if let title, !title.isEmpty { + params["title"] = title.urlDecoded() } - if let body { - params["body"] = body + if let body, !body.isEmpty { + params["body"] = body.urlDecoded() } if title == nil, body == nil { params["body"] = "Empty Notification" @@ -62,17 +64,17 @@ struct PushToOtherIntent: AppIntent { if isCall { params["call"] = 1 } - if let sound { + if let sound, !sound.isEmpty { params["sound"] = sound } if let icon { params["icon"] = icon.absoluteString } - if let group { + if let group, !group.isEmpty { params["group"] = group } - let response = await AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default) + let response = await AF.request(address, method: .post, parameters: params, encoding: JSONEncoding.default) .serializingDecodable(PushResponse.self) .response