Skip to content

Commit

Permalink
feat: implement secrets customization
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry23011 committed Dec 1, 2023
1 parent 2e7b55f commit 7797a3c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Easydict/Feature/Service/Model/EZConstKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ static NSString *const EZDeepLAuthKey = @"EZDeepLAuthKey";
static NSString *const EZBingCookieKey = @"EZBingCookieKey";
static NSString *const EZNiuTransAPIKey = @"EZNiuTransAPIKey";
static NSString *const EZCaiyunToken = @"EZCaiyunToken";
//static NSString *const EZTencentSecretId = @"EZTencentSecretId";
//static NSString *const EZTencentSecretKey = @"EZTencentSecretKey";
static NSString *const EZTencentSecretId = @"EZTencentSecretId";
static NSString *const EZTencentSecretKey = @"EZTencentSecretKey";

@interface EZConstKey : NSObject

Expand Down
51 changes: 22 additions & 29 deletions Easydict/Feature/Service/Tencent/TencentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,28 @@ public final class TencentService: QueryService {

//MARK: API Request

//TODO: Implement user SecretId/SecretKey
// private static let defaultSecretId = ""
// private static let defaultSecretKey = ""
//
// private var secretId: String {
// let secretId = UserDefaults.standard.string(forKey: EZTencentSecretId)
// if let secretId, !secretId.isEmpty {
// return secretId
// } else {
// return TencentService.defaultSecretId
// }
// }
//
// private var secretKey: String {
// let secretKey = UserDefaults.standard.string(forKey: EZTencentSecretKey)
// if let secretKey, !secretKey.isEmpty {
// return secretKey
// } else {
// return TencentService.defaultSecretKey
// }
// }
private static let defaultSecretId = ""
private static let defaultSecretKey = ""

// easydict://writeKeyValue?EZTencentSecretId=xxx
private var secretId: String {
let secretId = UserDefaults.standard.string(forKey: EZTencentSecretId)
if let secretId, !secretId.isEmpty {
return secretId
} else {
return TencentService.defaultSecretId
}
}

// easydict://writeKeyValue?EZTencentSecretKey=xxx
private var secretKey: String {
let secretKey = UserDefaults.standard.string(forKey: EZTencentSecretKey)
if let secretKey, !secretKey.isEmpty {
return secretKey
} else {
return TencentService.defaultSecretKey
}
}

public override func translate(_ text: String, from: Language, to: Language, completion: @escaping (EZQueryResult, Error?) -> Void) {
if prehandleQueryTextLanguage(text, autoConvertChineseText: false, from: from, to: to, completion: completion) {
Expand Down Expand Up @@ -90,14 +91,6 @@ public final class TencentService: QueryService {
return digest.compactMap{String(format: "%02x", $0)}.joined()
}

// 密钥参数
// 需要设置环境变量 TENCENTCLOUD_SECRET_ID,值为示例的 AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******
//let secretId = ProcessInfo.processInfo.environment["TENCENTCLOUD_SECRET_ID"]
let secretId = ""
// 需要设置环境变量 TENCENTCLOUD_SECRET_KEY,值为示例的 Gu5t9xGARNpq86cd98joQYCN3*******
//let secretKey = ProcessInfo.processInfo.environment["TENCENTCLOUD_SECRET_KEY"]
let secretKey = ""

let service = "tmt"
let host = "tmt.tencentcloudapi.com"
let endpoint = "https://\(host)"
Expand Down
2 changes: 2 additions & 0 deletions Easydict/Feature/Utility/EZLinkParser/EZSchemeParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ - (NSArray *)allowedReadWriteKeys {
EZDeepLTranslationAPIKey,
EZNiuTransAPIKey,
EZCaiyunToken,
EZTencentSecretId,
EZTencentSecretKey,
EZBingCookieKey,

EZIntelligentQueryModeKey,
Expand Down

0 comments on commit 7797a3c

Please sign in to comment.