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