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
|
# share-copilot
|
||||||
|
|
||||||
|
- 作为代理服务器,中转copilot插件的API的请求
|
||||||
|
- 支持vscode插件和jetbrains插件
|
||||||
|
- 支持多用户共享一个token
|
||||||
|
- 优化请求逻辑,降低token被ban概率(别万人骑基本不可能封)
|
||||||
|

|
||||||
|
# 一、自行编译:
|
||||||
```
|
```
|
||||||
测试环境:Linux4.18.0-305.3.1.el8.x86_64 GNU/Linux
|
测试环境:Linux4.18.0-305.3.1.el8.x86_64 GNU/Linux
|
||||||
```
|
|
||||||
# 一、自编译:
|
|
||||||
|
|
||||||
需要 go环境 出问题自行chatgpt
|
需要 go环境 出问题自行chatgpt
|
||||||
|
```
|
||||||
```sh
|
```sh
|
||||||
wget https://dl.google.com/go/go1.21.1.linux-amd64.tar.gz
|
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
|
tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz
|
||||||
@@ -45,7 +48,7 @@ bash install.sh
|
|||||||
##### 2.1 config.json文件说明
|
##### 2.1 config.json文件说明
|
||||||
|
|
||||||
```js
|
```js
|
||||||
domain//绑定域名
|
domain//监听域名或ip 可用nginx反代
|
||||||
|
|
||||||
host //ip
|
host //ip
|
||||||
|
|
||||||
@@ -90,15 +93,15 @@ verification//自定义验证
|
|||||||
### 3.启动
|
### 3.启动
|
||||||
|
|
||||||
```
|
```
|
||||||
scop r --运行
|
scop r --运行 [Esc退出]
|
||||||
scop rb --后台运行
|
scop rb --后台运行
|
||||||
scop st --停止
|
scop st --停止
|
||||||
scop v --查看状态
|
scop v --查看状态
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4.完整示例一:
|
### 4.完整例子:
|
||||||
|
|
||||||
config.json
|
##### 4.1 服务端配置修改config.json
|
||||||
|
|
||||||
```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
|
```json
|
||||||
{
|
{
|
||||||
"github.com":{
|
"github.com":{
|
||||||
"user":"suibian",
|
"user":"suibian",//随意填写
|
||||||
"oauth_token":"i_am_free",
|
"oauth_token":"i_am_free",//与上面verification对应
|
||||||
"dev_override":{
|
"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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nsf/termbox-go"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,14 +19,6 @@ type Config struct {
|
|||||||
Verification string `json:"verification"`
|
Verification string `json:"verification"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InfoItem 表示要显示的内容项
|
|
||||||
type InfoItem struct {
|
|
||||||
Title string
|
|
||||||
Value string
|
|
||||||
TitleColor termbox.Attribute // 标题颜色
|
|
||||||
ValueColor termbox.Attribute // 内容颜色
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//初始化需要返回给客户端的响应体
|
//初始化需要返回给客户端的响应体
|
||||||
responseData map[string]interface{}
|
responseData map[string]interface{}
|
||||||
|
|||||||
+27
-54
@@ -4,9 +4,9 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/fatih/color"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"github.com/nsf/termbox-go"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -63,68 +63,41 @@ func initServer(engine *gin.Engine) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
func showMsg() {
|
func showMsg() {
|
||||||
exitChan := make(chan bool)
|
var url = ""
|
||||||
dataGetter := func() []InfoItem {
|
if configFile.Server.Port == 80 {
|
||||||
var url = ""
|
url = "http://" + configFile.Server.Domain
|
||||||
if configFile.Server.Port == 80 {
|
} else if configFile.Server.Port == 443 {
|
||||||
url = "http://" + configFile.Server.Domain
|
url = "https://" + configFile.Server.Domain
|
||||||
} else if configFile.Server.Port == 443 {
|
} else {
|
||||||
url = "https://" + configFile.Server.Domain
|
url = "http://" + configFile.Server.Domain + ":" + strconv.Itoa(configFile.Server.Port)
|
||||||
} 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()
|
requestCountMutex.Lock()
|
||||||
sCount := successCount
|
sCount := successCount
|
||||||
|
tCount := requestCount
|
||||||
gCount := githubApiCount
|
gCount := githubApiCount
|
||||||
requestCountMutex.Unlock()
|
requestCountMutex.Unlock()
|
||||||
currentTime := time.Now().Format("2006-01-02 15:04:05")
|
currentTime := time.Now().Format("2006-01-02 15:04:05")
|
||||||
if "00:00:00" == currentTime {
|
if "00:00:00" == currentTime {
|
||||||
resetRequestCount()
|
resetRequestCount()
|
||||||
}
|
}
|
||||||
return []InfoItem{
|
var s2 = color.WhiteString("[Succeed]")
|
||||||
{
|
var s3 = color.WhiteString("[Failed]")
|
||||||
Title: "[Jetbrains]",
|
var s4 = color.WhiteString("[GithubApi]")
|
||||||
Value: url + "/copilot_internal/v2/token",
|
// 打印文本
|
||||||
TitleColor: termbox.ColorGreen,
|
fmt.Printf("\033[G%s - %s: %s %s: %s %s: %s ",
|
||||||
ValueColor: termbox.ColorYellow,
|
color.HiYellowString(currentTime),
|
||||||
},
|
s2, color.GreenString(strconv.Itoa(sCount)),
|
||||||
{
|
s3, color.RedString(strconv.Itoa(tCount-sCount)),
|
||||||
Title: "[Vscode]",
|
s4, color.CyanString(strconv.Itoa(gCount)))
|
||||||
Value: url,
|
time.Sleep(1 * time.Second) //
|
||||||
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,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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 {
|
func getToken() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user