From b2b2e7d2f96df6b7e21e108846c41cd61091dd38 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 4 Sep 2026 22:36:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=AE=A2=E9=98=85/?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=BA=A7=E5=88=AB=E7=9A=84=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/preview.js | 4 +- backend/src/restful/sync.js | 2 +- backend/src/test/restful/file.spec.js | 58 +++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/backend/package.json b/backend/package.json index 6cb3f489..89c6c8f8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.38.1", + "version": "2.38.2", "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/restful/preview.js b/backend/src/restful/preview.js index 09258e21..3584ee69 100644 --- a/backend/src/restful/preview.js +++ b/backend/src/restful/preview.js @@ -106,7 +106,7 @@ async function compareSub(req, res) { sub.proxy, undefined, undefined, - undefined, + sub.noCache, true, { returnRaw: true }, ); @@ -266,7 +266,7 @@ async function compareCollection(req, res) { sub.proxy, undefined, undefined, - undefined, + sub.noCache, true, { returnRaw: true }, ); diff --git a/backend/src/restful/sync.js b/backend/src/restful/sync.js index dcef4ea2..d08fc57b 100644 --- a/backend/src/restful/sync.js +++ b/backend/src/restful/sync.js @@ -120,7 +120,7 @@ async function downloadFileSources({ file.proxy || proxy, undefined, undefined, - noCache, + noCache || file.noCache, undefined, { noFlow }, ); diff --git a/backend/src/test/restful/file.spec.js b/backend/src/test/restful/file.spec.js index 17e871bb..517f44cb 100644 --- a/backend/src/test/restful/file.spec.js +++ b/backend/src/test/restful/file.spec.js @@ -4,8 +4,11 @@ import { after, before, beforeEach, describe, it } from 'mocha'; import { FILES_KEY } from '@/constants'; let $; +let openApi; let registerFileRoutes; +let registerPreviewRoutes; let originalError; +let originalHTTP; let originalInfo; let originalNotify; let originalRead; @@ -104,6 +107,27 @@ async function requestFile(query = {}, { name = 'local-file' } = {}) { return res; } +async function preview(type, body) { + const app = createRouteApp(); + registerPreviewRoutes(app); + const path = `/api/preview/${type}`; + const res = createResponse(path); + + await app.handlers.get(`POST ${path}`)( + { + body, + headers: {}, + method: 'POST', + path, + query: {}, + url: path, + }, + res, + ); + + return res; +} + async function updateFile(data, { name = 'local-file' } = {}) { const handler = getHandler('/api/file/:name', 'PATCH'); const res = createResponse('/api/file/:name'); @@ -159,9 +183,12 @@ async function expectDecryptFailure(armored, secretKey) { describe('file routes', function () { before(async function () { ({ default: $ } = require('@/core/app')); + openApi = require('@/vendor/open-api'); ({ default: registerFileRoutes } = require('@/restful/file')); + ({ default: registerPreviewRoutes } = require('@/restful/preview')); ageUtils = require('@/utils/age'); + originalHTTP = openApi.HTTP; originalRead = $.read.bind($); originalWrite = $.write.bind($); originalInfo = $.info.bind($); @@ -179,9 +206,11 @@ describe('file routes', function () { $.error = originalError; $.notify = originalNotify; } + if (openApi) openApi.HTTP = originalHTTP; }); beforeEach(function () { + openApi.HTTP = originalHTTP; state = { [FILES_KEY]: [ { @@ -257,6 +286,35 @@ describe('file routes', function () { expect(res.sent).to.equal('base-script-carried'); }); + it('bypasses remote cache in subscription and file previews', async function () { + const requests = { sub: 0, file: 0 }; + openApi.HTTP = () => ({ + get: async ({ url }) => { + const type = url.includes('preview-sub') ? 'sub' : 'file'; + requests[type] += 1; + return { + body: + 'Cache = ss, 127.0.0.1, 8388, encrypt-method=aes-128-gcm, password=test', + headers: {}, + statusCode: 200, + }; + }, + }); + for (const type of ['sub', 'file']) { + const source = { + name: `preview-${type}`, + source: 'remote', + url: `https://example.com/preview-${type}-${Date.now()}`, + noCache: true, + process: [], + }; + await preview(type, source); + await preview(type, source); + } + + expect(requests).to.deep.equal({ sub: 2, file: 2 }); + }); + it('passes runtime file overrides to response transformers', async function () { state[FILES_KEY][0] = { name: 'local-file',