Skip to content

Commit 34f1c2a

Browse files
committed
feat: allow any url
1 parent 041a77a commit 34f1c2a

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# 使用官方 Go 基础镜像,这里可以指定 Go 版本
21
FROM golang:1.22-alpine AS builder
32

43
# 设置工作目录
@@ -27,4 +26,4 @@ COPY --from=builder /app/main .
2726
EXPOSE 80
2827

2928
# 运行可执行文件
30-
CMD ["./main"]
29+
ENTRYPOINT ["./main"]

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ A simple Go proxy for GitHub API, but MUCH lighter. Ported & modified from [huns
1111
### Docker
1212

1313
```bash
14+
# 直接运行,只允许代理 GitHub 链接
1415
docker run -d -p 80:80 --name gh-proxy-go anotia/gh-proxy-go
16+
# 允许代理任意链接
17+
docker run -d -p 80:80 --name gh-proxy-go anotia/gh-proxy-go --allow-any-url
1518
```
1619

1720
### 命令行运行
@@ -24,4 +27,7 @@ docker run -d -p 80:80 --name gh-proxy-go anotia/gh-proxy-go
2427

2528
# 修改端口 / 地址
2629
./gh-proxy-go --port 8080 --host 127.0.0.1
30+
31+
# 允许代理任意链接
32+
./gh-proxy-go --allow-any-url
2733
```

index.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@
128128
<h1 style="margin-bottom: 50px">GitHub 文件加速</h1>
129129
<form action="./" method="get" style="padding-bottom: 40px" target="_blank" class="flex" onsubmit="toSubmit(event)">
130130
<label class="block" style="width: fit-content">
131-
<input class="block url" name="q" type="text" placeholder="输入 GitHub 文件链接"
132-
pattern="^((https|http):\/\/)?(github\.com\/.+?\/.+?\/(?:releases|archive|blob|raw|suites)|((?:raw|gist)\.(?:githubusercontent|github)\.com))\/.+$"
133-
required>
131+
<input class="block url" name="q" type="text" placeholder="输入 GitHub 文件链接" required>
134132
<div class="bar"></div>
135133
</label>
136134
<input class="block btn" type="submit" value="下载">
@@ -147,7 +145,8 @@ <h1 style="margin-bottom: 50px">GitHub 文件加速</h1>
147145
</div>
148146
</form>
149147
<p style="position: sticky;top: calc(100% - 2.5em);">项目使用 Go 编写,开源于 <a style="color: #3294ea"
150-
href="https://github.com/AnotiaWang/gh-proxy-go">GitHub</a>,改编自 <a style="color: #3294ea" href="https://github.com/hunshcn/gh-proxy">hunshcn/gh-proxy</a>
148+
href="https://github.com/AnotiaWang/gh-proxy-go">GitHub</a>,改编自 <a style="color: #3294ea"
149+
href="https://github.com/hunshcn/gh-proxy">hunshcn/gh-proxy</a>
151150
</p>
152151
</body>
153152

main.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ var (
2020
jsdelivr = 0
2121
// whiteList = []string{}
2222
// blackList = []string{}
23-
passList = []string{}
24-
exp1 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:releases|archive)/.*$`)
25-
exp2 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:blob|raw)/.*$`)
26-
exp3 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:info|git-).*$`)
27-
exp4 = regexp.MustCompile(`^(?:https?://)?raw\.(?:githubusercontent|github)\.com/(?P<author>.+?)/(?P<repo>.+?)/.+?/.+$`)
28-
exp5 = regexp.MustCompile(`^(?:https?://)?gist\.(?:githubusercontent|github)\.com/(?P<author>.+?)/.+?/.+$`)
29-
exp6 = regexp.MustCompile(`(\.com/.*?/.+?)/(.+?/)`)
23+
passList = []string{}
24+
exp1 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:releases|archive)/.*$`)
25+
exp2 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:blob|raw)/.*$`)
26+
exp3 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:info|git-).*$`)
27+
exp4 = regexp.MustCompile(`^(?:https?://)?raw\.(?:githubusercontent|github)\.com/(?P<author>.+?)/(?P<repo>.+?)/.+?/.+$`)
28+
exp5 = regexp.MustCompile(`^(?:https?://)?gist\.(?:githubusercontent|github)\.com/(?P<author>.+?)/.+?/.+$`)
29+
exp6 = regexp.MustCompile(`(\.com/.*?/.+?)/(.+?/)`)
30+
allowAnyUrl bool
3031
)
3132

3233
func main() {
@@ -35,6 +36,7 @@ func main() {
3536

3637
flag.StringVar(&host, "host", "0.0.0.0", "Host address")
3738
flag.StringVar(&port, "port", "80", "Port number")
39+
flag.BoolVar(&allowAnyUrl, "allow-any-url", false, "Do not check if the URL is a GitHub URL")
3840
flag.Parse()
3941

4042
hostRegExp := regexp.MustCompile(`^\d+\.\d+\.\d+\.\d+$`)
@@ -80,6 +82,11 @@ func main() {
8082
handler(c, path)
8183
})
8284

85+
if allowAnyUrl {
86+
log.Println("Mode: Allow any URL")
87+
} else {
88+
log.Println("Mode: GitHub URL only")
89+
}
8390
log.Println("Starting server at " + host + ":" + port)
8491

8592
err := router.Run(host + ":" + port)
@@ -107,7 +114,7 @@ func handler(c *gin.Context, u string) {
107114
break
108115
}
109116
}
110-
} else {
117+
} else if !allowAnyUrl {
111118
c.String(http.StatusForbidden, "Invalid input.")
112119
return
113120
}

0 commit comments

Comments
 (0)