feat: 手动还原支持 Base64 文本文件

This commit is contained in:
xream
2025-07-19 12:55:32 +08:00
parent b3d66d42ff
commit 4c871964b0
2 changed files with 24 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.19.87",
"version": "2.19.88",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"scripts": {

View File

@@ -41,10 +41,30 @@ export default function register($app) {
);
})
.post((req, res) => {
const { content } = req.body;
$.write(content, '#sub-store');
let { content } = req.body;
try {
content = JSON.parse(Base64.decode(content));
if (Object.keys(content.settings).length === 0) {
throw new Error('备份文件应该至少包含 settings 字段');
}
} catch (err) {
try {
content = JSON.parse(content);
if (Object.keys(content.settings).length === 0) {
throw new Error('备份文件应该至少包含 settings 字段');
}
} catch (err) {
$.error(
`备份文件校验失败, 无法还原\nReason: ${
err.message ?? err
}`,
);
throw new Error('备份文件校验失败, 无法还原');
}
}
$.write(JSON.stringify(content, null, ` `), '#sub-store');
if ($.env.isNode) {
$.cache = JSON.parse(content);
$.cache = content;
$.persistCache();
}
migrate();