From 19ccd79750557bc6ae418a590303665efe2d4332 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 21 Aug 2026 04:19:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AE=80=E5=8D=95=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=B8=8B=20Loon=20=E8=A7=A3=E6=9E=90=E5=99=A8=E7=AD=89?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=B8=AD=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/products/cron-sync-artifacts.js | 2 +- backend/src/restful/artifacts.js | 6 +++--- backend/src/restful/index.js | 4 ++-- backend/src/restful/miscs.js | 4 ++-- backend/src/restful/settings.js | 6 +++--- backend/src/test/utils/download.spec.js | 10 ++++++++++ backend/src/utils/create-item-position.js | 4 ++-- backend/src/utils/download.js | 2 +- backend/src/utils/flow.js | 2 +- backend/src/utils/gist.js | 2 +- backend/src/utils/headers-resource-cache.js | 2 +- backend/src/utils/resource-cache.js | 2 +- backend/src/utils/script-resource-cache.js | 2 +- 14 files changed, 30 insertions(+), 20 deletions(-) diff --git a/backend/package.json b/backend/package.json index 6b4fb1a5..83e598c3 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.36.38", + "version": "2.36.39", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "packageManager": "pnpm@11.0.9", diff --git a/backend/src/products/cron-sync-artifacts.js b/backend/src/products/cron-sync-artifacts.js index 1a2f0af9..491bec00 100644 --- a/backend/src/products/cron-sync-artifacts.js +++ b/backend/src/products/cron-sync-artifacts.js @@ -43,7 +43,7 @@ import { if (col_names.length > 0) await produceArtifacts(col_names, 'collection'); } else { - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; const artifacts = $.read(ARTIFACTS_KEY); if (!artifacts || artifacts.length === 0) return; diff --git a/backend/src/restful/artifacts.js b/backend/src/restful/artifacts.js index e7768470..65dbfd3d 100644 --- a/backend/src/restful/artifacts.js +++ b/backend/src/restful/artifacts.js @@ -64,7 +64,7 @@ export default function register($app) { async function restoreArtifacts(_, res) { $.info('开始恢复远程配置...'); try { - const { gistToken, syncPlatform } = $.read(SETTINGS_KEY); + const { gistToken, syncPlatform } = $.read(SETTINGS_KEY) || {}; if (!gistToken) { return Promise.reject('未设置 GitHub Token!'); } @@ -355,7 +355,7 @@ function getArtifactGistEmptyFileFallback() { } async function syncToGist(files, options = {}) { - const { gistToken, syncPlatform } = $.read(SETTINGS_KEY); + const { gistToken, syncPlatform } = $.read(SETTINGS_KEY) || {}; if (!gistToken) { return Promise.reject('未设置 GitHub Token!'); } @@ -398,7 +398,7 @@ async function syncToGist(files, options = {}) { } catch (e) {} const url = body?.html_url ?? body?.web_url; - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; if (url) { $.log(`同步 Gist 后, 找到 Sub-Store Gist: ${url}`); settings.artifactStore = url; diff --git a/backend/src/restful/index.js b/backend/src/restful/index.js index 39748b81..93aa8dd2 100644 --- a/backend/src/restful/index.js +++ b/backend/src/restful/index.js @@ -91,7 +91,7 @@ export default function serve() { next(); return; } else { - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; if (settings?.appearanceSetting?.invalidShareFakeNode) { req.query._fakeNode = true; req.url = req.url.replace( @@ -395,7 +395,7 @@ export default function serve() { name: req.params.name, }); if (!token) { - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; if ( settings?.appearanceSetting ?.invalidShareFakeNode diff --git a/backend/src/restful/miscs.js b/backend/src/restful/miscs.js index 05cbe202..daae7ec6 100644 --- a/backend/src/restful/miscs.js +++ b/backend/src/restful/miscs.js @@ -243,7 +243,7 @@ async function gistBackupAction( action, { keep, encode, tokenStrategy: queryTokenStrategy } = {}, ) { - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; const { gistToken, syncPlatform } = settings; if (!gistToken) throw new Error('GitHub Token is required for backup!'); @@ -397,7 +397,7 @@ async function gistBackupAction( async function gistBackup(req, res) { const { action, keep, encode, tokenStrategy } = req.query; // read token - const { gistToken } = $.read(SETTINGS_KEY); + const { gistToken } = $.read(SETTINGS_KEY) || {}; if (!gistToken) { failed( res, diff --git a/backend/src/restful/settings.js b/backend/src/restful/settings.js index 0891d2b4..94a12ce5 100644 --- a/backend/src/restful/settings.js +++ b/backend/src/restful/settings.js @@ -100,7 +100,7 @@ async function getSettings(req, res) { async function updateSettings(req, res) { try { - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; const newSettings = { ...settings, ...req.body, @@ -207,7 +207,7 @@ async function updateSettings(req, res) { } export async function updateAvatar() { - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; const { githubUser: username, syncPlatform, @@ -273,7 +273,7 @@ export async function updateAvatar() { export async function updateArtifactStore() { $.log('Updating artifact store'); - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; const { gistToken, syncPlatform } = settings; if (gistToken) { const manager = new Gist({ diff --git a/backend/src/test/utils/download.spec.js b/backend/src/test/utils/download.spec.js index fbd0940e..f5e729f7 100644 --- a/backend/src/test/utils/download.spec.js +++ b/backend/src/test/utils/download.spec.js @@ -160,6 +160,16 @@ describe('download github proxy regex', function () { expect(capturedUrls).to.deep.equal(['https://example.com/archive.txt']); }); + it('uses download defaults when settings are missing', async function () { + delete state[SETTINGS_KEY]; + + await download('https://example.com/no-settings.txt'); + + expect(capturedUrls).to.deep.equal([ + 'https://example.com/no-settings.txt', + ]); + }); + it('matches regex patterns case-insensitively by default', async function () { state[SETTINGS_KEY].githubProxyRegex = '^https://RAW\\.GITHUBUSERCONTENT\\.COM'; diff --git a/backend/src/utils/create-item-position.js b/backend/src/utils/create-item-position.js index b1ac6169..17207a69 100644 --- a/backend/src/utils/create-item-position.js +++ b/backend/src/utils/create-item-position.js @@ -2,8 +2,8 @@ import { SETTINGS_KEY } from '@/constants'; import $ from '@/core/app'; export function getCreateItemPosition() { - const createItemPosition = - $.read(SETTINGS_KEY)?.appearanceSetting?.createItemPosition; + const createItemPosition = ($.read(SETTINGS_KEY) || {}).appearanceSetting + ?.createItemPosition; return createItemPosition === 'top' ? 'top' : 'bottom'; } diff --git a/backend/src/utils/download.js b/backend/src/utils/download.js index 8a60e6de..f8fccd95 100644 --- a/backend/src/utils/download.js +++ b/backend/src/utils/download.js @@ -170,7 +170,7 @@ export default async function download( defaultUserAgent, defaultTimeout, cacheThreshold: defaultCacheThreshold, - } = $.read(SETTINGS_KEY); + } = $.read(SETTINGS_KEY) || {}; const cacheThreshold = defaultCacheThreshold || 1024; let proxy = customProxy || defaultProxy; if ($.env.isNode) { diff --git a/backend/src/utils/flow.js b/backend/src/utils/flow.js index 9590e40b..7e47968f 100644 --- a/backend/src/utils/flow.js +++ b/backend/src/utils/flow.js @@ -64,7 +64,7 @@ export async function getFlowHeaders( : { insecure: true } : undefined; const { defaultProxy, defaultFlowUserAgent, defaultTimeout } = - $.read(SETTINGS_KEY); + $.read(SETTINGS_KEY) || {}; let proxy = customProxy || defaultProxy; if ($.env.isNode) { proxy = proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY'); diff --git a/backend/src/utils/gist.js b/backend/src/utils/gist.js index 1c85dba9..3fe4a432 100644 --- a/backend/src/utils/gist.js +++ b/backend/src/utils/gist.js @@ -57,7 +57,7 @@ export default class Gist { constructor({ token, key, syncPlatform }) { const { isStash, isLoon, isShadowRocket, isQX } = ENV(); const { defaultProxy, githubApiTimeout, githubProxy, githubApiUrl } = - $.read(SETTINGS_KEY); + $.read(SETTINGS_KEY) || {}; const githubApiRequestTimeout = githubApiTimeout || 10000; const githubGistBaseURL = getGithubGistBaseURL({ githubApiUrl, diff --git a/backend/src/utils/headers-resource-cache.js b/backend/src/utils/headers-resource-cache.js index 3bfee3fa..3a677e98 100644 --- a/backend/src/utils/headers-resource-cache.js +++ b/backend/src/utils/headers-resource-cache.js @@ -89,7 +89,7 @@ function normalizeTTL(ttl) { } function getTTL() { - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; let ttl = settings?.headersCacheTtl; if (ttl) { ttl = Number(ttl); diff --git a/backend/src/utils/resource-cache.js b/backend/src/utils/resource-cache.js index 63bf5b8d..d89df5ce 100644 --- a/backend/src/utils/resource-cache.js +++ b/backend/src/utils/resource-cache.js @@ -89,7 +89,7 @@ function normalizeTTL(ttl) { } function getTTL() { - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; let ttl = settings?.resourceCacheTtl; if (ttl) { ttl = Number(ttl); diff --git a/backend/src/utils/script-resource-cache.js b/backend/src/utils/script-resource-cache.js index ef2c8ea0..4434fcd5 100644 --- a/backend/src/utils/script-resource-cache.js +++ b/backend/src/utils/script-resource-cache.js @@ -89,7 +89,7 @@ function normalizeTTL(ttl) { } function getTTL() { - const settings = $.read(SETTINGS_KEY); + const settings = $.read(SETTINGS_KEY) || {}; let ttl = settings?.scriptCacheTtl; if (ttl) { ttl = Number(ttl);