diff --git a/Easydict/Feature/Service/Tencent/TencentResponse.swift b/Easydict/Feature/Service/Tencent/TencentResponse.swift index 6c09b6b35..fabb7066d 100644 --- a/Easydict/Feature/Service/Tencent/TencentResponse.swift +++ b/Easydict/Feature/Service/Tencent/TencentResponse.swift @@ -15,6 +15,6 @@ struct TencentResponse: Codable { var Target: String var TargetText: String } - + var Response: Response } diff --git a/Easydict/Feature/Service/Tencent/TencentService.swift b/Easydict/Feature/Service/Tencent/TencentService.swift index 37b394685..14ee0e18e 100644 --- a/Easydict/Feature/Service/Tencent/TencentService.swift +++ b/Easydict/Feature/Service/Tencent/TencentService.swift @@ -38,7 +38,7 @@ public final class TencentService: QueryService { throw QueryServiceError.notSupported } -//MARK: API Request +// MARK: API Request private static let defaultSecretId = "" private static let defaultSecretKey = "" @@ -82,13 +82,13 @@ public final class TencentService: QueryService { "SourceText": text, "Source": transType.sourceLanguage, "Target": transType.targetLanguage, - "ProjectId": projectId, + "ProjectId": projectId ] func sha256(msg: String) -> String { let data = msg.data(using: .utf8)! let digest = SHA256.hash(data: data) - return digest.compactMap{String(format: "%02x", $0)}.joined() + return digest.compactMap {String(format: "%02x", $0)}.joined() } let service = "tmt" @@ -104,7 +104,6 @@ public final class TencentService: QueryService { dateFormatter.timeZone = TimeZone(identifier: "UTC") let date = dateFormatter.string(from: Date(timeIntervalSince1970: TimeInterval(timestamp))) - // ************* 步骤 1:拼接规范请求串 ************* let httpRequestMethod = "POST" let canonicalUri = "/" @@ -139,21 +138,21 @@ public final class TencentService: QueryService { let dateData = Data(date.utf8) var symmetricKey = SymmetricKey(data: keyData) let secretDate = HMAC.authenticationCode(for: dateData, using: symmetricKey) - _ = Data(secretDate).map{String(format: "%02hhx", $0)}.joined() + _ = Data(secretDate).map {String(format: "%02hhx", $0)}.joined() let serviceData = Data(service.utf8) symmetricKey = SymmetricKey(data: Data(secretDate)) let secretService = HMAC.authenticationCode(for: serviceData, using: symmetricKey) - _ = Data(secretService).map{String(format: "%02hhx", $0)}.joined() + _ = Data(secretService).map {String(format: "%02hhx", $0)}.joined() let signingData = Data("tc3_request".utf8) symmetricKey = SymmetricKey(data: secretService) let secretSigning = HMAC.authenticationCode(for: signingData, using: symmetricKey) - _ = Data(secretSigning).map{String(format: "%02hhx", $0)}.joined() + _ = Data(secretSigning).map {String(format: "%02hhx", $0)}.joined() let stringToSignData = Data(stringToSign.utf8) symmetricKey = SymmetricKey(data: secretSigning) - let signature = HMAC.authenticationCode(for: stringToSignData, using: symmetricKey).map{String(format: "%02hhx", $0)}.joined() + let signature = HMAC.authenticationCode(for: stringToSignData, using: symmetricKey).map {String(format: "%02hhx", $0)}.joined() // ************* 步骤 4:拼接 Authorization ************* let authorization = """ @@ -167,7 +166,7 @@ public final class TencentService: QueryService { "X-TC-Action": action, "X-TC-Timestamp": "\(timestamp)", "X-TC-Version": version, - "X-TC-Region": region, + "X-TC-Region": region ] let request = AF.request(endpoint, diff --git a/Easydict/Feature/Service/Tencent/TencentTranslateType.swift b/Easydict/Feature/Service/Tencent/TencentTranslateType.swift index ab01578d1..a13ea3a73 100644 --- a/Easydict/Feature/Service/Tencent/TencentTranslateType.swift +++ b/Easydict/Feature/Service/Tencent/TencentTranslateType.swift @@ -33,7 +33,7 @@ struct TencentTranslateType: Equatable { .thai: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian], .malay: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian], .arabic: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian], - .hindi: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian], + .hindi: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian] ] static let supportLanguagesDictionary: [Language: String] = [ @@ -55,11 +55,11 @@ struct TencentTranslateType: Equatable { .thai: "th", .malay: "ms", .arabic: "ar", - .hindi: "hi", + .hindi: "hi" ] static func transType(from: Language, to: Language) -> TencentTranslateType { - if (supportedTypes[from]?.contains(to) == true) { + if supportedTypes[from]?.contains(to) == true { guard let from = supportLanguagesDictionary[from], let to = supportLanguagesDictionary[to] else { return .unsupported