Skip to content

Commit

Permalink
fix: 修复 代理依赖升级导致的错误;优化 Server 酱³ 调用方式为 安全模式
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Nov 7, 2024
1 parent b9d24aa commit 40b9888
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/push/server-chan-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class ServerChanV3 implements Send {
*/
private sendkey: string

private uid: string = ''

/**
* @author CaoMeiYouRen
* @date 2024-10-04
Expand All @@ -42,6 +44,10 @@ export class ServerChanV3 implements Send {
if (!this.sendkey) {
throw new Error('sendkey 是必须的!')
}
this.uid = this.sendkey.match(/^sctp(\d+)t/)?.[1]
if (!this.uid) {
throw new Error('sendkey 不合法!')
}
}

async send(text: string, desp: string = '', options: ServerChanV3Options = {}): Promise<any> {
Expand All @@ -55,7 +61,7 @@ export class ServerChanV3 implements Send {
...options,
}
return ajax({
url: `https://${this.sendkey}.push.ft07.com/send`,
url: `https://${this.uid}.push.ft07.com/send/${this.sendkey}.send`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
14 changes: 7 additions & 7 deletions src/utils/ajax.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios, { AxiosResponse, Method, AxiosRequestHeaders } from 'axios'
import debug from 'debug'
import HttpsProxyAgent from 'https-proxy-agent'
import SocksProxyAgent from 'socks-proxy-agent'
import { HttpsProxyAgent } from 'https-proxy-agent'
import { SocksProxyAgent } from 'socks-proxy-agent'
import { isHttpURL, isSocksUrl } from './helper'

const Debugger = debug('push:ajax')
Expand Down Expand Up @@ -43,15 +43,15 @@ export async function ajax<T = any>(config: AjaxConfig): Promise<AxiosResponse<T
Debugger('HTTPS_PROXY: %s', process.env.HTTPS_PROXY)
Debugger('SOCKS_PROXY: %s', process.env.SOCKS_PROXY)
if (isHttpURL(proxyUrl)) {
httpAgent = HttpsProxyAgent(proxyUrl)
httpAgent = new HttpsProxyAgent(proxyUrl)
} else if (isSocksUrl(proxyUrl)) {
httpAgent = SocksProxyAgent(proxyUrl)
httpAgent = new SocksProxyAgent(proxyUrl)
} else if (process.env.HTTPS_PROXY) {
httpAgent = HttpsProxyAgent(process.env.HTTPS_PROXY)
httpAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY)
} else if (process.env.HTTP_PROXY) {
httpAgent = HttpsProxyAgent(process.env.HTTP_PROXY)
httpAgent = new HttpsProxyAgent(process.env.HTTP_PROXY)
} else if (process.env.SOCKS_PROXY) {
httpAgent = SocksProxyAgent(process.env.SOCKS_PROXY)
httpAgent = new SocksProxyAgent(process.env.SOCKS_PROXY)
}
}
const response = await axios(url, {
Expand Down

0 comments on commit 40b9888

Please sign in to comment.