feat: 为 Gist 备份还原增加基础校验逻辑

This commit is contained in:
xream
2023-09-04 17:06:37 +08:00
parent 362cbe9686
commit b2878d8a2a
3 changed files with 19 additions and 2 deletions

View File

@@ -118,6 +118,23 @@ async function gistBackup(req, res) {
case 'download':
$.info(`还原备份中...`);
content = await gist.download(GIST_BACKUP_FILE_NAME);
try {
if (
Object.keys(JSON.parse(content).settings).length ===
0
) {
throw new Error(
'备份文件应该至少包含 settings 字段',
);
}
} catch (err) {
$.error(
`Gist 备份文件校验失败, 无法还原\nReason: ${
err.message ?? err
}`,
);
throw new Error('Gist 备份文件校验失败, 无法还原');
}
// restore settings
$.write(content, '#sub-store');
if ($.env.isNode) {