Skip to content

Commit fb7d663

Browse files
committed
feat: sub-store.json 初始化时, 支持读取 Base64 内容
1 parent 4c87196 commit fb7d663

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.19.88",
3+
"version": "2.19.89",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/vendor/open-api.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const isShadowRocket = 'undefined' !== typeof $rocket;
99
const isEgern = 'object' == typeof egern;
1010
const isLanceX = 'undefined' != typeof $native;
1111
const isGUIforCores = typeof $Plugins !== 'undefined';
12+
import { Base64 } from 'js-base64';
1213

1314
function isPlainObject(obj) {
1415
return (
@@ -120,13 +121,23 @@ export class OpenAPI {
120121
if (this.node.fs.existsSync(fpath)) {
121122
try {
122123
this.cache = JSON.parse(
123-
this.node.fs.readFileSync(`${fpath}`),
124+
this.node.fs.readFileSync(`${fpath}`, 'utf-8'),
124125
);
125126
} catch (e) {
126-
this.node.fs.copyFileSync(fpath, backupPath);
127-
this.error(
128-
`Failed to parse ${fpath}: ${e.message}. Backup created at ${backupPath}`,
129-
);
127+
try {
128+
const str = Base64.decode(
129+
this.node.fs.readFileSync(`${fpath}`, 'utf-8'),
130+
);
131+
this.cache = JSON.parse(str);
132+
this.node.fs.writeFileSync(fpath, str, {
133+
flag: 'w',
134+
});
135+
} catch (e) {
136+
this.node.fs.copyFileSync(fpath, backupPath);
137+
this.error(
138+
`Failed to parse ${fpath}: ${e.message}. Backup created at ${backupPath}`,
139+
);
140+
}
130141
}
131142
}
132143
if (!isPlainObject(this.cache)) {

0 commit comments

Comments
 (0)