feat: Node.js 支持使用环境变量 SUB_STORE_BACKEND_DEFAULT_PROXY 设置默认代理; ProxyUtils 增加 download 方法

This commit is contained in:
xream
2024-10-07 18:43:29 +08:00
parent 6d86235040
commit ac75b9e78b
6 changed files with 18 additions and 5 deletions

View File

@@ -292,6 +292,7 @@ export const ProxyUtils = {
getISO,
MMDB,
Gist,
download,
};
function tryParse(parser, line) {

View File

@@ -45,7 +45,10 @@ export default async function download(
const { isNode, isStash, isLoon, isShadowRocket, isQX } = ENV();
const { defaultProxy, defaultUserAgent, defaultTimeout, cacheThreshold } =
$.read(SETTINGS_KEY);
const proxy = customProxy || defaultProxy;
let proxy = customProxy || defaultProxy;
if ($.env.isNode) {
proxy = proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY');
}
const userAgent = ua || defaultUserAgent || 'clash.meta';
const requestTimeout = timeout || defaultTimeout;
const id = hex_md5(userAgent + url);

View File

@@ -49,7 +49,11 @@ export async function getFlowHeaders(
} else {
const { defaultProxy, defaultFlowUserAgent, defaultTimeout } =
$.read(SETTINGS_KEY);
const proxy = customProxy || defaultProxy;
let proxy = customProxy || defaultProxy;
if ($.env.isNode) {
proxy =
proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY');
}
const userAgent =
ua ||
defaultFlowUserAgent ||

View File

@@ -9,8 +9,12 @@ import { SETTINGS_KEY } from '@/constants';
export default class Gist {
constructor({ token, key, syncPlatform }) {
const { isStash, isLoon, isShadowRocket, isQX } = ENV();
const { defaultProxy: proxy, defaultTimeout: timeout } =
$.read(SETTINGS_KEY);
const { defaultProxy, defaultTimeout: timeout } = $.read(SETTINGS_KEY);
let proxy = defaultProxy;
if ($.env.isNode) {
proxy =
proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY');
}
if (syncPlatform === 'gitlab') {
this.headers = {