🔖 chore: Rename relay/util to relay/relay_util package and add utils package

This commit is contained in:
MartialBE
2024-05-29 00:36:54 +08:00
parent 853f2681f4
commit 79524108a3
61 changed files with 309 additions and 265 deletions

View File

@@ -2,6 +2,7 @@ package telegram
import (
"one-api/common"
"one-api/common/utils"
"strings"
"github.com/PaulSonOfLars/gotgbot/v2"
@@ -15,7 +16,7 @@ func commandAffStart(b *gotgbot.Bot, ctx *ext.Context) error {
}
if user.AffCode == "" {
user.AffCode = common.GetRandomString(4)
user.AffCode = utils.GetRandomString(4)
if err := user.Update(false); err != nil {
ctx.EffectiveMessage.Reply(b, "系统错误,请稍后再试", nil)
return nil

View File

@@ -1,8 +1,10 @@
package telegram
import (
"context"
"errors"
"fmt"
"net"
"net/http"
"net/url"
"one-api/common"
@@ -243,22 +245,16 @@ func getHttpClient() (httpClient *http.Client) {
},
}
case "socks5":
var auth *proxy.Auth = nil
password, isSetPassword := proxyURL.User.Password()
if isSetPassword {
auth = &proxy.Auth{
User: proxyURL.User.Username(),
Password: password,
}
}
dialer, err := proxy.SOCKS5("tcp", proxyURL.Host, auth, proxy.Direct)
dialer, err := proxy.FromURL(proxyURL, proxy.Direct)
if err != nil {
common.SysLog("failed to create TG SOCKS5 dialer: " + err.Error())
return
}
httpClient = &http.Client{
Transport: &http.Transport{
Dial: dialer.Dial,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return dialer.(proxy.ContextDialer).DialContext(ctx, network, addr)
},
},
}
default: