Skip to content

Commit

Permalink
style: code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry23011 committed Nov 26, 2023
1 parent 4ff9a08 commit 5ecfdbd
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions Easydict/Feature/Service/Tencent/TencentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -93,6 +91,7 @@ public final class TencentService: QueryService {
"ProjectId": "0",
]

//MARK: Header Reqest
let timeStamp = String(Int(Date().timeIntervalSince1970))

let headers: HTTPHeaders = [
Expand All @@ -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)
Expand Down

0 comments on commit 5ecfdbd

Please sign in to comment.