From ce6cd794c8302257dfdd14cd64b74fb90d42c881 Mon Sep 17 00:00:00 2001 From: xream Date: Wed, 13 Dec 2023 09:54:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=20?= =?UTF-8?q?`SUB=5FSTORE=5FDATA=5FURL`=20=E5=90=AF=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=BB=8E=E6=AD=A4=E5=9C=B0=E5=9D=80=E6=8B=89?= =?UTF-8?q?=E5=8F=96=E5=B9=B6=E6=81=A2=E5=A4=8D=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/index.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index cb71c1c..7f7ce35 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.126", + "version": "2.14.127", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/index.js b/backend/src/restful/index.js index 185d59b..940056a 100644 --- a/backend/src/restful/index.js +++ b/backend/src/restful/index.js @@ -1,5 +1,7 @@ import express from '@/vendor/express'; import $ from '@/core/app'; +import migrate from '@/utils/migration'; +import download from '@/utils/download'; import registerSubscriptionRoutes from './subscriptions'; import registerCollectionRoutes from './collections'; @@ -41,6 +43,7 @@ export default function serve() { if ($.env.isNode) { const path = eval(`require("path")`); const fs = eval(`require("fs")`); + const data_url = eval('process.env.SUB_STORE_DATA_URL'); const fe_be_path = eval('process.env.SUB_STORE_FRONTEND_BACKEND_PATH'); const fe_port = eval('process.env.SUB_STORE_FRONTEND_PORT') || 3001; const fe_host = @@ -133,5 +136,23 @@ export default function serve() { } }); } + if (data_url) { + $.info(`[BACKEND] downloading data from ${data_url}`); + download(data_url) + .then((content) => { + $.write(content, '#sub-store'); + + $.cache = JSON.parse(content); + $.persistCache(); + + migrate(); + $.info(`[BACKEND] restored data from ${data_url}`); + }) + .catch((e) => { + $.error(`[BACKEND] restore data failed`); + console.error(e); + throw e; + }); + } } }