mirror of
https://gitee.com/chuangxxt/share-copilot
synced 2026-12-02 06:17:53 +00:00
Compare commits
5
Commits
2188e6a776
..
1.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ac0e083e6 | ||
|
|
e331cb9885 | ||
|
|
d274cf819a | ||
|
|
088c15e54b | ||
|
|
23b7c3e825 |
@@ -1,12 +1,15 @@
|
||||
# share-copilot
|
||||
|
||||
- 作为代理服务器,中转copilot插件的API的请求
|
||||
- 支持vscode插件和jetbrains插件
|
||||
- 支持多用户共享一个token
|
||||
- 优化请求逻辑,降低token被ban概率(别万人骑基本不可能封)
|
||||

|
||||
# 一、自行编译:
|
||||
```
|
||||
测试环境:Linux4.18.0-305.3.1.el8.x86_64 GNU/Linux
|
||||
```
|
||||
# 一、自编译:
|
||||
|
||||
需要 go环境 出问题自行chatgpt
|
||||
|
||||
```
|
||||
```sh
|
||||
wget https://dl.google.com/go/go1.21.1.linux-amd64.tar.gz
|
||||
tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz
|
||||
@@ -45,7 +48,7 @@ bash install.sh
|
||||
##### 2.1 config.json文件说明
|
||||
|
||||
```js
|
||||
domain//绑定域名
|
||||
domain//监听域名或ip 可用nginx反代
|
||||
|
||||
host //ip
|
||||
|
||||
@@ -90,15 +93,15 @@ verification//自定义验证
|
||||
### 3.启动
|
||||
|
||||
```
|
||||
scop r --运行
|
||||
scop r --运行 [Esc退出]
|
||||
scop rb --后台运行
|
||||
scop st --停止
|
||||
scop v --查看状态
|
||||
```
|
||||
|
||||
### 4.完整示例一:
|
||||
### 4.完整例子:
|
||||
|
||||
config.json
|
||||
##### 4.1 服务端配置修改config.json
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -120,25 +123,51 @@ config.json
|
||||
}
|
||||
```
|
||||
|
||||
运行截图
|
||||
##### 4.2 运行成功截图:
|
||||
|
||||

|
||||

|
||||
|
||||
时间-合计请求次数: 0 | 成功次数 0 | 失败次数 0 统计次数在00:00:00归零
|
||||
[Jetbrains]:用于Jetbrains插件
|
||||
[Vscode]: 用于Vscode插件
|
||||
[User Request]: 插件请求代理服务器成功次数--统计次数在00:00:00归零
|
||||
[GithubApi request]: 代理服务器请求githubApi次数
|
||||
`正常情况下GithubApi request小于User Request,因为请求的Token 几十分钟才过期`
|
||||
|
||||
修改%userprofile%\AppData\Local\github-copilot\host.json
|
||||
------
|
||||
|
||||
##### 4.3本地配置修改:
|
||||
|
||||
**以windows为例**
|
||||
|
||||
- **jetbrains插件修改:%userprofile%\AppData\Local\github-copilot\host.json**
|
||||
|
||||
```json
|
||||
{
|
||||
"github.com":{
|
||||
"user":"suibian",
|
||||
"oauth_token":"i_am_free",
|
||||
"user":"suibian",//随意填写
|
||||
"oauth_token":"i_am_free",//与上面verification对应
|
||||
"dev_override":{
|
||||
"copilot_token_url":"https://api.example.com/copilot_internal/v2/token"
|
||||
"copilot_token_url":"https://api.example.com/copilot_internal/v2/token"
|
||||
//你的地址
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
测试:
|
||||
- **vscode插件修改:%userprofile%\.vscode\extensions\github.copilot-xxxx\dist\extension.js**
|
||||
|
||||
```js
|
||||
//添加下列代码,注意vscode插件更新需要重新添加,jetbrains则不用
|
||||
process.env.GITHUB_TOKEN="i_am_free"; //与上面verification对应
|
||||
process.env.GITHUB_API_URL="https://api.example.com"; //你的地址
|
||||
process.env.CODESPACES="true";
|
||||
process.env.GITHUB_SERVER_URL="https://github.com";
|
||||
```
|
||||
|
||||
------
|
||||
|
||||
##### **4.4测试成功:**
|
||||
|
||||

|
||||
|
||||
# 三、求投喂!谢谢您!
|
||||

|
||||
Binary file not shown.
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/nsf/termbox-go"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -20,14 +19,6 @@ type Config struct {
|
||||
Verification string `json:"verification"`
|
||||
}
|
||||
|
||||
// InfoItem 表示要显示的内容项
|
||||
type InfoItem struct {
|
||||
Title string
|
||||
Value string
|
||||
TitleColor termbox.Attribute // 标题颜色
|
||||
ValueColor termbox.Attribute // 内容颜色
|
||||
}
|
||||
|
||||
var (
|
||||
//初始化需要返回给客户端的响应体
|
||||
responseData map[string]interface{}
|
||||
|
||||
+27
-54
@@ -4,9 +4,9 @@ import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/fatih/color"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/nsf/termbox-go"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
@@ -63,68 +63,41 @@ func initServer(engine *gin.Engine) {
|
||||
}()
|
||||
}
|
||||
func showMsg() {
|
||||
exitChan := make(chan bool)
|
||||
dataGetter := func() []InfoItem {
|
||||
var url = ""
|
||||
if configFile.Server.Port == 80 {
|
||||
url = "http://" + configFile.Server.Domain
|
||||
} else if configFile.Server.Port == 443 {
|
||||
url = "https://" + configFile.Server.Domain
|
||||
} else {
|
||||
url = "http://" + configFile.Server.Domain + ":" + strconv.Itoa(configFile.Server.Port)
|
||||
}
|
||||
var url = ""
|
||||
if configFile.Server.Port == 80 {
|
||||
url = "http://" + configFile.Server.Domain
|
||||
} else if configFile.Server.Port == 443 {
|
||||
url = "https://" + configFile.Server.Domain
|
||||
} else {
|
||||
url = "http://" + configFile.Server.Domain + ":" + strconv.Itoa(configFile.Server.Port)
|
||||
}
|
||||
var jetStr = color.WhiteString("[Jetbrains]")
|
||||
var vsStr = color.WhiteString("[Vscode]")
|
||||
|
||||
fmt.Println(jetStr + ": " + color.HiBlueString(url+"/copilot_internal/v2/token"))
|
||||
fmt.Println(vsStr + ": " + color.HiBlueString(url))
|
||||
fmt.Println(color.WhiteString("-----------------------------------------------------------------------"))
|
||||
for {
|
||||
requestCountMutex.Lock()
|
||||
sCount := successCount
|
||||
tCount := requestCount
|
||||
gCount := githubApiCount
|
||||
requestCountMutex.Unlock()
|
||||
currentTime := time.Now().Format("2006-01-02 15:04:05")
|
||||
if "00:00:00" == currentTime {
|
||||
resetRequestCount()
|
||||
}
|
||||
return []InfoItem{
|
||||
{
|
||||
Title: "[Jetbrains]",
|
||||
Value: url + "/copilot_internal/v2/token",
|
||||
TitleColor: termbox.ColorGreen,
|
||||
ValueColor: termbox.ColorYellow,
|
||||
},
|
||||
{
|
||||
Title: "[Vscode]",
|
||||
Value: url,
|
||||
TitleColor: termbox.ColorGreen,
|
||||
ValueColor: termbox.ColorYellow,
|
||||
},
|
||||
{
|
||||
Title: "[User Request]:",
|
||||
Value: strconv.Itoa(sCount),
|
||||
TitleColor: termbox.ColorGreen,
|
||||
ValueColor: termbox.ColorYellow,
|
||||
},
|
||||
{
|
||||
Title: "[GithubApi request]:",
|
||||
Value: strconv.Itoa(gCount),
|
||||
TitleColor: termbox.ColorGreen,
|
||||
ValueColor: termbox.ColorYellow,
|
||||
},
|
||||
{
|
||||
Title: "Time:",
|
||||
Value: currentTime,
|
||||
TitleColor: termbox.ColorGreen,
|
||||
ValueColor: termbox.ColorYellow,
|
||||
},
|
||||
}
|
||||
var s2 = color.WhiteString("[Succeed]")
|
||||
var s3 = color.WhiteString("[Failed]")
|
||||
var s4 = color.WhiteString("[GithubApi]")
|
||||
// 打印文本
|
||||
fmt.Printf("\033[G%s - %s: %s %s: %s %s: %s ",
|
||||
color.HiYellowString(currentTime),
|
||||
s2, color.GreenString(strconv.Itoa(sCount)),
|
||||
s3, color.RedString(strconv.Itoa(tCount-sCount)),
|
||||
s4, color.CyanString(strconv.Itoa(gCount)))
|
||||
time.Sleep(1 * time.Second) //
|
||||
}
|
||||
exitChan = make(chan bool)
|
||||
// 调用显示函数,传递数据获取器函数
|
||||
go DisplayInfo(dataGetter, exitChan)
|
||||
for {
|
||||
ev := termbox.PollEvent()
|
||||
if ev.Type == termbox.EventKey && ev.Key == termbox.KeyEsc {
|
||||
exitChan <- true // 发送退出信号
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
func getToken() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user