From b1af118ba5cf6a0113f0a5831ececfc8e0c219ef Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 15 Aug 2025 18:49:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=8B=A5=E8=AE=BE=E7=BD=AE=20$options.?= =?UTF-8?q?=5Fres.status,=20=E6=8B=89=E5=8F=96=E6=96=87=E4=BB=B6=E6=97=B6?= =?UTF-8?q?=E5=B0=86=E8=AE=BE=E7=BD=AE=E8=87=AA=E5=AE=9A=E4=B9=89=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E7=8A=B6=E6=80=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/file.js | 3 +++ scripts/demo.js | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index 0121c73a..b17b06b2 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.20.4", + "version": "2.20.5", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/file.js b/backend/src/restful/file.js index 286322cb..26c1765f 100644 --- a/backend/src/restful/file.js +++ b/backend/src/restful/file.js @@ -183,6 +183,9 @@ async function getFile(req, res) { }, ); } + if (output?.$options?._res?.status) { + res.status(output.$options._res.status); + } res.send(output?.$content ?? ''); } catch (err) { $.notify( diff --git a/scripts/demo.js b/scripts/demo.js index d7947b00..238476d3 100644 --- a/scripts/demo.js +++ b/scripts/demo.js @@ -68,6 +68,25 @@ function operator(proxies = [], targetPlatform, context) { // } // } + // 若设置 $options._res.status + // 则会在输出文件时设置响应状态码, 例如: + + // $options._res = { + // status: 404 + // } + + // 一个示例: 请求来自分享且 ua 符合时, 返回自定义状态码和响应内容 + + // const { headers, url, path } = $options._req || {} + // const ua = headers?.['user-agent'] || headers?.['User-Agent'] + + // if (/^\/share\//.test(url) && !/surge/i.test(ua)) { + // $options._res = { + // status: 418 + // } + // $content = `I'm a teapot` + // } + // targetPlatform 为输出的目标平台 // lodash