Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions others/translate/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,18 @@
}
}

// 保存到本地存储
localStorage.setItem('translateApiConfig', JSON.stringify(apiConfig));
// 保存到本地存储(移除敏感字段,避免明文持久化)
const safeApiConfig = JSON.parse(JSON.stringify(apiConfig));
if (safeApiConfig.baidu) {
delete safeApiConfig.baidu.secretKey;
}
if (safeApiConfig.youdao) {
delete safeApiConfig.youdao.secretKey;
}
if (safeApiConfig.google) {
delete safeApiConfig.google.apiKey;
}
localStorage.setItem('translateApiConfig', JSON.stringify(safeApiConfig));

return true;
} catch (e) {
Expand Down Expand Up @@ -272,8 +282,18 @@
TranslateAPI.setService(currentService);
}

// 保存到本地存储
localStorage.setItem('translateApiConfig', JSON.stringify(apiConfig));
// 保存到本地存储(移除敏感字段,避免明文持久化)
const safeApiConfig = JSON.parse(JSON.stringify(apiConfig));
if (safeApiConfig.baidu) {
delete safeApiConfig.baidu.secretKey;
}
if (safeApiConfig.youdao) {
delete safeApiConfig.youdao.secretKey;
}
if (safeApiConfig.google) {
delete safeApiConfig.google.apiKey;
}
localStorage.setItem('translateApiConfig', JSON.stringify(safeApiConfig));

// 更新API状态
this.checkApiStatus();
Expand Down Expand Up @@ -1300,7 +1320,8 @@
const baiduAppId = baiduAppIdElement.value;
const baiduSecretKey = baiduSecretKeyElement.value;
if (baiduAppId && baiduSecretKey) {
TranslateApp.saveApiConfig('api', 'baidu', baiduAppId, baiduSecretKey);
// 不在本地存储中持久化密钥,仅在当前运行时设置
TranslateApp.saveApiConfig('api', 'baidu', baiduAppId, '');
TranslateAPI.setApiKey('baidu', baiduAppId, baiduSecretKey);
}
}
Expand All @@ -1312,7 +1333,8 @@
const youdaoAppId = youdaoAppIdElement.value;
const youdaoSecretKey = youdaoSecretKeyElement.value;
if (youdaoAppId && youdaoSecretKey) {
TranslateApp.saveApiConfig('api', 'youdao', youdaoAppId, youdaoSecretKey);
// 不在本地存储中持久化密钥,仅在当前运行时设置
TranslateApp.saveApiConfig('api', 'youdao', youdaoAppId, '');
TranslateAPI.setApiKey('youdao', youdaoAppId, youdaoSecretKey);
}
}
Expand Down