Skip to content

Commit 84144ad

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

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
# json config
33
sub-store.json
4+
sub-store_*.json
45
root.json
56

67
# Logs

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.90",
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: 20 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,27 @@ 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
);
126+
if (!isPlainObject(this.cache))
127+
throw new Error('Invalid Data');
125128
} catch (e) {
126-
this.node.fs.copyFileSync(fpath, backupPath);
127-
this.error(
128-
`Failed to parse ${fpath}: ${e.message}. Backup created at ${backupPath}`,
129-
);
129+
try {
130+
const str = Base64.decode(
131+
this.node.fs.readFileSync(`${fpath}`, 'utf-8'),
132+
);
133+
this.cache = JSON.parse(str);
134+
this.node.fs.writeFileSync(fpath, str, {
135+
flag: 'w',
136+
});
137+
if (!isPlainObject(this.cache))
138+
throw new Error('Invalid Data');
139+
} catch (e) {
140+
this.node.fs.copyFileSync(fpath, backupPath);
141+
this.error(
142+
`Failed to parse ${fpath}: ${e.message}. Backup created at ${backupPath}`,
143+
);
144+
}
130145
}
131146
}
132147
if (!isPlainObject(this.cache)) {

0 commit comments

Comments
 (0)