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 f3200aea8c
commit 6d43961e96
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
6 changed files with 18 additions and 5 deletions

View File

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

View File

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

View File

@ -45,7 +45,10 @@ export default async function download(
const { isNode, isStash, isLoon, isShadowRocket, isQX } = ENV(); const { isNode, isStash, isLoon, isShadowRocket, isQX } = ENV();
const { defaultProxy, defaultUserAgent, defaultTimeout, cacheThreshold } = const { defaultProxy, defaultUserAgent, defaultTimeout, cacheThreshold } =
$.read(SETTINGS_KEY); $.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 userAgent = ua || defaultUserAgent || 'clash.meta';
const requestTimeout = timeout || defaultTimeout; const requestTimeout = timeout || defaultTimeout;
const id = hex_md5(userAgent + url); const id = hex_md5(userAgent + url);

View File

@ -49,7 +49,11 @@ export async function getFlowHeaders(
} else { } else {
const { defaultProxy, defaultFlowUserAgent, defaultTimeout } = const { defaultProxy, defaultFlowUserAgent, defaultTimeout } =
$.read(SETTINGS_KEY); $.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 = const userAgent =
ua || ua ||
defaultFlowUserAgent || defaultFlowUserAgent ||

View File

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

View File

@ -66,6 +66,7 @@ function operator(proxies = [], targetPlatform, context) {
// removeFlag, // 移除 emoji 旗帜 // removeFlag, // 移除 emoji 旗帜
// getISO, // 获取 ISO 3166-1 alpha-2 代码 // getISO, // 获取 ISO 3166-1 alpha-2 代码
// Gist, // Gist 类 // Gist, // Gist 类
// download, // 内部的下载方法, 见 backend/src/utils/download.js
// } // }
// 如果只是为了快速修改或者筛选 可以参考 脚本操作支持节点快捷脚本 https://t.me/zhetengsha/970 和 脚本筛选支持节点快捷脚本 https://t.me/zhetengsha/1009 // 如果只是为了快速修改或者筛选 可以参考 脚本操作支持节点快捷脚本 https://t.me/zhetengsha/970 和 脚本筛选支持节点快捷脚本 https://t.me/zhetengsha/1009