Skip to content

Commit e4f646a

Browse files
committed
feat: 若设置 $options._res.headers, 拉取文件时将设置自定义响应头
1 parent 532be2f commit e4f646a

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

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.19.55",
3+
"version": "2.19.56",
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: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ async function getFile(req, res) {
150150
proxy,
151151
noCache,
152152
produceType,
153+
all: true,
153154
});
154155

155156
try {
@@ -184,9 +185,15 @@ async function getFile(req, res) {
184185
)}`,
185186
);
186187
}
187-
res.set('Content-Type', 'text/plain; charset=utf-8').send(
188-
output ?? '',
189-
);
188+
res.set('Content-Type', 'text/plain; charset=utf-8');
189+
if (output?.$options?._res?.headers) {
190+
Object.entries(output.$options._res.headers).forEach(
191+
([key, value]) => {
192+
res.set(key, value);
193+
},
194+
);
195+
}
196+
res.send(output?.$content ?? '');
190197
} catch (err) {
191198
$.notify(
192199
`🌍 Sub-Store 下载文件失败`,

backend/src/restful/sync.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ async function produceArtifact({
4040
$options,
4141
proxy,
4242
noCache,
43+
all,
4344
}) {
4445
platform = platform || 'JSON';
4546

@@ -595,7 +596,7 @@ async function produceArtifact({
595596
)
596597
: { $content: filesContent, $files: files, $options };
597598

598-
return processed?.$content ?? '';
599+
return (all ? processed : processed?.$content) ?? '';
599600
}
600601
}
601602

scripts/demo.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ function operator(proxies = [], targetPlatform, context) {
5959
// }
6060
// console.log($options)
6161

62+
// 若设置 $options._res.headers
63+
// 则会在输出文件时设置响应头, 例如:
64+
65+
// $options._res = {
66+
// headers: {
67+
// 'X-Custom': '1'
68+
// }
69+
// }
70+
6271
// targetPlatform 为输出的目标平台
6372

6473
// lodash

0 commit comments

Comments
 (0)