mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
33 lines
753 B
JavaScript
33 lines
753 B
JavaScript
// workaround for ver 7.x and ver 5.x
|
|
import HttpsProxyAgent from 'https-proxy-agent'
|
|
import { Config } from './config.js'
|
|
import fetch from 'node-fetch'
|
|
|
|
let proxy = HttpsProxyAgent
|
|
if (typeof proxy !== 'function') {
|
|
proxy = (p) => {
|
|
return new HttpsProxyAgent.HttpsProxyAgent(p)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* return a proxy function
|
|
* @returns {*|createHttpsProxyAgent|((opts: (string | createHttpsProxyAgent.HttpsProxyAgentOptions)) => HttpsProxyAgent)}
|
|
*/
|
|
export function getProxy () {
|
|
return proxy
|
|
}
|
|
|
|
export const newFetch = (url, options = {}) => {
|
|
const defaultOptions = Config.proxy
|
|
? {
|
|
agent: proxy(Config.proxy)
|
|
}
|
|
: {}
|
|
const mergedOptions = {
|
|
...defaultOptions,
|
|
...options
|
|
}
|
|
|
|
return fetch(url, mergedOptions)
|
|
}
|