磁链增加代理配置
This commit is contained in:
@@ -30,6 +30,11 @@ export interface AdminConfig {
|
||||
PansouUsername?: string;
|
||||
PansouPassword?: string;
|
||||
PansouKeywordBlocklist?: string;
|
||||
// 磁链配置
|
||||
MagnetProxy?: string;
|
||||
MagnetMikanReverseProxy?: string;
|
||||
MagnetDmhyReverseProxy?: string;
|
||||
MagnetAcgripReverseProxy?: string;
|
||||
// 评论功能开关
|
||||
EnableComments: boolean;
|
||||
// 自定义去广告代码
|
||||
|
||||
@@ -256,6 +256,11 @@ async function getInitConfig(configFile: string, subConfig: {
|
||||
PansouUsername: '',
|
||||
PansouPassword: '',
|
||||
PansouKeywordBlocklist: '',
|
||||
// 磁链配置
|
||||
MagnetProxy: '',
|
||||
MagnetMikanReverseProxy: '',
|
||||
MagnetDmhyReverseProxy: '',
|
||||
MagnetAcgripReverseProxy: '',
|
||||
// 评论功能开关
|
||||
EnableComments: false,
|
||||
},
|
||||
@@ -432,6 +437,10 @@ export function configSelfCheck(adminConfig: AdminConfig): AdminConfig {
|
||||
PansouUsername: '',
|
||||
PansouPassword: '',
|
||||
PansouKeywordBlocklist: '',
|
||||
MagnetProxy: '',
|
||||
MagnetMikanReverseProxy: '',
|
||||
MagnetDmhyReverseProxy: '',
|
||||
MagnetAcgripReverseProxy: '',
|
||||
EnableComments: false,
|
||||
};
|
||||
}
|
||||
@@ -449,6 +458,18 @@ export function configSelfCheck(adminConfig: AdminConfig): AdminConfig {
|
||||
if (adminConfig.SiteConfig.PansouKeywordBlocklist === undefined) {
|
||||
adminConfig.SiteConfig.PansouKeywordBlocklist = '';
|
||||
}
|
||||
if (adminConfig.SiteConfig.MagnetProxy === undefined) {
|
||||
adminConfig.SiteConfig.MagnetProxy = '';
|
||||
}
|
||||
if (adminConfig.SiteConfig.MagnetMikanReverseProxy === undefined) {
|
||||
adminConfig.SiteConfig.MagnetMikanReverseProxy = '';
|
||||
}
|
||||
if (adminConfig.SiteConfig.MagnetDmhyReverseProxy === undefined) {
|
||||
adminConfig.SiteConfig.MagnetDmhyReverseProxy = '';
|
||||
}
|
||||
if (adminConfig.SiteConfig.MagnetAcgripReverseProxy === undefined) {
|
||||
adminConfig.SiteConfig.MagnetAcgripReverseProxy = '';
|
||||
}
|
||||
if (!adminConfig.UserConfig) {
|
||||
adminConfig.UserConfig = { Users: [] };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||
import nodeFetch from 'node-fetch';
|
||||
|
||||
function isCloudflareEnvironment(): boolean {
|
||||
return process.env.CF_PAGES === '1' || process.env.BUILD_TARGET === 'cloudflare';
|
||||
}
|
||||
|
||||
export function getMagnetBaseUrl(defaultBaseUrl: string, reverseProxyBaseUrl?: string): string {
|
||||
return (reverseProxyBaseUrl || defaultBaseUrl).replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
export async function universalMagnetFetch(
|
||||
url: string,
|
||||
proxy?: string,
|
||||
init?: RequestInit
|
||||
): Promise<Response> {
|
||||
if (isCloudflareEnvironment()) {
|
||||
const response = await fetch(url, {
|
||||
...init,
|
||||
signal: AbortSignal.timeout(15000),
|
||||
});
|
||||
return response as unknown as Response;
|
||||
}
|
||||
|
||||
const fetchOptions: any = proxy
|
||||
? {
|
||||
...init,
|
||||
agent: new HttpsProxyAgent(proxy, {
|
||||
timeout: 30000,
|
||||
keepAlive: false,
|
||||
}),
|
||||
signal: AbortSignal.timeout(30000),
|
||||
}
|
||||
: {
|
||||
...init,
|
||||
signal: AbortSignal.timeout(15000),
|
||||
};
|
||||
|
||||
return nodeFetch(url, fetchOptions) as unknown as Response;
|
||||
}
|
||||
Reference in New Issue
Block a user