2 Commits
Author SHA1 Message Date
Geekertao bc23f5039a fix: 修复限流和文件大小限制的逻辑,添加404处理
修改限流和文件大小检查逻辑,当配置值小于等于0时不进行限制
添加对GitHub返回404状态码时的自定义页面处理
2026-01-18 07:42:36 +08:00
Geekertao 2a647ad3e3 ci(github): 将工作流中的GITHUB_TOKEN替换为PAT_TOKEN
使用PAT_TOKEN以获取更高的权限来执行版本管理工作流
2026-01-18 06:01:30 +08:00
2 changed files with 11 additions and 4 deletions

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.PAT_TOKEN }}
fetch-depth: 0
- name: Configure Git
+10 -3
View File
@@ -216,8 +216,8 @@ func handler(c *gin.Context) {
ipRequests[ip] = recentTimes
}
log.Debugf("clientIP: %s Rate: %d\n", clientIP, len(ipRequests[clientIP]))
// 检查当前 IP 的请求次数是否超过限制
if len(ipRequests[clientIP]) > int(limitRate) {
// 检查当前 IP 的请求次数是否超过限制(如果 limitRate <= 0 则不限制)
if limitRate > 0 && len(ipRequests[clientIP]) > int(limitRate) {
ipLock.Unlock()
c.String(http.StatusTooManyRequests, "Too Many Requests.")
return
@@ -292,7 +292,8 @@ func proxy(c *gin.Context, u string) {
limitSize := config.RequestLimit.LimitSize * 1024 * 1024 // Convert MB to Bytes
configLock.RUnlock()
if size > limitSize {
// 如果 limitSize <= 0 则不限制文件大小
if limitSize > 0 && size > limitSize {
c.String(http.StatusRequestEntityTooLarge, "File too large.")
return
}
@@ -302,6 +303,12 @@ func proxy(c *gin.Context, u string) {
resp.Header.Del("Referrer-Policy")
resp.Header.Del("Strict-Transport-Security")
// 如果 GitHub 返回 404,显示我们的 404 页面
if resp.StatusCode == http.StatusNotFound {
render404(c, tmpl404)
return
}
for key, values := range resp.Header {
for _, value := range values {
c.Header(key, value)