From 5ecfdbda998168dc51a156293c2f7a0d3db54e4c Mon Sep 17 00:00:00 2001 From: Jerry <89069957+Jerry23011@users.noreply.github.com> Date: Sat, 25 Nov 2023 20:29:37 -0800 Subject: [PATCH] style: code formatting --- .../Service/Tencent/TencentService.swift | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/Easydict/Feature/Service/Tencent/TencentService.swift b/Easydict/Feature/Service/Tencent/TencentService.swift index 88f81ca6e..d23d403b5 100644 --- a/Easydict/Feature/Service/Tencent/TencentService.swift +++ b/Easydict/Feature/Service/Tencent/TencentService.swift @@ -65,7 +65,6 @@ public final class TencentService: QueryService { private var token: String { let token = UserDefaults.standard.string(forKey: EZTencentAPIKey) - if let token, !token.isEmpty { return token } else { @@ -77,7 +76,6 @@ public final class TencentService: QueryService { if prehandleQueryTextLanguage(text, autoConvertChineseText: false, from: from, to: to, completion: completion) { return } - let transType = TencentTranslateType.type(from: from, to: to) guard transType != .unsupported else { result.errorType = .unsupportedLanguage @@ -93,6 +91,7 @@ public final class TencentService: QueryService { "ProjectId": "0", ] +//MARK: Header Reqest let timeStamp = String(Int(Date().timeIntervalSince1970)) let headers: HTTPHeaders = [ @@ -106,40 +105,29 @@ public final class TencentService: QueryService { "X-TC-Token": "", ] - // Use the Alamofire module to create and send a POST request to the API endpoint with the parameters and headers + let request = AF.request(apiEndPoint, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers) - // Validate the response + .validate() - // Decode the response as a CaiyunResponse object .responseDecodable(of: TencentResponse.self) { [weak self] response in - // Use a weak reference to self to avoid memory leaks guard let self else { return } - // Get the result object from self let result = self.result - // Switch on the response result switch response.result { - // If success, assign the value to a constant case let .success(value): - // Set the from, to, queryText, and translatedResults properties of the result object with the corresponding values result.from = from result.to = to result.queryText = text result.translatedResults = value.TargetText - // Call the completion closure with the result object and nil error completion(result, nil) - // If failure, assign the error to a constant case let .failure(error): - // Log the error message NSLog("Tencent lookup error \(error)") - // Call the completion closure with the result object and the error completion(result, error) } } - // Set the stop closure of the queryModel object with a closure that cancels the request queryModel.setStop({ request.cancel() }, serviceType: serviceType().rawValue)