mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-10 00:52:40 +00:00
feat: sub-store.json 初始化时, 支持读取 Base64 内容
Some checks failed
build / build (push) Has been cancelled
Some checks failed
build / build (push) Has been cancelled
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
.DS_Store
|
||||
# json config
|
||||
sub-store.json
|
||||
sub-store_*.json
|
||||
root.json
|
||||
|
||||
# Logs
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.19.88",
|
||||
"version": "2.19.90",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
||||
25
backend/src/vendor/open-api.js
vendored
25
backend/src/vendor/open-api.js
vendored
@@ -9,6 +9,7 @@ const isShadowRocket = 'undefined' !== typeof $rocket;
|
||||
const isEgern = 'object' == typeof egern;
|
||||
const isLanceX = 'undefined' != typeof $native;
|
||||
const isGUIforCores = typeof $Plugins !== 'undefined';
|
||||
import { Base64 } from 'js-base64';
|
||||
|
||||
function isPlainObject(obj) {
|
||||
return (
|
||||
@@ -120,13 +121,27 @@ export class OpenAPI {
|
||||
if (this.node.fs.existsSync(fpath)) {
|
||||
try {
|
||||
this.cache = JSON.parse(
|
||||
this.node.fs.readFileSync(`${fpath}`),
|
||||
this.node.fs.readFileSync(`${fpath}`, 'utf-8'),
|
||||
);
|
||||
if (!isPlainObject(this.cache))
|
||||
throw new Error('Invalid Data');
|
||||
} catch (e) {
|
||||
this.node.fs.copyFileSync(fpath, backupPath);
|
||||
this.error(
|
||||
`Failed to parse ${fpath}: ${e.message}. Backup created at ${backupPath}`,
|
||||
);
|
||||
try {
|
||||
const str = Base64.decode(
|
||||
this.node.fs.readFileSync(`${fpath}`, 'utf-8'),
|
||||
);
|
||||
this.cache = JSON.parse(str);
|
||||
this.node.fs.writeFileSync(fpath, str, {
|
||||
flag: 'w',
|
||||
});
|
||||
if (!isPlainObject(this.cache))
|
||||
throw new Error('Invalid Data');
|
||||
} catch (e) {
|
||||
this.node.fs.copyFileSync(fpath, backupPath);
|
||||
this.error(
|
||||
`Failed to parse ${fpath}: ${e.message}. Backup created at ${backupPath}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isPlainObject(this.cache)) {
|
||||
|
||||
Reference in New Issue
Block a user