protocol-proxy 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config-store.js +17 -4
- package/package.json +1 -1
package/lib/config-store.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
5
|
+
const CONFIG_PATH = path.join(os.homedir(), '.protocol-proxy', 'proxies.json');
|
|
6
|
+
|
|
7
|
+
// 迁移旧配置(从包目录到用户主目录)
|
|
8
|
+
const OLD_CONFIG_PATH = process.pkg
|
|
9
|
+
? path.join(path.dirname(process.execPath), 'config', 'proxies.json')
|
|
10
|
+
: path.join(__dirname, '..', 'config', 'proxies.json');
|
|
11
|
+
|
|
12
|
+
function migrateOldConfig() {
|
|
13
|
+
if (fs.existsSync(CONFIG_PATH) || !fs.existsSync(OLD_CONFIG_PATH)) return;
|
|
14
|
+
try {
|
|
15
|
+
const dir = path.dirname(CONFIG_PATH);
|
|
16
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
17
|
+
fs.copyFileSync(OLD_CONFIG_PATH, CONFIG_PATH);
|
|
18
|
+
} catch {}
|
|
19
|
+
}
|
|
20
|
+
migrateOldConfig();
|
|
8
21
|
|
|
9
22
|
let configCache = null;
|
|
10
23
|
|