Skip to content

Commit b1af118

Browse files
committed
feat: 若设置 $options._res.status, 拉取文件时将设置自定义响应状态码
1 parent 3b3e34d commit b1af118

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.20.4",
3+
"version": "2.20.5",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/restful/file.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ async function getFile(req, res) {
183183
},
184184
);
185185
}
186+
if (output?.$options?._res?.status) {
187+
res.status(output.$options._res.status);
188+
}
186189
res.send(output?.$content ?? '');
187190
} catch (err) {
188191
$.notify(

scripts/demo.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ function operator(proxies = [], targetPlatform, context) {
6868
// }
6969
// }
7070

71+
// 若设置 $options._res.status
72+
// 则会在输出文件时设置响应状态码, 例如:
73+
74+
// $options._res = {
75+
// status: 404
76+
// }
77+
78+
// 一个示例: 请求来自分享且 ua 符合时, 返回自定义状态码和响应内容
79+
80+
// const { headers, url, path } = $options._req || {}
81+
// const ua = headers?.['user-agent'] || headers?.['User-Agent']
82+
83+
// if (/^\/share\//.test(url) && !/surge/i.test(ua)) {
84+
// $options._res = {
85+
// status: 418
86+
// }
87+
// $content = `I'm a teapot`
88+
// }
89+
7190
// targetPlatform 为输出的目标平台
7291

7392
// lodash

0 commit comments

Comments
 (0)