feat: Introduce core application structure, configuration, monitoring, and team management features.
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
@@ -941,10 +943,44 @@ func (d *DB) DeleteCodexProxy(id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// ClearCodexProxies 清空所有代理
|
||||
func (d *DB) ClearCodexProxies() error {
|
||||
_, err := d.db.Exec("DELETE FROM codex_auth_proxies")
|
||||
return err
|
||||
// GetCodexProxyByID 获取指定 ID 的代理地址
|
||||
func (d *DB) GetCodexProxyByID(id int64) (string, error) {
|
||||
var proxyURL string
|
||||
err := d.db.QueryRow("SELECT proxy_url FROM codex_auth_proxies WHERE id = ?", id).Scan(&proxyURL)
|
||||
if err == sql.ErrNoRows {
|
||||
return "", nil
|
||||
}
|
||||
return proxyURL, err
|
||||
}
|
||||
|
||||
// ResolveProxy 解析代理字符串(支持 pool:random, pool:id:N, 或直接 URL)
|
||||
func (d *DB) ResolveProxy(proxyStr string) string {
|
||||
if proxyStr == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 兼容旧的 [RANDOM] 格式
|
||||
if proxyStr == "pool:random" || proxyStr == "[RANDOM]" {
|
||||
p, _ := d.GetRandomCodexProxy()
|
||||
return p
|
||||
}
|
||||
|
||||
// 处理 pool:id:N 格式
|
||||
if strings.HasPrefix(proxyStr, "pool:id:") {
|
||||
idStr := strings.TrimPrefix(proxyStr, "pool:id:")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err == nil {
|
||||
p, _ := d.GetCodexProxyByID(id)
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
// 否则视为字面 URL,如果没协议头加一个(保持现有行为)
|
||||
if !strings.HasPrefix(proxyStr, "http://") && !strings.HasPrefix(proxyStr, "https://") && !strings.HasPrefix(proxyStr, "socks5://") {
|
||||
return "http://" + proxyStr
|
||||
}
|
||||
|
||||
return proxyStr
|
||||
}
|
||||
|
||||
// GetCodexProxyStats 获取代理统计
|
||||
|
||||
Reference in New Issue
Block a user