|
@@ -28,6 +28,7 @@ import (
|
|
"github.com/G-Node/gogs/pkg/tool"
|
|
"github.com/G-Node/gogs/pkg/tool"
|
|
"io"
|
|
"io"
|
|
"os"
|
|
"os"
|
|
|
|
+ "github.com/go-macaron/captcha"
|
|
)
|
|
)
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -129,18 +130,20 @@ func renderDirectory(c *context.Context, treeLink string) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink string) {
|
|
|
|
|
|
+func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink string, cpt *captcha.Captcha) {
|
|
c.Data["IsViewFile"] = true
|
|
c.Data["IsViewFile"] = true
|
|
blob := entry.Blob()
|
|
blob := entry.Blob()
|
|
log.Trace("Blob size is %s", blob.Size())
|
|
log.Trace("Blob size is %s", blob.Size())
|
|
|
|
+ if blob.Size() > gannex.MEGABYTE*10 && setting.Service.EnableCaptcha && !cpt.VerifyReq(c.Req) {
|
|
|
|
+ c.Data["EnableCaptcha"] = true
|
|
|
|
+ c.HTML(200, "repo/download")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
c.Data["FileSize"] = blob.Size()
|
|
c.Data["FileSize"] = blob.Size()
|
|
c.Data["FileName"] = blob.Name()
|
|
c.Data["FileName"] = blob.Name()
|
|
c.Data["HighlightClass"] = highlight.FileNameToHighlightClass(blob.Name())
|
|
c.Data["HighlightClass"] = highlight.FileNameToHighlightClass(blob.Name())
|
|
c.Data["RawFileLink"] = rawLink + "/" + c.Repo.TreePath
|
|
c.Data["RawFileLink"] = rawLink + "/" + c.Repo.TreePath
|
|
- if blob.Size() > 1024*1024*100 {
|
|
|
|
- c.Data["IsFileTooLarge"] = true
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
r, w := io.Pipe()
|
|
r, w := io.Pipe()
|
|
defer r.Close()
|
|
defer r.Close()
|
|
defer w.Close()
|
|
defer w.Close()
|
|
@@ -162,6 +165,12 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
|
|
log.Trace("Could not get annex file: %v", err)
|
|
log.Trace("Could not get annex file: %v", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ if af.Info.Size() > gannex.MEGABYTE*setting.Repository.CaptchaMinFileSize && setting.Service.EnableCaptcha &&
|
|
|
|
+ !cpt.VerifyReq(c.Req) {
|
|
|
|
+ c.Data["EnableCaptcha"] = true
|
|
|
|
+ c.HTML(200, "repo/download")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
afp, err = af.Open()
|
|
afp, err = af.Open()
|
|
defer afp.Close()
|
|
defer afp.Close()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -252,13 +261,13 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
|
|
c.Data["EditFileTooltip"] = c.Tr("repo.editor.fork_before_edit")
|
|
c.Data["EditFileTooltip"] = c.Tr("repo.editor.fork_before_edit")
|
|
}
|
|
}
|
|
|
|
|
|
- case tool.IsPDFFile(buf):
|
|
|
|
|
|
+ case tool.IsPDFFile(buf) && (c.Data["FileSize"].(int64) < setting.Repository.RawCaptchaMinFileSize*gannex.MEGABYTE):
|
|
c.Data["IsPDFFile"] = true
|
|
c.Data["IsPDFFile"] = true
|
|
- case tool.IsVideoFile(buf):
|
|
|
|
|
|
+ case tool.IsVideoFile(buf) && (c.Data["FileSize"].(int64) < setting.Repository.RawCaptchaMinFileSize*gannex.MEGABYTE):
|
|
c.Data["IsVideoFile"] = true
|
|
c.Data["IsVideoFile"] = true
|
|
- case tool.IsImageFile(buf):
|
|
|
|
|
|
+ case tool.IsImageFile(buf) && (c.Data["FileSize"].(int64) < setting.Repository.RawCaptchaMinFileSize*gannex.MEGABYTE):
|
|
c.Data["IsImageFile"] = true
|
|
c.Data["IsImageFile"] = true
|
|
- case tool.IsAnnexedFile(buf):
|
|
|
|
|
|
+ case tool.IsAnnexedFile(buf) && (c.Data["FileSize"].(int64) < setting.Repository.RawCaptchaMinFileSize*gannex.MEGABYTE):
|
|
c.Data["IsAnnexedFile"] = true
|
|
c.Data["IsAnnexedFile"] = true
|
|
}
|
|
}
|
|
|
|
|
|
@@ -285,7 +294,7 @@ func setEditorconfigIfExists(c *context.Context) {
|
|
c.Data["Editorconfig"] = ec
|
|
c.Data["Editorconfig"] = ec
|
|
}
|
|
}
|
|
|
|
|
|
-func Home(c *context.Context) {
|
|
|
|
|
|
+func Home(c *context.Context, cpt *captcha.Captcha) {
|
|
c.Data["PageIsViewFiles"] = true
|
|
c.Data["PageIsViewFiles"] = true
|
|
|
|
|
|
if c.Repo.Repository.IsBare {
|
|
if c.Repo.Repository.IsBare {
|
|
@@ -334,7 +343,7 @@ func Home(c *context.Context) {
|
|
if entry.IsDir() {
|
|
if entry.IsDir() {
|
|
renderDirectory(c, treeLink)
|
|
renderDirectory(c, treeLink)
|
|
} else {
|
|
} else {
|
|
- renderFile(c, entry, treeLink, rawLink)
|
|
|
|
|
|
+ renderFile(c, entry, treeLink, rawLink, cpt)
|
|
}
|
|
}
|
|
if c.Written() {
|
|
if c.Written() {
|
|
return
|
|
return
|