From 000e90d1141bb384e1142541b4b44d2bd9936d8d Mon Sep 17 00:00:00 2001 From: xream Date: Mon, 4 Dec 2023 16:07:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=8B=E5=8A=A8=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=96=87=E4=BB=B6=E5=92=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E4=B8=8A=E4=BC=A0=E6=81=A2=E5=A4=8D(?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E7=89=88=E6=9C=AC=20>=20`2.14.15`)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/miscs.js | 22 ++++++++++++++++++---- backend/src/restful/settings.js | 7 ++++++- 3 files changed, 25 insertions(+), 6 deletions(-) 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);