forked from aurora-develop/aurora
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 正式接入抽离的客户端库。 * 整理main包,把所有初始化任务抽离出来。尝试集成vercel的api请求模式。 * 整理main包,把所有初始化任务抽离出来。尝试集成vercel的api请求模式。将funcaptcha、tls-client、endless包更到最新。 * 可以设置是否支持流式传输。 --------- Co-authored-by: xiaozhou26 <[email protected]>
- Loading branch information
1 parent
1dd8a15
commit ca2fbf4
Showing
14 changed files
with
152 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package api | ||
|
||
import ( | ||
"aurora/initialize" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
var router *gin.Engine | ||
|
||
func init() { | ||
// 初始化gin | ||
router = initialize.RegisterRouter() | ||
} | ||
|
||
func Listen(w http.ResponseWriter, r *http.Request) { | ||
router.ServeHTTP(w, r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package initialize | ||
|
||
import ( | ||
"bufio" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package initialize | ||
|
||
import ( | ||
"aurora/internal/proxys" | ||
"bufio" | ||
"log/slog" | ||
"net/url" | ||
"os" | ||
) | ||
|
||
func checkProxy() *proxys.IProxy { | ||
var proxies []string | ||
proxyUrl := os.Getenv("PROXY_URL") | ||
if proxyUrl != "" { | ||
proxies = append(proxies, proxyUrl) | ||
} | ||
|
||
if _, err := os.Stat("proxies.txt"); err == nil { | ||
file, _ := os.Open("proxies.txt") | ||
defer file.Close() | ||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
proxy := scanner.Text() | ||
parsedURL, err := url.Parse(proxy) | ||
if err != nil { | ||
slog.Warn("proxy url is invalid", "url", proxy, "err", err) | ||
continue | ||
} | ||
|
||
// 如果缺少端口信息,不是完整的代理链接 | ||
if parsedURL.Port() != "" { | ||
proxies = append(proxies, proxy) | ||
} else { | ||
continue | ||
} | ||
} | ||
} | ||
|
||
if len(proxies) == 0 { | ||
proxy := os.Getenv("http_proxy") | ||
if proxy != "" { | ||
proxies = append(proxies, proxy) | ||
} | ||
} | ||
|
||
proxyIP := proxys.NewIProxyIP(proxies) | ||
return &proxyIP | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package initialize | ||
|
||
import ( | ||
"aurora/middlewares" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func RegisterRouter() *gin.Engine { | ||
handler := NewHandle( | ||
checkProxy(), | ||
readAccessToken(), | ||
) | ||
|
||
router := gin.Default() | ||
router.Use(middlewares.Cors) | ||
|
||
router.GET("/", func(c *gin.Context) { | ||
c.JSON(200, gin.H{ | ||
"message": "Hello, world!", | ||
}) | ||
}) | ||
|
||
router.GET("/ping", func(c *gin.Context) { | ||
c.JSON(200, gin.H{ | ||
"message": "pong", | ||
}) | ||
}) | ||
|
||
router.POST("/auth/session", handler.session) | ||
router.POST("/auth/refresh", handler.refresh) | ||
router.OPTIONS("/v1/chat/completions", optionsHandler) | ||
|
||
authGroup := router.Group("").Use(middlewares.Authorization) | ||
authGroup.POST("/v1/chat/completions", handler.nightmare) | ||
authGroup.GET("/v1/models", handler.engines) | ||
return router | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.