From 217fdae7f178dd8390b7dcd12088ba40bed29020 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 18 Jul 2025 16:10:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Node=20=E7=8E=AF=E5=A2=83=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20SUB=5FSTORE=5FDATA=5FURL=20=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E5=90=8E,=20=E6=94=AF=E6=8C=81=20SUB=5FSTORE?= =?UTF-8?q?=5FDATA=5FURL=5FPOST=20=E6=89=A7=E8=A1=8C=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/index.js | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/backend/package.json b/backend/package.json index e0aae64..e9a2a9e 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.19.83", + "version": "2.19.84", "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 1f784d9..152d5a5 100644 --- a/backend/src/restful/index.js +++ b/backend/src/restful/index.js @@ -1,3 +1,4 @@ +import _ from 'lodash'; import express from '@/vendor/express'; import $ from '@/core/app'; import migrate from '@/utils/migration'; @@ -304,6 +305,7 @@ export default function serve() { const path = eval(`require("path")`); const fs = eval(`require("fs")`); const data_url = eval('process.env.SUB_STORE_DATA_URL'); + const data_url_post = eval('process.env.SUB_STORE_DATA_URL_POST'); 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 = @@ -424,10 +426,30 @@ export default function serve() { if (data_url) { $.info(`[BACKEND] downloading data from ${data_url}`); download(data_url) - .then((content) => { - $.write(content, '#sub-store'); + .then(async (content) => { + try { + content = JSON.parse(content); + if (Object.keys(content.settings).length === 0) { + throw new Error( + '备份文件应该至少包含 settings 字段', + ); + } + } catch (err) { + $.error( + `Gist 备份文件校验失败, 无法还原\nReason: ${ + err.message ?? err + }`, + ); + throw new Error('Gist 备份文件校验失败, 无法还原'); + } + if (data_url_post) { + $.info('[BACKEND] executing post-processing script'); + eval(data_url_post); + } - $.cache = JSON.parse(content); + $.write(JSON.stringify(content, null, ` `), '#sub-store'); + + $.cache = content; $.persistCache(); migrate();