소스 검색

[GinR] Allow raw download without captcha

cgars 7 년 전
부모
커밋
da4b6c7af4
1개의 변경된 파일3개의 추가작업 그리고 8개의 파일을 삭제
  1. 3 8
      routes/repo/download.go

+ 3 - 8
routes/repo/download.go

@@ -34,7 +34,7 @@ func ServeData(c *context.Context, name string, reader io.Reader, cpt *captcha.C
 
 		}
 		if af.Info.Size() > gannex.MEGABYTE*setting.Repository.RawCaptchaMinFileSize && !cpt.VerifyReq(c.Req) &&
-			!c.IsLogged {
+			!c.IsLogged && !(cpt==nil){
 			c.Data["EnableCaptcha"] = true
 			c.HTML(200, "repo/download")
 			return nil
@@ -75,12 +75,6 @@ func ServeBlob(c *context.Context, blob *git.Blob, cpt *captcha.Captcha) error {
 
 func SingleDownload(c *context.Context, cpt *captcha.Captcha) {
 	blob, err := c.Repo.Commit.GetBlobByPath(c.Repo.TreePath)
-	if blob.Size() > gannex.MEGABYTE*setting.Repository.RawCaptchaMinFileSize && setting.Service.EnableCaptcha &&
-		!cpt.VerifyReq(c.Req) && !c.IsLogged {
-		c.Data["EnableCaptcha"] = true
-		c.HTML(200, "repo/download")
-		return
-	}
 	if err != nil {
 		if git.IsErrNotExist(err) {
 			c.Handle(404, "GetBlobByPath", nil)
@@ -89,7 +83,8 @@ func SingleDownload(c *context.Context, cpt *captcha.Captcha) {
 		}
 		return
 	}
-	if err = ServeBlob(c, blob, cpt); err != nil {
+	// reallow direct download independent of size
+	if err = ServeBlob(c, blob, nil); err != nil {
 		c.Handle(500, "ServeBlob", err)
 	}
 }