Compare commits

..

4 Commits

Author SHA1 Message Date
xream
f3200aea8c feat: 流量和同步配置也使用默认代理/策略 2024-10-07 18:34:39 +08:00
xream
e2346d16a2 feat: 新增全局代理/策略设置, 前端 > 2.14.265 2024-10-07 18:05:06 +08:00
xream
dc320eaa6c feat(file): 新增启用下载(文件名为显示名称), 前端 > 2.14.264 2024-10-07 17:26:15 +08:00
xream
02031019f7 doc: demo.js 2024-09-22 06:02:58 +08:00
6 changed files with 87 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.385",
"version": "2.14.388",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@@ -141,7 +141,14 @@ async function getFile(req, res) {
)}`,
);
}
if (file.download) {
res.set(
'Content-Disposition',
`attachment; filename*=UTF-8''${encodeURIComponent(
file.displayName || file.name,
)}`,
);
}
res.set('Content-Type', 'text/plain; charset=utf-8').send(
output ?? '',
);

View File

@@ -18,7 +18,7 @@ export default async function download(
rawUrl = '',
ua,
timeout,
proxy,
customProxy,
skipCustomCache,
awaitCustomCache,
) {
@@ -43,8 +43,9 @@ export default async function download(
}
}
const { isNode, isStash, isLoon, isShadowRocket, isQX } = ENV();
const { defaultUserAgent, defaultTimeout, cacheThreshold } =
const { defaultProxy, defaultUserAgent, defaultTimeout, cacheThreshold } =
$.read(SETTINGS_KEY);
const proxy = customProxy || defaultProxy;
const userAgent = ua || defaultUserAgent || 'clash.meta';
const requestTimeout = timeout || defaultTimeout;
const id = hex_md5(userAgent + url);

View File

@@ -10,7 +10,13 @@ export function getFlowField(headers) {
)[0];
return headers[subkey];
}
export async function getFlowHeaders(rawUrl, ua, timeout, proxy, flowUrl) {
export async function getFlowHeaders(
rawUrl,
ua,
timeout,
customProxy,
flowUrl,
) {
let url = flowUrl || rawUrl || '';
let $arguments = {};
const rawArgs = url.split('#');
@@ -41,7 +47,9 @@ export async function getFlowHeaders(rawUrl, ua, timeout, proxy, flowUrl) {
// $.info(`使用缓存的流量信息: ${url}`);
flowInfo = cached;
} else {
const { defaultFlowUserAgent, defaultTimeout } = $.read(SETTINGS_KEY);
const { defaultProxy, defaultFlowUserAgent, defaultTimeout } =
$.read(SETTINGS_KEY);
const proxy = customProxy || defaultProxy;
const userAgent =
ua ||
defaultFlowUserAgent ||
@@ -67,7 +75,7 @@ export async function getFlowHeaders(rawUrl, ua, timeout, proxy, flowUrl) {
$.info(
`使用 HEAD 方法从响应头获取流量信息: ${url}, User-Agent: ${
userAgent || ''
}`,
}, Proxy: ${proxy}`,
);
const { headers } = await http.head({
url: url
@@ -97,14 +105,14 @@ export async function getFlowHeaders(rawUrl, ua, timeout, proxy, flowUrl) {
$.error(
`使用 HEAD 方法从响应头获取流量信息失败: ${url}, User-Agent: ${
userAgent || ''
}: ${e.message ?? e}`,
}, Proxy: ${proxy}: ${e.message ?? e}`,
);
}
if (!flowInfo) {
$.info(
`使用 GET 方法获取流量信息: ${url}, User-Agent: ${
userAgent || ''
}`,
}, Proxy: ${proxy}`,
);
const { headers } = await http.get({
url: url
@@ -113,8 +121,21 @@ export async function getFlowHeaders(rawUrl, ua, timeout, proxy, flowUrl) {
.filter((i) => i.length)[0],
headers: {
'User-Agent': userAgent,
...(isStash && proxy
? {
'X-Stash-Selected-Proxy':
encodeURIComponent(proxy),
}
: {}),
...(isShadowRocket && proxy
? { 'X-Surge-Policy': proxy }
: {}),
},
timeout: requestTimeout,
...(proxy ? { proxy } : {}),
...(isLoon && proxy ? { node: proxy } : {}),
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
...(proxy ? getPolicyDescriptor(proxy) : {}),
});
flowInfo = getFlowField(headers);
}

View File

@@ -1,10 +1,17 @@
import { HTTP } from '@/vendor/open-api';
import { HTTP, ENV } from '@/vendor/open-api';
import { getPolicyDescriptor } from '@/utils';
import $ from '@/core/app';
import { SETTINGS_KEY } from '@/constants';
/**
* Gist backup
*/
export default class Gist {
constructor({ token, key, syncPlatform }) {
const { isStash, isLoon, isShadowRocket, isQX } = ENV();
const { defaultProxy: proxy, defaultTimeout: timeout } =
$.read(SETTINGS_KEY);
if (syncPlatform === 'gitlab') {
this.headers = {
'PRIVATE-TOKEN': `${token}`,
@@ -13,7 +20,25 @@ export default class Gist {
};
this.http = HTTP({
baseURL: 'https://gitlab.com/api/v4',
headers: { ...this.headers },
headers: {
...this.headers,
...(isStash && proxy
? {
'X-Stash-Selected-Proxy':
encodeURIComponent(proxy),
}
: {}),
...(isShadowRocket && proxy
? { 'X-Surge-Policy': proxy }
: {}),
},
...(proxy ? { proxy } : {}),
...(isLoon && proxy ? { node: proxy } : {}),
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
...(proxy ? getPolicyDescriptor(proxy) : {}),
timeout,
events: {
onResponse: (resp) => {
if (/^[45]/.test(String(resp.statusCode))) {
@@ -35,7 +60,25 @@ export default class Gist {
};
this.http = HTTP({
baseURL: 'https://api.github.com',
headers: { ...this.headers },
headers: {
...this.headers,
...(isStash && proxy
? {
'X-Stash-Selected-Proxy':
encodeURIComponent(proxy),
}
: {}),
...(isShadowRocket && proxy
? { 'X-Surge-Policy': proxy }
: {}),
},
...(proxy ? { proxy } : {}),
...(isLoon && proxy ? { node: proxy } : {}),
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
...(proxy ? getPolicyDescriptor(proxy) : {}),
timeout,
events: {
onResponse: (resp) => {
if (/^[45]/.test(String(resp.statusCode))) {

View File

@@ -18,6 +18,9 @@ function operator(proxies = [], targetPlatform, context) {
// 10. `sni` 在某些协议里会自动与 `servername` 转换
// 11. 读取节点的 ca-str 和 _ca (后端文件路径) 字段, 自动计算 fingerprint (参考 https://t.me/zhetengsha/1512)
// 12. 以 Surge 为例, 最新的参数一般我都会跟进, 以 Surge 文档为例, 一些常用的: TUIC/Hysteria 2 的 `ecn`, Snell 的 `reuse` 连接复用, QUIC 策略 block-quic`, Hysteria 2 下载带宽 `down`
// 13. `test-url` 为测延迟链接, `test-timeout` 为测延迟超时
// 14. `ports` 为端口跳跃, `hop-interval` 变换端口号的时间间隔
// 15. `ip-version` 设置节点使用 IP 版本可选dualipv4ipv6ipv4-preferipv6-prefer. 会进行内部转换, 若无法匹配则使用原始值
// require 为 Node.js 的 require, 在 Node.js 运行环境下 可以用来引入模块