Skip to content

Commit 4c87196

Browse files
committed
feat: 手动还原支持 Base64 文本文件
1 parent b3d66d4 commit 4c87196

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
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.87",
3+
"version": "2.19.88",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/restful/miscs.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,30 @@ export default function register($app) {
4141
);
4242
})
4343
.post((req, res) => {
44-
const { content } = req.body;
45-
$.write(content, '#sub-store');
44+
let { content } = req.body;
45+
try {
46+
content = JSON.parse(Base64.decode(content));
47+
if (Object.keys(content.settings).length === 0) {
48+
throw new Error('备份文件应该至少包含 settings 字段');
49+
}
50+
} catch (err) {
51+
try {
52+
content = JSON.parse(content);
53+
if (Object.keys(content.settings).length === 0) {
54+
throw new Error('备份文件应该至少包含 settings 字段');
55+
}
56+
} catch (err) {
57+
$.error(
58+
`备份文件校验失败, 无法还原\nReason: ${
59+
err.message ?? err
60+
}`,
61+
);
62+
throw new Error('备份文件校验失败, 无法还原');
63+
}
64+
}
65+
$.write(JSON.stringify(content, null, ` `), '#sub-store');
4666
if ($.env.isNode) {
47-
$.cache = JSON.parse(content);
67+
$.cache = content;
4868
$.persistCache();
4969
}
5070
migrate();

0 commit comments

Comments
 (0)