diff --git a/backend/package.json b/backend/package.json index e1ea87dc0..d60e71e6d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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": { diff --git a/backend/src/restful/miscs.js b/backend/src/restful/miscs.js index b527a48a2..6b62c4839 100644 --- a/backend/src/restful/miscs.js +++ b/backend/src/restful/miscs.js @@ -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 diff --git a/backend/src/restful/settings.js b/backend/src/restful/settings.js index d8f9e7d60..d80f48ee8 100644 --- a/backend/src/restful/settings.js +++ b/backend/src/restful/settings.js @@ -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);