optimize: 兼容使用 `1.7.3` 及以下版本的配置文件 (#339)

pull/340/head
王良 2024-09-03 14:55:32 +08:00 committed by GitHub
parent 486912c0fe
commit cc833719bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 5 deletions

View File

@ -23,15 +23,23 @@ function _getRemoteSavePath (suffix = '') {
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {
fs.mkdirSync(dir) fs.mkdirSync(dir)
} }
return path.join(dir, `remote_config${suffix}.json5`) return path.join(dir, `/remote_config${suffix}.json5`)
} }
function _getConfigPath () { function _getConfigPath () {
const dir = getDefaultConfigBasePath() const dir = getDefaultConfigBasePath()
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {
fs.mkdirSync(dir) fs.mkdirSync(dir)
} else {
// 兼容1.7.3及以下版本的配置文件处理逻辑
const newFilePath = path.join(dir, '/config.json')
const oldFilePath = path.join(dir, '/config.json5')
if (!fs.existsSync(newFilePath) && fs.existsSync(oldFilePath)) {
return oldFilePath // 如果新文件不存在,且旧文件存在,则返回旧文件路径
} }
return path.join(dir, 'config.json') return newFilePath
}
return path.join(dir, '/config.json')
} }
let timer let timer

View File

@ -6,11 +6,11 @@ function getUserBasePath () {
} }
function getRootCaCertPath () { function getRootCaCertPath () {
return getUserBasePath() + '/dev-sidecar.ca.crt' return path.join(getUserBasePath(), '/dev-sidecar.ca.crt')
} }
function getRootCaKeyPath () { function getRootCaKeyPath () {
return getUserBasePath() + '/dev-sidecar.ca.key.pem' return path.join(getUserBasePath(), '/dev-sidecar.ca.key.pem')
} }
module.exports = { module.exports = {

View File

@ -138,8 +138,16 @@ function _getSettingsPath () {
const dir = getDefaultConfigBasePath() const dir = getDefaultConfigBasePath()
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {
fs.mkdirSync(dir) fs.mkdirSync(dir)
} else {
// 兼容1.7.3及以下版本的配置文件处理逻辑
const newFilePath = path.join(dir, '/setting.json')
const oldFilePath = path.join(dir, '/setting.json5')
if (!fs.existsSync(newFilePath) && fs.existsSync(oldFilePath)) {
return oldFilePath // 如果新文件不存在,且旧文件存在,则返回旧文件路径
} }
return dir + '/setting.json' return newFilePath
}
return path.join(dir, '/setting.json')
} }
function invoke (api, param) { function invoke (api, param) {