fix some bug

This commit is contained in:
luyoyu 2023-09-21 03:15:57 +08:00
parent 390aa9429b
commit 15e82057af
4 changed files with 12 additions and 11 deletions

View File

@ -51,9 +51,11 @@ set "GITHUB_SERVER_URL=https://github.com"
##### 2.测试 ##### 2.测试
如图代码提示已经走代理服务器了这样就全是走一个ip了虽然不知道有没有意义 代码提示已经走代理服务器了这样就全是走一个ip了虽然不知道有没有意义
如果你是贩子,甚至可以搞点小动作
如果你是贩子,甚至可以搞点有意思的东西

View File

@ -19,6 +19,8 @@ type Config struct {
Token []string `json:"token"` Token []string `json:"token"`
} `json:"copilot_config"` } `json:"copilot_config"`
Verification string `json:"verification"` Verification string `json:"verification"`
DiyMsg string `json:"diyMsg"`
IsModMsg bool `json:"isModMsg"`
} }
// 全局变量 // 全局变量
@ -38,12 +40,7 @@ var (
requestCount = 0 requestCount = 0
//请求成功计数 //请求成功计数
successCount = 0 successCount = 0
)
// 测试的玩意儿
var (
diyMsg = ";//授权已经过期,重新获取-> https://www.sharecopilot.top"
completionUrl = "https://copilot-proxy.githubusercontent.com/v1/engines/copilot-codex/completions" completionUrl = "https://copilot-proxy.githubusercontent.com/v1/engines/copilot-codex/completions"
telemetryUrl = "https://copilot-telemetry.githubusercontent.com/telemetry" telemetryUrl = "https://copilot-telemetry.githubusercontent.com/telemetry"
isModMsg = false //是否修改代码提示返回的信息
) )

View File

@ -28,7 +28,7 @@ func VerifyRequestMiddleware() gin.HandlerFunc {
if configFile.Verification != "" { if configFile.Verification != "" {
authHeader := c.GetHeader("Authorization") authHeader := c.GetHeader("Authorization")
if authHeader != "token "+configFile.Verification { if authHeader != "token "+configFile.Verification {
c.JSON(401, gin.H{"error": "Unauthorized"}) c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
return return
} }
} }

View File

@ -91,7 +91,7 @@ func registerProxyRoute(r *gin.Engine, routePath, targetURL string) {
proxy := &httputil.ReverseProxy{ proxy := &httputil.ReverseProxy{
Director: func(req *http.Request) { Director: func(req *http.Request) {
req.URL.Host = target.Host req.URL.Host = target.Host
req.URL.Scheme = "https" req.URL.Scheme = "http"
req.Host = target.Host req.Host = target.Host
}, },
ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) { ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) {
@ -103,10 +103,12 @@ func registerProxyRoute(r *gin.Engine, routePath, targetURL string) {
req.URL.Scheme = "https" req.URL.Scheme = "https"
req.Host = target.Host req.Host = target.Host
} }
if isModMsg { if configFile.IsModMsg {
modProxyResp(c, proxy) modProxyResp(c, proxy)
} }
proxy.ServeHTTP(c.Writer, c.Request) proxy.ServeHTTP(c.Writer, c.Request)
c.Writer.Header().Set("X-Forwarded-Proto", "http")
}) })
} }
@ -133,7 +135,7 @@ func modProxyResp(c *gin.Context, proxy *httputil.ReverseProxy) {
fmt.Println("No match found.") fmt.Println("No match found.")
} }
// 将字符串转换为[]rune类型的字符数组 // 将字符串转换为[]rune类型的字符数组
runes := []rune(diyMsg) runes := []rune(configFile.DiyMsg)
newStr := "" newStr := ""
// 遍历字符数组,对每个字符进行处理 // 遍历字符数组,对每个字符进行处理
for _, r := range runes { for _, r := range runes {