Skip to content

Commit

Permalink
feat: 手动下载备份文件和使用备份上传恢复(前端版本 > 2.14.15)
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Dec 4, 2023
1 parent c2499f6 commit 000e90d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.109",
"version": "2.14.110",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
22 changes: 18 additions & 4 deletions backend/src/restful/miscs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,26 @@ export default function register($app) {
// Storage management
$app.route('/api/storage')
.get((req, res) => {
res.json($.read('#sub-store'));
res.set('content-type', 'application/json')
.set(
'content-disposition',
'attachment; filename="sub-store.json"',
)
.send(
$.env.isNode
? JSON.stringify($.cache)
: $.read('#sub-store'),
);
})
.post((req, res) => {
const data = req.body;
$.write(JSON.stringify(data), '#sub-store');
res.end();
const { content } = req.body;
$.write(content, '#sub-store');
if ($.env.isNode) {
$.cache = JSON.parse(content);
$.persistCache();
}
migrate();
success(res);
});

// Redirect sub.store to vercel webpage
Expand Down
7 changes: 6 additions & 1 deletion backend/src/restful/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ export default function register($app) {
}

async function getSettings(req, res) {
const settings = $.read(SETTINGS_KEY);
let settings = $.read(SETTINGS_KEY);
if (!settings) {
settings = {};
$.write(settings, SETTINGS_KEY);
}

if (!settings.avatarUrl) await updateGitHubAvatar();
if (!settings.artifactStore) await updateArtifactStore();
success(res, settings);
Expand Down

0 comments on commit 000e90d

Please sign in to comment.