mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-30 08:28:10 +00:00
feat: 若设置 $options._res.status, 拉取文件时将设置自定义响应状态码
This commit is contained in:
3 files changed
+23
-1
No files matched your search
@@ -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": {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user